@extends('layouts.portal')

@section('title', 'Laba rugi sederhana — '.config('portal.product_line'))
@section('page_heading', 'Laporan — Laba rugi sederhana')
@section('page_subheading', 'Rincian indikatif untuk pemantauan — bukan laporan akuntansi penuh.')

@php $pl = $data['combined']['simple_pl'] ?? []; @endphp

@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

    <p class="mb-4 text-sm text-slate-600">{{ $pl['disclaimer'] ?? '' }}</p>

    <div class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm">
        <div class="grid divide-y divide-slate-100 md:grid-cols-2 md:divide-x md:divide-y-0">
            <div class="p-5 md:p-6">
                <h2 class="text-sm font-semibold uppercase tracking-wide text-sky-800">{{ config('portal.sources.esborder.title') }}</h2>
                <dl class="mt-4 space-y-3 text-sm">
                    <div class="flex justify-between gap-4 border-b border-slate-100 pb-2"><dt class="text-slate-600">Pendapatan (revenue)</dt><dd class="font-semibold tabular-nums text-slate-900">Rp {{ number_format($pl['fnb_revenue'] ?? 0, 0, ',', '.') }}</dd></div>
                    <div class="flex justify-between gap-4 border-b border-slate-100 pb-2"><dt class="text-slate-600">HPP / COGS</dt><dd class="font-semibold tabular-nums text-slate-900">(Rp {{ number_format($pl['fnb_cogs'] ?? 0, 0, ',', '.') }})</dd></div>
                    <div class="flex justify-between gap-4"><dt class="font-medium text-slate-800">Laba kotor FnB</dt><dd class="text-base font-bold tabular-nums text-emerald-700">Rp {{ number_format($pl['fnb_gross_profit'] ?? 0, 0, ',', '.') }}</dd></div>
                </dl>
            </div>
            <div class="p-5 md:p-6">
                <h2 class="text-sm font-semibold uppercase tracking-wide text-violet-800">{{ config('portal.sources.sysreflex.title') }}</h2>
                <dl class="mt-4 space-y-3 text-sm">
                    <div class="flex justify-between gap-4 border-b border-slate-100 pb-2"><dt class="text-slate-600">Omzet layanan</dt><dd class="font-semibold tabular-nums text-slate-900">Rp {{ number_format($pl['reflex_gross_revenue'] ?? 0, 0, ',', '.') }}</dd></div>
                    <div class="flex justify-between gap-4 border-b border-slate-100 pb-2"><dt class="text-slate-600">Komisi therapist</dt><dd class="font-semibold tabular-nums text-slate-900">(Rp {{ number_format($pl['reflex_commission'] ?? 0, 0, ',', '.') }})</dd></div>
                    <div class="flex justify-between gap-4"><dt class="font-medium text-slate-800">Margin setelah komisi</dt><dd class="text-base font-bold tabular-nums text-emerald-700">Rp {{ number_format($pl['reflex_margin_after_commission'] ?? 0, 0, ',', '.') }}</dd></div>
                </dl>
            </div>
        </div>
        <div class="border-t border-slate-200 bg-slate-50 px-5 py-4 md:px-6">
            <div class="flex flex-wrap items-center justify-between gap-3 text-sm">
                <span class="text-slate-600">Total baris pendapatan (FnB + refleks)</span>
                <span class="font-semibold tabular-nums text-slate-900">Rp {{ number_format($pl['total_revenue_lines'] ?? 0, 0, ',', '.') }}</span>
            </div>
            <div class="mt-2 flex flex-wrap items-center justify-between gap-3 text-sm">
                <span class="font-medium text-slate-800">Kontribusi gabungan (indikatif)</span>
                <span class="text-lg font-bold tabular-nums text-emerald-700">Rp {{ number_format($pl['combined_contribution'] ?? 0, 0, ',', '.') }}</span>
            </div>
        </div>
    </div>
@endsection
