<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
import { Head, Link } from '@inertiajs/vue3';

defineProps({
    events: { type: Object, required: true },
    eventTypes: { type: Object, default: () => ({}) },
    filters: { type: Object, default: () => ({}) },
});
</script>

<template>
    <Head title="Salud — Control Ganadero" />

    <AuthenticatedLayout>
        <template #header><h3 class="mb-0">Eventos de salud</h3></template>
        <template #breadcrumb>
            <li class="breadcrumb-item"><Link :href="route('dashboard')">Inicio</Link></li>
            <li class="breadcrumb-item active">Salud</li>
        </template>

        <div class="card">
            <div class="card-header">
                <h3 class="card-title">Historial</h3>
                <div class="card-tools">
                    <Link :href="route('admin.ranch.health.create')" class="btn btn-sm btn-success">
                        <i class="fa-solid fa-plus me-1"></i> Registrar
                    </Link>
                </div>
            </div>
            <div class="card-body table-responsive p-0">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th>Fecha</th>
                            <th>Arete</th>
                            <th>Tipo</th>
                            <th>Título</th>
                            <th>Costo</th>
                            <th>Usuario</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="e in events.data" :key="e.id">
                            <td>{{ e.event_date }}</td>
                            <td>{{ e.cattle?.ear_tag }}</td>
                            <td>{{ eventTypes[e.event_type] || e.event_type }}</td>
                            <td>{{ e.title }}</td>
                            <td>{{ e.cost ?? '—' }}</td>
                            <td>{{ e.user?.name || '—' }}</td>
                        </tr>
                        <tr v-if="!events.data?.length">
                            <td colspan="6" class="text-center text-muted py-4">Sin eventos</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </AuthenticatedLayout>
</template>
