'use strict';

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

const index = require('./index-46fb0736.js');
const index$1 = require('./index-479f5bd8.js');

const pdsTableHeadCellCss = ":host{--border-head-cell-default:var(--pine-border-width-thin) solid var(--pine-color-grey-300);--box-shadow-default:3px 3px 6px -2px rgba(0, 0, 0, 0.1);--color-background-fixed:var(--pine-color-white);--color-sorting:var(--pine-color-grey-950);--color-text-default:var(--pine-color-grey-700);--dimension-fixed-cell-position:0;--font-size-head-cell:var(--pine-font-size-085);--font-weight-cell-default:var(--pine-font-weight-normal);--line-height-cell-default:var(--pine-line-height-125);--padding-cell-default:calc(var(--pine-spacing-300) / 2);--spacing-margin-inline-start-arrow:var(--pine-spacing-050);--spacing-padding-arrow:calc(var(--pine-spacing-050) / 2);--spacing-padding-block-compact:var(--pine-spacing-050);-webkit-border-after:var(--border-head-cell-default);border-block-end:var(--border-head-cell-default);color:var(--color-text-default);display:table-cell;font-size:var(--font-size-head-cell);font-style:normal;font-weight:var(--font-weight-cell-default);line-height:var(--line-height-cell-default);padding:var(--padding-cell-default);text-align:start;vertical-align:inherit}:host(.is-compact){padding-block:var(--spacing-padding-block-compact)}:host(.is-fixed){background:var(--color-background-fixed);left:var(--dimension-fixed-cell-position);position:-webkit-sticky;position:sticky;z-index:1}:host(.has-scrolled.is-fixed){-webkit-box-shadow:var(--box-shadow-default);box-shadow:var(--box-shadow-default)}:host(.is-sortable){cursor:pointer}:host(.is-sortable) pds-icon{-webkit-margin-start:var(--spacing-margin-inline-start-arrow);margin-inline-start:var(--spacing-margin-inline-start-arrow);-webkit-padding-before:var(--spacing-padding-arrow);padding-block-start:var(--spacing-padding-arrow);position:absolute}:host(.is-sortable:hover),:host(.is-active){color:var(--color-sorting)}";
const PdsTableHeadCellStyle0 = pdsTableHeadCellCss;

const PdsTableHeadCell = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.pdsTableSort = index.createEvent(this, "pdsTableSort", 7);
        this.handleScroll = () => {
            if (this.tableRef.scrollLeft > 0) {
                this.tableScrolling = true;
            }
            else {
                this.tableScrolling = false;
            }
        };
        this.toggleSort = () => {
            if (this.sortable) {
                const column = this.hostElement.innerText.trim();
                this.sortingDirection = this.sortingDirection === 'asc' ? 'desc' : 'asc';
                this.tableRef.querySelectorAll('pds-table-head-cell').forEach((headCell) => {
                    headCell.classList.remove('is-active');
                });
                this.hostElement.classList.toggle('is-active');
                this.pdsTableSort.emit({ column, direction: this.sortingDirection });
            }
        };
        this.sortable = undefined;
        this.sortingDirection = 'asc';
        this.tableScrolling = false;
        this.isSelected = false;
    }
    componentWillRender() {
        this.tableRef = this.hostElement.closest('pds-table');
    }
    componentDidLoad() {
        if (this.tableRef && this.tableRef.responsive && this.tableRef.fixedColumn) {
            this.tableRef.addEventListener('scroll', this.handleScroll);
        }
    }
    classNames() {
        const classNames = [];
        if (this.tableRef && this.tableRef.compact) {
            classNames.push('is-compact');
        }
        if (this.sortable) {
            classNames.push('is-sortable');
        }
        if (this.sortable && this.sortingDirection !== null) {
            classNames.push('sort-' + this.sortingDirection);
        }
        if (this.tableRef && this.tableRef.fixedColumn && this.tableScrolling) {
            classNames.push('has-scrolled');
        }
        return classNames.join('  ');
    }
    render() {
        return (index.h(index.Host, { key: '72e242a22774d4b534b7a8653673606e0e9c6ef1', class: this.classNames(), role: "columnheader", onClick: this.toggleSort, style: this.tableRef &&
                this.tableRef.fixedColumn &&
                this.tableRef.selectable
                ? { '--fixed-cell-position': '40px' }
                : {} }, index.h("slot", { key: '08e1d5aab1761ed097e2669716884196c946bcc3' }), this.sortable && (index.h("pds-icon", { key: '43421a2b1401426878601468acee702ce45404bf', icon: this.sortingDirection === 'asc' ? index$1.upSmall : index$1.downSmall }))));
    }
    get hostElement() { return index.getElement(this); }
};
PdsTableHeadCell.style = PdsTableHeadCellStyle0;

exports.pds_table_head_cell = PdsTableHeadCell;

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