import { h } from '../webmapgl.core.js';

class TableColumn {
    constructor() {
        this.sortable = true;
        this.visible = true;
    }
    componentWillLoad() {
        this.updateFormat();
    }
    componentDidLoad() {
        this.change();
    }
    componentDidUpdate() {
        this.change();
    }
    componentDidUnload() {
        this.change();
    }
    updateFormat() {
        if (typeof this.format === 'string') {
            let format;
            try {
                format = JSON.parse(this.format);
            }
            catch (e) {
                if (/SyntaxError/.test(e)) {
                    if (['currency', 'decimal', 'percent'].indexOf(this.format) !== -1) {
                        format = {
                            style: this.format
                        };
                        if (this.format === 'currency')
                            format['currency'] = 'USD';
                    }
                }
                else {
                    throw e;
                }
            }
            this.format = format;
        }
    }
    change() {
        this.glTableColumnChanged.emit(this);
    }
    static get is() { return "gl-table-column"; }
    static get properties() { return {
        "attribute": {
            "type": String,
            "attr": "attribute"
        },
        "component": {
            "type": String,
            "attr": "component"
        },
        "componentProps": {
            "type": "Any",
            "attr": "component-props"
        },
        "format": {
            "type": "Any",
            "attr": "format",
            "mutable": true,
            "watchCallbacks": ["updateFormat"]
        },
        "label": {
            "type": String,
            "attr": "label"
        },
        "sortable": {
            "type": Boolean,
            "attr": "sortable"
        },
        "visible": {
            "type": Boolean,
            "attr": "visible"
        }
    }; }
    static get events() { return [{
            "name": "glTableColumnChanged",
            "method": "glTableColumnChanged",
            "bubbles": true,
            "cancelable": true,
            "composed": true
        }]; }
}

export { TableColumn as GlTableColumn };
