@extends('layouts.admin')

@section('title', 'Accounts')

@section('content')
<div class="fundi-page-header">
    <div>
        <h1>Accounts</h1>
        <p class="fundi-page-header__desc">Customer deposit and operational accounts.</p>
    </div>
    <a href="{{ route('admin.accounts.create') }}" class="fundi-btn fundi-btn--primary">Open Account</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="Account no. or customer">
    </div>
    <div class="fundi-form-group">
        <label for="account_type">Type</label>
        <select id="account_type" name="account_type" class="fundi-select">
            <option value="">All types</option>
            @foreach(['savings','current','investment','loan_disbursement','escrow'] as $t)
                <option value="{{ $t }}" @selected(request('account_type') === $t)>{{ ucfirst(str_replace('_',' ',$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</option>
            @foreach(['active','dormant','frozen','closed'] as $s)
                <option value="{{ $s }}" @selected(request('status') === $s)>{{ ucfirst($s) }}</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>Account No.</th>
                        <th>Customer</th>
                        <th>Type</th>
                        <th class="num">Balance</th>
                        <th class="num">Available</th>
                        <th>Branch</th>
                        <th>Status</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($accounts as $account)
                        <tr>
                            <td>{{ $account->account_no }}</td>
                            <td>{{ $account->customer->display_name ?? '—' }}</td>
                            <td>{{ ucfirst(str_replace('_',' ',$account->account_type)) }}</td>
                            <td class="num">{{ money($account->balance) }}</td>
                            <td class="num">{{ money($account->available_balance) }}</td>
                            <td>{{ $account->branch->name ?? '—' }}</td>
                            <td><x-status-badge :status="$account->status" /></td>
                            <td class="actions"><a href="{{ route('admin.accounts.show', $account) }}" class="fundi-btn fundi-btn--link fundi-btn--sm">View</a></td>
                        </tr>
                    @empty
                        <tr><td colspan="8" class="fundi-empty">No accounts found.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if($accounts->hasPages())
            <div class="fundi-pagination">{{ $accounts->links() }}</div>
        @endif
    </div>
</div>
@endsection
