<x-layouts.tenant pageTitle="Órdenes — {{ $patient->fullName() }}">
    <x-page-header :title="'Órdenes: '.$patient->fullName()" subtitle="Historial de órdenes y recomendaciones clínicas">
        <div class="flex gap-2">
            <x-btn href="{{ route('tenant.orders.create', $patient) }}" variant="primary">+ Nueva orden</x-btn>
            <x-btn :href="route('tenant.patients.show', $patient)" variant="secondary">Ver paciente</x-btn>
        </div>
    </x-page-header>

    <x-card>
        @forelse($orders as $order)
            <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">{{ $order->title }}</p>
                    <p class="text-xs text-gray-500 mt-0.5">
                        {{ $types[$order->type] ?? $order->type }} · {{ $order->created_at->format('d/m/Y') }}
                        @if($order->employee) · Prof: {{ $order->employee->user?->name }} @endif
                    </p>
                </div>
                <div class="flex items-center gap-3">
                    <span class="text-xs px-2 py-0.5 rounded-full
                        {{ $order->status === 'signed' ? 'bg-green-100 text-green-700' : 'bg-yellow-100 text-yellow-700' }}">
                        {{ ucfirst($order->status) }}
                    </span>
                    <a href="{{ route('tenant.orders.show', [$patient, $order]) }}" class="text-xs text-amber-600 hover:underline">Ver</a>
                    @if($order->isSigned())
                        <a href="{{ route('tenant.pdf.order', [$patient, $order]) }}" 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 órdenes registradas.</p>
        @endforelse

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