<x-app-layout title="Physiotherapy reports">
    <div class="space-y-6">
        <div class="flex flex-wrap items-center justify-between gap-3">
            <div>
                <h1 class="text-xl font-semibold text-slate-900">Physiotherapy reports</h1>
                <p class="mt-1 text-sm text-slate-500">Arrivals, high pain, diagnoses, session outcomes, length of stay, and physio service revenue.</p>
            </div>
            <a href="{{ route('care.specialty.show', 'physiotherapy') }}" class="text-sm font-medium text-indigo-600">← Specialty home</a>
        </div>

        <form method="GET" class="flex flex-wrap items-end gap-3 rounded-2xl border border-slate-200 bg-white p-4">
            <div>
                <label class="block text-xs font-medium text-slate-600">From</label>
                <input type="date" name="from" value="{{ $report['from'] ?? '' }}" class="mt-1 rounded-xl border border-slate-200 px-3 py-2 text-sm">
            </div>
            <div>
                <label class="block text-xs font-medium text-slate-600">To</label>
                <input type="date" name="to" value="{{ $report['to'] ?? '' }}" class="mt-1 rounded-xl border border-slate-200 px-3 py-2 text-sm">
            </div>
            <button type="submit" class="rounded-xl bg-indigo-600 px-4 py-2 text-sm font-semibold text-white">Apply</button>
        </form>

        <div class="grid gap-4 sm:grid-cols-4">
            <div class="rounded-2xl border border-slate-200 bg-white p-4">
                <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Arrivals today</p>
                <p class="mt-2 text-2xl font-semibold tabular-nums text-slate-900">{{ number_format($report['arrivals_today']) }}</p>
            </div>
            <div class="rounded-2xl border border-slate-200 bg-white p-4">
                <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Completed today</p>
                <p class="mt-2 text-2xl font-semibold tabular-nums text-slate-900">{{ number_format($report['completed_today']) }}</p>
            </div>
            <div class="rounded-2xl border border-slate-200 bg-white p-4">
                <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">High pain open</p>
                <p class="mt-2 text-2xl font-semibold tabular-nums text-rose-700">{{ number_format($report['high_pain_open']) }}</p>
            </div>
            <div class="rounded-2xl border border-slate-200 bg-white p-4">
                <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Avg LOS (range)</p>
                <p class="mt-2 text-2xl font-semibold tabular-nums text-slate-900">
                    {{ $report['avg_los_minutes'] !== null ? $report['avg_los_minutes'].' min' : '—' }}
                </p>
            </div>
        </div>

        <div class="grid gap-4 lg:grid-cols-2">
            <section class="rounded-2xl border border-slate-200 bg-white p-5">
                <h2 class="text-sm font-semibold text-slate-900">Diagnoses</h2>
                <ul class="mt-3 space-y-2 text-sm">
                    @forelse ($report['diagnosis_breakdown'] as $row)
                        <li class="flex justify-between gap-3">
                            <span>{{ $row['diagnosis'] }}</span>
                            <span class="tabular-nums text-slate-600">{{ $row['total'] }}</span>
                        </li>
                    @empty
                        <li class="text-slate-500">No diagnosis records in range.</li>
                    @endforelse
                </ul>
            </section>

            <section class="rounded-2xl border border-slate-200 bg-white p-5">
                <h2 class="text-sm font-semibold text-slate-900">Session outcomes</h2>
                <ul class="mt-3 space-y-2 text-sm">
                    @forelse ($report['session_outcomes'] as $row)
                        <li class="flex justify-between gap-3">
                            <span>{{ $row['outcome'] }}</span>
                            <span class="tabular-nums text-slate-600">{{ $row['total'] }}</span>
                        </li>
                    @empty
                        <li class="text-slate-500">No sessions in range.</li>
                    @endforelse
                </ul>
            </section>
        </div>

        <section class="rounded-2xl border border-slate-200 bg-white p-5">
            <h2 class="text-sm font-semibold text-slate-900">Physiotherapy service revenue</h2>
            <ul class="mt-3 space-y-2 text-sm">
                @forelse ($report['revenue_by_service'] as $row)
                    <li class="flex justify-between gap-3">
                        <span>{{ $row->description }} <span class="text-slate-400">×{{ $row->total }}</span></span>
                        <span class="tabular-nums">{{ $currency }} {{ number_format($row->amount_minor / 100, 2) }}</span>
                    </li>
                @empty
                    <li class="text-slate-500">No billed physiotherapy services in range.</li>
                @endforelse
            </ul>
        </section>
    </div>
</x-app-layout>
