'use strict';

var index = require('./index-BUvWX8u2.js');
var closest = require('./closest-BZXvuB_Y.js');

const pdsTableHeadCss = ":host{--border-head-default:var(--pine-border-width-thin) solid var(--pine-color-background-subtle);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(--pine-color-background-container);inset-inline-start:var(--pine-dimension-none);position:-webkit-sticky;position:sticky;z-index:var(--pine-z-index-raised)}:host pds-table-checkbox-cell{-webkit-border-after:var(--border-head-default);border-block-end:var(--border-head-default)}:host([border]){-webkit-border-after:var(--pine-border-width-thin) solid var(--pine-color-border-subtle);border-block-end:var(--pine-border-width-thin) solid var(--pine-color-border-subtle);-webkit-border-before:var(--pine-border-width-thin) solid var(--pine-color-border-subtle);border-block-start:var(--pine-border-width-thin) solid var(--pine-color-border-subtle)}:host([border]) pds-table-head-cell{-webkit-border-after:var(--pine-border-width-thin) solid var(--pine-color-border-subtle);border-block-end:var(--pine-border-width-thin) solid var(--pine-color-border-subtle);-webkit-border-before:var(--pine-border-width-thin) solid var(--pine-color-border-subtle);border-block-start:var(--pine-border-width-thin) solid var(--pine-color-border-subtle)}:host([background]){background-color:var(--pine-color-background-subtle)}:host([background]) pds-table-head-cell{background-color:var(--pine-color-background-subtle)}";

const PdsTableHead = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.pdsTableSelectAll = index.createEvent(this, "pdsTableSelectAll");
        /**
         * Adds top and bottom borders to the table head.
         * @defaultValue false
         */
        this.border = false;
        /**
         * Adds a subtle background color to the table head.
         * @defaultValue false
         */
        this.background = false;
        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 });
            }
        };
    }
    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: 'd5d5906bdb23794b911ecd5904a4cc58aa5380d6', role: "row", part: "head" }, this.tableRef && this.tableRef.selectable && (index.h("pds-table-head-cell", { key: '85df57fb4371e4fba855e16ce62c8329b49e08cf', part: this.tableRef.selectable ? 'checkbox-cell' : '' }, !this.tableRef.disableSelectAll && (index.h("pds-checkbox", { key: '92bd5565463e29d249d1ac71d9dc0d000f3eea79', componentId: this.generateUniqueId(), indeterminate: this.indeterminate, onInput: this.handleInput, label: "Select All Rows", hideLabel: true, checked: this.isSelected, part: "select-all-checkbox" })))), index.h("slot", { key: '494dc0395da229a264c38540479f36967601cc26' })));
    }
    get hostElement() { return index.getElement(this); }
};
PdsTableHead.style = pdsTableHeadCss;

exports.pds_table_head = PdsTableHead;
//# sourceMappingURL=pds-table-head.entry.cjs.js.map
