import ExploitantController from '@/actions/App/Http/Controllers/Referentiels/ExploitantController';
import { ReferentielPage } from '@/components/referentiel-page';
import { dashboard } from '@/routes';
import { index } from '@/routes/exploitants';
import type { Exploitant } from '@/types/business';

export default function Exploitants({
    exploitants,
}: {
    exploitants: Exploitant[];
}) {
    return (
        <ReferentielPage
            title="Exploitants"
            description="Référentiel des sociétés et groupements exploitants forestiers"
            singular="exploitant"
            items={exploitants}
            storeUrl={ExploitantController.store.url()}
            updateUrl={(id) => ExploitantController.update.url(id)}
            toggleUrl={(id) => ExploitantController.toggle.url(id)}
            destroyUrl={(id) => ExploitantController.destroy.url(id)}
            nameOf={(e) => e.nom}
            columns={[
                { header: 'Raison sociale', value: (e) => e.nom },
                { header: 'Code', value: (e) => e.code ?? null },
                { header: 'Marteau', value: (e) => e.marteau },
                { header: 'Ville', value: (e) => e.ville ?? null },
                { header: 'Téléphone', value: (e) => e.telephone ?? null },
            ]}
            fields={[
                { name: 'nom', label: 'Raison sociale', required: true },
                { name: 'code', label: 'Code exploitant' },
                { name: 'marteau', label: 'Marteau', required: true },
                { name: 'boite_postale', label: 'Boîte postale' },
                { name: 'ville', label: 'Ville' },
                { name: 'telephone', label: 'Téléphone' },
                {
                    name: 'actif',
                    label: 'Actif (proposé à la saisie)',
                    type: 'checkbox',
                },
            ]}
        />
    );
}

Exploitants.layout = {
    breadcrumbs: [
        { title: 'Tableau de bord', href: dashboard() },
        { title: 'Exploitants', href: index() },
    ],
};
