<x-app-layout title="Dentistry 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">Dentistry reports</h1>
                <p class="mt-1 text-sm text-slate-500">Procedures, revenue, unfinished plans, and imaging volume.</p>
            </div>
            <a href="{{ route('care.specialty.show', 'dentistry') }}" 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-3">
            <div class="rounded-2xl border border-slate-200 bg-white p-4">
                <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Unfinished plan items</p>
                <p class="mt-2 text-2xl font-semibold tabular-nums text-slate-900">{{ number_format($report['unfinished_items']) }}</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 chair time (month)</p>
                <p class="mt-2 text-2xl font-semibold tabular-nums text-slate-900">
                    {{ $report['avg_chair_minutes'] !== null ? $report['avg_chair_minutes'].' min' : '—' }}
                </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">Imaging studies (month)</p>
                <p class="mt-2 text-2xl font-semibold tabular-nums text-slate-900">
                    {{ number_format($report['imaging_by_modality']->sum('total')) }}
                </p>
            </div>
        </div>

        <section class="rounded-2xl border border-slate-200 bg-white p-5">
            <h2 class="text-sm font-semibold text-slate-900">Procedures today</h2>
            <ul class="mt-3 space-y-1 text-sm">
                @forelse ($report['procedures_today'] as $row)
                    <li class="flex justify-between gap-3">
                        <span>{{ $row->label }} × {{ $row->total }}</span>
                        <span class="tabular-nums">{{ $currency }} {{ number_format($row->amount_minor / 100, 2) }}</span>
                    </li>
                @empty
                    <li class="text-slate-500">No procedures today.</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">Procedures this month</h2>
            <ul class="mt-3 space-y-1 text-sm">
                @forelse ($report['procedures_month'] as $row)
                    <li class="flex justify-between gap-3">
                        <span>{{ $row->label }} × {{ $row->total }}</span>
                        <span class="tabular-nums">{{ $currency }} {{ number_format($row->amount_minor / 100, 2) }}</span>
                    </li>
                @empty
                    <li class="text-slate-500">No procedures this month.</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">Revenue by procedure (range)</h2>
            <ul class="mt-3 space-y-1 text-sm">
                @forelse ($report['revenue_by_code'] as $row)
                    <li class="flex justify-between gap-3">
                        <span>{{ $row->description }} × {{ $row->total }}</span>
                        <span class="tabular-nums">{{ $currency }} {{ number_format($row->amount_minor / 100, 2) }}</span>
                    </li>
                @empty
                    <li class="text-slate-500">No dental procedure revenue in this 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">Imaging by modality</h2>
            <ul class="mt-3 space-y-1 text-sm">
                @forelse ($report['imaging_by_modality'] as $row)
                    <li class="flex justify-between gap-3">
                        <span>{{ $modalities[$row->modality] ?? $row->modality }}</span>
                        <span class="tabular-nums">{{ $row->total }}</span>
                    </li>
                @empty
                    <li class="text-slate-500">No imaging this month.</li>
                @endforelse
            </ul>
        </section>
    </div>
</x-app-layout>
