@extends('page.auth.layout')

@section('title', 'Kayıt Ol')

@section('content')
    <div class="space-y-6">
        <!-- Header -->
        <div class="text-center">
            <h2 class="text-3xl font-bold text-gray-900">
                Hoş Geldiniz
            </h2>
            <p class="mt-2 text-sm text-gray-600">
                Hesabınızı oluşturun ve keşfetmeye başlayın
            </p>
        </div>

        <!-- Success Message -->
        @if (session('success'))
            <div class="rounded-xl bg-green-50 p-4 border border-green-200">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <svg class="h-5 w-5 text-green-400" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd"
                                  d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
                                  clip-rule="evenodd"/>
                        </svg>
                    </div>
                    <div class="ml-3">
                        <p class="text-sm font-medium text-green-800">{{ session('success') }}</p>
                    </div>
                </div>
            </div>
        @endif

        <!-- Error Messages -->
        @if ($errors->any())
            <div class="rounded-xl bg-red-50 p-4 border border-red-200">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd"
                                  d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z"
                                  clip-rule="evenodd"/>
                        </svg>
                    </div>
                    <div class="ml-3">
                        <h3 class="text-sm font-medium text-red-800">Lütfen aşağıdaki hataları düzeltin:</h3>
                        <ul class="mt-2 text-sm text-red-700 space-y-1">
                            @foreach ($errors->all() as $error)
                                <li>• {{ $error }}</li>
                            @endforeach
                        </ul>
                    </div>
                </div>
            </div>
        @endif

        <!-- Registration Form -->
        <form action="{{ route('customer.register') }}" method="POST" class="space-y-5">
            @csrf

            <!-- Name Fields -->
            <div class="grid grid-cols-2 gap-4">
                <div class="space-y-1">
                    <label for="first_name" class="block text-sm font-medium text-gray-700">
                        Ad <span class="text-red-500">*</span>
                    </label>
                    <input id="first_name" name="first_name" type="text" required value="{{ old('first_name') }}"
                           class="input-focus appearance-none block w-full px-4 py-3 border border-gray-300 rounded-xl text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200 @error('first_name') border-red-500 @enderror"
                           placeholder="Adınız">
                </div>

                <div class="space-y-1">
                    <label for="last_name" class="block text-sm font-medium text-gray-700">
                        Soyad <span class="text-red-500">*</span>
                    </label>
                    <input id="last_name" name="last_name" type="text" required value="{{ old('last_name') }}"
                           class="input-focus appearance-none block w-full px-4 py-3 border border-gray-300 rounded-xl text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200 @error('last_name') border-red-500 @enderror"
                           placeholder="Soyadınız">
                </div>
            </div>

            <!-- Email -->
            <div class="space-y-1">
                <label for="email" class="block text-sm font-medium text-gray-700">
                    E-posta Adresi <span class="text-red-500">*</span>
                </label>
                <div class="relative">
                    <div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
                        <svg class="h-5 w-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M16 12a4 4 0 10-8 0 4 4 0 008 0zm0 0v1.5a2.5 2.5 0 005 0V12a9 9 0 10-9 9m4.5-1.206a8.959 8.959 0 01-4.5 1.207"/>
                        </svg>
                    </div>
                    <input id="email" name="email" type="email" autocomplete="email" required value="{{ old('email') }}"
                           class="input-focus appearance-none block w-full pl-12 pr-4 py-3 border border-gray-300 rounded-xl text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200 @error('email') border-red-500 @enderror"
                           placeholder="ornek@email.com">
                </div>
            </div>

            <!-- Phone -->
            <div class="space-y-1">
                <label for="phone" class="block text-sm font-medium text-gray-700">
                    Telefon Numarası <span class="text-red-500">*</span>
                </label>
                <div class="relative">
                    <div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
                        <svg class="h-5 w-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"/>
                        </svg>
                    </div>
                    <input id="phone" name="phone" type="tel" required value="{{ old('phone') }}"
                           class="input-focus appearance-none block w-full pl-12 pr-4 py-3 border border-gray-300 rounded-xl text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200 @error('phone') border-red-500 @enderror"
                           placeholder="5XX XXX XX XX">
                </div>
            </div>

            <!-- Optional Fields Toggle -->
            <div class="border-t border-gray-200 pt-4">
                <button type="button" onclick="toggleOptionalFields()"
                        class="flex items-center text-sm font-medium text-purple-600 hover:text-purple-700 transition-colors duration-200">
                    <svg id="optional-icon" class="w-5 h-5 mr-2 transform transition-transform duration-200" fill="none"
                         stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
                    </svg>
                    <span id="optional-text">İsteğe Bağlı Bilgiler</span>
                </button>
            </div>

            <!-- Optional Fields -->
            <div id="optional-fields" class="hidden space-y-5">
                <!-- National ID -->
                <div class="space-y-1">
                    <label for="national_id" class="block text-sm font-medium text-gray-700">TC Kimlik No</label>
                    <input id="national_id" name="national_id" type="text" maxlength="11"
                           value="{{ old('national_id') }}"
                           class="input-focus appearance-none block w-full px-4 py-3 border border-gray-300 rounded-xl text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200 @error('national_id') border-red-500 @enderror"
                           placeholder="XXXXXXXXXXX">
                </div>

                <!-- Birth Date & Gender -->
                <div class="grid grid-cols-2 gap-4">
                    <div class="space-y-1">
                        <label for="birth_date" class="block text-sm font-medium text-gray-700">Doğum Tarihi</label>
                        <input id="birth_date" name="birth_date" type="date" value="{{ old('birth_date') }}"
                               class="input-focus appearance-none block w-full px-4 py-3 border border-gray-300 rounded-xl text-gray-900 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200 @error('birth_date') border-red-500 @enderror">
                    </div>

                    <div class="space-y-1">
                        <label for="gender" class="block text-sm font-medium text-gray-700">Cinsiyet</label>
                        <select id="gender" name="gender"
                                class="input-focus appearance-none block w-full px-4 py-3 border border-gray-300 rounded-xl text-gray-900 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200 @error('gender') border-red-500 @enderror">
                            <option value="">Seçiniz</option>
                            <option value="male" {{ old('gender') == 'male' ? 'selected' : '' }}>Erkek</option>
                            <option value="female" {{ old('gender') == 'female' ? 'selected' : '' }}>Kadın</option>
                            <option value="other" {{ old('gender') == 'other' ? 'selected' : '' }}>Diğer</option>
                        </select>
                    </div>
                </div>

                <!-- City -->
                <div class="space-y-1">
                    <label for="city" class="block text-sm font-medium text-gray-700">Şehir</label>
                    <input id="city" name="city" type="text" value="{{ old('city') }}"
                           class="input-focus appearance-none block w-full px-4 py-3 border border-gray-300 rounded-xl text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200 @error('city') border-red-500 @enderror"
                           placeholder="İstanbul">
                </div>

                <!-- Address -->
                <div class="space-y-1">
                    <label for="address" class="block text-sm font-medium text-gray-700">Adres</label>
                    <textarea id="address" name="address" rows="3"
                              class="input-focus appearance-none block w-full px-4 py-3 border border-gray-300 rounded-xl text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200 @error('address') border-red-500 @enderror"
                              placeholder="Tam adresiniz">{{ old('address') }}</textarea>
                </div>
            </div>

            <!-- Password -->
            <div class="space-y-1">
                <label for="password" class="block text-sm font-medium text-gray-700">
                    Şifre <span class="text-red-500">*</span>
                </label>
                <div class="relative">
                    <input id="password" name="password" type="password" required
                           class="input-focus appearance-none block w-full px-4 py-3 pr-12 border border-gray-300 rounded-xl text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200 @error('password') border-red-500 @enderror"
                           placeholder="En az 8 karakter">
                    <button type="button" data-toggle-password="#password"
                            class="absolute inset-y-0 right-0 pr-4 flex items-center">
                        <svg class="h-5 w-5 text-gray-400 hover:text-gray-600 transition-colors duration-200"
                             fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
                        </svg>
                    </button>
                </div>
                <p class="text-xs text-gray-500 mt-1">Şifreniz en az 8 karakter içermelidir</p>
            </div>

            <!-- Password Confirmation -->
            <div class="space-y-1">
                <label for="password_confirmation" class="block text-sm font-medium text-gray-700">
                    Şifre Tekrar <span class="text-red-500">*</span>
                </label>
                <div class="relative">
                    <input id="password_confirmation" name="password_confirmation" type="password" required
                           class="input-focus appearance-none block w-full px-4 py-3 pr-12 border border-gray-300 rounded-xl text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200"
                           placeholder="Şifrenizi tekrar girin">
                    <button type="button" data-toggle-password="#password_confirmation"
                            class="absolute inset-y-0 right-0 pr-4 flex items-center">
                        <svg class="h-5 w-5 text-gray-400 hover:text-gray-600 transition-colors duration-200"
                             fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
                        </svg>
                    </button>
                </div>
            </div>

            <!-- Terms & Conditions -->
            <div class="flex items-start space-x-3 bg-gray-50 p-4 rounded-xl">
                <div class="flex items-center h-5 pt-1">
                    <input id="terms" name="terms" type="checkbox" required
                           class="w-4 h-4 text-purple-600 border-gray-300 rounded focus:ring-purple-500 focus:ring-2 transition-all duration-200 @error('terms') border-red-500 @enderror">
                </div>
                <label for="terms" class="text-sm text-gray-700 leading-relaxed">
                    <a href="#"
                       class="font-medium text-purple-600 hover:text-purple-700 transition-colors duration-200">Kullanım
                        koşullarını</a>,
                    <a href="#"
                       class="font-medium text-purple-600 hover:text-purple-700 transition-colors duration-200">gizlilik
                        politikasını</a> ve
                    <a href="#"
                       class="font-medium text-purple-600 hover:text-purple-700 transition-colors duration-200">KVKK
                        metnini</a> okudum ve kabul ediyorum.
                </label>
            </div>

            <!-- Submit Button -->
            <button type="submit"
                    class="btn-hover w-full flex justify-center items-center px-6 py-4 border border-transparent text-base font-medium rounded-xl text-white bg-gradient-to-r from-purple-600 to-indigo-600 hover:from-purple-700 hover:to-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 shadow-lg">
                <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                          d="M18 9v3m0 0v3m0-3h3m-3 0h-3m-2-5a4 4 0 11-8 0 4 4 0 018 0zM3 20a6 6 0 0112 0v1H3v-1z"/>
                </svg>
                Hesap Oluştur
            </button>
        </form>

        <!-- Login Link -->
        <div class="text-center pt-4 border-t border-gray-200">
            <p class="text-sm text-gray-600">
                Zaten hesabınız var mı?
                <a href="{{ route('customer.login') }}"
                   class="font-medium text-purple-600 hover:text-purple-700 transition-colors duration-200">
                    Giriş yapın
                </a>
            </p>
        </div>
    </div>

    @push('scripts')
        <script>
            function toggleOptionalFields() {
                const fields = document.getElementById('optional-fields');
                const icon = document.getElementById('optional-icon');
                const text = document.getElementById('optional-text');

                if (fields.classList.contains('hidden')) {
                    fields.classList.remove('hidden');
                    icon.style.transform = 'rotate(45deg)';
                    text.textContent = 'İsteğe Bağlı Bilgileri Gizle';
                } else {
                    fields.classList.add('hidden');
                    icon.style.transform = 'rotate(0deg)';
                    text.textContent = 'İsteğe Bağlı Bilgiler';
                }
            }
        </script>
    @endpush
@endsection
