import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-cd2796be.js';
import { c as closest } from './closest-d2d192be.js';

const pdsTableRowCss = ":host{--color-background-fixed:var(--pine-color-white);--color-background-interactive:var(--pine-color-grey-200);border-color:inherit;display:table-row;vertical-align:inherit}:host::part(checkbox-cell){background-color:var(--color-background-fixed);left:0;position:-webkit-sticky;position:sticky;z-index:1}:host(:hover),:host(:hover)::part(checkbox-cell),:host(:hover) ::slotted(pds-table-cell),:host(.is-selected),:host(.is-selected)::part(checkbox-cell),:host(.is-selected) ::slotted(pds-table-cell){background:var(--color-background-interactive)}";
const PdsTableRowStyle0 = pdsTableRowCss;

const PdsTableRow = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.pdsTableRowSelected = createEvent(this, "pdsTableRowSelected", 7);
        this.handleClick = () => {
            this.isSelected = !this.isSelected; // Toggle the selected state
            this.handleSelect(this.isSelected);
        };
        this.handleSelect = (isSelected) => {
            this.indeterminate = false;
            if (!closest('pds-table-head', this.hostElement)) {
                const rowIndex = Array.from(this.hostElement.parentNode.children).indexOf(this.hostElement);
                this.pdsTableRowSelected.emit({
                    rowIndex,
                    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.indeterminate = undefined;
        this.isSelected = undefined;
    }
    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");
        }
    }
    componentWillLoad() {
        if (this.isSelected) {
            this.handleSelect(this.isSelected);
        }
    }
    render() {
        return (h(Host, { key: 'dbfba35e818a96281f5df7e51e60f0bbaf4d5527', class: this.classNames(), role: "row" }, this.tableRef && this.tableRef.selectable && (h("pds-table-cell", { key: 'a0d9118e63db0829f4352875cbacf76c11978fff', part: this.tableRef.fixedColumn ? 'checkbox-cell' : '', class: this.tableRef.selectable ? 'has-checkbox' : '' }, h("pds-checkbox", { key: '60ebde7bb2e745af55e3713b952f963d50396485', componentId: this.generateUniqueId(), onClick: this.handleClick, indeterminate: this.indeterminate, label: "Select Row", labelHidden: true, checked: this.isSelected }))), h("slot", { key: '97f90a8d36781f3b278f83b16c778d5e2b6e9bce' })));
    }
    get hostElement() { return getElement(this); }
};
PdsTableRow.style = PdsTableRowStyle0;

export { PdsTableRow as pds_table_row };

//# sourceMappingURL=pds-table-row.entry.js.map