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

defineProps({
    calvings: { type: Object, required: true },
    genders: { type: Object, default: () => ({}) },
});
</script>

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

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

        <div class="card">
            <div class="card-header">
                <h3 class="card-title">Registro de partos</h3>
                <div class="card-tools">
                    <Link :href="route('admin.ranch.calvings.create')" class="btn btn-sm btn-success">
                        <i class="fa-solid fa-plus me-1"></i> Registrar parto
                    </Link>
                </div>
            </div>
            <div class="card-body table-responsive p-0">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th>Fecha</th>
                            <th>Madre</th>
                            <th>Cría</th>
                            <th>Sexo</th>
                            <th>Peso al nacer</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="c in calvings.data" :key="c.id">
                            <td>{{ c.calving_date }}</td>
                            <td>{{ c.mother?.ear_tag }}</td>
                            <td>
                                <Link v-if="c.calf_id" :href="route('admin.ranch.cattle.show', c.calf_id)">
                                    {{ c.calf?.ear_tag }}
                                </Link>
                            </td>
                            <td>{{ genders[c.calf?.gender] || c.calf?.gender || '—' }}</td>
                            <td>{{ c.birth_weight_kg ?? '—' }}</td>
                        </tr>
                        <tr v-if="!calvings.data?.length">
                            <td colspan="5" class="text-center text-muted py-4">Sin partos</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </AuthenticatedLayout>
</template>
