@extends('layouts.dasht')
@section('content')
<div class="max-w-3xl mx-auto">
    <div class="mb-8">
        <h1 class="text-3xl font-bold text-gray-900 dark:text-white">Complete Payment</h1>
        <p class="mt-2 text-gray-600 dark:text-gray-400">Order #{{ $order->order_number }} — {{ $order->vipCard->name }}</p>
    </div>

    @if(session('success'))
    <div class="bg-green-50 dark:bg-green-900/30 border border-green-200 dark:border-green-800 rounded-lg p-4 mb-6">
        <p class="text-green-700 dark:text-green-400">{{ session('success') }}</p>
    </div>
    @endif

    @if(session('error'))
    <div class="bg-red-50 dark:bg-red-900/30 border border-red-200 dark:border-red-800 rounded-lg p-4 mb-6">
        <p class="text-red-700 dark:text-red-400">{{ session('error') }}</p>
    </div>
    @endif

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

    <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
        {{-- Left: Payment Info --}}
        <div class="space-y-6">
            <div class="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 p-6">
                <h2 class="text-lg font-bold text-gray-900 dark:text-white mb-4">Payment Details</h2>
                <div class="space-y-4">
                    <div>
                        <span class="text-sm text-gray-500 dark:text-gray-400">Payment Method</span>
                        <p class="font-medium text-gray-900 dark:text-white">{{ $payment_mode->name }}</p>
                    </div>
                    @if($payment_mode->wallet_address)
                    <div>
                        <span class="text-sm text-gray-500 dark:text-gray-400">
                            {{ $payment_mode->methodtype == 'crypto' ? 'Wallet Address' : 'Account Details' }}
                        </span>
                        <div class="mt-1 p-3 bg-gray-50 dark:bg-gray-700 rounded-lg break-all font-mono text-sm text-gray-900 dark:text-white">
                            {{ $payment_mode->wallet_address }}
                        </div>
                    </div>
                    @endif
                    <div>
                        <span class="text-sm text-gray-500 dark:text-gray-400">Amount to Pay</span>
                        <p class="text-2xl font-bold text-primary-500">${{ number_format($order->amount, 2) }}</p>
                    </div>
                </div>
            </div>

            {{-- Upload Payment Proof --}}
            <div class="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 p-6">
                <h2 class="text-lg font-bold text-gray-900 dark:text-white mb-4">Upload Payment Proof</h2>
                <p class="text-sm text-gray-500 dark:text-gray-400 mb-4">After making payment, upload a screenshot or receipt as proof.</p>

                @if($order->payment_proof)
                    <div class="mb-4 p-3 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg">
                        <p class="text-sm text-green-700 dark:text-green-400 flex items-center gap-2">
                            <i data-lucide="check-circle" class="w-4 h-4"></i>
                            Payment proof already uploaded.
                        </p>
                        <a href="{{ asset('dash/' . $order->payment_proof) }}" target="_blank" class="text-sm text-primary-500 hover:text-primary-600 mt-1 inline-block">View uploaded proof</a>
                    </div>
                @endif

                <form action="{{ route('vip-cards.save-proof', $order) }}" method="POST" enctype="multipart/form-data">
                    @csrf
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                            {{ $order->payment_proof ? 'Upload New Proof (replaces existing)' : 'Payment Proof *' }}
                        </label>
                        <input type="file" name="payment_proof" accept="image/*" required
                               class="w-full px-4 py-2.5 rounded-lg border border-gray-200 dark:border-gray-600 bg-gray-50 dark:bg-gray-700 text-gray-900 dark:text-white file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-medium file:bg-primary-50 file:text-primary-700 dark:file:bg-primary-900/30 dark:file:text-primary-400 hover:file:bg-primary-100">
                        <p class="text-xs text-gray-500 dark:text-gray-400 mt-1">JPG, PNG, GIF, WebP — Max 5MB</p>
                    </div>
                    <button type="submit" class="w-full px-6 py-3 bg-primary-500 hover:bg-primary-600 text-white rounded-xl font-medium transition-colors flex items-center justify-center gap-2">
                        <i data-lucide="upload" class="w-4 h-4"></i>
                        Upload Proof
                    </button>
                </form>
            </div>
        </div>

        {{-- Right: Order Summary --}}
        <div>
            <div class="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 p-6 sticky top-4">
                <h2 class="text-lg font-bold text-gray-900 dark:text-white mb-4">Order Summary</h2>

                @if($order->vipCard->card_image)
                    <img src="{{ asset('dash/' . $order->vipCard->card_image) }}" alt="{{ $order->vipCard->name }}"
                         class="w-full rounded-lg object-cover mb-4" style="max-height:160px;">
                @endif

                <h3 class="font-bold text-gray-900 dark:text-white">{{ $order->vipCard->name }}</h3>
                <p class="text-sm text-gray-500 dark:text-gray-400 mb-4">{{ $order->vipCard->duration_text }} membership</p>

                <div class="space-y-3 text-sm">
                    <div class="flex justify-between">
                        <span class="text-gray-500 dark:text-gray-400">Order Number</span>
                        <span class="font-medium text-gray-900 dark:text-white">{{ $order->order_number }}</span>
                    </div>
                    <div class="flex justify-between">
                        <span class="text-gray-500 dark:text-gray-400">Status</span>
                        <span class="px-2 py-1 text-xs rounded-full font-medium
                            {{ $order->status == 'pending' ? 'bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-400' : 'bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400' }}">
                            {{ ucfirst($order->status) }}
                        </span>
                    </div>
                    <div class="flex justify-between">
                        <span class="text-gray-500 dark:text-gray-400">Payment</span>
                        <span class="px-2 py-1 text-xs rounded-full font-medium
                            {{ $order->payment_status == 'verified' ? 'bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400' : ($order->payment_status == 'failed' ? 'bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400' : 'bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-400') }}">
                            {{ ucfirst($order->payment_status) }}
                        </span>
                    </div>
                    <div class="flex justify-between font-bold pt-3 border-t border-gray-200 dark:border-gray-700">
                        <span class="text-gray-900 dark:text-white">Total</span>
                        <span class="text-primary-500">${{ number_format($order->amount, 2) }}</span>
                    </div>
                </div>

                <a href="{{ route('vip-cards.my-memberships') }}" class="block w-full text-center mt-6 px-4 py-2.5 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-xl hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-sm font-medium">
                    View My Memberships
                </a>
            </div>
        </div>
    </div>
</div>
@endsection
