@extends('layouts.auth')

@section('title', 'Sign Up')

@section('content')
<div class="min-h-screen flex">
    <!-- Left Side - Form -->
    <div class="w-full lg:w-1/2 flex items-center justify-center p-4 sm:p-8 bg-gray-50">
        <div class="w-full max-w-lg animate-fade-in">
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <div class="text-center mb-8">
                    <div class="inline-flex items-center justify-center w-16 h-16 bg-green-100 rounded-full mb-4">
                        <i class="fas fa-user-plus text-2xl text-green-600"></i>
                    </div>
                    <h2 class="text-2xl font-bold text-gray-800">Create Account</h2>
                    <p class="text-gray-500 mt-2">Join our community today</p>
                </div>

                <form method="POST" action="{{ route('register') }}" class="space-y-5">
                    @csrf
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <!-- Account Type -->
                        <div class="md:col-span-2">
                            <label class="block text-sm font-medium text-gray-700 mb-3">Account Type *</label>
                            <div class="grid grid-cols-2 gap-4">
                                <label class="cursor-pointer">
                                    <input type="radio" name="account_type" value="customer" checked 
                                        class="peer sr-only"
                                        onchange="toggleVendorFields()">
                                    <div class="p-4 border-2 border-gray-200 rounded-lg peer-checked:border-primary-500 peer-checked:bg-primary-50 transition">
                                        <div class="text-center">
                                            <i class="fas fa-shopping-cart text-2xl text-gray-400 peer-checked:text-primary-600 mb-2"></i>
                                            <p class="font-medium text-gray-800">Customer</p>
                                            <p class="text-xs text-gray-500">Shop for auto parts</p>
                                        </div>
                                    </div>
                                </label>
                                
                                <label class="cursor-pointer">
                                    <input type="radio" name="account_type" value="vendor" 
                                        class="peer sr-only"
                                        onchange="toggleVendorFields()">
                                    <div class="p-4 border-2 border-gray-200 rounded-lg peer-checked:border-primary-500 peer-checked:bg-primary-50 transition">
                                        <div class="text-center">
                                            <i class="fas fa-store text-2xl text-gray-400 peer-checked:text-primary-600 mb-2"></i>
                                            <p class="font-medium text-gray-800">Vendor</p>
                                            <p class="text-xs text-gray-500">Sell auto parts</p>
                                        </div>
                                    </div>
                                </label>
                            </div>
                        </div>

                        <!-- Name -->
                        <div class="md:col-span-2">
                            <label class="block text-sm font-medium text-gray-700 mb-2">Full Name *</label>
                            <div class="relative">
                                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                    <i class="fas fa-user text-gray-400"></i>
                                </div>
                                <input type="text" name="name" value="{{ old('name') }}" required
                                    class="w-full pl-10 pr-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent input-focus transition"
                                    placeholder="John Doe">
                            </div>
                            @error('name')
                                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                            @enderror
                        </div>

                        <!-- Username -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Username *</label>
                            <div class="relative">
                                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                    <i class="fas fa-at text-gray-400"></i>
                                </div>
                                <input type="text" name="username" value="{{ old('username') }}" required
                                    class="w-full pl-10 pr-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent input-focus transition"
                                    placeholder="johndoe">
                            </div>
                            @error('username')
                                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                            @enderror
                        </div>

                        <!-- Email -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Email *</label>
                            <div class="relative">
                                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                    <i class="fas fa-envelope text-gray-400"></i>
                                </div>
                                <input type="email" name="email" value="{{ old('email') }}" required
                                    class="w-full pl-10 pr-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent input-focus transition"
                                    placeholder="name@example.com">
                            </div>
                            @error('email')
                                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                            @enderror
                        </div>

                        <!-- Birthdate -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Birthdate</label>
                            <input type="date" name="birthdate" value="{{ old('birthdate') }}"
                                class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent input-focus transition">
                            @error('birthdate')
                                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                            @enderror
                        </div>

                        <!-- Gender -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Gender</label>
                            <select name="gender" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent input-focus transition">
                                <option value="">Select...</option>
                                <option value="male" {{ old('gender') == 'male' ? 'selected' : '' }}>Male</option>
                                <option value="female" {{ old('gender') == 'female' ? 'selected' : '' }}>Female</option>
                                <option value="other" {{ old('gender') == 'other' ? 'selected' : '' }}>Other</option>
                                <option value="prefer_not_to_say" {{ old('gender') == 'prefer_not_to_say' ? 'selected' : '' }}>Prefer not to say</option>
                            </select>
                            @error('gender')
                                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                            @enderror
                        </div>
                    </div>

                    <!-- Password -->
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Password *</label>
                            <input type="password" name="password" required
                                class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent input-focus transition"
                                placeholder="Min 8 characters">
                            @error('password')
                                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                            @enderror
                        </div>

                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Confirm Password *</label>
                            <input type="password" name="password_confirmation" required
                                class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent input-focus transition"
                                placeholder="Repeat password">
                        </div>
                    </div>

                    <!-- Terms -->
                    <div class="flex items-start">
                        <input type="checkbox" name="terms" required class="mt-1 w-4 h-4 text-primary-600 border-gray-300 rounded focus:ring-primary-500">
                        <label class="ml-2 text-sm text-gray-600">
                            I agree to the <a href="#" class="text-primary-600 hover:underline">Terms of Service</a> and <a href="#" class="text-primary-600 hover:underline">Privacy Policy</a> *
                        </label>
                    </div>
                    @error('terms')
                        <p class="text-sm text-red-600">{{ $message }}</p>
                    @enderror

                    <!-- Vendor Fields (Hidden by default) -->
                    <div id="vendor-fields" class="hidden space-y-5 border-t border-gray-200 pt-5">
                        <h4 class="font-semibold text-gray-800"><i class="fas fa-store mr-2"></i>Store Information</h4>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Store Name *</label>
                            <input type="text" name="store_name" value="{{ old('store_name') }}"
                                class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent input-focus transition"
                                placeholder="Your Auto Parts Store">
                            @error('store_name')
                                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                            @enderror
                        </div>

                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Store Description</label>
                            <textarea name="store_description" rows="3"
                                class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent input-focus transition"
                                placeholder="Describe your store and the auto parts you sell...">{{ old('store_description') }}</textarea>
                            @error('store_description')
                                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                            @enderror
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">Phone *</label>
                                <input type="tel" name="phone" value="{{ old('phone') }}"
                                    class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent input-focus transition"
                                    placeholder="+1 (555) 123-4567">
                                @error('phone')
                                    <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                                @enderror
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">Business Address *</label>
                                <input type="text" name="address" value="{{ old('address') }}"
                                    class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent input-focus transition"
                                    placeholder="123 Main St, City, Country">
                                @error('address')
                                    <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                                @enderror
                            </div>
                        </div>
                    </div>

                    <!-- Submit -->
                    <button type="submit" 
                        class="w-full bg-primary-600 text-white py-3 rounded-lg font-semibold hover:bg-primary-700 btn-hover transition duration-200">
                        Create Account
                    </button>
                </form>

                <!-- Social Login -->
                @php
                    $googleEnabled = \App\Models\Setting::get('google_enabled') && \App\Models\Setting::get('google_client_id');
                    $facebookEnabled = \App\Models\Setting::get('facebook_enabled') && \App\Models\Setting::get('facebook_client_id');
                    $githubEnabled = \App\Models\Setting::get('github_enabled') && \App\Models\Setting::get('github_client_id');
                    $anySocialEnabled = $googleEnabled || $facebookEnabled || $githubEnabled;
                @endphp

                @if($anySocialEnabled)
                <div class="mt-6">
                    <div class="relative">
                        <div class="absolute inset-0 flex items-center">
                            <div class="w-full border-t border-gray-300"></div>
                        </div>
                        <div class="relative flex justify-center text-sm">
                            <span class="px-2 bg-white text-gray-500">Or sign up with</span>
                        </div>
                    </div>

                    <div class="mt-6 grid grid-cols-3 gap-3">
                        @if($googleEnabled)
                        <a href="{{ route('social.login', 'google') }}" 
                            class="flex items-center justify-center px-4 py-2 border border-gray-300 rounded-lg hover:bg-gray-50 transition">
                            <i class="fab fa-google text-red-500"></i>
                        </a>
                        @endif
                        
                        @if($facebookEnabled)
                        <a href="{{ route('social.login', 'facebook') }}" 
                            class="flex items-center justify-center px-4 py-2 border border-gray-300 rounded-lg hover:bg-gray-50 transition">
                            <i class="fab fa-facebook text-blue-600"></i>
                        </a>
                        @endif
                        
                        @if($githubEnabled)
                        <a href="{{ route('social.login', 'github') }}" 
                            class="flex items-center justify-center px-4 py-2 border border-gray-300 rounded-lg hover:bg-gray-50 transition">
                            <i class="fab fa-github text-gray-800"></i>
                        </a>
                        @endif
                    </div>
                </div>
                @endif

                <p class="mt-6 text-center text-sm text-gray-600">
                    Already have an account?
                    <a href="{{ route('login') }}" class="font-medium text-primary-600 hover:text-primary-700">
                        Sign in
                    </a>
                </p>
            </div>
        </div>
    </div>

    <!-- Right Side - Image/Branding -->
    <div class="hidden lg:flex lg:w-1/2 gradient-bg items-center justify-center relative overflow-hidden">
        <div class="absolute inset-0 opacity-10">
            <svg class="w-full h-full" viewBox="0 0 100 100" preserveAspectRatio="none">
                <path d="M0,50 Q25,30 50,50 T100,50 L100,100 L0,100 Z" fill="white">
                    <animate attributeName="d" 
                        values="M0,50 Q25,30 50,50 T100,50 L100,100 L0,100 Z;
                                M0,50 Q25,70 50,50 T100,50 L100,100 L0,100 Z;
                                M0,50 Q25,30 50,50 T100,50 L100,100 L0,100 Z"
                        dur="10s" repeatCount="indefinite"/>
                </path>
            </svg>
        </div>
        
        <div class="text-center text-white z-10 px-8">
            <div class="mb-6">
                <i class="fas fa-globe text-6xl mb-4"></i>
            </div>
            <h1 class="text-4xl font-bold mb-4">Join Our Community!</h1>
            <p class="text-xl opacity-90 mb-8">Connect with millions of people worldwide.</p>
            
            <div class="flex gap-4 justify-center">
                <div class="text-center">
                    <p class="text-3xl font-bold">10M+</p>
                    <p class="text-sm opacity-80">Active Users</p>
                </div>
                <div class="w-px bg-white/30"></div>
                <div class="text-center">
                    <p class="text-3xl font-bold">50M+</p>
                    <p class="text-sm opacity-80">Posts Shared</p>
                </div>
            </div>
        </div>
    </div>
</div>

@push('scripts')
<script>
    function toggleVendorFields() {
        const accountType = document.querySelector('input[name="account_type"]:checked').value;
        const vendorFields = document.getElementById('vendor-fields');
        const vendorInputs = vendorFields.querySelectorAll('input, textarea');
        
        if (accountType === 'vendor') {
            vendorFields.classList.remove('hidden');
            vendorInputs.forEach(input => {
                input.setAttribute('required', 'required');
            });
        } else {
            vendorFields.classList.add('hidden');
            vendorInputs.forEach(input => {
                input.removeAttribute('required');
            });
        }
    }
    
    // Initialize on page load
    document.addEventListener('DOMContentLoaded', toggleVendorFields);
</script>
@endpush

@endsection
