document.addEventListener('DOMContentLoaded', function () {
    document.getElementById("back-button").addEventListener("click", function(e) {
        this.innerHTML = `<img src="${swpanel_ai_data.pluginUrl}../admin/assets/img/loader_points_white.svg" alt="Loading...">`;
    });
    document.getElementById("continue-button").addEventListener("click", function(e) {
        this.innerHTML = `<img src="${swpanel_ai_data.pluginUrl}../admin/assets/img/loader_points_white.svg" alt="Loading...">`;
    });

    const tokenInput = document.getElementById('swpanel_ai_license_token');
    const secretInput = document.getElementById('swpanel_ai_license_secret');
    const continueButton = document.getElementById('continue-button');

    function updateButtonState() {
        if (!tokenInput || !continueButton || !secretInput) return;
        const hasToken = tokenInput.value.trim().length > 0;
        const hasSecret = secretInput.value.trim().length > 0;

        continueButton.disabled = !(hasToken) || !(hasSecret);
    }
    updateButtonState();

    if (tokenInput) tokenInput.addEventListener('input', updateButtonState);
    if (secretInput) secretInput.addEventListener('input', updateButtonState);
});