document.addEventListener("DOMContentLoaded", function() {
    const menu = document.getElementById('project-video-report-menu');
    const toggleButton = document.getElementById('project-video-report-button-toggle');
    const overlay = document.getElementById('project-video-report-overlay');

    // 点击按钮显示/隐藏菜单
    toggleButton.addEventListener('click', function () {
        if (!toggleButton.classList.contains('disabled')) { // 只有未提交时才能打开菜单
            menu.style.display = 'flex';
            overlay.style.display = 'block';
        }
    });

    // 点击空白区域关闭菜单
    overlay.addEventListener('click', function () {
        menu.style.display = 'none';
        overlay.style.display = 'none';
    });

    // 选项点击事件（不同的 GET 请求）
    function handleOption(type, optionText) {
        const apiUrl = `/000/report_error_video/report.php?type=${type}&vod_url=${encodeURIComponent(window.location.href)}`;

        // 无论请求结果如何，按钮文本都更新为 "已提交"
        toggleButton.textContent = `${optionText} 已提交`;
        toggleButton.classList.add("disabled");
        toggleButton.disabled = true;

        // 关闭菜单
        menu.style.display = 'none';
        overlay.style.display = 'none';

        // 发送请求，不处理返回结果
        fetch(apiUrl, {
            method: 'GET',
        }).catch(error => {
            console.error('提交失败:', error);
            // 即使请求失败，按钮状态已经更新为“已提交”
        });
    }

    // 将handleOption函数暴露给外部HTML调用
    window.handleOption = handleOption;
});
