document.addEventListener('DOMContentLoaded', () => {
    const ipInput = document.getElementById('ip');
    const portInput = document.getElementById('port');
    const characterVoiceInput = document.getElementById('characterVoice');
    const languageSelect = document.getElementById('language');
    const saveButton = document.getElementById('save');
    const buyCoffeeButton = document.getElementById('buyCoffee');

    // Load saved settings
    chrome.storage.sync.get(['ip', 'port', 'characterVoice', 'language'], (data) => {
        if (data.ip) ipInput.value = data.ip;
        if (data.port) portInput.value = data.port;
        if (data.characterVoice) characterVoiceInput.value = data.characterVoice;
        if (data.language) languageSelect.value = data.language;
    });

    // Save settings
    saveButton.addEventListener('click', () => {
        const ip = ipInput.value;
        const port = portInput.value;
        const characterVoice = characterVoiceInput.value;
        const language = languageSelect.value;

        chrome.storage.sync.set({ ip, port, characterVoice, language }, () => {
           // alert('Settings saved successfully!');
            // Restart the extension
            chrome.runtime.reload();
        });
    });

    // Buy me a coffee button - Open Stripe checkout
    buyCoffeeButton.addEventListener('click', () => {
        // Replace with your actual Stripe checkout URL
        const stripeCheckoutUrl = 'https://buy.stripe.com/test_8wM8xd1onfwNbh63cc'; 
        window.open(stripeCheckoutUrl, '_blank');
    });
});
