<x-admin-app-layout>
    <div class="white-box">
        <x-admin::page-header title="{{ __('KYC Verify') }}" :buttons="$buttons" :isFilterable="false" />
        <div class="">
            {{-- User Information Card --}}
            <div class="mb-8 border border-gray-200 rounded-lg shadow-sm">
                <div class="border-b border-gray-200 px-6 py-4">
                    <h2 class="text-xl font-semibold flex items-center">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20"
                            fill="currentColor">
                            <path fill-rule="evenodd"
                                d="M4 4a2 2 0 012-2h8a2 2 0 012 2v12a2 2 0 01-2 2H6a2 2 0 01-2-2V4zm2-1h8a1 1 0 011 1v12a1 1 0 01-1 1H6a1 1 0 01-1-1V4a1 1 0 011-1z"
                                clip-rule="evenodd" />
                        </svg>
                        {{ __('User Information') }}
                    </h2>
                </div>

                <div class="p-6">
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="space-y-4">
                            <div>
                                <label class="text-sm font-medium text-gray-500">{{ __('City') }}</label>
                                <p class="mt-1 text-lg font-medium">{{ $user->city }}</p>
                            </div>
                            <div>
                                <label class="text-sm font-medium text-gray-500">{{ __('State') }}</label>
                                <p class="mt-1 text-lg font-medium flex items-center">
                                    <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-2 text-gray-400"
                                        viewBox="0 0 20 20" fill="currentColor">
                                        <path
                                            d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884z" />
                                        <path d="M18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z" />
                                    </svg>
                                    {{ $user->state }} {{ $user->zip_code }}
                                </p>
                            </div>
                        </div>

                        <div class="space-y-4">
                            <div>
                                <label class="text-sm font-medium text-gray-500">{{ __('Address') }}</label>
                                <p class="mt-1 text-lg font-medium">
                                    {{ $user->address }}
                                </p>
                            </div>
                            <div>
                                <label class="text-sm font-medium text-gray-500">{{ __('Country') }}</label>
                                <p class="mt-1 text-lg font-medium">{{ $user->country }}</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            {{-- KYC Details Card --}}
            <div class="border border-gray-200 rounded-lg shadow-sm">
                <div class="border-b border-gray-200 px-6 py-4">
                    <h2 class="text-xl font-semibold">{{ __('KYC Details') }}</h2>
                </div>

                <div class="p-6">
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        @foreach ($user->kyc->forms as $form)
                            @switch($form->kycForm->field_type)
                                @case('file')
                                    <div class="border border-gray-200 rounded-lg p-4">
                                        <label class="text-sm font-medium text-gray-500">
                                            {{ $form->kycForm->label }}
                                        </label>
                                        <div class="mt-2">
                                            @php
                                                $fileExtension = pathinfo($form->value, PATHINFO_EXTENSION);
                                                $isPdf = strtolower($fileExtension) === 'pdf';
                                            @endphp

                                            <div class="mt-2 flex items-center space-x-4">
                                                @if ($isPdf)
                                                    <div class="flex items-center">
                                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-red-500"
                                                            fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                            <path stroke-linecap="round" stroke-linejoin="round"
                                                                stroke-width="2"
                                                                d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z" />
                                                        </svg>
                                                    </div>
                                                @else
                                                    <div class="flex items-center">
                                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-gray-400"
                                                            fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                            <path stroke-linecap="round" stroke-linejoin="round"
                                                                stroke-width="2"
                                                                d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z" />
                                                        </svg>
                                                    </div>
                                                @endif

                                                <div class="flex flex-col">
                                                    <span class="text-sm font-medium text-gray-900">
                                                        {{ basename($form->value) }}
                                                    </span>
                                                    <span class="text-xs text-gray-500 uppercase">
                                                        {{ $fileExtension }}
                                                    </span>
                                                    <a href="{{ asset($form->value) }}" target="_blank"
                                                        class="mt-1 text-sm text-blue-600 hover:text-blue-800">
                                                        {{ __('View File') }}
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                @break

                                @case('image')
                                    @php
                                        $fileExtension = pathinfo($form->value, PATHINFO_EXTENSION);
                                    @endphp
                                    <div class="border border-gray-200 rounded-lg p-4">
                                        <label class="text-sm font-medium text-gray-500">
                                            {{ $form->kycForm->label }}
                                        </label>
                                        <div class="mt-2">
                                            <div class="mt-2 flex items-center space-x-4">
                                                <div class="relative group">
                                                    <img src="{{ asset($form->value) }}" alt="Document Preview"
                                                        class="h-20 w-20 object-cover rounded-lg cursor-pointer hover:opacity-75 transition-opacity">
                                                    <div
                                                        class="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
                                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 text-white"
                                                            fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                            <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>
                                                    </div>
                                                </div>

                                                <div class="flex flex-col">
                                                    <span class="text-sm font-medium text-gray-900">
                                                        {{ basename($form->value) }}
                                                    </span>
                                                    <span class="text-xs text-gray-500 uppercase">
                                                        {{ $fileExtension }}
                                                    </span>
                                                    <a href="{{ asset($form->value) }}" target="_blank"
                                                        class="mt-1 text-sm text-blue-600 hover:text-blue-800">
                                                        {{ __('View File') }}
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                @break

                                @case('text')
                                @case('textarea')

                                @case('select')
                                    <div class="border border-gray-200 rounded-lg p-4">
                                        <label class="text-sm font-medium text-gray-500">
                                            {{ $form->kycForm->label }}
                                        </label>
                                        <p class="mt-2 text-lg">
                                            {{ $form->value }}
                                        </p>
                                    </div>
                                @break

                                @default
                                @break
                            @endswitch
                        @endforeach
                    </div>
                </div>
            </div>

            {{-- Action Buttons --}}
            @if (!$user->is_kyc_verified && $user->kyc->status == \App\Enums\KycStatusEnum::PENDING)
                <div class="mt-6 flex justify-end space-x-4">
                    <x-admin::primary-button :href="route('admin.users.kyc.verify.accept', $user->id)">
                        {{ __('Accept') }}
                    </x-admin::primary-button>
                    <x-admin::danger-button :href="route('admin.users.kyc.verify.reject', $user->id)">
                        {{ __('Reject') }}
                    </x-admin::danger-button>
                </div>
            @else
                <div class="mt-6 flex justify-end space-x-4">
                    @if ($user->is_kyc_verified)
                        <p class="text-green-600">{{ __('Verified') }}</p>
                    @else
                        <p class="text-red-600">{{ __('Rejected') }}</p>
                    @endif
                </div>
            @endif

        </div>
    </div>
</x-admin-app-layout>
