@extends('layouts.portal')

@section('title', 'Ringkasan laporan — '.config('portal.product_line'))
@section('page_heading', 'Laporan — Ringkasan')
@section('page_subheading', 'Angka kunci periode terpilih. Gunakan tab di atas untuk detail laba rugi, harian, item, layanan, dan sumber data.')

@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="mb-6 grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
        <div class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
            <p class="text-xs font-medium uppercase tracking-wide text-slate-500">Revenue gabungan</p>
            <p class="mt-2 text-2xl font-bold tracking-tight text-slate-900">Rp {{ number_format($data['combined']['total_revenue_all_businesses'] ?? 0, 0, ',', '.') }}</p>
        </div>
        <div class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
            <p class="text-xs font-medium uppercase tracking-wide text-slate-500">Kontribusi gabungan <span class="font-normal normal-case text-slate-400">(indikatif)</span></p>
            <p class="mt-2 text-2xl font-bold tracking-tight text-emerald-700">Rp {{ number_format($data['combined']['total_gross_profit_combined'] ?? 0, 0, ',', '.') }}</p>
        </div>
        <div class="rounded-2xl border border-sky-100 bg-sky-50/80 p-5 shadow-sm">
            <p class="text-xs font-medium uppercase tracking-wide text-slate-600">{{ config('portal.sources.esborder.title') }}</p>
            @if ($data['esborder']['ok'] ?? false)
                <span class="mt-2 inline-flex rounded-full bg-emerald-100 px-2 py-0.5 text-xs font-semibold text-emerald-800">Terhubung</span>
            @else
                <span class="mt-2 inline-flex rounded-full bg-red-100 px-2 py-0.5 text-xs font-semibold text-red-800">Perlu setup</span>
            @endif
            <p class="mt-2 text-lg font-semibold text-slate-900">Rp {{ number_format($data['esborder']['revenue'] ?? 0, 0, ',', '.') }}</p>
            <p class="mt-1 text-xs text-slate-600">{{ number_format($data['esborder']['order_count'] ?? 0, 0, ',', '.') }} order selesai</p>
        </div>
        <div class="rounded-2xl border border-violet-100 bg-violet-50/80 p-5 shadow-sm">
            <p class="text-xs font-medium uppercase tracking-wide text-slate-600">{{ config('portal.sources.sysreflex.title') }}</p>
            @if ($data['sysreflex']['ok'] ?? false)
                <span class="mt-2 inline-flex rounded-full bg-emerald-100 px-2 py-0.5 text-xs font-semibold text-emerald-800">Terhubung</span>
            @else
                <span class="mt-2 inline-flex rounded-full bg-red-100 px-2 py-0.5 text-xs font-semibold text-red-800">Perlu setup</span>
            @endif
            <p class="mt-2 text-lg font-semibold text-slate-900">Rp {{ number_format($data['sysreflex']['gross_revenue'] ?? 0, 0, ',', '.') }}</p>
            <p class="mt-1 text-xs text-slate-600">{{ number_format($data['sysreflex']['transaction_count'] ?? 0, 0, ',', '.') }} transaksi</p>
        </div>
    </div>

    <div class="rounded-2xl border border-slate-200 bg-white p-5 text-sm text-slate-600 shadow-sm">
        <p class="font-medium text-slate-800">Langkah berikutnya</p>
        <ul class="mt-2 list-disc space-y-1 pl-5">
            <li>Tab <strong>Laba rugi</strong> — rincian pendapatan &amp; biaya indikatif per sumber.</li>
            <li>Tab <strong>Harian</strong> — tabel gabungan per tanggal dengan halaman (paginate).</li>
            <li>Tab <strong>Item FnB</strong> / <strong>Layanan</strong> — detail terlaris &amp; layanan teratas, juga berpaginasi.</li>
            <li>Tab <strong>Detail sumber</strong> — outlet, harian FnB, harian refleksologi (masing-masing paginate).</li>
        </ul>
        <p class="mt-3 text-xs text-slate-500">{{ $data['combined']['note'] ?? '' }}</p>
    </div>
@endsection
