@extends('layouts.app')

@section('title', 'Register')

@section('content')
<!-- Page Header -->
<section class="bg-gray-100 py-16">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        <h1 class="text-3xl md:text-4xl font-bold text-gray-900">Conference Registration</h1>
        <p class="text-gray-600 mt-2">Register for the 72nd TEFLIN International Conference</p>
    </div>
</section>

<section class="py-12">
    <div class="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8">
        <div class="bg-white rounded-xl shadow-sm p-6 lg:p-8">
            @if(session('error'))
            <div class="mb-6 p-4 bg-red-50 border border-red-200 text-red-700 rounded-lg">
                {{ session('error') }}
            </div>
            @endif

            @if($errors->any())
            <div class="mb-6 p-4 bg-red-50 border border-red-200 text-red-700 rounded-lg">
                <ul class="list-disc list-inside space-y-1">
                    @foreach($errors->all() as $error)
                    <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
            @endif

            <form action="{{ route('registration.store') }}" method="POST" enctype="multipart/form-data" class="space-y-6">
                @csrf
                
                <div class="border-b pb-6">
                    <h2 class="text-lg font-semibold text-gray-900 mb-4">Personal Information</h2>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Full Name *</label>
                            <input type="text" name="name" value="{{ old('name') }}" required class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Email *</label>
                            <input type="email" name="email" value="{{ old('email') }}" required class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Phone</label>
                            <input type="text" name="phone" value="{{ old('phone') }}" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Institution *</label>
                            <input type="text" name="institution" value="{{ old('institution') }}" required class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Country</label>
                            <input type="text" name="country" value="{{ old('country') }}" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
                        </div>
                    </div>
                </div>

                <div class="border-b pb-6">
                    <h2 class="text-lg font-semibold text-gray-900 mb-4">Registration Category</h2>
                    <div class="space-y-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Select Category *</label>
                            <select name="category" x-ref="categorySelect" required class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-teflin-blue focus:border-teflin-blue">
                                <option value="">Select your category</option>
                                <option value="general_presenter" {{ old('category') === 'general_presenter' ? 'selected' : '' }}>General presenters - IDR 1,400,000</option>
                                <option value="teflin_member_presenter" {{ old('category') === 'teflin_member_presenter' ? 'selected' : '' }}>TEFLIN member presenters - IDR 1,350,000</option>
                                <option value="teacher_student_presenter" {{ old('category') === 'teacher_student_presenter' ? 'selected' : '' }}>Teacher/student presenters - IDR 1,000,000</option>
                                <option value="participant" {{ old('category') === 'participant' ? 'selected' : '' }}>Participants (non-presenters) - IDR 1,000,000</option>
                                <option value="international" {{ old('category') === 'international' ? 'selected' : '' }}>International Participants & Presenters - USD 130</option>
                            </select>
                        </div>
                        
                        <div x-show="isPresenter" x-transition>
                            <label class="block text-sm font-medium text-gray-700 mb-1">
                                Presentation Type *
                            </label>
                            <select name="presentation_type" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-teflin-blue focus:border-teflin-blue">
                                <option value="">Select presentation type</option>
                                <option value="paper_presentation" {{ old('presentation_type') === 'paper_presentation' ? 'selected' : '' }}>Paper Presentation</option>
                                <option value="poster_presentation" {{ old('presentation_type') === 'poster_presentation' ? 'selected' : '' }}>Poster Presentation</option>
                            </select>
                            <p class="text-xs text-gray-500 mt-1">Please select how you will present at the conference.</p>
                        </div>
                    </div>
                </div>

                <div class="border-b pb-6" x-data="{ isPresenter: false }" x-init="$watch('$refs.categorySelect.value', val => isPresenter = val.toLowerCase().includes('presenter'))">
                    <h2 class="text-lg font-semibold text-gray-900 mb-4">
                        Acceptance Code
                        <span x-show="isPresenter" class="text-red-500 text-sm font-normal">(Required for Presenters)</span>
                    </h2>
                    <div class="bg-amber-50 border-l-4 border-amber-400 p-4 mb-4">
                        <div class="flex">
                            <svg class="w-5 h-5 text-amber-400 mr-2 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>
                            <p class="text-sm text-amber-700">
                                <strong>Presenters:</strong> You must enter the registration code sent to your email after your abstract was accepted. The email used for registration must match your submission email.
                            </p>
                        </div>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">
                            Registration Code from Acceptance Email
                            <span x-show="isPresenter" class="text-red-500">*</span>
                        </label>
                        <input type="text" name="registration_code_input" value="{{ old('registration_code_input') }}" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500" placeholder="REG-XXXXXXXX">
                        <p class="text-xs text-gray-500 mt-1">Non-presenters can leave this field empty.</p>
                    </div>
                </div>

                <div>
                    <h2 class="text-lg font-semibold text-gray-900 mb-4">Payment Proof (Optional)</h2>
                    <p class="text-sm text-gray-500 mb-4">You can upload your payment proof now or later.</p>
                    <div class="border-2 border-dashed border-gray-300 rounded-lg p-6 text-center" id="payment-upload-area">
                        <input type="file" name="payment_proof" accept=".jpg,.jpeg,.png,.pdf" class="hidden" id="payment_proof" onchange="updatePaymentFileName(this)">
                        <label for="payment_proof" class="cursor-pointer block">
                            <svg class="w-12 h-12 text-gray-400 mx-auto mb-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/></svg>
                            <p class="text-gray-600" id="payment-upload-text">Click to upload payment proof</p>
                            <p class="text-sm text-gray-500">JPG, PNG, PDF (Max 5MB)</p>
                        </label>
                        <div id="payment-name-display" class="hidden mt-3 text-sm text-green-600 font-medium"></div>
                    </div>
                </div>

                <script>
                function updatePaymentFileName(input) {
                    const fileNameDisplay = document.getElementById('payment-name-display');
                    const uploadText = document.getElementById('payment-upload-text');
                    const uploadArea = document.getElementById('payment-upload-area');
                    
                    if (input.files && input.files[0]) {
                        const fileName = input.files[0].name;
                        const fileSize = (input.files[0].size / 1024 / 1024).toFixed(2);
                        
                        fileNameDisplay.innerHTML = `✓ Selected: ${fileName} (${fileSize} MB)`;
                        fileNameDisplay.classList.remove('hidden');
                        uploadText.textContent = 'File selected - Click to change';
                        uploadArea.classList.add('border-green-500', 'bg-green-50');
                        uploadArea.classList.remove('border-gray-300');
                    }
                }
                </script>

                <div class="flex items-start gap-3 p-4 bg-gray-50 rounded-lg">
                    <input type="checkbox" required class="mt-1 h-4 w-4 text-primary-600 border-gray-300 rounded focus:ring-primary-500">
                    <p class="text-sm text-gray-600">I agree to the conference terms and conditions and confirm that all information provided is accurate.</p>
                </div>

                <button type="submit" class="w-full py-3 bg-teflin-blue text-white font-semibold rounded-lg hover:bg-teflin-blue-dark transition">
                    Complete Registration
                </button>
            </form>
        </div>
    </div>
</section>
@endsection
