/**
 * Copyright Aquera Inc 2025
 *
 * This source code is licensed under the BSD-3-Clause license found in the
 * LICENSE file in the root directory of this source tree.
 */
import { __decorate } from "tslib";
import { html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { styles } from './nile-grid-head-item.css';
import NileElement from '../../internal/nile-element';
import { initHeadResize, headResizeMove, headResizeDone, addListeners, removeListeners, } from './nile-grid-head-item.utils';
/**
 * Nile grid-head-item component.
 *
 * @tag nile-grid-head-item
 *
 */
let NileGridHeadItem = class NileGridHeadItem extends NileElement {
    constructor() {
        super(...arguments);
        this.colspan = 1;
        this.rowspan = 1;
        this.resizable = false;
        this.width = null;
        this.sticky = null;
        this.lockWidth = false;
        this.onHandlePointerDown = (ev) => {
            const el = this;
            const nileGrid = this.closest('nile-grid');
            const downXRef = { value: 0 };
            const startWRef = { value: 0 };
            const result = initHeadResize(el, ev, downXRef, startWRef);
            if (!result)
                return;
            const { target, col } = result;
            const move = (e) => headResizeMove(el, col, startWRef.value, downXRef.value, e, nileGrid);
            const done = (e) => {
                headResizeDone(el, col, e, target, move);
                removeListeners(target, move, done);
            };
            addListeners(target, move, done);
        };
        /* #endregion */
    }
    /**
     * The styles for nile-grid-head-item
     * @remarks If you are extending this class you can extend the base styles with super. Eg `return [super(), myCustomStyles]`
     */
    static get styles() {
        return [styles];
    }
    connectedCallback() {
        super.connectedCallback();
        this.setAttribute('role', 'row');
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.removeAttribute('role');
    }
    render() {
        return html `
      <div part="grid-head-item-base" class="head-item-base">
        <slot></slot>
        ${this.resizable
            ? html `
              <div
                aria-hidden="false"
                class="resize-handle"
                part="resize-handle"
                @pointerdown=${this.onHandlePointerDown}
              ></div>
            `
            : null}
      </div>
    `;
    }
};
__decorate([
    property({ type: Number, reflect: true, attribute: true })
], NileGridHeadItem.prototype, "colspan", void 0);
__decorate([
    property({ type: Number, reflect: true, attribute: true })
], NileGridHeadItem.prototype, "rowspan", void 0);
__decorate([
    property({ type: Boolean, reflect: true, attribute: true })
], NileGridHeadItem.prototype, "resizable", void 0);
__decorate([
    property({ type: String, reflect: true, attribute: true })
], NileGridHeadItem.prototype, "width", void 0);
__decorate([
    property({ type: String, reflect: true, attribute: true })
], NileGridHeadItem.prototype, "sticky", void 0);
__decorate([
    property({ type: Boolean, reflect: true, attribute: true })
], NileGridHeadItem.prototype, "lockWidth", void 0);
NileGridHeadItem = __decorate([
    customElement('nile-grid-head-item')
], NileGridHeadItem);
export { NileGridHeadItem };
export default NileGridHeadItem;
//# sourceMappingURL=nile-grid-head-item.js.map