// Partial: _divider.js.j2 — Resizable panel dividers (unified for both modes)

function initDividers() {
    initDivider('divider-left', 'nav-panel', 'left');
    initDivider('divider-right', 'file-viewer-panel', 'right');
}

function initDivider(dividerId, panelId, side) {
    const divider = document.getElementById(dividerId);
    const panel = document.getElementById(panelId);
    const layout = document.getElementById('layout');
    let isDragging = false;

    divider.addEventListener('mousedown', function(e) {
        isDragging = true;
        divider.classList.add('dragging');
        document.body.style.cursor = 'col-resize';
        document.body.style.userSelect = 'none';
        e.preventDefault();
    });

    document.addEventListener('mousemove', function(e) {
        if (!isDragging) return;
        const layoutRect = layout.getBoundingClientRect();
        if (side === 'left') {
            const width = Math.max(150, Math.min(500, e.clientX - layoutRect.left));
            panel.style.width = width + 'px';
        } else {
            const width = Math.max(250, Math.min(layoutRect.width * 0.6, layoutRect.right - e.clientX));
            panel.style.width = width + 'px';
        }
    });

    document.addEventListener('mouseup', function() {
        if (!isDragging) return;
        isDragging = false;
        divider.classList.remove('dragging');
        document.body.style.cursor = '';
        document.body.style.userSelect = '';
        saveState();
    });
}
