'use strict';

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

const index = require('./index-ed42e2ee.js');
const closest = require('./closest-b45138d3.js');

const pdsTableHeadCss = ":host{--border-head-default:var(--pine-border-width-thin) solid var(--pine-color-grey-300);--color-background-fixed:var(--pine-color-base-white);border-color:inherit;-webkit-box-sizing:border-box;box-sizing:border-box;display:table-header-group;vertical-align:middle}:host::part(checkbox-cell){background-color:var(--color-background-fixed);left:0;position:-webkit-sticky;position:sticky;z-index:1}:host pds-table-checkbox-cell{-webkit-border-after:var(--border-head-default);border-block-end:var(--border-head-default)}";
const PdsTableHeadStyle0 = pdsTableHeadCss;

const PdsTableHead = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.pdsTableSelectAll = index.createEvent(this, "pdsTableSelectAll", 7);
        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.handleInput = (ev) => {
            this.isSelected = !ev.target.checked;
            this.handleSelect(this.isSelected);
        };
        this.handleSelect = (isSelected) => {
            this.indeterminate = false;
            if (closest.closest('pds-table-head', this.hostElement)) {
                this.pdsTableSelectAll.emit({ isSelected });
            }
        };
        this.indeterminate = undefined;
        this.isSelected = undefined;
    }
    componentWillLoad() {
        if (this.isSelected) {
            this.handleSelect(this.isSelected);
        }
    }
    componentWillRender() {
        this.tableRef = this.hostElement.closest('pds-table');
        if (this.tableRef && this.tableRef.fixedColumn) {
            const tableCell = this.hostElement.querySelector('pds-table-head-cell:first-child');
            tableCell === null || tableCell === void 0 ? void 0 : tableCell.classList.add("is-fixed");
        }
    }
    render() {
        return (index.h(index.Host, { key: '7729235908073cae63294e4ad641bae0403e2c34', role: "row" }, this.tableRef && this.tableRef.selectable && (index.h("pds-table-head-cell", { key: '2bb801124a3f8d1c9f18d03d1461953da4cdafc6', part: this.tableRef.selectable ? 'checkbox-cell' : '' }, index.h("pds-checkbox", { key: '2119be5b2db13a44add35fa9c9fc761a68a2b060', componentId: this.generateUniqueId(), indeterminate: this.indeterminate, onInput: this.handleInput, label: "Select All Rows", labelHidden: true, checked: this.isSelected }))), index.h("slot", { key: 'baa5b3af10a77e1a8aff537c3c731fbc59a54ca8' })));
    }
    get hostElement() { return index.getElement(this); }
};
PdsTableHead.style = PdsTableHeadStyle0;

exports.pds_table_head = PdsTableHead;

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