<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sign Up - Vitxpert Cloud HR System</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
    <style>
        body { font-family: 'Inter', sans-serif; background-color: #fffdf9; }
    </style>
</head>
<body class="text-gray-800 min-h-screen flex flex-col relative">
    @include('frontend.partials.header')

    <!-- Main Content -->
    <main class="flex-1 flex flex-col items-center justify-center p-8">
        
        <div class="w-full max-w-4xl text-left mb-6">
            <h1 class="text-2xl font-semibold text-gray-800">Sign up (Get 250 free users for cloud and mobile app)</h1>
            <p class="text-sm text-gray-500 mt-1">Create new account to get free cloud software for 12 Months.</p>
        </div>

        <div class="w-full max-w-4xl bg-white p-10 rounded-2xl shadow-xl border border-orange-50">
            @if ($errors->any())
                <div class="bg-red-100 text-red-700 p-4 rounded mb-6 text-sm">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif

            <form action="{{ url('register') }}" method="POST" id="registerForm">
                @csrf
                <div class="grid grid-cols-1 md:grid-cols-2 gap-x-12 gap-y-6">
                    
                    <!-- Left Column -->
                    <div>
                        <label class="block text-gray-700 text-sm font-bold mb-2">Company Name <span class="text-red-500">*</span></label>
                        <input type="text" id="company_name" name="company_name" required class="w-full border border-gray-200 rounded-lg py-3 px-4 focus:outline-none focus:border-[#ff5722] focus:ring-1 focus:ring-[#ff5722] bg-yellow-50" placeholder="Vitxpert India (P) Ltd">
                    </div>

                    <!-- Right Column -->
                    <div>
                        <label class="block text-gray-700 text-sm font-bold mb-2">Company Address <span class="text-red-500">*</span></label>
                        <input type="text" id="company_address" name="company_address" required class="w-full border border-gray-200 rounded-lg py-3 px-4 focus:outline-none focus:border-[#ff5722] focus:ring-1 focus:ring-[#ff5722]" placeholder="Delhi">
                    </div>

                    <!-- Left Column -->
                    <div>
                        <label class="block text-gray-700 text-sm font-bold mb-2">Email address <span class="text-red-500">*</span></label>
                        <input type="email" id="email" name="email" required class="w-full border border-gray-200 rounded-lg py-3 px-4 focus:outline-none focus:border-[#ff5722] focus:ring-1 focus:ring-[#ff5722]" placeholder="Email Address">
                    </div>

                    <!-- Right Column -->
                    <div>
                        <label class="block text-gray-700 text-sm font-bold mb-2">Phone number <span class="text-red-500">*</span></label>
                        <div class="flex space-x-2">
                            <div class="relative flex-1">
                                <input type="text" id="phone" name="phone" required class="w-full border border-gray-200 rounded-lg py-3 pl-4 pr-10 focus:outline-none focus:border-[#ff5722] focus:ring-1 focus:ring-[#ff5722]" placeholder="Phone Number">
                                <div class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
                                    <i class="fa-regular fa-user text-gray-400"></i>
                                </div>
                            </div>
                            <button type="button" id="sendOtpBtn" class="bg-[#ff5722] hover:bg-[#e64a19] text-white font-bold py-3 px-6 rounded-lg shadow-md transition duration-200 whitespace-nowrap">
                                Send OTP
                            </button>
                        </div>
                    </div>

                    <!-- 
                        THE FOLLOWING FIELDS ARE FROZEN UNTIL OTP VERIFICATION
                    -->

                    <!-- Left Column -->
                    <div>
                        <label class="block text-gray-700 text-sm font-bold mb-2">Corporate ID <span class="text-red-500">*</span></label>
                        <input type="text" name="corporate_id" disabled class="frozen-field opacity-60 cursor-not-allowed w-full border border-gray-200 rounded-lg py-3 px-4 focus:outline-none focus:border-[#ff5722] focus:ring-1 focus:ring-[#ff5722] bg-gray-50" placeholder="Corporate ID">
                    </div>

                    <!-- Right Column -->
                    <div>
                        <label class="block text-gray-700 text-sm font-bold mb-2">User Name <span class="text-red-500">*</span></label>
                        <input type="text" name="username" disabled class="frozen-field opacity-60 cursor-not-allowed w-full border border-gray-200 rounded-lg py-3 px-4 focus:outline-none focus:border-[#ff5722] focus:ring-1 focus:ring-[#ff5722] bg-gray-50" placeholder="UserName">
                    </div>
                    
                    <!-- Left Column -->
                    <div>
                        <label class="block text-gray-700 text-sm font-bold mb-2">Password <span class="text-red-500">*</span></label>
                        <input type="password" name="password" disabled class="frozen-field opacity-60 cursor-not-allowed w-full border border-gray-200 rounded-lg py-3 px-4 focus:outline-none focus:border-[#ff5722] focus:ring-1 focus:ring-[#ff5722] bg-gray-50" placeholder="Password">
                    </div>

                    <!-- Right Column -->
                    <div>
                        <label class="block text-gray-700 text-sm font-bold mb-2">Confirm password <span class="text-red-500">*</span></label>
                        <input type="password" name="password_confirmation" disabled class="frozen-field opacity-60 cursor-not-allowed w-full border border-gray-200 rounded-lg py-3 px-4 focus:outline-none focus:border-[#ff5722] focus:ring-1 focus:ring-[#ff5722] bg-gray-50" placeholder="Confirm Password">
                    </div>
                    
                    <!-- Left Column -->
                    <div>
                        <label class="block text-gray-700 text-sm font-bold mb-2">Partner ID</label>
                        <input type="text" name="partner_id" disabled class="frozen-field opacity-60 cursor-not-allowed w-full border border-gray-200 rounded-lg py-3 px-4 focus:outline-none focus:border-[#ff5722] focus:ring-1 focus:ring-[#ff5722] bg-gray-50" placeholder="Partner ID">
                    </div>

                    <!-- Right Column -->
                    <div>
                        <label class="block text-gray-700 text-sm font-bold mb-2">Dealer Name</label>
                        <input type="text" name="dealer_name" disabled class="frozen-field opacity-60 cursor-not-allowed w-full border border-gray-200 rounded-lg py-3 px-4 focus:outline-none focus:border-[#ff5722] focus:ring-1 focus:ring-[#ff5722] bg-gray-50" placeholder="Dealer Name">
                    </div>

                </div>

                <div class="mt-8 flex justify-end">
                     <button type="submit" id="submitBtn" disabled class="bg-gray-400 cursor-not-allowed text-white font-bold py-3 px-12 rounded-lg shadow-md transition duration-200">
                        Sign Up
                    </button>
                </div>
            </form>
        </div>

    </main>

    <!-- OTP Modal Overlay -->
    <div id="otpModal" class="fixed inset-0 bg-black bg-opacity-50 z-50 hidden flex items-center justify-center backdrop-blur-sm transition-opacity">
        <div class="bg-white w-full max-w-md rounded-2xl shadow-2xl p-8 transform transition-all scale-95 opacity-0" id="otpModalContent">
            <h2 class="text-2xl text-gray-800 mb-1">We have sent you an otp to</h2>
            <h2 class="text-2xl text-gray-800 font-semibold mb-6">your <span class="font-normal text-gray-500">email</span> and phone number</h2>
            
            <div class="mb-4">
                <label class="block text-gray-700 text-sm font-semibold mb-2">Enter your OTP</label>
                <input type="text" id="otpInput" class="w-full border border-gray-300 rounded-lg py-3 px-4 focus:outline-none focus:border-[#ff5722] focus:ring-1 focus:ring-[#ff5722] tracking-widest text-lg" placeholder="******" maxlength="6">
            </div>
            
            <p class="text-gray-400 text-sm mb-8 font-medium">Your OTP will be valid for 5 mins only.</p>
            
            <div class="flex justify-end space-x-4 border-t border-gray-100 pt-4">
                <button type="button" id="verifyOtpBtn" class="bg-[#ff5722] hover:bg-[#e64a19] text-white font-semibold py-2 px-6 rounded-lg transition duration-200">
                    Verify
                </button>
                <button type="button" id="closeModalBtn" class="bg-gray-100 hover:bg-gray-200 text-gray-700 font-semibold py-2 px-6 rounded-lg transition duration-200">
                    Close
                </button>
            </div>
        </div>
    </div>

    <script>
        $(document).ready(function() {
            // Open Modal
            $('#sendOtpBtn').click(function() {
                const cName = $('#company_name').val();
                const cAddress = $('#company_address').val();
                const email = $('#email').val();
                const phone = $('#phone').val();

                if(!cName || !cAddress || !email || !phone) {
                    alert('Please fill Company Name, Address, Email, and Phone before sending OTP.');
                    return;
                }

                $('#otpModal').removeClass('hidden');
                setTimeout(function() {
                    $('#otpModalContent').removeClass('scale-95 opacity-0').addClass('scale-100 opacity-100');
                    $('#otpInput').focus();
                }, 10);
            });

            // Close Modal
            function closeModal() {
                $('#otpModalContent').removeClass('scale-100 opacity-100').addClass('scale-95 opacity-0');
                setTimeout(function() {
                    $('#otpModal').addClass('hidden');
                }, 300);
            }
            
            $('#closeModalBtn').click(closeModal);

            // Verify OTP
            $('#verifyOtpBtn').click(function() {
                const otp = $.trim($('#otpInput').val());
                
                // For demonstration, let's accept any 6 digit code or '123456'
                if(otp.length >= 4) {
                    // Success! Unfreeze the fields
                    $('.frozen-field').prop('disabled', false).removeClass('opacity-60 cursor-not-allowed');
                    
                    // Enable submit button
                    $('#submitBtn').prop('disabled', false)
                                 .removeClass('bg-gray-400 cursor-not-allowed')
                                 .addClass('bg-[#ff5722] hover:bg-[#e64a19]');
                    
                    // Change Send OTP button text
                    $('#sendOtpBtn').text('Verified ✔')
                                  .removeClass('bg-[#ff5722] hover:bg-[#e64a19]')
                                  .addClass('bg-green-500 cursor-default')
                                  .prop('disabled', true);

                    closeModal();
                } else {
                    alert('Invalid OTP. Please enter a valid code.');
                }
            });
        });
    </script>
</body>
</html>
