@extends('admin.layouts.app')

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

@section('content')
<div class="space-y-6">
    <!-- Customer Info -->
    <div class="bg-white rounded-lg shadow p-6">
        <div class="flex justify-between items-start mb-4">
            <div>
                <h3 class="text-lg font-semibold">{{ $customer->name }}</h3>
                <p class="text-sm text-gray-500">Member since {{ $customer->created_at->format('F Y') }}</p>
            </div>
            <form method="POST" action="{{ route('admin.customers.status.update', $customer) }}">
                @csrf
                @method('PUT')
                <input type="hidden" name="is_active" value="{{ $customer->deleted_at ? '1' : '0' }}">
                <button type="submit" class="px-4 py-2 rounded text-sm {{ $customer->deleted_at ? 'bg-green-500 text-white' : 'bg-red-500 text-white' }}">
                    {{ $customer->deleted_at ? 'Enable Account' : 'Disable Account' }}
                </button>
            </form>
        </div>

        <div class="grid grid-cols-2 gap-6">
            <div>
                <h4 class="font-semibold mb-2">Contact Information</h4>
                <p class="text-sm"><strong>Email:</strong> {{ $customer->email }}</p>
                <p class="text-sm"><strong>Phone:</strong> {{ $customer->phone ?? 'N/A' }}</p>
                <p class="text-sm"><strong>Address:</strong> {{ $customer->address ?? 'N/A' }}</p>
            </div>
            <div>
                <h4 class="font-semibold mb-2">Account Statistics</h4>
                <p class="text-sm"><strong>Total Orders:</strong> {{ $customer->orders->count() }}</p>
                <p class="text-sm"><strong>Total Spent:</strong> {{ $currency_symbol }}{{ number_format($customer->orders->sum('total'), 2) }}</p>
                <p class="text-sm"><strong>Account Status:</strong> 
                    <span class="px-2 py-1 text-xs rounded-full {{ $customer->deleted_at ? 'bg-red-100 text-red-800' : 'bg-green-100 text-green-800' }}">
                        {{ $customer->deleted_at ? 'Disabled' : 'Active' }}
                    </span>
                </p>
            </div>
        </div>
    </div>

    <!-- Order History -->
    <div class="bg-white rounded-lg shadow p-6">
        <h3 class="text-lg font-semibold mb-4">Order History</h3>
        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-50">
                    <tr>
                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Order #</th>
                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Date</th>
                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Total</th>
                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Actions</th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    @forelse($orders as $order)
                    <tr>
                        <td class="px-4 py-3">
                            <a href="{{ route('admin.orders.show', $order) }}" class="text-blue-600 hover:underline">
                                {{ $order->order_number }}
                            </a>
                        </td>
                        <td class="px-4 py-3 text-sm">{{ $order->created_at->format('M d, Y') }}</td>
                        <td class="px-4 py-3 text-sm">{{ $currency_symbol }}{{ number_format($order->total, 2) }}</td>
                        <td class="px-4 py-3">
                            <span class="px-2 py-1 text-xs rounded-full 
                                {{ $order->status === 'paid' ? 'bg-green-100 text-green-800' : '' }}
                                {{ $order->status === 'pending' ? 'bg-yellow-100 text-yellow-800' : '' }}
                                {{ $order->status === 'cancelled' ? 'bg-red-100 text-red-800' : '' }}">
                                {{ ucfirst($order->status) }}
                            </span>
                        </td>
                        <td class="px-4 py-3">
                            <a href="{{ route('admin.orders.show', $order) }}" class="text-blue-600 hover:text-blue-900">
                                <i class="fas fa-eye"></i>
                            </a>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="5" class="px-4 py-8 text-center text-gray-500">No orders found</td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        <!-- Pagination -->
        <div class="mt-4">
            {{ $orders->links() }}
        </div>
    </div>
</div>
@endsection
