<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Food Item Form</title>    
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            padding: 20px;
        }

        .container {
            max-width: 400px;
            margin: 0 auto;
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            font-weight: bold;
            margin-bottom: 5px;
        }

        .form-group input[type="text"] {
            width: 100%;
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }

        .form-group input[type="submit"] {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        .form-group input[type="submit"]:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>Add New Food Item</h2>
        <form id="foodForm" action="/LandingPage/admin/dashboard/new" method="POST">
            <div class="form-group">
                <label for="category">Category:</label>
                <select id="category" name="category">
                    <option value="Breakfast">Breakfast</option>
                    <option value="Lunch">Lunch</option>
                    <option value="Dinner">Dinner</option>
                </select>
            </div>  
            <div class="form-group">
                <label for="imageURL">Image URL:</label>
                <input type="text" id="imageURL" name="imageURL" required>
            </div>
            <div class="form-group">
                <label for="name">Name:</label>
                <input type="text" id="name" name="name" required>
            </div>
            <div class="form-group">
                <label for="price">Price:</label>
                <input type="text" id="price" name="price" required>
            </div>
            <div class="form-group">
                <input type="submit" value="Add Food Item">
            </div>
        </form>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            document.getElementById('foodForm').addEventListener('submit', function(event) {
                // Prevent form submission if validation fails
                if (!validateForm()) {
                    event.preventDefault();
                }
            });
        });

        function validateForm() {
            var imageURL = document.getElementById('imageURL').value.trim();
            var name = document.getElementById('name').value.trim();
            var price = document.getElementById('price').value.trim();
            var category = document.getElementById('category').value.trim();

            if (imageURL === '' || name === '' || price === '' || category === '') {
                alert('Please fill in all fields.');
                return false;
            }

            if (isNaN(price)) {
                alert('Price must be a number.');
                return false;
            }

            return true;
        }
    </script>

</body>
</html>
