<x-layouts.admin title="Transfer #{{ $transfer->id }} | Admin Suite" activePage="admin-transfers">
<div class="space-y-8 w-full">
    <div class="flex items-center gap-4">
        <a href="{{ route('admin.transfers.index') }}" class="material-symbols-outlined text-on-surface-variant hover:text-primary transition-colors">arrow_back</a>
        <div>
            <h2 class="font-serif text-3xl text-on-surface">Transfer #{{ $transfer->id }}</h2>
            <p class="text-on-surface-variant text-sm mt-1">Review transfer request details.</p>
        </div>
    </div>

    <!-- Status Badge -->
    <div class="flex items-center gap-3">
        <span class="inline-flex items-center px-4 py-2 rounded-full text-xs font-bold uppercase tracking-wider
            @if($transfer->status->value === 'approved') bg-secondary-container text-secondary
            @elseif($transfer->status->value === 'pending') bg-surface-container-highest text-on-surface-variant
            @elseif($transfer->status->value === 'rejected') bg-error-container text-on-error-container
            @endif
        ">
            <span class="material-symbols-outlined text-sm mr-1">
                @if($transfer->status->value === 'approved') check_circle
                @elseif($transfer->status->value === 'pending') schedule
                @else cancel
                @endif
            </span>
            {{ ucfirst($transfer->status->value) }}
        </span>
        <span class="text-xs text-on-surface-variant">{{ $transfer->created_at->format('M d, Y \a\t h:i A') }}</span>
    </div>

    <!-- Transfer Details -->
    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
        <!-- Sender Info -->
        <div class="bg-surface-container-lowest p-6 space-y-4">
            <h3 class="text-xs font-label font-bold uppercase tracking-widest text-on-surface-variant flex items-center gap-2">
                <span class="material-symbols-outlined text-sm">person</span> Sender
            </h3>
            <div class="space-y-3">
                <div class="flex justify-between">
                    <span class="text-xs text-on-surface-variant">Name</span>
                    <span class="text-sm font-semibold">{{ $transfer->fromAccount?->user?->first_name }} {{ $transfer->fromAccount?->user?->last_name }}</span>
                </div>
                <div class="flex justify-between">
                    <span class="text-xs text-on-surface-variant">Account</span>
                    <span class="text-sm font-mono">{{ $transfer->fromAccount?->account_number }}</span>
                </div>
                <div class="flex justify-between">
                    <span class="text-xs text-on-surface-variant">Email</span>
                    <span class="text-sm">{{ $transfer->fromAccount?->user?->email }}</span>
                </div>
            </div>
        </div>

        <!-- Recipient Info -->
        <div class="bg-surface-container-lowest p-6 space-y-4">
            <h3 class="text-xs font-label font-bold uppercase tracking-widest text-on-surface-variant flex items-center gap-2">
                <span class="material-symbols-outlined text-sm">send</span> Recipient
            </h3>
            <div class="space-y-3">
                @if($transfer->toAccount)
                    <div class="flex justify-between">
                        <span class="text-xs text-on-surface-variant">Name</span>
                        <span class="text-sm font-semibold">{{ $transfer->toAccount->user?->first_name }} {{ $transfer->toAccount->user?->last_name }}</span>
                    </div>
                    <div class="flex justify-between">
                        <span class="text-xs text-on-surface-variant">Account</span>
                        <span class="text-sm font-mono">{{ $transfer->toAccount->account_number }}</span>
                    </div>
                @elseif($transfer->recipient_details)
                    @foreach($transfer->recipient_details as $key => $value)
                        @if($value)
                        <div class="flex justify-between">
                            <span class="text-xs text-on-surface-variant capitalize">{{ str_replace('_', ' ', $key) }}</span>
                            <span class="text-sm font-semibold">{{ $value }}</span>
                        </div>
                        @endif
                    @endforeach
                @endif
            </div>
        </div>
    </div>

    <!-- Financial Details -->
    <div class="bg-surface-container-lowest p-6 space-y-4">
        <h3 class="text-xs font-label font-bold uppercase tracking-widest text-on-surface-variant flex items-center gap-2">
            <span class="material-symbols-outlined text-sm">payments</span> Financial Details
        </h3>
        <div class="grid grid-cols-2 md:grid-cols-4 gap-6">
            <div>
                <p class="text-xs text-on-surface-variant mb-1">Transfer Type</p>
                <p class="text-sm font-semibold capitalize">{{ $transfer->type->label() }}</p>
            </div>
            <div>
                <p class="text-xs text-on-surface-variant mb-1">Amount</p>
                <p class="text-lg font-serif font-bold">{{ $transfer->currency }} {{ number_format($transfer->amount, 2) }}</p>
            </div>
            <div>
                <p class="text-xs text-on-surface-variant mb-1">Fee</p>
                <p class="text-sm font-semibold">{{ $transfer->fee > 0 ? $transfer->currency . ' ' . number_format($transfer->fee, 2) : 'None' }}</p>
            </div>
            <div>
                <p class="text-xs text-on-surface-variant mb-1">Total Debited</p>
                <p class="text-sm font-semibold">{{ $transfer->currency }} {{ number_format($transfer->amount + $transfer->fee, 2) }}</p>
            </div>
        </div>
        @if($transfer->description)
        <div class="pt-4 border-t border-surface-container">
            <p class="text-xs text-on-surface-variant mb-1">Description</p>
            <p class="text-sm">{{ $transfer->description }}</p>
        </div>
        @endif
    </div>

    <!-- Approve/Reject Actions (only for pending) -->
    @if($transfer->status === \App\Enums\RequestStatus::Pending)
    <div class="bg-surface-container-lowest p-6 space-y-6">
        <h3 class="text-xs font-label font-bold uppercase tracking-widest text-on-surface-variant flex items-center gap-2">
            <span class="material-symbols-outlined text-sm">gavel</span> Actions
        </h3>
        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <!-- Approve -->
            <form method="POST" action="{{ route('admin.transfers.approve', $transfer) }}" class="bg-green-50/50 border border-green-200 rounded-lg p-5 space-y-4">
                @csrf
                <div class="flex items-center gap-2">
                    <span class="material-symbols-outlined text-green-700">check_circle</span>
                    <span class="font-semibold text-green-800 text-sm">Approve Transfer</span>
                </div>
                <label class="flex items-center gap-3 cursor-pointer">
                    <input type="checkbox" name="notify_user" value="1" class="rounded border-green-300 text-green-600 focus:ring-green-500">
                    <span class="text-sm text-green-800">Send email notification to user</span>
                </label>
                <button type="submit" class="w-full py-2.5 bg-green-600 text-white text-sm font-label font-medium rounded-md hover:bg-green-700 transition-colors">
                    Approve
                </button>
            </form>

            <!-- Reject -->
            <form method="POST" action="{{ route('admin.transfers.reject', $transfer) }}" class="bg-red-50/50 border border-red-200 rounded-lg p-5 space-y-4">
                @csrf
                <div class="flex items-center gap-2">
                    <span class="material-symbols-outlined text-red-700">cancel</span>
                    <span class="font-semibold text-red-800 text-sm">Reject Transfer</span>
                </div>
                <label class="flex items-center gap-3 cursor-pointer">
                    <input type="checkbox" name="notify_user" value="1" class="rounded border-red-300 text-red-600 focus:ring-red-500">
                    <span class="text-sm text-red-800">Send email notification to user</span>
                </label>
                <button type="submit" class="w-full py-2.5 bg-red-600 text-white text-sm font-label font-medium rounded-md hover:bg-red-700 transition-colors">
                    Reject & Refund
                </button>
            </form>
        </div>
    </div>
    @endif
</div>
</x-layouts.admin>
