@extends('layouts.portal')

@section('title', 'Laporan harian — '.config('portal.product_line'))
@section('page_heading', 'Laporan — Harian (gabungan)')
@section('page_subheading', 'Satu baris per tanggal: order & omzet FnB vs transaksi & omzet refleksologi. Gunakan nomor halaman di bawah tabel.')

@section('content')
    @include('owner.reports._nav')
    @include('owner.reports._filters')

    @if (!empty($data['errors']))
        <div class="mb-6 rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-950" role="alert">
            <p class="font-semibold text-amber-900">Perlu perhatian</p>
            <ul class="mt-2 list-disc space-y-1 pl-5">
                @foreach ($data['errors'] as $err)
                    <li><span class="font-medium">{{ $err['source'] }}</span>: {{ $err['message'] }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <div class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm">
        <div class="border-b border-slate-100 px-4 py-3 md:px-5">
            <h2 class="text-sm font-semibold text-slate-900">Tabel harian periode {{ $dateFrom }} — {{ $dateTo }}</h2>
            <p class="mt-0.5 text-xs text-slate-500">Total {{ $dailyPaginator->total() }} hari dengan data · menampilkan {{ $dailyPaginator->count() }} baris di halaman ini.</p>
        </div>
        @if ($dailyPaginator->total() > 0)
            <div class="overflow-x-auto">
                <table class="min-w-full text-sm">
                    <thead class="bg-slate-50 text-left text-xs uppercase text-slate-600">
                        <tr>
                            <th class="px-4 py-3">Tanggal</th>
                            <th class="px-4 py-3 text-right">Order FnB</th>
                            <th class="px-4 py-3 text-right">Rev. FnB</th>
                            <th class="px-4 py-3 text-right">Trx reflex</th>
                            <th class="px-4 py-3 text-right">Omzet reflex</th>
                            <th class="px-4 py-3 text-right">Rev. gabungan</th>
                            <th class="px-4 py-3 text-right">Kontrib. gab.</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-slate-100">
                        @foreach ($dailyPaginator as $row)
                            <tr class="hover:bg-slate-50/80">
                                <td class="whitespace-nowrap px-4 py-2.5 font-medium text-slate-800">{{ $row['date'] }}</td>
                                <td class="px-4 py-2.5 text-right tabular-nums text-slate-700">{{ number_format($row['fnb_order_count'] ?? 0, 0, ',', '.') }}</td>
                                <td class="px-4 py-2.5 text-right tabular-nums text-slate-700">Rp {{ number_format($row['fnb_revenue'] ?? 0, 0, ',', '.') }}</td>
                                <td class="px-4 py-2.5 text-right tabular-nums text-slate-700">{{ number_format($row['reflex_transaction_count'] ?? 0, 0, ',', '.') }}</td>
                                <td class="px-4 py-2.5 text-right tabular-nums text-slate-700">Rp {{ number_format($row['reflex_gross_revenue'] ?? 0, 0, ',', '.') }}</td>
                                <td class="px-4 py-2.5 text-right tabular-nums font-medium text-slate-900">Rp {{ number_format($row['combined_revenue'] ?? 0, 0, ',', '.') }}</td>
                                <td class="px-4 py-2.5 text-right tabular-nums text-emerald-700">Rp {{ number_format($row['combined_contribution'] ?? 0, 0, ',', '.') }}</td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
            <div class="border-t border-slate-100 px-4 py-3">
                {{ $dailyPaginator->withQueryString()->links('vendor.pagination.tailwind') }}
            </div>
        @else
            <div class="px-4 py-10 text-center text-sm text-slate-500">Belum ada baris harian untuk rentang ini.</div>
        @endif
    </div>
@endsection
