'use strict';

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

const index = require('./index-c18b5a7b.js');

const pdsTableRowCss = ":host{--background-fixed:var(--pine-color-base-white);--background-interactive:var(--pine-color-neutral-grey-200);border-color:inherit;display:table-row;vertical-align:inherit}:host::part(checkbox-cell){background-color:var(--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(--background-interactive)}";
const PdsTableRowStyle0 = pdsTableRowCss;

const PdsTableRow = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.pdsTableRowSelected = index.createEvent(this, "pdsTableRowSelected", 7);
        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 (index.h(index.Host, { key: 'b809dac3a76a195446be9cec359887f701213c83', class: this.classNames(), role: "row" }, this.tableRef && this.tableRef.selectable && (index.h("pds-table-cell", { part: this.tableRef.fixedColumn ? 'checkbox-cell' : '', class: this.tableRef.selectable ? 'has-checkbox' : '' }, index.h("pds-checkbox", { componentId: this.generateUniqueId(), onClick: this.handleCheckboxClick, label: "Select Row", labelHidden: true, checked: this.isSelected }))), index.h("slot", { key: '30e8125faa0238ff4c9d2e2ce4dc927173ab35ef' })));
    }
    get hostElement() { return index.getElement(this); }
};
PdsTableRow.style = PdsTableRowStyle0;

exports.pds_table_row = PdsTableRow;

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