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

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

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

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

        <div class="card">
            <div class="card-header">
                <h3 class="card-title">Lotes</h3>
                <div class="card-tools">
                    <Link :href="route('admin.ranch.fattening.create')" class="btn btn-sm btn-success">
                        <i class="fa-solid fa-plus me-1"></i> Nuevo lote
                    </Link>
                </div>
            </div>
            <div class="card-body table-responsive p-0">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th>Nombre</th>
                            <th>Entrada</th>
                            <th>Animales</th>
                            <th>Estado</th>
                            <th class="text-end">Acciones</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="lot in lots.data" :key="lot.id">
                            <td><strong>{{ lot.name }}</strong></td>
                            <td>{{ lot.entry_date }}</td>
                            <td>{{ lot.animals_count ?? 0 }}</td>
                            <td>
                                <span class="badge" :class="lot.status === 'open' ? 'text-bg-success' : 'text-bg-secondary'">
                                    {{ lot.status === 'open' ? 'Abierto' : 'Cerrado' }}
                                </span>
                            </td>
                            <td class="text-end">
                                <Link :href="route('admin.ranch.fattening.show', lot.id)" class="btn btn-sm btn-outline-primary">
                                    Ver
                                </Link>
                            </td>
                        </tr>
                        <tr v-if="!lots.data?.length">
                            <td colspan="5" class="text-center text-muted py-4">Sin lotes</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </AuthenticatedLayout>
</template>
