<x-site-layout title="Become a Member">

    {{-- Hero --}}
    <section class="relative bg-gradient-to-r from-green-600 to-emerald-700 py-16">
        <div class="absolute inset-0 bg-black opacity-10"></div>
        <div class="relative max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
            <span class="inline-block px-4 py-1 bg-white bg-opacity-20 rounded-full text-white text-sm font-medium mb-4">
                <i class="fas fa-id-card mr-1"></i> Membership Registration
            </span>
            <h1 class="text-4xl md:text-5xl font-bold text-white mb-4">Become a Member</h1>
            <p class="text-green-100 text-lg max-w-5xl mx-auto">
                Join SSHIA and gain access to exclusive resources, networking opportunities, and professional development programmes tailored for health professionals.
            </p>
            <div class="flex flex-wrap justify-center gap-6 mt-8 text-sm text-green-100">
                <span><i class="fas fa-check-circle mr-1"></i> Professional Network</span>
                <span><i class="fas fa-check-circle mr-1"></i> Exclusive Resources</span>
                <span><i class="fas fa-check-circle mr-1"></i> Training Access</span>
                <span><i class="fas fa-check-circle mr-1"></i> Advocacy Support</span>
            </div>
        </div>
    </section>

    {{-- Breadcrumb --}}
    <div class="bg-gray-50 border-b border-gray-200">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-3">
            <nav class="flex items-center space-x-2 text-sm text-gray-600" aria-label="Breadcrumb">
                <a href="{{ url('/') }}" class="hover:text-green-600 transition flex items-center">
                    <i class="fas fa-home mr-1"></i>Home
                </a>
                <i class="fas fa-chevron-right text-gray-400 text-xs"></i>
                <span class="text-gray-500">Register</span>
                <i class="fas fa-chevron-right text-gray-400 text-xs"></i>
                <span class="text-gray-900 font-medium">Become a Member</span>
            </nav>
        </div>
    </div>

    {{-- Notice Banner --}}
    <div class="bg-amber-50 border-b border-amber-200">
        <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-3 flex items-center gap-2 text-sm text-amber-800">
            <i class="fas fa-info-circle text-amber-500"></i>
            Applications are reviewed within <strong>3–5 business days</strong>. You will receive an email notification once a decision is made.
        </div>
    </div>

    {{-- Form --}}
    <section class="py-12 bg-gray-50">
        <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">

            @if(session('error'))
                <div class="mb-6 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-xl flex items-center gap-2">
                    <i class="fas fa-exclamation-circle"></i> {{ session('error') }}
                </div>
            @endif

            @if($errors->any())
                <div class="mb-6 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-xl">
                    <p class="font-medium flex items-center gap-2"><i class="fas fa-exclamation-triangle"></i> Please fix the errors below.</p>
                </div>
            @endif

            <form action="{{ route('register.role.member.store') }}" method="POST" class="space-y-6">
                @csrf

                {{-- Personal Information --}}
                <div class="bg-white rounded-2xl shadow-sm overflow-hidden">
                    <div class="bg-gray-50 px-6 py-4 border-b border-gray-100">
                        <h2 class="text-base font-semibold text-gray-900 flex items-center gap-2">
                            <i class="fas fa-user text-green-600"></i> Personal Information
                        </h2>
                    </div>
                    <div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-5">
                        <div>
                            <label for="first_name" class="block text-sm font-medium text-gray-700 mb-1">First Name <span class="text-red-500">*</span></label>
                            <input type="text" id="first_name" name="first_name" value="{{ old('first_name') }}"
                                   class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                                   placeholder="First name" required>
                            @error('first_name')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                        </div>
                        <div>
                            <label for="last_name" class="block text-sm font-medium text-gray-700 mb-1">Last Name <span class="text-red-500">*</span></label>
                            <input type="text" id="last_name" name="last_name" value="{{ old('last_name') }}"
                                   class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                                   placeholder="Last name" required>
                            @error('last_name')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                        </div>
                        <div>
                            <label for="email" class="block text-sm font-medium text-gray-700 mb-1">Email Address <span class="text-red-500">*</span></label>
                            <input type="email" id="email" name="email" value="{{ old('email') }}"
                                   class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                                   placeholder="your@email.com" required>
                            @error('email')<p class="mt-1 text-sm text-red-600">{!! $message !!}</p>@enderror
                        </div>
                        <div>
                            <label for="phone" class="block text-sm font-medium text-gray-700 mb-1">Phone Number <span class="text-red-500">*</span></label>
                            <input type="tel" id="phone" name="phone" value="{{ old('phone') }}"
                                   class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                                   placeholder="+256 7XX XXX XXX" required>
                            @error('phone')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                        </div>
                    </div>
                </div>

                {{-- Membership Category --}}
                <div class="bg-white rounded-2xl shadow-sm overflow-hidden" x-data="{ selectedFee: '' }">
                    <div class="bg-gray-50 px-6 py-4 border-b border-gray-100">
                        <h2 class="text-base font-semibold text-gray-900 flex items-center gap-2">
                            <i class="fas fa-id-card text-green-600"></i> Membership Category
                        </h2>
                    </div>
                    <div class="p-6">
                        <label for="membership_category_id" class="block text-sm font-medium text-gray-700 mb-2">
                            Select Category <span class="text-red-500">*</span>
                        </label>
                        <select id="membership_category_id" name="membership_category_id"
                                class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                                @change="selectedFee = $event.target.options[$event.target.selectedIndex].dataset.fee"
                                required>
                            <option value="">-- Select a Membership Category --</option>
                            @foreach($categories as $category)
                                @php $fee = $category->activeSubscriptionFee(); @endphp
                                <option value="{{ $category->id }}"
                                        data-fee="{{ $fee ? $fee->amount . ' ' . $fee->currency : '' }}"
                                        {{ old('membership_category_id') == $category->id ? 'selected' : '' }}>
                                    {{ $category->name }}
                                    @if($fee) — {{ $fee->formatted_amount ?? $fee->amount . ' ' . $fee->currency }} @endif
                                </option>
                            @endforeach
                        </select>
                        @error('membership_category_id')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                        <div x-show="selectedFee" class="mt-3 bg-amber-50 border border-amber-200 rounded-lg px-4 py-3 text-sm text-amber-800">
                            <i class="fas fa-credit-card mr-1"></i>
                            Payment of <strong x-text="selectedFee"></strong> will be required upon approval.
                        </div>
                    </div>
                </div>

                {{-- Address --}}
                <div class="bg-white rounded-2xl shadow-sm overflow-hidden">
                    <div class="bg-gray-50 px-6 py-4 border-b border-gray-100">
                        <h2 class="text-base font-semibold text-gray-900 flex items-center gap-2">
                            <i class="fas fa-map-marker-alt text-green-600"></i> Address
                        </h2>
                    </div>
                    <div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-5">
                        <div class="md:col-span-2">
                            <label for="address" class="block text-sm font-medium text-gray-700 mb-1">Street Address</label>
                            <input type="text" id="address" name="address" value="{{ old('address') }}"
                                   class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                                   placeholder="Street address">
                        </div>
                        <div>
                            <label for="city" class="block text-sm font-medium text-gray-700 mb-1">City</label>
                            <input type="text" id="city" name="city" value="{{ old('city') }}"
                                   class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                                   placeholder="City">
                        </div>
                        <div>
                            <label for="country" class="block text-sm font-medium text-gray-700 mb-1">Country</label>
                            <input type="text" id="country" name="country" value="{{ old('country') }}"
                                   class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                                   placeholder="Country">
                        </div>
                    </div>
                </div>

                {{-- Professional Information --}}
                <div class="bg-white rounded-2xl shadow-sm overflow-hidden">
                    <div class="bg-gray-50 px-6 py-4 border-b border-gray-100">
                        <h2 class="text-base font-semibold text-gray-900 flex items-center gap-2">
                            <i class="fas fa-briefcase text-green-600"></i> Professional Information
                        </h2>
                    </div>
                    <div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-5">
                        <div>
                            <label for="occupation" class="block text-sm font-medium text-gray-700 mb-1">Occupation</label>
                            <input type="text" id="occupation" name="occupation" value="{{ old('occupation') }}"
                                   class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                                   placeholder="Your occupation">
                        </div>
                        <div>
                            <label for="organization" class="block text-sm font-medium text-gray-700 mb-1">Organization</label>
                            <input type="text" id="organization" name="organization" value="{{ old('organization') }}"
                                   class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                                   placeholder="Your organization">
                        </div>
                        <div class="md:col-span-2">
                            <label for="professional_background" class="block text-sm font-medium text-gray-700 mb-1">Professional Background</label>
                            <textarea id="professional_background" name="professional_background" rows="4"
                                      class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                                      placeholder="Briefly describe your professional background...">{{ old('professional_background') }}</textarea>
                        </div>
                    </div>
                </div>

                {{-- Account Security --}}
                <div class="bg-white rounded-2xl shadow-sm overflow-hidden">
                    <div class="bg-gray-50 px-6 py-4 border-b border-gray-100">
                        <h2 class="text-base font-semibold text-gray-900 flex items-center gap-2">
                            <i class="fas fa-lock text-green-600"></i> Account Security
                        </h2>
                    </div>
                    <div class="p-6">
                        @include('registration._partials.password-fields', ['color' => 'green'])
                    </div>
                </div>

                {{-- Terms --}}
                <div class="bg-white rounded-2xl shadow-sm p-6">
                    <label class="flex items-start gap-3 cursor-pointer">
                        <input type="checkbox" name="terms_accepted" value="1"
                               class="mt-1 h-4 w-4 text-green-600 border-gray-300 rounded focus:ring-green-500"
                               {{ old('terms_accepted') ? 'checked' : '' }} required>
                        <span class="text-sm text-gray-600">
                            I agree to the <a href="{{ route('pages.terms') }}" class="text-green-600 hover:underline" target="_blank">Terms and Conditions</a>
                            and <a href="{{ route('pages.privacy') }}" class="text-green-600 hover:underline" target="_blank">Privacy Policy</a>.
                            I understand my membership is subject to approval. <span class="text-red-500">*</span>
                        </span>
                    </label>
                    @error('terms_accepted')<p class="mt-2 text-sm text-red-600">{{ $message }}</p>@enderror
                </div>

                @include('registration._partials.bottom-nav', ['color' => 'green', 'submitLabel' => 'Submit Membership Application'])
            </form>
        </div>
    </section>

</x-site-layout>
