{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Register</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">

    <style>
        body {
            font-family: 'Poppins', sans-serif;
            background-color: #f8f9fa;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .container {
            max-width: 900px;
            background: #fff;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            border-radius: 15px;
            overflow: hidden;
        }

        .row {
            display: flex;
            align-items: stretch;
        }

        .left-section {
            background: url("{% static 'img/login2.jpg' %}") no-repeat center center/cover;
            min-height: 400px;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #fff;
            padding: 40px;
        }

        .right-section {
            padding: 60px;
        }

        .register-title {
            font-weight: bold;
            font-size: 24px;
            color: #333;
            text-align: center;
        }

        .form-control {
            background: rgba(0, 0, 0, 0.05);
            border: none;
            padding: 10px;
            font-size: 16px;
        }

        .form-control:focus {
            box-shadow: none;
            border: 2px solidrgb(13, 34, 102);
        }

        .btn-primary {
            background: #6222CC;
            border: none;
            padding: 12px;
            font-size: 16px;
            width: 100%;
            transition: 0.3s;
        }

        .btn-primary:hover {
            background: #6222CC;
        }

        .text-primary {
            color: #6222CC;
            text-decoration: none;
        }

        .text-primary:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>

<div class="container">
    <div class="row">
        <div class="col-md-6 left-section"></div>

        <div class="col-md-6 right-section">
            <h3 class="register-title mb-4">Register here!</h3>

            {% if messages %}
                {% for message in messages %}
                    <div class="alert {% if message.tags == 'error' %}alert-danger{% else %}alert-success{% endif %} text-center" role="alert">
                        {{ message }}
                    </div>
                {% endfor %}
            {% endif %}

            <form method="post">
                {% csrf_token %} 

                
                <div class="row">
                    
                    <div class="col-md-6 mb-3">
                        <label for="username" class="form-label">Username</label>
                        <input type="text" name="username" class="form-control" id="username" placeholder="Enter your username" required>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label for="full_name" class="form-label">Full Name</label>
                        <input type="text" name="full_name" class="form-control" id="full_name" placeholder="Enter your full name" required>
                    </div>
                </div>
                
                <!-- Full Name and Email side by side -->
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label for="phone" class="form-label">Phone Number</label>
                        <input type="tel" name="phone" class="form-control" id="phone" placeholder="Enter your phone number" required>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label for="email" class="form-label">Email</label>
                        <input type="email" name="email" class="form-control" id="email" placeholder="Enter your email" required>
                    </div>
                </div>

                

                <!-- Password and Confirm Password side by side -->
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label for="password" class="form-label">Password</label>
                        <input type="password" name="password" class="form-control" id="password" placeholder="Enter your password" required>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label for="confirm_password" class="form-label">Confirm Password</label>
                        <input type="password" name="confirm_password" class="form-control" id="confirm_password" placeholder="Re-enter your password" required>
                    </div>
                </div>

                <button type="submit" class="btn btn-primary">Register</button>
            </form>

            <p class="mt-3">
                Already have an account? <a href="{% url 'loginview' %}" class="text-primary">Login here</a>
            </p>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        const form = document.querySelector("form");

        form.addEventListener("submit", function (event) {
            let isValid = true;

            const username = document.getElementById("username").value.trim();
            const email = document.getElementById("email").value.trim();
            const password = document.getElementById("password").value.trim();
            const confirmPassword = document.getElementById("confirm_password").value.trim();

            // Username should be alphanumeric (same as login)
            if (!/^[a-zA-Z0-9]+$/.test(username)) {
                alert("Username should contain only letters and numbers.");
                isValid = false;
            }

            // Email validation (same as login)
            if (!/^\S+@\S+\.\S+$/.test(email)) {
                alert("Please enter a valid email address.");
                isValid = false;
            }

            // Password validation (same as login)
            if (password.length < 6) {
                alert("Password must be at least 6 characters long.");
                isValid = false;
            }

            // Confirm password match
            if (password !== confirmPassword) {
                alert("Passwords do not match.");
                isValid = false;
            }

            if (!isValid) {
                event.preventDefault();
            }
        });
    });
</script>

</body>
</html>
