import { p as proxyCustomElement, H, h } from './p-BhqVmlhr.js';
import { d as defineCustomElement$4 } from './p-BxLSOqmG.js';
import { d as defineCustomElement$3 } from './p-DiC-xcof.js';
import { d as defineCustomElement$2 } 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,
                });
            }
        };
    }
    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;
    }
    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() {
        return (h("div", { key: 'e20b62a294ad20edd1e67d5057a41c4c7917f7c7', class: `table-wrapper ${this.contained ? 'table-contained' : ''}` }, h("table", { key: '25a2d102adf56ea8f485a0b6c1059cfa021ca471', class: ` azm-table ${this.contained ? 'table-contained' : ''}`, style: { direction: this.direction ? 'rtl' : 'ltr' } }, h("thead", { key: '807a6a1906eb20310a2674aa7c66507ae36f7d4c' }, h("tr", { key: '80f7ac56f40cfcc06cf583aa3849f3d398d71e04', class: `${this.rowDivider ? 'row-divider' : ''}` }, this.showSelectCheckBox && (h("th", { key: '4443000072bcffc5ccb59e93fb5cf0e4d07310be', style: { width: '20px' } }, h("dga-checkbox", { key: '5984553442dce3ab19a255aef82fd90e46ba26fe', 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: "btn btn--sort btn--icon btn--md", onClick: () => this.sortData('up', propertyName, index) }, h("dga-icon", { icon: "SortByUp02Icon" }))), isSort && (!sort || sort == 'down') && type == 'propertyName' && (h("button", { class: "btn btn--sort btn--icon btn--md", onClick: () => this.sortData('down', propertyName, index) }, h("dga-icon", { icon: "SortByDown02Icon" }))), header.isFilter && (h("button", { class: "btn btn--sort btn--icon btn--md ", onClick: () => this.pressOnFilter && this.pressOnFilter(propertyName) }, h("dga-icon", { icon: "FilterIcon" })))))));
        }))), h("tbody", { key: '2433ddd2de6ab22766c00ea10589ff045dcf40ab' }, 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 }))))))))));
    }
}, [0, "dga-data-table-old", {
        "data": [16],
        "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$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["dga-data-table-old", "dga-checkbox", "dga-icon", "dga-icon-v2"];
    components.forEach(tagName => { switch (tagName) {
        case "dga-data-table-old":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, DgaDataTable);
            }
            break;
        case "dga-checkbox":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "dga-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "dga-icon-v2":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}

const DgaDataTableOld = DgaDataTable;
const defineCustomElement = defineCustomElement$1;

export { DgaDataTableOld, defineCustomElement };
