var main_tabs = new Tabs('#main_tabs');

document.addEventListener('optionsPageReady', function () {
    /* Options page is ready. Write your code here */

    // var o_storage_area = document.getElementById("o_storage_area");    
    // chrome.storage.local.get("o_storage_area").then((result) => {
    //     o_storage_area.value = result.o_storage_area || "local";
    //     console.log("Storage is: " + o_storage_area.value);
    //     o_storage_area.addEventListener("change", function () {
    //         console.log("Storage change: " + this.value);
    //         saveStorageArea(this.value);            
    //         setTimeout(function () { location.reload() }, 1000);
    //     });
    // });

    document.getElementById("o_hotkeys_settings_btn").addEventListener("click", function() {
        chrome.tabs.create({ url: "chrome://extensions/configureCommands" });
    });

    var o_history_enabled = document.getElementById("o_history_enabled");

    if(o_history_enabled.checked)
    {
        chrome.permissions.contains({
            permissions: ['history']
        }, function(result) {
            o_history_enabled.checked = result;
        });
    }
    
    o_history_enabled.addEventListener("change", function () {
        if (this.checked) {
            chrome.permissions.request({
                permissions: ['history']
            }, function (granted) {
                o_history_enabled.checked = granted;
            });
        }
    });    

    // This event will fire when option is saved to storage (with success or error)
    // event.detail.success = true (on success) or event.detail.success = false (on error)
    // event.detail.val is option which was saved
    document.addEventListener('optionSaved', function (event) {
        console.log('Option saved. ', event.detail);
    });    
});

window.addEventListener('load', function () {
    //
});

