@extends('adminlte::page')

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

@section('content_header')
    <h1>{{ $customer->name }}</h1>
@stop

@section('content')
    <div class="row">
        <div class="col-lg-4">
            <div class="card">
                <div class="card-header"><h3 class="card-title">Customer Info</h3></div>
                <div class="card-body">
                    <p><strong>Email:</strong> {{ $customer->email }}</p>
                    <p><strong>Phone:</strong> {{ $customer->phone ?? '—' }}</p>
                    <p><strong>Joined:</strong> {{ $customer->created_at->format('d M, Y') }}</p>
                    <p><strong>Status:</strong> {{ $customer->is_active ? 'Active' : 'Disabled' }}</p>
                </div>
            </div>

            <div class="card">
                <div class="card-header"><h3 class="card-title">Addresses</h3></div>
                <div class="card-body">
                    @forelse($customer->addresses as $address)
                        <div class="mb-3 pb-2 border-bottom">
                            <strong>{{ $address->label }}</strong>@if($address->is_default) <span class="badge bg-info">Default</span>@endif
                            <p class="mb-0 small">{{ $address->full_name }}, {{ $address->phone }}</p>
                            <p class="mb-0 small">{{ $address->address_line1 }}, {{ $address->city }}</p>
                        </div>
                    @empty
                        <p class="text-muted mb-0">No saved addresses.</p>
                    @endforelse
                </div>
            </div>
        </div>

        <div class="col-lg-8">
            <div class="card">
                <div class="card-header"><h3 class="card-title">Order History</h3></div>
                <div class="card-body p-0">
                    <table class="table table-striped mb-0">
                        <thead>
                            <tr>
                                <th>Order #</th>
                                <th>Total</th>
                                <th>Status</th>
                                <th>Date</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse($customer->orders as $order)
                                <tr>
                                    <td>{{ $order->order_number }}</td>
                                    <td>Rs. {{ number_format($order->total) }}</td>
                                    <td><span class="badge bg-{{ $order->statusBadgeColor() }}">{{ ucfirst($order->status) }}</span></td>
                                    <td>{{ $order->created_at->format('d M, Y') }}</td>
                                    <td><a href="{{ route('admin.orders.show', $order) }}" class="btn btn-primary btn-sm">View</a></td>
                                </tr>
                            @empty
                                <tr><td colspan="5" class="text-center text-muted py-3">No orders yet.</td></tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@stop
