@extends('layouts.app')
@section('title', __('Customers'))
@section('content')
<div class="card">
    <div class="card-body">
        <div class="d-flex flex-wrap gap-2 justify-content-between mb-3">
            <form class="d-flex gap-2"><input name="search" class="form-control" placeholder="{{ __('Search customer or phone') }}" value="{{ request('search') }}"><button class="btn btn-light"><i class="fa-solid fa-magnifying-glass"></i></button></form>
            <a href="{{ route('customers.create') }}" class="btn btn-success"><i class="fa-solid fa-user-plus me-1"></i>{{ __('Add Customer') }}</a>
        </div>
        <div class="table-responsive">
            <table class="table align-middle">
                <thead><tr><th>{{ __('Customer') }}</th><th>{{ __('Phone') }}</th><th>{{ __('Type') }}</th><th>{{ __('Balance Due') }}</th><th></th></tr></thead>
                <tbody>
                    @forelse($customers as $customer)
                        <tr><td><strong>{{ $customer->name }}</strong><small class="d-block text-muted">{{ $customer->address }}</small></td><td>{{ $customer->phone ?: '-' }}</td><td><span class="badge badge-soft rounded-pill">{{ __($customer->type === 'retail' ? 'Retail' : 'Wholesale') }}</span></td><td class="money {{ $customer->balance > 0 ? 'text-danger fw-bold' : '' }}">{{ number_format($customer->balance, 2) }} {{ $moneyCode }}</td><td class="text-end"><a href="{{ route('reports.customer-ledger', $customer) }}" class="btn btn-light btn-sm"><i class="fa-solid fa-book"></i></a><a href="{{ route('customers.edit', $customer) }}" class="btn btn-light btn-sm"><i class="fa-solid fa-pen"></i></a><form class="d-inline" method="POST" action="{{ route('customers.destroy', $customer) }}" onsubmit="return confirm('{{ __('Remove this customer?') }}')">@csrf @method('DELETE')<button class="btn btn-light btn-sm text-danger"><i class="fa-solid fa-trash"></i></button></form></td></tr>
                    @empty
                        <tr><td colspan="5" class="text-center text-muted py-5">{{ __('No customers yet.') }}</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        {{ $customers->links('pagination::bootstrap-5') }}
    </div>
</div>
@endsection
