let startNumber = 0;
let endNumber = 0;
let selectedStore = 'random';

window.addEventListener('load', () => {
    window.appointment.scanDevices().then((deviceList) => {
        // Make the list
        let deviceListSection = document.getElementById('device_list');
        let deviceNumberInfo = document.createElement("div")
        deviceNumberInfo.innerHTML = "连接的设备数:" + deviceList.length;
        deviceListSection.appendChild(deviceNumberInfo);
        for (i = 0; i < deviceList.length; ++i) {
            // Create an item for each one
            let listItem = document.createElement('li');
            // Add the item text
            listItem.innerHTML = deviceList[i].join(" : ");
            // Add listItem to the listElement
            deviceListSection.appendChild(listItem);
        }
    })
    document.getElementById("start_book_btn").addEventListener('click', () => {
        let audioAnalyse = document.getElementById("audio_analyse").checked;
        let alertBeep = document.getElementById("alert_beep").checked;
        window.appointment.startBook(startNumber, endNumber, selectedStore, audioAnalyse, alertBeep);
    })

    document.getElementById("scheduler_book_btn").addEventListener('click', () => {
        let audioAnalyse = document.getElementById("audio_analyse").checked;
        let alertBeep = document.getElementById("alert_beep").checked;
        window.appointment.scheduleBook(startNumber, endNumber, selectedStore, audioAnalyse, alertBeep);
    })

    document.getElementById("clear_all_browsers").addEventListener('click', () => {
        window.appointment.clearAllBrowsers();
    })
    document.getElementById("store_selector").addEventListener('change', (event) => {
        selectedStore = event.target.value
    })
    document.getElementById("start_number").addEventListener('change', (event) => {
        startNumber = event.target.value
    })
    document.getElementById("end_number").addEventListener('change', (event) => {
        endNumber = event.target.value
    })
})