
document.addEventListener("DOMContentLoaded", function() {
    var modal = document.getElementById("DebugModal");
    var btn = document.getElementById("debugButton");
    var span = document.getElementsByClassName("close")[0];
    var getTab = document.getElementById("getTab");
    var postTab = document.getElementById("postTab");
    var inputTab = document.getElementById("inputTab");
    var getData = document.getElementById("getData");
    var postData = document.getElementById("postData");
    var inputData = document.getElementById("inputData");

    // Draggable Button
    let isDragging = false;
    let offsetX, offsetY;

    btn.addEventListener('mousedown', function(e) {
        isDragging = true;
        offsetX = e.clientX - btn.getBoundingClientRect().left;
        offsetY = e.clientY - btn.getBoundingClientRect().top;
        btn.style.cursor = 'grabbing';
        btn.style.width = btn.offsetWidth + 'px';  // Set the width explicitly to prevent resizing
    });

    document.addEventListener('mousemove', function(e) {
        if (isDragging) {
            btn.style.left = (e.clientX - offsetX) + 'px';
            btn.style.top = (e.clientY - offsetY) + 'px';
        }
    });

    document.addEventListener('mouseup', function() {
        isDragging = false;
        btn.style.cursor = 'grab';
    });

    // Double click to open modal
    btn.addEventListener('dblclick', function(e) {
        if (!isDragging) {
            modal.classList.remove("hidden");
        }
    });

    // Close modal
    span.onclick = function() {
        modal.classList.add("hidden");
    }

    window.onclick = function(event) {
        if (event.target == modal) {
            modal.classList.add("hidden");
        }
    }

    // Tabs functionality
    getTab.onclick = function() {
        getData.classList.remove("hidden");
        postData.classList.add("hidden");
        inputData.classList.add("hidden");

        getTab.classList.add("bg-blue-700");
        postTab.classList.remove("bg-blue-700");
        inputTab.classList.remove("bg-blue-700");
    }

    postTab.onclick = function() {
        postData.classList.remove("hidden");
        getData.classList.add("hidden");
        inputData.classList.add("hidden");

        postTab.classList.add("bg-blue-700");
        getTab.classList.remove("bg-blue-700");
        inputTab.classList.remove("bg-blue-700");
    }

    inputTab.onclick = function() {
        inputData.classList.remove("hidden");
        getData.classList.add("hidden");
        postData.classList.add("hidden");

        inputTab.classList.add("bg-blue-700");
        getTab.classList.remove("bg-blue-700");
        postTab.classList.remove("bg-blue-700");
    }
});
