@extends('layouts.app')
@section('title', 'Sales List')
@section('breadcrumb')
    @include('components.breadcrumb', ['items' => ['Sales Management' => null, 'Sales List' => null]])
@endsection
@section('content')
<div>
    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
        <div><h1 class="text-2xl font-bold text-slate-900 dark:text-white">Sales List</h1><p class="text-sm text-slate-500 mt-1">{{ $sales->total() }} records</p></div>
        <x-button variant="success" icon="plus" :href="route('sales.create')">New Sale</x-button>
    </div>
    <x-card :padding="false">
        <table class="w-full text-sm">
            <thead><tr class="bg-slate-50 dark:bg-slate-900/50 border-b border-slate-200">
                <th class="px-4 py-3 text-left text-[11px] font-bold uppercase text-slate-500">Date</th>
                <th class="px-4 py-3 text-left text-[11px] font-bold uppercase text-slate-500">Voucher</th>
                <th class="px-4 py-3 text-left text-[11px] font-bold uppercase text-slate-500">Customer</th>
                <th class="px-4 py-3 text-right text-[11px] font-bold uppercase text-slate-500">Grand Total</th>
                <th class="px-4 py-3 text-right text-[11px] font-bold uppercase text-slate-500">Paid</th>
                <th class="px-4 py-3 text-right text-[11px] font-bold uppercase text-slate-500">Due</th>
                <th class="px-4 py-3 text-center text-[11px] font-bold uppercase text-slate-500">Action</th>
            </tr></thead>
            <tbody class="divide-y divide-slate-100">
                @forelse($sales as $s)
                <tr class="hover:bg-slate-50/50">
                    <td class="px-4 py-3 text-xs text-slate-500">{{ $s->sales_date->format('d M Y') }}</td>
                    <td class="px-4 py-3 text-xs font-mono text-emerald-600 font-semibold">{{ $s->voucher_no }}</td>
                    <td class="px-4 py-3 text-sm font-medium">{{ $s->party->name ?? '—' }}</td>
                    <td class="px-4 py-3 text-right font-bold text-emerald-600 counter-num">৳{{ number_format($s->grand_total) }}</td>
                    <td class="px-4 py-3 text-right text-emerald-600 counter-num">৳{{ number_format($s->paid_amount) }}</td>
                    <td class="px-4 py-3 text-right text-rose-600 counter-num">৳{{ number_format($s->due_amount) }}</td>
                    <td class="px-4 py-3 text-center">
                        <div class="flex items-center justify-center gap-1">
                            <a href="{{ route('sales.show', $s->id) }}" class="w-8 h-8 flex items-center justify-center rounded-lg hover:bg-slate-100"><i data-lucide="eye" class="w-4 h-4"></i></a>
                            <a href="{{ route('sales.edit', $s->id) }}" class="w-8 h-8 flex items-center justify-center rounded-lg hover:bg-slate-100"><i data-lucide="edit-2" class="w-4 h-4"></i></a>
                        </div>
                    </td>
                </tr>
                @empty
                <tr><td colspan="7" class="text-center py-8 text-slate-500">No sales found.</td></tr>
                @endforelse
            </tbody>
        </table>
        @if($sales->hasPages())
        <div class="px-4 py-3 border-t border-slate-200">{{ $sales->withQueryString()->links() }}</div>
        @endif
    </x-card>
</div>
@endsection
