import { p as proxyCustomElement, H, h } from './p-BhqVmlhr.js';
import { d as defineCustomElement$3 } from './p-BxLSOqmG.js';
import { d as defineCustomElement$2 } from './p-DiC-xcof.js';
import { d as defineCustomElement$1 } from './p-Cv0O724A.js';

var __rest = (undefined && undefined.__rest) || function (s, e) {
    var t = {};
    for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
            t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
const DgaDataTable = /*@__PURE__*/ proxyCustomElement(class DgaDataTable extends H {
    constructor() {
        super();
        this.__registerHost();
        this.data = [
            {
                selected: true,
            },
            {
                selected: true,
            },
        ];
        this.rowDivider = true;
        this.showSelectCheckBox = true;
        this.alternate = true;
        this.cells = [
            {
                propertyName: 'test',
                isFilter: false,
                isSort: false,
                title: 'Test',
                type: 'propertyName',
                colSpan: 1,
            },
            {
                propertyName: 'test',
                isFilter: false,
                isSort: false,
                title: 'Test',
                type: 'propertyName',
                colSpan: 1,
            },
        ];
        this.contained = true;
        this.sortedData = [];
        this.direction = false;
        this.sortData = (sortType = 'up', sortingProperty, index) => {
            if (sortType === 'up') {
                const clonedData = [...this.data.sort((a, b) => (b[sortingProperty] > a[sortingProperty] ? 1 : a[sortingProperty] > b[sortingProperty] ? -1 : 0))];
                this.sortedData = clonedData;
            }
            else if (sortType === 'down') {
                const clonedData = [...this.data.sort((a, b) => (a[sortingProperty] > b[sortingProperty] ? 1 : b[sortingProperty] > a[sortingProperty] ? -1 : 0))];
                this.sortedData = clonedData;
            }
            this.cells[index].sort = sortType == 'down' ? 'up' : 'down';
        };
        this.handleSelectedRowChanges = (checked, index) => {
            const cloneData = [...this.data];
            cloneData[index].selected = checked;
            this.sortedData = cloneData;
            if (this.getSelectedRows) {
                this.getSelectedRows({
                    selectedRows: cloneData.filter(item => item.selected),
                    currentSelectedRow: cloneData[index],
                    currentSelectedRowIndex: index,
                });
            }
        };
        this.selectAll = (checked) => {
            const cloneData = [...this.data];
            cloneData.forEach(item => (item.selected = checked));
            this.sortedData = cloneData;
            if (this.getSelectedRows) {
                this.getSelectedRows({
                    selectedRows: cloneData,
                });
            }
        };
    }
    // Add a watcher for the data prop
    //  @Watch('data')
    //  dataWatcher(newValue: any[]) {
    //    this.initializeData(newValue);
    //  }
    // Initialize data method
    initializeData(data) {
        if (data && data.length > 0) {
            const clonedData = [...data];
            this.sortedData = clonedData;
        }
    }
    // componentDidLoad() {
    //   if (document.dir) {
    //     if (document.dir === 'rtl') this.direction = true;
    //     else this.direction = false;
    //   } else if (document.documentElement.lang) {
    //     if (document.documentElement.lang === 'ar') this.direction = true;
    //     else this.direction = false;
    //   } else this.direction = false;
    // }
    componentWillLoad() {
        // Initialize direction
        if (document.dir) {
            this.direction = document.dir === 'rtl';
        }
        else if (document.documentElement.lang) {
            this.direction = document.documentElement.lang === 'ar';
        }
        else {
            this.direction = false;
        }
        // Initialize data
        this.initializeData(this.data);
    }
    // componentDidUpdate() {
    //   const cloneData = [
    //     ...this.data.map(item => {
    //       item.selected = false;
    //       return item;
    //     }),
    //   ];
    //   this.sortedData = cloneData;
    // }
    //     @Prop() onColor: boolean;
    //     @Prop() size: "sm" | "md" | "lg";
    //     @Prop() items: {
    //         label: React.ReactNode;
    //         content: React.ReactNode;
    //     }[] = [
    //         {
    //             label:"test label",
    //             content:"test content"
    //         },
    //         {
    //             label:"test label",
    //             content:"test content"
    //         },
    //         {
    //             label:"test label",
    //             content:"test content"
    //         }
    //     ];
    //     @State() selected: number = 0;
    //     private handleSelect = (index: number) => {
    //         this.selected = index;
    //     };
    render() {
        console.log(this.sortedData, "this.sortedData");
        return (h("div", { key: '1f9543a605c90fb731b87690b789befcb2fe1ff3', class: `table-wrapper ${this.contained ? 'table-contained' : ''}` }, h("table", { key: '6fb15399504af87ab22a29e6dfdc06c3e0cb414d', class: ` azm-table ${this.contained ? 'table-contained' : ''}`, style: { direction: this.direction ? 'rtl' : 'ltr' } }, h("thead", { key: 'fc4bb6483281c5a35b7a84050a1b8e1120bbfb37' }, h("tr", { key: '8d1c9aa85b88e9f5e4f8e89745d843cf0850acc2', class: `${this.rowDivider ? 'row-divider' : ''}` }, this.showSelectCheckBox && (h("th", { key: '4b03683271eae037be53414cc1c59ff6c357f097', style: { width: '20px' } }, h("dga-checkbox", { key: 'ed30d783b71fb9b2b6c6e78eb971cbdf8b81dfe4', showBorderOnFocusAndFocusOute: false, value: 'true', onChange: (event) => this.selectAll(event.target.checked) }))), this.cells.map((_a, index) => {
            var { sort, isSort, propertyName, type } = _a, header = __rest(_a, ["sort", "isSort", "propertyName", "type"]);
            return (h("th", { key: index }, h("span", null, h("span", { class: "text" }, header.title), h("span", { class: "icon-wrapper" }, isSort && sort == 'up' && type == 'propertyName' && (h("button", { class: "dga-btn dga-btn--sort dga-btn--icon dga-btn--md", onClick: () => this.sortData('up', propertyName, index) }, h("dga-icon", { icon: "SortByUp02Icon", variant: 'stroke', type: 'rounded', size: 16 }))), isSort && (!sort || sort == 'down') && type == 'propertyName' && (h("button", { class: "dga-btn dga-btn--sort dga-btn--icon dga-btn--md", onClick: () => this.sortData('down', propertyName, index) }, h("dga-icon", { icon: "SortByDown02Icon", variant: 'stroke', type: 'rounded', size: 16 }))), header.isFilter && (h("button", { class: "dga-btn dga-btn--sort dga-btn--icon dga-btn--md ", onClick: () => this.pressOnFilter && this.pressOnFilter(propertyName) }, h("dga-icon", { icon: "FilterIcon", variant: 'stroke', type: 'rounded', size: 16 })))))));
        }))), h("tbody", { key: '33f8d0cc7ddf274c42700795d93fc36e959f3609' }, this.sortedData.map((row, rowIndex) => (h("tr", { class: `${this.rowDivider ? 'row-divider' : ''} ${this.alternate ? 'alternate' : ''} ${row.selected ? 'row-selected' : ''} `, key: rowIndex }, this.showSelectCheckBox && (h("td", null, h("dga-checkbox", { name: rowIndex + 'checkboxSelection', value: row.selected, id: rowIndex + 'checkboxSelection', showBorderOnFocusAndFocusOute: false, onChange: event => this.handleSelectedRowChanges(event.target.checked, rowIndex), checked: row.selected }))), this.cells.map((_a, cellIndex) => {
            var { El } = _a, cell = __rest(_a, ["El"]);
            return (h("td", { key: cellIndex, colSpan: cell.colSpan ? cell.colSpan : 1 }, cell.type === "element" && El ? (h(El, Object.assign({}, row))) : (row[cell.propertyName])));
        }))))))));
    }
}, [0, "dga-data-table", {
        "columns": [16],
        "data": [1544],
        "rowDivider": [4, "row-divider"],
        "showSelectCheckBox": [4, "show-select-check-box"],
        "alternate": [4],
        "cells": [16],
        "contained": [4],
        "getSelectedRows": [8, "get-selected-rows"],
        "pressOnFilter": [8, "press-on-filter"],
        "sortedData": [32],
        "direction": [32]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["dga-data-table", "dga-checkbox", "dga-icon", "dga-icon-v2"];
    components.forEach(tagName => { switch (tagName) {
        case "dga-data-table":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, DgaDataTable);
            }
            break;
        case "dga-checkbox":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "dga-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "dga-icon-v2":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { DgaDataTable as D, defineCustomElement as d };
