import { h } from '@stencil/core';
export class Datatable {
    constructor() {
        this.sortColsMap = new Map();
    }
    componentDidLoad() {
        this.header = this.host.querySelector('materials-datatable-header');
        Array.from(this.header.querySelectorAll('materials-datatable-header-column')).filter(c => c.sortable).forEach(col => {
            this.sortColsMap.set(col.value, col);
        });
        this.footer = this.host.querySelector('materials-datatable-footer');
        this.rows = Array.from(this.host.querySelectorAll('materials-datatable-body-row'));
        this.updateChildrenProperties();
    }
    updateChildrenProperties() {
        if (this.color && this.header) {
            this.header.color = this.color;
        }
        if (this.color && this.footer) {
            this.footer.color = this.color;
        }
        if (this.dense || this.oddEvenStyle) {
            this.rows.forEach((row, index) => {
                if (this.dense) {
                    row.dense = true;
                }
                if (this.oddEvenStyle) {
                    row.classList.add(index % 2 === 0 ? 'odd' : 'even');
                    row.classList.remove(index % 2 === 0 ? 'even' : 'odd');
                }
            });
        }
    }
    listenSort(event) {
        event.stopPropagation();
        this.sortColsMap.forEach(col => {
            col.sorted = col.value === event.detail.columnName;
        });
        this.sort.emit(event.detail);
    }
    render() {
        return (h("div", { class: "container" },
            h("slot", { name: "header" }),
            h("slot", { name: "body" }),
            h("slot", { name: "footer" })));
    }
    static get is() { return "materials-datatable"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() { return {
        "$": ["datatable.scss"]
    }; }
    static get styleUrls() { return {
        "$": ["datatable.css"]
    }; }
    static get properties() { return {
        "color": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "'primary' | 'secondary'",
                "resolved": "\"primary\" | \"secondary\"",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Set the color scheme for the datatable"
            },
            "attribute": "color",
            "reflect": false
        },
        "dense": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Apply low density on the element"
            },
            "attribute": "dense",
            "reflect": false
        },
        "oddEvenStyle": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Apply odd style to the element"
            },
            "attribute": "odd-even-style",
            "reflect": false
        }
    }; }
    static get events() { return [{
            "method": "sort",
            "name": "sort",
            "bubbles": true,
            "cancelable": true,
            "composed": true,
            "docs": {
                "tags": [],
                "text": "Emitted when datatable is sorted"
            },
            "complexType": {
                "original": "Sort",
                "resolved": "Sort",
                "references": {
                    "Sort": {
                        "location": "import",
                        "path": "./sort"
                    }
                }
            }
        }]; }
    static get elementRef() { return "host"; }
    static get watchers() { return [{
            "propName": "color",
            "methodName": "updateChildrenProperties"
        }, {
            "propName": "dense",
            "methodName": "updateChildrenProperties"
        }, {
            "propName": "oddEvenStyle",
            "methodName": "updateChildrenProperties"
        }]; }
    static get listeners() { return [{
            "name": "child:sort",
            "method": "listenSort",
            "target": undefined,
            "capture": false,
            "passive": false
        }]; }
}
