@extends('layouts.admin')

@section('title', 'Customers')

@section('content')
<div class="fundi-page-header">
    <div>
        <h1>Customers</h1>
        <p class="fundi-page-header__desc">Manage customer profiles, KYC, and relationships.</p>
    </div>
    <a href="{{ route('admin.customers.create') }}" class="fundi-btn fundi-btn--primary">New Customer</a>
</div>

<form method="GET" class="fundi-filters">
    <div class="fundi-form-group">
        <label for="search">Search</label>
        <input type="text" id="search" name="search" class="fundi-input" value="{{ request('search') }}" placeholder="Name, no., email, phone">
    </div>
    <div class="fundi-form-group">
        <label for="type">Type</label>
        <select id="type" name="type" class="fundi-select">
            <option value="">All types</option>
            @foreach(['individual','sme','corporate','contractor','government'] as $t)
                <option value="{{ $t }}" @selected(request('type') === $t)>{{ ucfirst($t) }}</option>
            @endforeach
        </select>
    </div>
    <div class="fundi-form-group">
        <label for="status">Status</label>
        <select id="status" name="status" class="fundi-select">
            <option value="">All statuses</option>
            @foreach(['active','inactive','blacklisted','closed'] as $s)
                <option value="{{ $s }}" @selected(request('status') === $s)>{{ ucfirst($s) }}</option>
            @endforeach
        </select>
    </div>
    <div class="fundi-form-group">
        <label for="kyc_status">KYC</label>
        <select id="kyc_status" name="kyc_status" class="fundi-select">
            <option value="">All</option>
            @foreach(['pending','in_review','verified','rejected'] as $k)
                <option value="{{ $k }}" @selected(request('kyc_status') === $k)>{{ ucwords(str_replace('_',' ',$k)) }}</option>
            @endforeach
        </select>
    </div>
    <button type="submit" class="fundi-btn fundi-btn--secondary">Filter</button>
</form>

<div class="fundi-card">
    <div class="fundi-card__body">
        <div class="fundi-table-wrap">
            <table class="fundi-table">
                <thead>
                    <tr>
                        <th>Customer No.</th>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Phone</th>
                        <th>Branch</th>
                        <th>KYC</th>
                        <th>Status</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($customers as $customer)
                        <tr>
                            <td>{{ $customer->customer_no }}</td>
                            <td>{{ $customer->display_name }}</td>
                            <td>{{ ucfirst($customer->type) }}</td>
                            <td>{{ $customer->phone }}</td>
                            <td>{{ $customer->branch->name ?? '—' }}</td>
                            <td><x-status-badge :status="$customer->kyc_status" /></td>
                            <td><x-status-badge :status="$customer->status" /></td>
                            <td class="actions"><a href="{{ route('admin.customers.show', $customer) }}" class="fundi-btn fundi-btn--link fundi-btn--sm">View</a></td>
                        </tr>
                    @empty
                        <tr><td colspan="8" class="fundi-empty">No customers found.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if($customers->hasPages())
            <div class="fundi-pagination">{{ $customers->links() }}</div>
        @endif
    </div>
</div>
@endsection
