@extends('layouts.admin')

@section('title', 'POS Expenses')
@section('page-title', 'POS Expenses')

@section('content')
<div class="space-y-6">
    <section class="rounded-3xl border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-700 dark:bg-slate-900">
        <form method="GET" class="grid gap-4 lg:grid-cols-[2fr_auto]">
            <input type="text" name="q" value="{{ request('q') }}" placeholder="Title, category, or user email"
                   class="w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm outline-none transition focus:border-brand-600 focus:ring-4 focus:ring-brand-600/10 dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100">
            <button type="submit" class="rounded-2xl bg-brand-600 px-5 py-3 text-sm font-semibold text-white transition hover:bg-brand-700">Filter</button>
        </form>
    </section>

    <section class="rounded-3xl border border-slate-200 bg-white shadow-sm dark:border-slate-700 dark:bg-slate-900">
        <div class="overflow-x-auto">
            <table class="min-w-full text-left text-sm">
                <thead class="border-b border-slate-200 bg-slate-50 text-slate-500 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-400">
                    <tr>
                        <th class="px-6 py-4 font-semibold">User</th>
                        <th class="px-6 py-4 font-semibold">Title</th>
                        <th class="px-6 py-4 font-semibold">Category</th>
                        <th class="px-6 py-4 font-semibold">Amount</th>
                        <th class="px-6 py-4 font-semibold">Payment</th>
                        <th class="px-6 py-4 font-semibold">Date</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100 dark:divide-slate-700">
                    @forelse($expenses as $expense)
                        <tr class="table-row-hover">
                            <td class="px-6 py-4">
                                <div class="font-semibold text-slate-900 dark:text-slate-100">{{ $expense->user->name ?? 'Unknown' }}</div>
                                <div class="text-xs text-slate-500">{{ $expense->user->email ?? '—' }}</div>
                            </td>
                            <td class="px-6 py-4 font-semibold text-slate-900 dark:text-slate-100">{{ $expense->title }}</td>
                            <td class="px-6 py-4 text-slate-600 dark:text-slate-300">{{ $expense->category_name ?: '—' }}</td>
                            <td class="px-6 py-4 font-semibold text-slate-900 dark:text-slate-100">{{ number_format($expense->amount, 2) }}</td>
                            <td class="px-6 py-4 text-slate-600 dark:text-slate-300">{{ $expense->payment_method ?: '—' }}</td>
                            <td class="px-6 py-4 text-slate-500 text-xs">
                                {{ $expense->expense_date ? \Carbon\Carbon::parse($expense->expense_date)->format('d M Y') : '—' }}
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="6" class="px-6 py-16 text-center text-sm text-slate-500">No expenses synced yet.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        <div class="border-t border-slate-200 px-6 py-4 dark:border-slate-700">{{ $expenses->links() }}</div>
    </section>
</div>
@endsection
