'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const __chunk_1 = require('./chunk-91f43df3.js');
const __chunk_2 = require('./chunk-a2a6832b.js');

class AttributeValues {
    constructor(hostRef) {
        __chunk_1.registerInstance(this, hostRef);
        this.options = [];
        this.header = __chunk_2._t('webmapgl.attribute-values.header');
        this.limit = 1;
        this.valueMaxWidth = '200px';
    }
    componentWillLoad() {
        this.parseAttributeOptions();
    }
    parseAttributeOptions() {
        this.options = (typeof this.attributeOptions === 'string') ?
            JSON.parse(this.attributeOptions) : this.attributeOptions;
    }
    getItemsForFeature(feature, options) {
        return options
            .filter((attr) => attr.name != this.headerAttribute
            && feature.properties[attr.name] !== undefined)
            .map((attr) => (__chunk_1.h("ion-item", null, __chunk_1.h("ion-label", { position: this.labelPosition }, attr.alias || attr.name), __chunk_1.h("ion-note", { slot: (this.labelPosition != 'stacked') ? 'end' : null, "text-wrap": true, style: { 'max-width': this.valueMaxWidth } }, feature.properties[attr.name]))));
    }
    generateOptions(feature) {
        let opts = [];
        for (let prop in feature.properties) {
            opts.push({
                name: prop
            });
        }
        return opts;
    }
    render() {
        if (!this.features || !this.features.length)
            return null;
        let items = [];
        for (let feature of this.features.slice(0, this.limit)) {
            let header = (this.headerAttribute) ?
                feature.properties[this.headerAttribute] : this.header;
            items.push(__chunk_1.h("ion-item-divider", null, __chunk_1.h("ion-label", null, header)));
            let featureOpts = this.options || this.generateOptions(feature);
            Array.prototype.push.apply(items, this.getItemsForFeature(feature, featureOpts));
        }
        return (__chunk_1.h("ion-list", null, items));
    }
    get el() { return __chunk_1.getElement(this); }
    static get watchers() { return {
        "attributeOptions": ["parseAttributeOptions"]
    }; }
    static get style() { return "gl-attribute-values ion-note{font-size:14px;line-height:14px;padding-top:16px;text-align:right}"; }
}

exports.gl_attribute_values = AttributeValues;
