<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Random Name Picker</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        .container {
            text-align: center;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        input {
            padding: 8px;
            margin: 5px;
            width: 80%;
            max-width: 300px;
        }
        button {
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        button:hover {
            background-color: #45a049;
        }
        .result {
            margin-top: 20px;
            font-size: 24px;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Random Name Picker</h1>
        <p>Enter names, separated by commas:</p>
        <input type="text" id="nameInput" placeholder="Juan, Alice, Ahmed, etc." required>
        <br><br>
        <button onclick="pickRandomName()">Pick a Winner</button>
        <div class="result" id="winner" aria-live="polite"></div>
    </div>

    <script>
        function pickRandomName() {
            // Get the names from the input field and split them into an array
            const names = document.getElementById("nameInput").value.split(",");
            // Trim whitespace from each name
            const trimmedNames = names.map(name => name.trim()).filter(name => name !== "");

            if (trimmedNames.length > 0) {
                // Pick a random index
                const randomIndex = Math.floor(Math.random() * trimmedNames.length);
                // Display the result
                document.getElementById("winner").innerText = "The winner is: " + trimmedNames[randomIndex];
            } else {
                document.getElementById("winner").innerText = "Please enter some names!";
            }
        }
    </script>
</body>
</html>