/** initHeadResize
 * @param el Target element
 * @param ev Pointer event
 * @param downXRef Reference to store downX value
 * @param startWRef Reference to store startW value
 * @returns Object containing target element and column index
 */
export function initHeadResize(el, ev, downXRef, startWRef) {
    ev.preventDefault();
    ev.stopPropagation();
    const cStart = Number(el.dataset.cStart);
    if (!cStart)
        return null;
    const span = Number(el.getAttribute('colspan')) || 1;
    const col = Math.max(0, cStart + span - 1 - 1);
    downXRef.value = ev.clientX;
    startWRef.value = el.getBoundingClientRect().width;
    const target = ev.currentTarget;
    target.setPointerCapture(ev.pointerId);
    el.dispatchEvent(new CustomEvent('nile-column-resize', {
        detail: { col, widthPx: startWRef.value },
        bubbles: true,
        composed: true,
    }));
    el.dispatchEvent(new CustomEvent('nile-resize-start', { bubbles: true, composed: true }));
    return { target, col };
}
/** headResizeMove
 * @param el Target element
 * @param col Column index
 * @param startW Starting width
 * @param downX Down X coordinate
 * @param e Pointer event
 * @param nileGrid NileGrid instance
 * @returns void
 */
export function headResizeMove(el, col, startW, downX, e, nileGrid) {
    const widthPx = Math.max(nileGrid.minColumnWidth, Math.round(startW + (e.clientX - downX)));
    el.dispatchEvent(new CustomEvent('nile-column-resize', {
        detail: { col, widthPx },
        bubbles: true,
        composed: true,
    }));
}
/** headResizeDone
 * @param el Target element
 * @param ev Pointer event
 * @param target Target element
 * @param move Pointer move handler
 * @returns void
 */
export function headResizeDone(el, col, ev, target, move) {
    target.releasePointerCapture(ev.pointerId);
    target.removeEventListener('pointermove', move);
    el.dispatchEvent(new CustomEvent('nile-resize-end', { bubbles: true, composed: true, detail: { col: col } }));
}
/** addListeners
 * @param target Target element
 * @param move Pointer move handler
 * @param done Pointer up handler
 * @returns void
 */
export function addListeners(target, move, done) {
    target.addEventListener('pointermove', move);
    target.addEventListener('pointerup', done);
    target.addEventListener('pointercancel', done);
    window.addEventListener('pointerup', done, { once: true });
}
/** removeListeners
 * @param target Target element
 * @param move Pointer move handler
 * @param done Pointer up handler
 * @returns void
 */
export function removeListeners(target, move, done) {
    target.removeEventListener('pointermove', move);
    target.removeEventListener('pointerup', done);
    target.removeEventListener('pointercancel', done);
    window.removeEventListener('pointerup', done);
}
//# sourceMappingURL=nile-grid-head-item.utils.js.map