<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>USB Validator</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            flex-direction: column;
            font-family: Arial, sans-serif;
            text-align: center;
            padding: 20px;
            background-color: #f4f4f4;
            overflow: auto; /* Allow scrolling if content overflows */
        }
        h1 {
            font-size: 2em;
            margin-bottom: 20px;
        }
        p {
            font-size: 1.2em;
            margin: 10px 0;
        }
        ol {
            font-size: 1.2em;
            margin: 20px 0;
            text-align: left;
            display: inline-block;
        }
        strong {
            font-weight: bold;
        }
        button {
            font-size: 1.5em;
            padding: 15px 30px;
            cursor: pointer;
            margin-top: 20px;
        }
        /* White text for the warning message, but now hidden */
        .warning-message {
            color: white;
            background-color: red;
            font-size: 1.5em;
            padding: 20px;
            margin-top: 20px;
            display: none; /* This hides the warning message */
        }
        /* Ensure text wraps and fits within the available width */
        .important-note {
            font-size: 1.2em;
            line-height: 1.5;  /* Ensures better spacing between lines */
            margin-top: 20px;
            margin-bottom: 20px;
            word-wrap: break-word; /* Ensures long words break and wrap onto the next line */
            white-space: normal;   /* Ensures the text wraps naturally */
        }
    </style>
</head>
<body>

    <!-- Create 20 blank lines -->
    <br><br><br><br><br><br><br><br><br><br>
    <br><br><br><br><br><br><br><br><br><br>

    <!-- Hidden Warning message -->
    <p class="warning-message">
        This page should not be modified under any circumstances because it will affect the validation process.
    </p>

    <h1>USB Drive Validator</h1>

    <p><strong>Step-by-Step Instructions:</strong></p>
    <ol>
        <li>Insert the USB drive that you want to validate into your computer.</li>
        <li>Click on the "Save Validator File" button below to browse for a location to save the file (including your USB drive).</li>
        <li>Once saved, navigate to your USB drive on your computer.</li>
        <li>Copy the file to the root directory of the USB drive (don't place it inside any folders).</li>
        <li>The USB drive is now validated. Do not remove the USB drive from your computer until the process is complete.</li>
    </ol>

    <p><strong>Important Notes:</strong></p>
    <p class="important-note">1. Do not share this file with anyone. It is only for your personal use and verification.</p>
    <p class="important-note">2. Do not modify this file in any way, as it could invalidate its purpose and authenticity.</p>
    <p class="important-note">3. If you encounter any issues, please contact your manager or send an email to Cyber Fulfillment <CyberFulfillment@toronto.ca>.</p>

    <!-- Save Validator File button -->
    <button onclick="saveValidatorFile()">Save Validator File</button>

    <script>
        async function saveValidatorFile() {
            const content = `
                <!DOCTYPE html>
                <html lang="en">
                <head>
                    <meta charset="UTF-8">
                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
                    <title>USB Validator</title>
                </head>
                <body>
                    <h1>This is a control file to identify valid USB devices for City of Toronto</h1>
                    <p><strong>Important Notes:</strong></p>
                    <p>1. Do not share this file with anyone. It is only for your personal use and verification.</p>
                    <p>2. Do not modify this file in any way, as it could invalidate its purpose and authenticity.</p>
                </body>
                </html>
            `;

            const blob = new Blob([content], { type: 'text/html' });

            // Check if the File System Access API is supported
            if ('showSaveFilePicker' in window) {
                try {
                    // Open the Save File Picker dialog
                    const handle = await window.showSaveFilePicker({
                        suggestedName: 'USB_Validator.html', // Suggested filename
                        types: [
                            {
                                description: 'HTML Files',
                                accept: { 'text/html': ['.html'] }
                            }
                        ]
                    });

                    // Create a writable stream and write the Blob content to the file
                    const writable = await handle.createWritable();
                    await writable.write(blob);
                    await writable.close();

                    alert('USB validator file successfully saved!');
                } catch (error) {
                    console.error('Error while saving file:', error);
                    alert('File saving failed or was cancelled.');
                }
            } else {
                // Fallback if File System Access API is not supported
                alert('Your browser does not support the File System Access API. Please try using a supported browser like Chrome or Edge.');
            }
        }
    </script>
</body>
</html>
