<x-app-layout>
    <x-slot name="header">{{ __('Bank Withdrawals') }}</x-slot>

    <div class="d-flex justify-content-between align-items-center mb-3">
        <h5 class="fw-semibold mb-0"><i class="bi bi-bank me-2 text-primary"></i>{{ __('Bank Withdrawals') }}</h5>
        <a href="{{ route('bank-withdrawals.create') }}" class="btn btn-primary btn-sm">
            <i class="bi bi-plus-lg me-1"></i>{{ __('New Withdrawal') }}
        </a>
    </div>

    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    @endif

    <div class="card shadow-sm">
        <div class="card-body p-0">
            <table class="table table-hover mb-0 align-middle">
                <thead class="table-light">
                    <tr>
                        <th>#</th>
                        <th>{{ __('Date') }}</th>
                        <th>{{ __('Amount') }}</th>
                        <th>{{ __('Bank Account') }}</th>
                        <th>{{ __('Reference') }}</th>
                        <th>{{ __('Notes') }}</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($withdrawals as $w)
                        <tr>
                            <td>{{ $loop->iteration + ($withdrawals->currentPage() - 1) * $withdrawals->perPage() }}</td>
                            <td>{{ $w->withdrawal_date->format('Y-m-d') }}</td>
                            <td>{{ number_format($w->amount, 2) }} {{ $w->currency?->code ?? '' }}</td>
                            <td>{{ $w->bank_account ?? '—' }}</td>
                            <td>{{ $w->reference ?? '—' }}</td>
                            <td>{{ $w->notes }}</td>
                            <td>
                                <form action="{{ route('bank-withdrawals.destroy', $w) }}" method="POST" onsubmit="return confirm('{{ __('Delete this record?') }}')">
                                    @csrf
                                    @method('DELETE')
                                    <button class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
                                </form>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="7" class="text-center text-muted py-4">{{ __('No withdrawals found.') }}</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if($withdrawals->hasPages())
            <div class="card-footer">{{ $withdrawals->links() }}</div>
        @endif
    </div>
</x-app-layout>
