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

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

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

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

        <div class="card">
            <div class="card-header">
                <h3 class="card-title">Historial de pesajes</h3>
                <div class="card-tools">
                    <Link :href="route('admin.ranch.weights.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>Peso (kg)</th>
                            <th>Ganancia</th>
                            <th>GDP</th>
                            <th>Usuario</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="r in records.data" :key="r.id">
                            <td>{{ r.weighed_at }}</td>
                            <td>
                                <Link :href="route('admin.ranch.cattle.show', r.cattle_id)">{{ r.cattle?.ear_tag }}</Link>
                            </td>
                            <td>{{ r.weight_kg }}</td>
                            <td>{{ r.weight_gain_kg ?? '—' }}</td>
                            <td>{{ r.daily_weight_gain ?? '—' }}</td>
                            <td>{{ r.user?.name || '—' }}</td>
                        </tr>
                        <tr v-if="!records.data?.length">
                            <td colspan="6" class="text-center text-muted py-4">Sin pesajes</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </AuthenticatedLayout>
</template>
