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

    <div class="mb-3">
        <a href="{{ route('purchases.create') }}" class="btn btn-primary">{{ __('Add Purchase') }}</a>
    </div>

    <div class="card shadow-sm">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-striped mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>{{ __('Item') }}</th>
                            <th>{{ __('Cost') }}</th>
                            <th>{{ __('Quantity') }}</th>
                            <th>{{ __('Vendor') }}</th>
                            <th>{{ __('Date') }}</th>
                            <th>{{ __('Actions') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($purchases as $purchase)
                            <tr>
                                <td>{{ ucfirst($purchase->item_type) }}</td>
                                <td>{{ number_format($purchase->cost, 2) }} {{ $purchase->currency?->symbol ?? '' }}</td>
                                <td>{{ $purchase->quantity }}</td>
                                <td>{{ $purchase->vendor }}</td>
                                <td>{{ $purchase->purchase_date->format('Y-m-d') }}</td>
                                <td>
                                    <form action="{{ route('purchases.destroy', $purchase) }}" method="POST" class="d-inline-block">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-sm btn-danger">{{ __('Delete') }}</button>
                                    </form>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="6" class="text-center">{{ __('No purchases found.') }}</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="mt-3">{{ $purchases->links() }}</div>
</x-app-layout>
