/**
 * Theme Index9: "Amber Split" — Panel toggle + Password toggle
 */
(function () {
    'use strict';

    var closeBtn = document.getElementById('idx9ClosePanel');

    /* Panel section toggling (Terms, About shown on right panel) */
    document.querySelectorAll('[data-panel-target]').forEach(function (link) {
        link.addEventListener('click', function (e) {
            e.preventDefault();
            var target = this.getAttribute('data-panel-target');
            showPanel(target);
        });
    });

    function showPanel(name) {
        document.querySelectorAll('.idx9-panel-section').forEach(function (sec) {
            sec.classList.remove('active');
        });
        var panel = document.querySelector('[data-panel="' + name + '"]');
        if (panel) {
            panel.classList.add('active');
        }
        if (closeBtn && name !== 'home') {
            closeBtn.classList.add('visible');
        }
    }

    /* Close panel -> back to home */
    if (closeBtn) {
        closeBtn.addEventListener('click', function () {
            showPanel('home');
            this.classList.remove('visible');
        });
    }

    /* Password toggle */
    document.querySelectorAll('.toggle-password').forEach(function (btn) {
        btn.addEventListener('click', function () {
            var target = document.querySelector(this.getAttribute('data-target'));
            if (!target) return;
            var isPassword = target.type === 'password';
            target.type = isPassword ? 'text' : 'password';
            var icon = this.querySelector('i');
            if (icon) {
                icon.classList.toggle('bi-eye', !isPassword);
                icon.classList.toggle('bi-eye-slash', isPassword);
            }
        });
    });

    /* Focus ring for input groups */
    document.querySelectorAll('.idx9-input').forEach(function (input) {
        input.addEventListener('focus', function () {
            var group = this.closest('.idx9-input-group');
            if (group) group.classList.add('focused');
        });
        input.addEventListener('blur', function () {
            var group = this.closest('.idx9-input-group');
            if (group) group.classList.remove('focused');
        });
    });
})();
