import { Host, h } from "@stencil/core";
export class PdsTableRow {
    constructor() {
        this.handleCheckboxClick = () => {
            this.isSelected = !this.isSelected; // Toggle the selected state
            const selectedIndex = Array.from(this.hostElement.parentNode.children).indexOf(this.hostElement);
            this.pdsTableRowSelected.emit({ rowIndex: selectedIndex, isSelected: this.isSelected });
        };
        this.generateUniqueId = () => {
            const randomString = Math.random().toString(36).substring(2, 8);
            const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
            const uniqueId = `${randomString}-${timestamp}`;
            return uniqueId;
        };
        this.isSelected = false;
    }
    classNames() {
        const classNames = [];
        if (this.isSelected) {
            classNames.push("is-selected");
        }
        return classNames.join('  ');
    }
    componentWillRender() {
        this.tableRef = this.hostElement.closest('pds-table');
        if (this.tableRef && this.tableRef.fixedColumn) {
            const tableCell = this.hostElement.querySelector('pds-table-cell');
            tableCell === null || tableCell === void 0 ? void 0 : tableCell.classList.add("is-fixed");
        }
    }
    render() {
        return (h(Host, { key: 'b809dac3a76a195446be9cec359887f701213c83', class: this.classNames(), role: "row" }, this.tableRef && this.tableRef.selectable && (h("pds-table-cell", { part: this.tableRef.fixedColumn ? 'checkbox-cell' : '', class: this.tableRef.selectable ? 'has-checkbox' : '' }, h("pds-checkbox", { componentId: this.generateUniqueId(), onClick: this.handleCheckboxClick, label: "Select Row", labelHidden: true, checked: this.isSelected }))), h("slot", { key: '30e8125faa0238ff4c9d2e2ce4dc927173ab35ef' })));
    }
    static get is() { return "pds-table-row"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["pds-table-row.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["pds-table-row.css"]
        };
    }
    static get states() {
        return {
            "isSelected": {}
        };
    }
    static get events() {
        return [{
                "method": "pdsTableRowSelected",
                "name": "pdsTableRowSelected",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Event that is emitted when the checkbox is clicked, carrying the selected value."
                },
                "complexType": {
                    "original": "{ rowIndex: number; isSelected: boolean; }",
                    "resolved": "{ rowIndex: number; isSelected: boolean; }",
                    "references": {}
                }
            }];
    }
    static get elementRef() { return "hostElement"; }
}
//# sourceMappingURL=pds-table-row.js.map
