'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-a0b63bee.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 = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        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 (index.h("div", { key: '486261d777a76a8f743b78ee9b914a33c3517771', class: `table-wrapper ${this.contained ? 'table-contained' : ''}` }, index.h("table", { key: '4947f0d9ae3c57567f791f493800d24887ceb710', class: ` azm-table ${this.contained ? 'table-contained' : ''}`, style: { direction: this.direction ? 'rtl' : 'ltr' } }, index.h("thead", { key: '0f23ad0e92c6fc7447f25ac88e3f8dc8d4d34f7f' }, index.h("tr", { key: '907d886131b971f82ba38d6b7c618036305c4c35', class: `${this.rowDivider ? 'row-divider' : ''}` }, this.showSelectCheckBox && (index.h("th", { key: 'c1bd0bb7f57a1b1fffb495ff7856f642562f4a51', style: { width: '20px' } }, index.h("dga-checkbox", { key: 'a7eafc197701ac7e69c9c6497dfad9e05d6d66c1', showBorderOnFocusAndFocusOute: false, value: 'true', onChange: (event) => this.selectAll(event.target.checked) }))), this.cells.map((_a, index$1) => {
            var { sort, isSort, propertyName, type } = _a, header = __rest(_a, ["sort", "isSort", "propertyName", "type"]);
            return (index.h("th", { key: index$1 }, index.h("span", null, index.h("span", { class: "text" }, header.title), index.h("span", { class: "icon-wrapper" }, isSort && sort == 'up' && type == 'propertyName' && (index.h("button", { class: "btn btn--sort btn--icon btn--md", onClick: () => this.sortData('up', propertyName, index$1) }, index.h("dga-icon", { icon: "SortByUp02Icon" }))), isSort && (!sort || sort == 'down') && type == 'propertyName' && (index.h("button", { class: "btn btn--sort btn--icon btn--md", onClick: () => this.sortData('down', propertyName, index$1) }, index.h("dga-icon", { icon: "SortByDown02Icon" }))), header.isFilter && (index.h("button", { class: "btn btn--sort btn--icon btn--md ", onClick: () => this.pressOnFilter && this.pressOnFilter(propertyName) }, index.h("dga-icon", { icon: "FilterIcon" })))))));
        }))), index.h("tbody", { key: '0157efcc873b02e690231494601df9a2466af704' }, this.sortedData.map((row, rowIndex) => (index.h("tr", { class: `${this.rowDivider ? 'row-divider' : ''} ${this.alternate ? 'alternate' : ''} ${row.selected ? 'row-selected' : ''} `, key: rowIndex }, this.showSelectCheckBox && (index.h("td", null, index.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 }))))))))));
    }
};

exports.dga_data_table = DgaDataTable;

//# sourceMappingURL=dga-data-table.cjs.entry.js.map