import { r as registerInstance, h, d as getElement } from './chunk-eb0263ab.js';
import { _ as _t } from './chunk-a41b3114.js';

class AttributeValues {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.options = [];
        this.header = _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) => (h("ion-item", null, h("ion-label", { position: this.labelPosition }, attr.alias || attr.name), 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(h("ion-item-divider", null, h("ion-label", null, header)));
            let featureOpts = this.options || this.generateOptions(feature);
            Array.prototype.push.apply(items, this.getItemsForFeature(feature, featureOpts));
        }
        return (h("ion-list", null, items));
    }
    get el() { return 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}"; }
}

export { AttributeValues as gl_attribute_values };
