@extends('layouts.admin')

@section('title', 'Customer: ' . $customer->name)

@section('content')
<div class="max-w-[1600px] mx-auto">
    <!-- Header -->
    <div class="flex flex-col md:flex-row md:items-center justify-between gap-8 mb-12">
        <div class="flex items-center gap-6">
            <a href="{{ route('admin.customers.index') }}" class="w-14 h-14 flex items-center justify-center bg-white border border-gray-100 rounded-2xl text-gray-400 hover:text-brand hover:border-brand/20 transition-all duration-300 shadow-sm group">
                <i class="fas fa-chevron-left text-xs group-hover:-translate-x-1 transition-transform"></i>
            </a>
            <div>
                <div class="flex items-center gap-3 mb-2">
                    <span class="px-3 py-1 bg-brand/10 text-brand text-xs font-medium rounded-full">Customer</span>
                    <span class="text-xs text-gray-500">Details</span>
                </div>
                <h1 class="text-3xl font-bold text-gray-900 leading-tight">{{ $customer->name }}</h1>
                <p class="text-gray-500 text-sm font-medium mt-1">Joined on {{ $customer->created_at->format('d F Y') }}</p>
            </div>
        </div>
        <div class="flex items-center gap-4">
            <button class="flex items-center gap-2 bg-white border border-gray-200 text-gray-600 px-5 py-2.5 rounded-xl text-sm font-medium hover:bg-red-50 hover:text-red-600 hover:border-red-100 transition">
                <i class="fas fa-ban text-[10px]"></i>
                Restrict Account
            </button>
        </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-12 gap-8">
        <!-- Sidebar Column -->
        <div class="lg:col-span-4 space-y-8">
            <!-- Profile Card -->
            <div class="bg-white rounded-3xl border border-gray-100 shadow-sm overflow-hidden">
                <div class="p-10 flex flex-col items-center text-center bg-gray-50/30 border-b border-gray-50">
                    <div class="w-32 h-32 rounded-3xl bg-gradient-to-br from-gray-50 to-gray-100 flex items-center justify-center text-gray-400 text-4xl font-semibold mb-6 border-4 border-white shadow-lg">
                        {{ substr($customer->name, 0, 1) }}
                    </div>
                    <h2 class="text-2xl font-semibold text-gray-900">{{ $customer->name }}</h2>
                    <p class="text-gray-500 text-xs mt-1">Customer ID: #{{ str_pad($customer->id, 5, '0', STR_PAD_LEFT) }}</p>
                    <div class="mt-6">
                        <span class="px-3 py-1 bg-emerald-50 text-emerald-600 rounded-full text-xs font-medium inline-flex items-center gap-2">
                            <span class="w-1.5 h-1.5 rounded-full bg-emerald-500"></span>
                            Verified Account
                        </span>
                    </div>
                </div>
                <div class="p-8 space-y-6">
                    <div class="flex items-center gap-4">
                        <div class="w-10 h-10 rounded-xl bg-gray-50 flex items-center justify-center text-gray-400">
                            <i class="far fa-envelope text-xs"></i>
                        </div>
                        <div>
                            <span class="block text-xs text-gray-500 mb-0.5">Email</span>
                            <span class="text-sm font-medium text-gray-900">{{ $customer->email }}</span>
                        </div>
                    </div>
                    <div class="flex items-center gap-4">
                        <div class="w-10 h-10 rounded-xl bg-gray-50 flex items-center justify-center text-gray-400">
                            <i class="fas fa-phone text-xs"></i>
                        </div>
                        <div>
                            <span class="block text-xs text-gray-500 mb-0.5">Phone</span>
                            <span class="text-sm font-medium text-gray-900">{{ $customer->phone ?? 'Not provided' }}</span>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Quick Stats -->
            <div class="grid grid-cols-2 gap-4">
                <div class="bg-white p-6 rounded-3xl border border-gray-100 shadow-sm group hover:border-brand/20 transition-all duration-300">
                    <div class="w-10 h-10 rounded-xl bg-blue-50 flex items-center justify-center text-blue-500 mb-4 group-hover:bg-brand group-hover:text-white transition-all duration-300">
                        <i class="fas fa-shopping-bag text-xs"></i>
                    </div>
                    <p class="text-xs text-gray-500 mb-1">Total orders</p>
                    <h3 class="text-xl font-semibold text-gray-900">{{ $customer->orders_count }}</h3>
                </div>
                <div class="bg-white p-6 rounded-3xl border border-gray-100 shadow-sm group hover:border-brand/20 transition-all duration-300">
                    <div class="w-10 h-10 rounded-xl bg-emerald-50 flex items-center justify-center text-emerald-500 mb-4 group-hover:bg-brand group-hover:text-white transition-all duration-300">
                        <i class="fas fa-wallet text-xs"></i>
                    </div>
                    <p class="text-xs text-gray-500 mb-1">Total spent</p>
                    <h3 class="text-xl font-semibold text-gray-900">{{ $currencySymbol ?? '$' }}{{ number_format($totalSpent, 2) }}</h3>
                </div>
            </div>
        </div>

        <!-- Main Content Column -->
        <div class="lg:col-span-8">
            <div class="bg-white rounded-3xl border border-gray-100 shadow-sm overflow-hidden h-full">
                <div class="px-8 py-6 border-b border-gray-50 flex items-center justify-between">
                    <div>
                        <h3 class="text-lg font-semibold text-gray-900">Recent orders</h3>
                        <p class="text-xs text-gray-500 mt-0.5">Most recent transactions</p>
                    </div>
                    <a href="{{ route('admin.orders.index', ['search' => $customer->email]) }}" class="text-sm font-medium text-brand hover:underline transition-colors">View all orders</a>
                </div>
                
                @if($recentOrders->count() > 0)
                <div class="overflow-x-auto">
                    <table class="w-full text-left">
                        <thead>
                            <tr class="bg-gray-50/30">
                                <th class="px-8 py-5 text-xs font-medium text-gray-500">Order ID</th>
                                <th class="px-8 py-5 text-xs font-medium text-gray-500">Date</th>
                                <th class="px-8 py-5 text-xs font-medium text-gray-500">Status</th>
                                <th class="px-8 py-5 text-xs font-medium text-gray-500 text-right">Total</th>
                                <th class="px-8 py-5 text-xs font-medium text-gray-500 text-center">Action</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-gray-50">
                            @foreach($recentOrders as $order)
                            <tr class="hover:bg-gray-50/50 transition-colors group">
                                <td class="px-8 py-5">
                                    <span class="font-medium text-gray-900">#{{ str_pad($order->id, 5, '0', STR_PAD_LEFT) }}</span>
                                </td>
                                <td class="px-8 py-5">
                                    <div class="flex flex-col">
                                        <span class="text-xs font-medium text-gray-900">{{ $order->created_at->format('d M, Y') }}</span>
                                        <span class="text-xs text-gray-500 mt-0.5">{{ $order->created_at->diffForHumans() }}</span>
                                    </div>
                                </td>
                                <td class="px-8 py-5">
                                    <span class="px-3 py-1 rounded-full text-xs font-medium inline-flex items-center gap-1.5
                                        {{ $order->status === 'delivered' ? 'bg-emerald-50 text-emerald-600' : 
                                           ($order->status === 'cancelled' ? 'bg-red-50 text-red-600' : 
                                           ($order->status === 'shipped' ? 'bg-blue-50 text-blue-600' : 
                                           ($order->status === 'processing' ? 'bg-brand/10 text-brand' : 'bg-amber-50 text-amber-600'))) }}">
                                        <span class="w-1 h-1 rounded-full 
                                            {{ $order->status === 'delivered' ? 'bg-emerald-500' : 
                                               ($order->status === 'cancelled' ? 'bg-red-500' : 
                                               ($order->status === 'shipped' ? 'bg-blue-500' : 
                                               ($order->status === 'processing' ? 'bg-brand' : 'bg-amber-500'))) }}"></span>
                                        {{ ucfirst($order->status) }}
                                    </span>
                                </td>
                                <td class="px-8 py-5 text-right">
                                    <span class="text-sm font-semibold text-gray-900">{{ $currencySymbol ?? '$' }}{{ number_format($order->total, 2) }}</span>
                                </td>
                                <td class="px-8 py-5 text-center">
                                    <a href="{{ route('admin.orders.show', $order->id) }}" class="w-8 h-8 flex items-center justify-center bg-gray-50 text-gray-400 rounded-lg hover:bg-brand/10 hover:text-brand transition-all duration-300">
                                        <i class="fas fa-eye text-[10px]"></i>
                                    </a>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
                @else
                <div class="p-20 text-center">
                    <div class="w-16 h-16 bg-gray-50 rounded-2xl flex items-center justify-center mb-4 mx-auto">
                        <i class="fas fa-box-open text-gray-200 text-2xl"></i>
                    </div>
                    <h3 class="text-lg font-semibold text-gray-900 mb-1">No orders found</h3>
                    <p class="text-gray-500 text-sm max-w-xs mx-auto">This customer hasn't placed any orders yet.</p>
                </div>
                @endif
            </div>
        </div>
    </div>
</div>
@endsection
