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

    <div class="mb-3">
        @can('sales.create')
        <a href="{{ route('sales.create') }}" class="btn btn-primary"><i class="bi bi-plus-circle me-1"></i>{{ __('Add Sale') }}</a>
        @endcan
    </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>{{ __('Customer') }}</th>
                            <th>{{ __('Amount') }}</th>
                            <th>{{ __('Source') }}</th>
                            <th>{{ __('Payment Method') }}</th>
                            <th>{{ __('Date') }}</th>
                            <th>{{ __('Actions') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($sales as $sale)
                            <tr>
                                <td>{{ $sale->customer?->name ?? __('Walk-in') }}</td>
                                <td>{{ number_format($sale->amount, 2) }} {{ $sale->currency?->symbol ?? '' }}</td>
                                <td>{{ ucwords(str_replace('_', ' ', $sale->source)) }}</td>
                                <td>{{ ucfirst($sale->payment_method) }}</td>
                                <td>{{ $sale->sale_date->format('Y-m-d') }}</td>
                                <td>
                                    @can('sales.delete')
                                    <form action="{{ route('sales.destroy', $sale) }}" method="POST" class="d-inline-block" onsubmit="return confirm('Delete?')">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
                                    </form>
                                    @endcan
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="6" class="text-center">{{ __('No sales found.') }}</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>

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