@extends('layouts.app')
@section('title', __('Suppliers'))
@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" value="{{ request('search') }}" placeholder="{{ __('Search supplier or phone') }}"><button class="btn btn-light"><i class="fa-solid fa-magnifying-glass"></i></button></form>
            <a class="btn btn-success" href="{{ route('suppliers.create') }}"><i class="fa-solid fa-plus me-1"></i>{{ __('Add Supplier') }}</a>
        </div>
        <div class="table-responsive">
            <table class="table align-middle">
                <thead><tr><th>{{ __('Supplier') }}</th><th>{{ __('Phone') }}</th><th>{{ __('Balance Due') }}</th><th>{{ __('Ledger') }}</th><th></th></tr></thead>
                <tbody>
                    @forelse($suppliers as $supplier)
                        <tr><td><strong>{{ $supplier->name }}</strong><small class="d-block text-muted">{{ $supplier->address }}</small></td><td>{{ $supplier->phone ?: '-' }}</td><td class="money {{ $supplier->balance > 0 ? 'text-danger fw-bold' : '' }}">{{ number_format($supplier->balance, 2) }} {{ $moneyCode }}</td><td><a href="{{ route('reports.supplier-ledger', $supplier) }}" class="btn btn-light btn-sm"><i class="fa-solid fa-book"></i></a></td><td class="text-end"><a href="{{ route('suppliers.edit', $supplier) }}" class="btn btn-light btn-sm"><i class="fa-solid fa-pen"></i></a><form class="d-inline" method="POST" action="{{ route('suppliers.destroy', $supplier) }}">@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 suppliers yet.') }}</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        {{ $suppliers->links('pagination::bootstrap-5') }}
    </div>
</div>
@endsection
