@extends('layouts.app')
@section('title', 'Laporan Pengeluaran Toko')
@section('page-title', 'Laporan Pengeluaran Toko')

@section('content')
<div class="space-y-5">
    {{-- Filter & Summary --}}
    <div class="grid grid-cols-1 lg:grid-cols-3 gap-5">
        <div class="lg:col-span-2 bg-white rounded-3xl border border-slate-200 p-6 shadow-sm">
            <form method="GET" class="flex flex-wrap items-end gap-4">
                <div>
                    <label class="text-[10px] font-bold text-slate-400 uppercase tracking-widest block mb-1">Mulai</label>
                    <input type="date" name="start" value="{{ $start->format('Y-m-d') }}" 
                        class="px-4 py-2 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 outline-none">
                </div>
                <div>
                    <label class="text-[10px] font-bold text-slate-400 uppercase tracking-widest block mb-1">Selesai</label>
                    <input type="date" name="end" value="{{ $end->format('Y-m-d') }}" 
                        class="px-4 py-2 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 outline-none">
                </div>
                <button type="submit" class="px-6 py-2 bg-slate-900 text-white font-bold rounded-xl text-sm hover:bg-slate-800 transition">Filter</button>
            </form>
        </div>
        
        <div class="bg-rose-600 rounded-3xl p-6 text-white shadow-xl shadow-rose-600/20 flex flex-col justify-center">
            <div class="text-[10px] font-bold uppercase tracking-widest opacity-80 mb-1">Total Pengeluaran</div>
            <div class="text-3xl font-black">Rp {{ number_format($summary->total_amount, 0, ',', '.') }}</div>
            <div class="text-xs mt-1 opacity-70">{{ $summary->total_count }} catatan pengeluaran</div>
        </div>
    </div>

    {{-- Table --}}
    <div class="bg-white rounded-3xl border border-slate-200 shadow-sm overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-sm">
                <thead>
                    <tr class="bg-slate-50 text-slate-500 border-b border-slate-200">
                        <th class="px-4 py-4 text-left font-bold uppercase tracking-tighter">Waktu</th>
                        <th class="px-4 py-4 text-left font-bold uppercase tracking-tighter">Kategori</th>
                        <th class="px-4 py-4 text-left font-bold uppercase tracking-tighter">Keterangan</th>
                        <th class="px-4 py-4 text-right font-bold uppercase tracking-tighter">Jumlah</th>
                        <th class="px-4 py-4 text-center font-bold uppercase tracking-tighter">Petugas</th>
                        <th class="px-4 py-4 text-center font-bold uppercase tracking-tighter">Sesi POS</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    @forelse($expenses as $e)
                    <tr class="hover:bg-slate-50/50 transition">
                        <td class="px-4 py-4">
                            <div class="font-bold text-slate-700">{{ $e->expense_date->format('d/m/Y') }}</div>
                            <div class="text-[10px] text-slate-400">{{ $e->expense_date->format('H:i') }}</div>
                        </td>
                        <td class="px-4 py-4">
                            <span class="px-2 py-1 rounded-lg text-[10px] font-bold bg-slate-100 text-slate-600 uppercase">{{ $e->category }}</span>
                        </td>
                        <td class="px-4 py-4 text-slate-600 italic">"{{ $e->description }}"</td>
                        <td class="px-4 py-4 text-right font-black text-rose-600">Rp {{ number_format($e->amount, 0, ',', '.') }}</td>
                        <td class="px-4 py-4 text-center text-xs text-slate-500">{{ $e->user->name }}</td>
                        <td class="px-4 py-4 text-center text-[10px] font-mono text-slate-400">
                            {{ $e->session ? '#S'.$e->session->id : '-' }}
                        </td>
                    </tr>
                    @empty
                    <tr><td colspan="6" class="px-4 py-16 text-center text-slate-400">Belum ada catatan pengeluaran</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        <div class="px-6 py-4 border-t border-slate-100">
            {{ $expenses->links() }}
        </div>
    </div>
</div>
@endsection
