<!-- Path: app/Views/auth/register.view.php -->
<div class="bg-slate-50 min-h-[calc(100vh-64px)] flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
    <div class="max-w-md w-full bg-white rounded-xl shadow-lg border border-slate-200 overflow-hidden">
        
        <div class="bg-navy-950 p-6 text-center">
            <h2 class="text-2xl font-bold text-white">Create Account</h2>
            <p class="text-slate-300 text-sm mt-1">Join the ERCS network to manage emergencies.</p>
        </div>

        <div class="p-8">
            <form id="registerForm" class="space-y-5">
                <div>
                    <label for="full_name" class="block text-sm font-medium text-slate-700 mb-1">Full Name</label>
                    <input type="text" name="full_name" id="full_name" required class="block w-full px-4 py-3 border border-slate-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-brandBlue-500 focus:border-brandBlue-500 transition-colors" placeholder="John Doe">
                </div>

                <div>
                    <label for="email" class="block text-sm font-medium text-slate-700 mb-1">Email Address</label>
                    <input type="email" name="email" id="email" required class="block w-full px-4 py-3 border border-slate-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-brandBlue-500 focus:border-brandBlue-500 transition-colors" placeholder="you@example.com">
                </div>

                <div>
                    <label for="phone_number" class="block text-sm font-medium text-slate-700 mb-1">Phone Number</label>
                    <input type="tel" name="phone_number" id="phone_number" required class="block w-full px-4 py-3 border border-slate-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-brandBlue-500 focus:border-brandBlue-500 transition-colors" placeholder="08000000000">
                </div>

                <div>
                    <label for="password" class="block text-sm font-medium text-slate-700 mb-1">Password</label>
                    <input type="password" name="password" id="password" required minlength="6" class="block w-full px-4 py-3 border border-slate-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-brandBlue-500 focus:border-brandBlue-500 transition-colors" placeholder="At least 6 characters">
                </div>

                <button type="submit" id="submitBtn" class="w-full flex justify-center py-3 px-4 border border-transparent rounded-md shadow-sm text-sm font-bold text-white bg-brandBlue-600 hover:bg-brandBlue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-brandBlue-500 transition-colors">
                    Register Account <i class="fas fa-user-plus ml-2 mt-1"></i>
                </button>
            </form>

            <div class="mt-6 text-center text-sm text-slate-600">
                Already have an account? 
                <a href="{{APP_URL}}/login" class="font-medium text-navy-900 hover:text-navy-800">Sign in here</a>
            </div>
        </div>
    </div>
</div>

@addScript
<script>
$(document).ready(function() {
    $('#registerForm').on('submit', function(e) {
        e.preventDefault();
        
        let $btn = $('#submitBtn');
        let originalText = $btn.html();
        
        $btn.html('<i class="fas fa-spinner fa-spin"></i> Processing...').prop('disabled', true);
        
        $.ajax({
            url: '{{APP_URL}}/register',
            type: 'POST',
            data: $(this).serialize(),
            success: function(response) {
                if(response.status === 'success') {
                    showNotification('success', 'Account Created', response.message);
                    setTimeout(function() {
                        window.location.href = '{{APP_URL}}' + response.redirect;
                    }, 1500);
                }
            },
            error: function(xhr) {
                let msg = 'Registration failed.';
                if(xhr.responseJSON && xhr.responseJSON.message) {
                    msg = xhr.responseJSON.message;
                } else if (xhr.responseJSON && xhr.responseJSON.errors) {
                    msg = Object.values(xhr.responseJSON.errors)[0][0]; 
                }
                showNotification('error', 'Error', msg);
                $btn.html(originalText).prop('disabled', false);
            }
        });
    });
});
</script>
@endAddScript