/**
 * ui.js - 화면 제어 모듈
 */

export let UI = {
    // 팝업 열기
    openPopup(targetSelector) {
        const popup = document.querySelector(targetSelector);
        const overlay = document.querySelector('.dim_layer') || document.querySelector('.login_overlay');

        if (popup && overlay) {
            overlay.style.display = 'block';
            popup.style.display = 'block';
        }
    },

    // 팝업 닫기 (모두 닫기)
    closePopup() {
        const overlay = document.querySelector('.dim_layer') || document.querySelector('.login_overlay');
        if (overlay) overlay.style.display = 'none';

        document.querySelectorAll('.pop_layer').forEach(p => p.style.display = 'none');
        document.querySelectorAll('.login_popup').forEach(p => p.style.display = 'none');
    },

    // 알림창 (SweetAlert2 래퍼)
    showAlert(title, text, icon = 'info') {
        if (typeof Swal !== 'undefined') {
            Swal.fire({
                title: title,
                text: text,
                icon: icon,
                confirmButtonColor: '#FFA500',
                confirmButtonText: '확인'
            });
        } else {
            alert(`${title}\n${text}`);
        }
    },

    // 확인창 (Promise 반환)
    async showConfirm(title, text) {
        if (typeof Swal !== 'undefined') {
            const result = await Swal.fire({
                title: title,
                text: text,
                icon: 'question',
                showCancelButton: true,
                confirmButtonColor: '#FFA500',
                cancelButtonColor: '#555555',
                confirmButtonText: '확인',
                cancelButtonText: '취소'
            });
            return result.isConfirmed;
        } else {
            return confirm(`${title}\n${text}`);
        }
    }
};