import { Host, h } from "@stencil/core";
export class XDatatableColumn {
    constructor() {
        this.content = undefined;
        this.field = undefined;
        this.label = undefined;
        this.resizable = false;
        this.sortable = false;
        this.sortdir = 'asc';
        this.type = 'default';
        this.width = undefined;
        this.align = "left";
        this.mapping = [];
    }
    /**
     * Element event on slot make changes
     */
    handleSlotChange() {
        this.computeChildMappingItems();
    }
    /**
     * Update the child mapping and render the result
     */
    computeChildMappingItems() {
        const mappings = Array.from(this.el.children)
            .filter(tab => tab.nodeName.toLowerCase() === 'x-datatable-map')
            .map(item => item)
            .filter(map => map.to)
            .reduce((_, map) => {
            if (!_.hasOwnProperty(map.to)) {
                _[map.to] = map.replace ? {} : null;
            }
            if (map.replace) {
                _[map.to][map.value] = map.replace;
            }
            if (map.from) {
                _[map.to] = map.from;
            }
            return _;
        }, {});
        this.mapping = Object.keys(mappings).map(map => {
            return {
                to: map,
                value: Object.keys(mappings[map]).length ? mappings[map] : null,
                from: typeof mappings[map] === 'string' ? mappings[map] : null,
            };
        });
    }
    /**
     * On element will mounted
     */
    componentWillLoad() {
        this.computeChildMappingItems();
        this.content = this.el.innerHTML;
    }
    /**
     * Render element
     */
    render() {
        return h(Host, { key: '5ff728d38f72875d6890ba501d04d4885c1738b9' });
    }
    static get is() { return "x-datatable-col"; }
    static get originalStyleUrls() {
        return {
            "$": ["style.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["style.css"]
        };
    }
    static get properties() {
        return {
            "content": {
                "type": "string",
                "mutable": true,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "InnerHTML after rendering"
                },
                "attribute": "content",
                "reflect": false
            },
            "field": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "JSON Path data field for column"
                },
                "attribute": "field",
                "reflect": false
            },
            "label": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Column label"
                },
                "attribute": "label",
                "reflect": false
            },
            "resizable": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Column is resizable by field"
                },
                "attribute": "resizable",
                "reflect": false,
                "defaultValue": "false"
            },
            "sortable": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Column is sortable and enable interactions"
                },
                "attribute": "sortable",
                "reflect": false,
                "defaultValue": "false"
            },
            "sortdir": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "DatatableColumnSortDirection",
                    "resolved": "\"asc\" | \"desc\"",
                    "references": {
                        "DatatableColumnSortDirection": {
                            "location": "local",
                            "path": "/opt/atlassian/pipelines/agent/build/src/components/x-datatable/component-column.tsx",
                            "id": "src/components/x-datatable/component-column.tsx::DatatableColumnSortDirection"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Column active sort direction"
                },
                "attribute": "sortdir",
                "reflect": false,
                "defaultValue": "'asc'"
            },
            "type": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "DataTableColumnType",
                    "resolved": "\"amount\" | \"badge\" | \"bold\" | \"date\" | \"default\" | \"icon\" | \"image\" | \"number\" | \"template\" | \"time\"",
                    "references": {
                        "DataTableColumnType": {
                            "location": "local",
                            "path": "/opt/atlassian/pipelines/agent/build/src/components/x-datatable/component-column.tsx",
                            "id": "src/components/x-datatable/component-column.tsx::DataTableColumnType"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Column type"
                },
                "attribute": "type",
                "reflect": false,
                "defaultValue": "'default'"
            },
            "width": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Column width"
                },
                "attribute": "width",
                "reflect": false
            },
            "align": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "DataTableColumnAlign",
                    "resolved": "\"center\" | \"left\" | \"right\"",
                    "references": {
                        "DataTableColumnAlign": {
                            "location": "local",
                            "path": "/opt/atlassian/pipelines/agent/build/src/components/x-datatable/component-column.tsx",
                            "id": "src/components/x-datatable/component-column.tsx::DataTableColumnAlign"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Column alignment"
                },
                "attribute": "align",
                "reflect": false,
                "defaultValue": "\"left\""
            },
            "mapping": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "Array<DatatableMappingData>",
                    "resolved": "DatatableMappingData[]",
                    "references": {
                        "Array": {
                            "location": "global",
                            "id": "global::Array"
                        },
                        "DatatableMappingData": {
                            "location": "local",
                            "path": "/opt/atlassian/pipelines/agent/build/src/components/x-datatable/component-column.tsx",
                            "id": "src/components/x-datatable/component-column.tsx::DatatableMappingData"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Column mapping content"
                },
                "defaultValue": "[]"
            }
        };
    }
    static get elementRef() { return "el"; }
    static get listeners() {
        return [{
                "name": "slotchange",
                "method": "handleSlotChange",
                "target": undefined,
                "capture": false,
                "passive": false
            }];
    }
}
