/**
 * 弹出层管理工具
 * 统一管理弹出层的 z-index、滚动锁定、Escape 关闭
 */
let zIndexCounter = 1000;
const scrollLockCount = { value: 0 };
/** 获取下一个 z-index */
export function getNextZIndex() {
    return ++zIndexCounter;
}
/** 锁定 body 滚动 */
export function lockScroll() {
    scrollLockCount.value++;
    if (scrollLockCount.value === 1) {
        document.body.style.overflow = 'hidden';
    }
}
/** 解锁 body 滚动 */
export function unlockScroll() {
    scrollLockCount.value = Math.max(0, scrollLockCount.value - 1);
    if (scrollLockCount.value === 0) {
        document.body.style.overflow = '';
    }
}
export function computePosition(triggerRect, popupWidth, popupHeight, placement = 'bottom', gap = 8) {
    const { top, left, width, height } = triggerRect;
    const vw = window.innerWidth;
    const vh = window.innerHeight;
    let pos;
    switch (placement) {
        case 'top':
            pos = { top: top - popupHeight - gap, left: left + width / 2 - popupWidth / 2 };
            break;
        case 'top-start':
            pos = { top: top - popupHeight - gap, left };
            break;
        case 'top-end':
            pos = { top: top - popupHeight - gap, left: left + width - popupWidth };
            break;
        case 'bottom':
            pos = { top: top + height + gap, left: left + width / 2 - popupWidth / 2 };
            break;
        case 'bottom-start':
            pos = { top: top + height + gap, left };
            break;
        case 'bottom-end':
            pos = { top: top + height + gap, left: left + width - popupWidth };
            break;
        case 'left':
            pos = { top: top + height / 2 - popupHeight / 2, left: left - popupWidth - gap };
            break;
        case 'left-start':
            pos = { top, left: left - popupWidth - gap };
            break;
        case 'left-end':
            pos = { top: top + height - popupHeight, left: left - popupWidth - gap };
            break;
        case 'right':
            pos = { top: top + height / 2 - popupHeight / 2, left: left + width + gap };
            break;
        case 'right-start':
            pos = { top, left: left + width + gap };
            break;
        case 'right-end':
            pos = { top: top + height - popupHeight, left: left + width + gap };
            break;
        default:
            pos = { top: top + height + gap, left };
    }
    // 视口边界修正
    pos.top = Math.max(4, Math.min(pos.top, vh - popupHeight - 4));
    pos.left = Math.max(4, Math.min(pos.left, vw - popupWidth - 4));
    return pos;
}
//# sourceMappingURL=popup-manager.js.map
