<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <style>
        html, body {
            height: 100%;
            width: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
            background-color: black;
        }
        #container {
            height: calc(100% - 30px);
            width: 100%;
            margin-top: 30px;
        }
        .button-row {
            position: absolute;
            top: 5px;
            left: 5px;
            display: flex;
            align-items: center;
            gap: 5px;
        }
        .add-button, .small-button {
            height: 24px;
            background-color: black;
            color: rgb(129, 129, 129);
            border: 1px solid #333;
            border-radius: 3px;
            font-size: 10px;
            font-weight: bold;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
            transition: all 0.2s ease-in-out;
        }
        #watermark {
    position: fixed;
    top: 10px;
    right: 10px;
    font-size: 14px;
    color: rgba(117, 117, 117, 0.5);
    font-family: Arial, sans-serif;
    font-weight: bold;
    pointer-events: none;
}

        .add-button {
            width: 24px;
        }
        .add-button:hover {
            background-color: #222;
            border-color: #555;
            transform: scale(1.1);
        }
        .small-button {
            width: 50px;
        }
        .small-button.active {
            background-color: #555;
            color: #fff;
        }
        .small-button:hover {
            background-color: #333;
            border-color: #555;
        }
    </style>
</head>
<body>
    <div class="button-row">
        <button class="add-button" id="add-button">+</button>
    </div>
    <div id="container"></div>

    <script src="./vs/loader.js" type="text/javascript"></script>
    <script type="text/javascript">
        var editors = {}; // Store editors' content by tab ID
        var activeTab = null; // Track active tab
        var tabCount = 0; // Number of tabs

        document.getElementById("add-button").addEventListener("click", function () {
            if (tabCount < 7) {
                addNewTab();
            }
        });

        function addNewTab() {
            const buttonRow = document.querySelector(".button-row");
            const newTabId = `tab${++tabCount}`;
            editors[newTabId] = ""; // Initialize tab content

            const newButton = document.createElement("button");
            newButton.classList.add("small-button");
            newButton.textContent = `Tab ${tabCount}`;
            newButton.dataset.tabId = newTabId;

            newButton.addEventListener("click", function () {
                switchTab(newTabId, newButton);
            });

            buttonRow.insertBefore(newButton, document.getElementById("add-button"));
            switchTab(newTabId, newButton);
        }

        function switchTab(tabId, buttonElement) {
            if (activeTab === tabId) return; // Do nothing if already active

            // Save current editor content if there's an active tab
            if (activeTab) {
                editors[activeTab] = editor.getValue();
                document.querySelector(`[data-tab-id="${activeTab}"]`).classList.remove("active");
            }

            activeTab = tabId;
            buttonElement.classList.add("active");

            // Load the content for the new active tab
            editor.setValue(editors[tabId] || "");
        }

        require(["./vs/editor/editor.main"], function () {
            monaco.editor.defineTheme('myCustomTheme', {
                base: 'vs-dark',
                inherit: true,
                rules: [],
                colors: {
                    'editor.background': '#000000',
                    'editor.foreground': '#FFFFFF'
                }
            });

            // Initialize the editor
            editor = monaco.editor.create(document.getElementById("container"), {
                value: '',
                language: "lua",
                theme: "myCustomTheme",
                dragAndDrop: true,
                links: true,
                minimap: {
                    enabled: false,
                },
                showFoldingControls: "always",
                smoothScrolling: true,
            });

            // Create the first tab by default
            addNewTab();
        });
    </script>
    <div id="watermark">Editor By Vulcanz</div>

</body>
</html>
