@extends('layouts.admin')

@section('title', 'Customers')

@section('content')
    <section class="dashboard-head">
        <div>
            <span class="eyebrow">People</span>
            <h1>Customers</h1>
        </div>
    </section>

    @if (session('status'))
        <p class="form-status">{{ session('status') }}</p>
    @endif

    <section class="panel">
        <div class="table-wrap">
            <table>
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Cart</th>
                        <th>Favorites</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($customers as $customer)
                        <tr>
                            <td><strong>{{ $customer->name }}</strong></td>
                            <td>{{ $customer->email }}</td>
                            <td>{{ $customer->cart_items_count }}</td>
                            <td>{{ $customer->favorites_count }}</td>
                            <td><span class="status {{ $customer->is_active ? 'paid' : 'refunded' }}">{{ $customer->is_active ? 'Active' : 'Inactive' }}</span></td>
                            <td>
                                <div class="table-actions">
                                    <a class="text-button" href="{{ route('admin.customers.show', $customer) }}">View</a>
                                    <form method="POST" action="{{ route('admin.customers.toggle', $customer) }}">
                                        @csrf
                                        @method('PATCH')
                                        <button class="text-button" type="submit">{{ $customer->is_active ? 'Disable' : 'Enable' }}</button>
                                    </form>
                                    <form method="POST" action="{{ route('admin.customers.destroy', $customer) }}" onsubmit="return confirm('Delete this customer?')">
                                        @csrf
                                        @method('DELETE')
                                        <button class="text-button danger" type="submit">Delete</button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6">No customers yet.</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        {{ $customers->links() }}
    </section>
@endsection
