// @ts-nocheck
import { h } from "@stencil/core";
export class DgaStructuredList {
    constructor() {
        this.data = [];
        this.rowDivider = true;
        this.colDivider = true;
        this.compact = false;
        this.selectable = true;
        this.alternate = true;
        this.cells = [];
        this.contained = true;
        this.sortedData = [];
        this.direction = false;
    }
    componentWillLoad() {
        this.initializeDirection();
        this.initializeSortedData();
    }
    handleDataChange() {
        this.initializeSortedData();
    }
    initializeDirection() {
        if (document.dir) {
            this.direction = document.dir === 'rtl';
        }
        else if (document.documentElement.lang) {
            this.direction = document.documentElement.lang === 'ar';
        }
        else {
            this.direction = false;
        }
    }
    initializeSortedData() {
        this.sortedData = this.data.map(item => {
            item.selected = false;
            return item;
        });
    }
    handleSelectedRowChanges(checked, rowIndex, propertyName, cellIndex) {
        const cloneData = [...this.sortedData];
        // cloneData[rowIndex].selected = {
        //   checked,
        //   rowIndex,
        //   propertyName,
        //   cellIndex,
        // };
        cloneData[rowIndex].selected = checked;
        this.sortedData = cloneData;
        if (this.getSelectedRows) {
            this.getSelectedRows({
                currentSelectedRowData: cloneData[rowIndex],
                currentSelectedCellName: propertyName,
                currentSelectedRowIndex: rowIndex,
                currentSelectedCellIndex: cellIndex,
            });
        }
    }
    render() {
        return (h("div", { key: '6ebdde1ae2be622ea59002794b45ab01f53fbdf1', class: `table-wrapper ${this.contained ? 'table-contained' : ''}` }, h("table", { key: '02b8e6b29794ea56bd62f6cebdc13ec0ff2d38d8', class: `azm-structured-table ${this.contained ? 'table-contained' : ''}`, style: { direction: this.direction ? 'rtl' : 'ltr' } }, h("thead", { key: 'cc1c18beeca9889c78e173105efcfed43e3682b4' }, h("tr", { key: '0d1803e64739796bf696c3e3bd57ab72f60fe2a8', class: `${this.rowDivider ? 'row-divider' : ''}` }, this.cells.map(({ title }, index) => (h("th", { key: index }, title))))), h("tbody", { key: '9b72f6f83de39c54c6c7aacfa4f28e9a22b10c4f' }, this.sortedData.map((row, rowIndex) => (h("tr", { class: `${this.rowDivider ? 'row-divider' : ''} ${this.alternate ? 'alternate' : ''}`, key: rowIndex }, this.cells.map(({ El, customAttribute, propertyName, type, colSpan }, cellIndex) => (h("td", Object.assign({ key: cellIndex, colSpan: colSpan || 1 }, ((customAttribute === null || customAttribute === void 0 ? void 0 : customAttribute.key) && {
            [customAttribute.key]: customAttribute.value || '',
        }), { class: `${this.compact ? "compact" : ""} ${this.colDivider ? 'col-divider' : ''}` }), h("div", null, this.selectable && (h("span", null, h("input", { type: "checkbox", name: `${rowIndex}checkboxSelection`, checked: row.selected, id: `${rowIndex}checkboxSelection${propertyName}`, onChange: event => this.handleSelectedRowChanges(event.target.checked, rowIndex, propertyName, cellIndex) }))), type === 'element' && El ? h(El, Object.assign({}, row)) : row[propertyName])))))))))));
    }
    static get is() { return "dga-structured-list"; }
    static get originalStyleUrls() {
        return {
            "$": ["dga-structured-list.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["dga-structured-list.css"]
        };
    }
    static get properties() {
        return {
            "data": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "any[]",
                    "resolved": "any[]",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "[]"
            },
            "rowDivider": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "row-divider",
                "reflect": false,
                "defaultValue": "true"
            },
            "colDivider": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "col-divider",
                "reflect": false,
                "defaultValue": "true"
            },
            "compact": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "compact",
                "reflect": false,
                "defaultValue": "false"
            },
            "selectable": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "selectable",
                "reflect": false,
                "defaultValue": "true"
            },
            "alternate": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "alternate",
                "reflect": false,
                "defaultValue": "true"
            },
            "cells": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "Array<{\n    title: string;\n    propertyName: string;\n    type: 'element' | 'propertyName';\n    El?: any;\n    elProperties?: string[];\n    colSpan?: number;\n    customAttribute?: {\n      key: string;\n      value: string;\n    };\n    sort?: 'up' | 'down' | 'none';\n    isSort?: boolean;\n    isFilter?: boolean;\n  }>",
                    "resolved": "{ title: string; propertyName: string; type: \"element\" | \"propertyName\"; El?: any; elProperties?: string[]; colSpan?: number; customAttribute?: { key: string; value: string; }; sort?: \"none\" | \"up\" | \"down\"; isSort?: boolean; isFilter?: boolean; }[]",
                    "references": {
                        "Array": {
                            "location": "global",
                            "id": "global::Array"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "[]"
            },
            "contained": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "contained",
                "reflect": false,
                "defaultValue": "true"
            },
            "getSelectedRows": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "(event?: any) => void",
                    "resolved": "(event?: any) => void",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            }
        };
    }
    static get states() {
        return {
            "sortedData": {},
            "direction": {}
        };
    }
    static get watchers() {
        return [{
                "propName": "data",
                "methodName": "handleDataChange"
            }];
    }
}
//# sourceMappingURL=dga-structured-list.js.map
