@php $canManage = $canConsult ?? false; @endphp

<section class="rounded-2xl border border-slate-200 bg-white p-5">
    <h3 class="text-sm font-semibold text-slate-900">Recalls</h3>
    <p class="mt-0.5 text-xs text-slate-500">Schedule follow-ups and mark them complete when the patient returns.</p>

    <ul class="mt-4 space-y-2 text-sm">
        @forelse ($dentalRecalls ?? [] as $recall)
            <li class="flex flex-wrap items-center justify-between gap-2 rounded-xl border border-slate-100 bg-slate-50 px-3 py-2">
                <div>
                    <p class="font-medium text-slate-800">{{ $recall->reason ?: 'Recall' }}</p>
                    <p class="text-xs text-slate-500">
                        Due {{ $recall->due_on?->format('d M Y') }} · {{ ucfirst($recall->status) }}
                    </p>
                </div>
                @if ($canManage && in_array($recall->status, ['scheduled', 'due'], true))
                    <div class="flex gap-2">
                        <form method="POST" action="{{ route('care.specialty.dentistry.recalls.complete', [$workspaceVisit, $recall]) }}">
                            @csrf
                            <button type="submit" class="text-xs font-medium text-emerald-700">Complete</button>
                        </form>
                        <form method="POST" action="{{ route('care.specialty.dentistry.recalls.cancel', [$workspaceVisit, $recall]) }}">
                            @csrf
                            <button type="submit" class="text-xs font-medium text-rose-600">Cancel</button>
                        </form>
                    </div>
                @endif
            </li>
        @empty
            <li class="text-slate-500">No recalls scheduled.</li>
        @endforelse
    </ul>

    @if ($canManage)
        <form method="POST" action="{{ route('care.specialty.dentistry.recalls', $workspaceVisit) }}" class="mt-6 space-y-3 border-t border-slate-100 pt-4">
            @csrf
            <h4 class="text-sm font-semibold text-slate-900">Schedule recall</h4>
            <div class="grid gap-3 sm:grid-cols-2">
                <div>
                    <label class="block text-xs font-medium text-slate-600">Due date</label>
                    <input type="date" name="due_on" required class="mt-1 w-full rounded-xl border border-slate-200 px-3 py-2 text-sm"
                           value="{{ now()->addMonths(6)->toDateString() }}">
                </div>
                <div>
                    <label class="block text-xs font-medium text-slate-600">Reason</label>
                    <input type="text" name="reason" placeholder="e.g. 6-month check" class="mt-1 w-full rounded-xl border border-slate-200 px-3 py-2 text-sm">
                </div>
                <div class="sm:col-span-2">
                    <label class="block text-xs font-medium text-slate-600">Notes</label>
                    <input type="text" name="notes" class="mt-1 w-full rounded-xl border border-slate-200 px-3 py-2 text-sm">
                </div>
            </div>
            <button type="submit" class="btn-primary">Schedule recall</button>
        </form>
    @endif
</section>
