<x-layouts.tenant pageTitle="Recetas — {{ $patient->fullName() }}">
    <x-page-header :title="'Recetas: '.$patient->fullName()" subtitle="Historial de prescripciones médicas">
        <div class="flex gap-2">
            <x-btn href="{{ route('tenant.prescriptions.create', $patient) }}" variant="primary">+ Nueva receta</x-btn>
            <x-btn :href="route('tenant.patients.show', $patient)" variant="secondary">Ver paciente</x-btn>
        </div>
    </x-page-header>

    <x-card>
        @forelse($prescriptions as $rx)
            <div class="flex items-center justify-between border-b border-gray-100 py-4 last:border-0">
                <div>
                    <p class="text-sm font-semibold text-gray-800">{{ $rx->prescription_number }}</p>
                    <p class="text-xs text-gray-500 mt-0.5">
                        {{ $rx->created_at->format('d/m/Y') }} ·
                        {{ $rx->items->count() }} medicamentos
                        @if($rx->employee) · Prof: {{ $rx->employee->user?->name }} @endif
                    </p>
                </div>
                <div class="flex items-center gap-3">
                    <span class="text-xs px-2 py-0.5 rounded-full font-medium
                        {{ $rx->status === 'signed' ? 'bg-green-100 text-green-700' : 'bg-yellow-100 text-yellow-700' }}">
                        {{ ucfirst($rx->status) }}
                    </span>
                    <a href="{{ route('tenant.prescriptions.show', [$patient, $rx]) }}"
                       class="text-xs text-teal-600 hover:underline">Ver</a>
                    @if($rx->isSigned())
                        <a href="{{ route('tenant.pdf.prescription', [$patient, $rx]) }}" target="_blank"
                           class="text-xs text-gray-500 hover:underline">↓ PDF</a>
                    @endif
                </div>
            </div>
        @empty
            <p class="text-center text-sm text-gray-400 py-8">Sin recetas registradas.</p>
        @endforelse

        @if($prescriptions->hasPages())
            <div class="mt-4">{{ $prescriptions->links() }}</div>
        @endif
    </x-card>
</x-layouts.tenant>
