// @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;
        // Generate a unique ID if not provided
        this.componentId = `quote-${Math.random().toString(36).substring(2, 9)}`;
        // Computed inline styles
        this.rootStyles = {};
    }
    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,
            });
        }
    }
    handleSxChange() {
        this.processStyling();
    }
    componentWillLoad() {
        // Initialize style manager
        this.sxStyleManager = new SxStyleManager(this.componentId);
        this.processStyling();
    }
    processStyling() {
        if (this.sx) {
            this.rootStyles = this.sxStyleManager.processSxProp(this.sx);
        }
    }
    disconnectedCallback() {
        var _a;
        // Clean up styles
        (_a = this.sxStyleManager) === null || _a === void 0 ? void 0 : _a.cleanup();
    }
    render() {
        return (h("div", { key: '2e05da8b8bef5a55ad03e0792aa605069d493001', class: `table-wrapper ${this.contained ? 'table-contained' : ''}` }, h("table", { key: '775c5f39e01ce7f307f5b357351c3a0ca35bb413', class: `azm-structured-table ${this.contained ? 'table-contained' : ''}`, style: { direction: this.direction ? 'rtl' : 'ltr' } }, h("thead", { key: 'dcc273c49193d47b1d12570ce95b7df4a2c72be2' }, h("tr", { key: 'fc42e1ffc24ae770cf7ca751c4df89d590b22d05', class: `${this.rowDivider ? 'row-divider' : ''}` }, this.cells.map(({ title }, index) => (h("th", { key: index }, title))))), h("tbody", { key: 'c53eac4a04b6d6cd0ac54abb46f7e2d89f4f8b3a' }, 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",
                "attribute": "data",
                "mutable": false,
                "complexType": {
                    "original": "any[]",
                    "resolved": "any[]",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "[]"
            },
            "rowDivider": {
                "type": "boolean",
                "attribute": "row-divider",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            },
            "colDivider": {
                "type": "boolean",
                "attribute": "col-divider",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            },
            "compact": {
                "type": "boolean",
                "attribute": "compact",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "selectable": {
                "type": "boolean",
                "attribute": "selectable",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            },
            "alternate": {
                "type": "boolean",
                "attribute": "alternate",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            },
            "cells": {
                "type": "unknown",
                "attribute": "cells",
                "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",
                "attribute": "contained",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            },
            "getSelectedRows": {
                "type": "unknown",
                "attribute": "get-selected-rows",
                "mutable": false,
                "complexType": {
                    "original": "(event?: any) => void",
                    "resolved": "(event?: any) => void",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "sx": {
                "type": "any",
                "attribute": "sx",
                "mutable": false,
                "complexType": {
                    "original": "SxProps",
                    "resolved": "SxProps",
                    "references": {
                        "SxProps": {
                            "location": "global",
                            "id": "global::SxProps"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            }
        };
    }
    static get states() {
        return {
            "sortedData": {},
            "direction": {}
        };
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "data",
                "methodName": "handleDataChange"
            }, {
                "propName": "sx",
                "methodName": "handleSxChange"
            }];
    }
}
