@extends('layouts.dasht')
@section('content')
<div class="max-w-4xl mx-auto">
    <a href="{{ route('vip-cards.my-memberships') }}" class="inline-flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400 hover:text-primary-500 mb-6 transition-colors">
        <i data-lucide="arrow-left" class="w-4 h-4"></i>
        Back to My Memberships
    </a>

    <div class="mb-8">
        <h1 class="text-3xl font-bold text-gray-900 dark:text-white">Membership Details</h1>
        <p class="mt-2 text-gray-600 dark:text-gray-400">Order #{{ $order->order_number }}</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

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
        {{-- Left: Card Visual + Status --}}
        <div>
            <div class="sticky top-4 space-y-4">
                {{-- Card Image --}}
                <div class="rounded-2xl overflow-hidden shadow-lg" style="background: linear-gradient(135deg, {{ $order->vipCard->color ?? '#1a1a1a' }} 0%, {{ $order->vipCard->color ?? '#1a1a1a' }}dd 100%);">
                    @if($order->vipCard && $order->vipCard->card_image)
                        <img src="{{ asset('dash/' . $order->vipCard->card_image) }}" alt="{{ $order->vipCard->name }}"
                             class="w-full object-cover">
                    @else
                        <div class="aspect-[3/2] flex items-center justify-center">
                            <i data-lucide="crown" class="w-16 h-16 text-white/30"></i>
                        </div>
                    @endif
                </div>

                {{-- Status Card --}}
                <div class="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 p-5 text-center">
                    @if($order->is_active)
                        <div class="w-12 h-12 mx-auto mb-3 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center">
                            <i data-lucide="badge-check" class="w-6 h-6 text-green-600 dark:text-green-400"></i>
                        </div>
                        <p class="font-bold text-green-600 dark:text-green-400 text-lg">Active</p>
                        <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">{{ $order->days_remaining }} days remaining</p>
                        <div class="mt-3 w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
                            @php
                                $totalDays = $order->vipCard->duration_days;
                                $elapsed = $totalDays - $order->days_remaining;
                                $pct = $totalDays > 0 ? min(100, ($elapsed / $totalDays) * 100) : 0;
                            @endphp
                            <div class="bg-green-500 h-2 rounded-full transition-all" style="width: {{ $pct }}%"></div>
                        </div>
                        <p class="text-xs text-gray-400 dark:text-gray-500 mt-2">Expires {{ $order->expires_at->format('M d, Y') }}</p>
                    @elseif($order->is_expired)
                        <div class="w-12 h-12 mx-auto mb-3 bg-gray-100 dark:bg-gray-700 rounded-full flex items-center justify-center">
                            <i data-lucide="clock" class="w-6 h-6 text-gray-500 dark:text-gray-400"></i>
                        </div>
                        <p class="font-bold text-gray-600 dark:text-gray-400 text-lg">Expired</p>
                        <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">Expired {{ $order->expires_at->diffForHumans() }}</p>
                        <a href="{{ route('vip-cards.index') }}" class="mt-4 block px-4 py-2.5 bg-primary-500 hover:bg-primary-600 text-white rounded-lg text-sm font-medium transition-colors">
                            Renew Membership
                        </a>
                    @elseif($order->status == 'pending')
                        <div class="w-12 h-12 mx-auto mb-3 bg-yellow-100 dark:bg-yellow-900/30 rounded-full flex items-center justify-center">
                            <i data-lucide="hourglass" class="w-6 h-6 text-yellow-600 dark:text-yellow-400"></i>
                        </div>
                        <p class="font-bold text-yellow-600 dark:text-yellow-400 text-lg">Pending Review</p>
                        <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">Awaiting admin approval</p>
                        @if(!$order->payment_proof)
                            <a href="{{ route('vip-cards.payment', $order) }}" class="mt-4 block px-4 py-2.5 bg-primary-500 hover:bg-primary-600 text-white rounded-lg text-sm font-medium transition-colors">
                                Upload Payment Proof
                            </a>
                        @endif
                    @elseif($order->status == 'cancelled')
                        <div class="w-12 h-12 mx-auto mb-3 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center">
                            <i data-lucide="x-circle" class="w-6 h-6 text-red-600 dark:text-red-400"></i>
                        </div>
                        <p class="font-bold text-red-600 dark:text-red-400 text-lg">Cancelled</p>
                    @elseif($order->status == 'refunded')
                        <div class="w-12 h-12 mx-auto mb-3 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center">
                            <i data-lucide="rotate-ccw" class="w-6 h-6 text-blue-600 dark:text-blue-400"></i>
                        </div>
                        <p class="font-bold text-blue-600 dark:text-blue-400 text-lg">Refunded</p>
                    @endif
                </div>
            </div>
        </div>

        {{-- Right: Details --}}
        <div class="lg:col-span-2 space-y-6">
            {{-- Order Information --}}
            <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">Order Information</h2>
                <div class="grid grid-cols-2 gap-y-4 gap-x-8 text-sm">
                    <div>
                        <span class="text-gray-500 dark:text-gray-400 block">Order Number</span>
                        <span class="font-medium text-gray-900 dark:text-white">{{ $order->order_number }}</span>
                    </div>
                    <div>
                        <span class="text-gray-500 dark:text-gray-400 block">VIP Card</span>
                        <span class="font-medium text-gray-900 dark:text-white">{{ $order->vipCard->name ?? 'N/A' }}</span>
                    </div>
                    <div>
                        <span class="text-gray-500 dark:text-gray-400 block">Amount Paid</span>
                        <span class="font-bold text-gray-900 dark:text-white">${{ number_format($order->amount, 2) }}</span>
                    </div>
                    <div>
                        <span class="text-gray-500 dark:text-gray-400 block">Payment Method</span>
                        <span class="font-medium text-gray-900 dark:text-white">{{ $order->payment_method ?? 'N/A' }}</span>
                    </div>
                    <div>
                        <span class="text-gray-500 dark:text-gray-400 block">Payment Status</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>
                        <span class="text-gray-500 dark:text-gray-400 block">Ordered On</span>
                        <span class="font-medium text-gray-900 dark:text-white">{{ $order->created_at->format('M d, Y H:i') }}</span>
                    </div>
                    @if($order->activated_at)
                    <div>
                        <span class="text-gray-500 dark:text-gray-400 block">Activated</span>
                        <span class="font-medium text-gray-900 dark:text-white">{{ $order->activated_at->format('M d, Y H:i') }}</span>
                    </div>
                    @endif
                    @if($order->expires_at)
                    <div>
                        <span class="text-gray-500 dark:text-gray-400 block">Expires</span>
                        <span class="font-medium text-gray-900 dark:text-white">{{ $order->expires_at->format('M d, Y H:i') }}</span>
                    </div>
                    @endif
                </div>
            </div>

            {{-- Benefits --}}
            @if($order->vipCard && $order->vipCard->benefits && count($order->vipCard->benefits) > 0)
            <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">Your Benefits</h2>
                <ul class="space-y-3">
                    @foreach($order->vipCard->benefits as $benefit)
                    <li class="flex items-start gap-3">
                        <div class="flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center mt-0.5
                            {{ $order->is_active ? 'bg-green-100 dark:bg-green-900/30' : 'bg-gray-100 dark:bg-gray-700' }}">
                            <i data-lucide="check" class="w-3.5 h-3.5 {{ $order->is_active ? 'text-green-600 dark:text-green-400' : 'text-gray-400 dark:text-gray-500' }}"></i>
                        </div>
                        <span class="{{ $order->is_active ? 'text-gray-700 dark:text-gray-300' : 'text-gray-400 dark:text-gray-500' }}">{{ $benefit }}</span>
                    </li>
                    @endforeach
                </ul>
            </div>
            @endif

            {{-- Payment Proof --}}
            @if($order->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">Payment Proof</h2>
                <a href="{{ asset('dash/' . $order->payment_proof) }}" target="_blank" class="block">
                    <img src="{{ asset('dash/' . $order->payment_proof) }}" alt="Payment proof"
                         class="max-h-64 rounded-lg border border-gray-200 dark:border-gray-700">
                </a>
            </div>
            @endif
        </div>
    </div>
</div>
@endsection
