@php
    $plan = $dentalPlan;
    $openItems = $plan?->items?->whereIn('status', ['proposed', 'accepted']) ?? collect();
@endphp

<section class="rounded-2xl border border-slate-200 bg-white p-5">
    <div class="flex flex-wrap items-start justify-between gap-3">
        <div>
            <h3 class="text-sm font-semibold text-slate-900">Overview</h3>
            <p class="mt-0.5 text-xs text-slate-500">Visit summary and open treatment work.</p>
        </div>
        <a href="{{ route('care.specialty.dentistry.reports') }}" class="text-sm font-medium text-indigo-600">Dentistry reports</a>
    </div>

    <dl class="mt-4 grid gap-3 text-sm sm:grid-cols-2">
        <div>
            <dt class="text-slate-500">Visit status</dt>
            <dd class="font-medium text-slate-900">{{ ucfirst(str_replace('_', ' ', $workspaceVisit->status)) }}</dd>
        </div>
        <div>
            <dt class="text-slate-500">Checked in</dt>
            <dd class="font-medium text-slate-900">{{ $workspaceVisit->checked_in_at?->format('d M Y H:i') ?? '—' }}</dd>
        </div>
        <div>
            <dt class="text-slate-500">Queue</dt>
            <dd class="font-medium text-slate-900">
                {{ $workspaceVisit->appointment?->queue_ticket_number ?? '—' }}
                @if ($workspaceVisit->appointment?->queue_ticket_status)
                    <span class="text-slate-500">({{ $workspaceVisit->appointment->queue_ticket_status }})</span>
                @endif
            </dd>
        </div>
        <div>
            <dt class="text-slate-500">Treatment plan</dt>
            <dd class="font-medium text-slate-900">
                @if ($plan)
                    {{ ucfirst(str_replace('_', ' ', $plan->status)) }}
                    · {{ $currency ?? 'GHS' }} {{ number_format($plan->estimate_minor / 100, 2) }}
                @else
                    None open
                @endif
            </dd>
        </div>
    </dl>

    @if ($openItems->isNotEmpty())
        <div class="mt-4 border-t border-slate-100 pt-4">
            <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Unfinished plan items</p>
            <ul class="mt-2 space-y-1 text-sm">
                @foreach ($openItems->take(8) as $item)
                    <li class="flex justify-between gap-3">
                        <span>
                            {{ $item->label }}
                            @if ($item->tooth_code) <span class="text-slate-400">· {{ $item->tooth_code }}</span> @endif
                        </span>
                        <span class="tabular-nums text-slate-500">{{ number_format($item->estimate_minor / 100, 2) }}</span>
                    </li>
                @endforeach
            </ul>
        </div>
    @endif

    @if (! empty($clinicalAlerts))
        <div class="mt-4 space-y-1.5 border-t border-slate-100 pt-4">
            <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Alerts</p>
            @foreach ($clinicalAlerts as $alert)
                <p class="text-sm {{ ($alert['severity'] ?? '') === 'critical' ? 'text-rose-700' : 'text-amber-800' }}">
                    {{ $alert['message'] ?? '' }}
                </p>
            @endforeach
        </div>
    @endif
</section>
