import { computed } from 'vue' import { useAuthStore } from '~/stores/auth' export interface BovineColumn { key: string label: string width?: string } export interface UseBovineColumnsOptions { /** * 'inventory' (par défaut) : colonnes complètes incluant Bâtiment + Case. * 'case' : pas de Bâtiment ni Case (déjà dans le titre de la page), * largeurs élargies pour combler l'espace. */ variant?: 'inventory' | 'case' } /** * Définition partagée des colonnes des tableaux bovins (inventory + case). * 4 variants : avec/sans colonnes prix × inventory/case. * * Les colonnes Prix/kg et Prix total sont visibles pour les rôles BUREAU * et ADMIN (BUREAU hérite ses droits price-visibility, ADMIN hérite de BUREAU). */ export const useBovineColumns = (options: UseBovineColumnsOptions = {}) => { const auth = useAuthStore() const withPricesInventory: BovineColumn[] = [ { key: 'nationalNumber', label: 'N° National', width: '80px' }, { key: 'workNumber', label: 'N° Travail', width: '60px' }, { key: 'sex', label: 'Sexe', width: '70px' }, { key: 'birthDate', label: 'Né le', width: '72px' }, { key: 'age', label: 'Age', width: '110px' }, { key: 'bovineType.label', label: 'Race', width: '90px' }, { key: 'buildingCase.building.label', label: 'Bâtiment', width: '1fr' }, { key: 'buildingCase.caseNumber', label: 'Case', width: '42px' }, { key: 'arrivalDate', label: 'Entrée le', width: '90px' }, { key: 'pricePerKg', label: 'Prix/kg', width: '65px' }, { key: 'finalPrice', label: 'Prix total', width: '80px' } ] const withoutPricesInventory: BovineColumn[] = [ { key: 'nationalNumber', label: 'N° National', width: '80px' }, { key: 'workNumber', label: 'N° Travail', width: '60px' }, { key: 'sex', label: 'Sexe', width: '70px' }, { key: 'birthDate', label: 'Né le', width: '72px' }, { key: 'age', label: 'Age', width: '110px' }, { key: 'bovineType.label', label: 'Race', width: '1fr' }, { key: 'buildingCase.building.label', label: 'Bâtiment', width: '120px' }, { key: 'buildingCase.caseNumber', label: 'Case', width: '42px' }, { key: 'arrivalDate', label: 'Entrée le', width: '90px' } ] const withPricesCase: BovineColumn[] = [ { key: 'nationalNumber', label: 'N° National', width: '110px' }, { key: 'workNumber', label: 'N° Travail', width: '85px' }, { key: 'sex', label: 'Sexe', width: '90px' }, { key: 'birthDate', label: 'Né le', width: '100px' }, { key: 'age', label: 'Age', width: '90px' }, { key: 'bovineType.label', label: 'Race', width: '1fr' }, { key: 'arrivalDate', label: 'Entrée le', width: '110px' }, { key: 'pricePerKg', label: 'Prix/kg', width: '85px' }, { key: 'finalPrice', label: 'Prix total', width: '105px' } ] const withoutPricesCase: BovineColumn[] = [ { key: 'nationalNumber', label: 'N° National', width: '130px' }, { key: 'workNumber', label: 'N° Travail', width: '100px' }, { key: 'sex', label: 'Sexe', width: '110px' }, { key: 'birthDate', label: 'Né le', width: '140px' }, { key: 'age', label: 'Age', width: '130px' }, { key: 'bovineType.label', label: 'Race', width: '1fr' }, { key: 'arrivalDate', label: 'Entrée le', width: '170px' } ] const columns = computed(() => { const isCase = options.variant === 'case' const seePrice = auth.isBureau if (isCase) { return seePrice ? withPricesCase : withoutPricesCase } return seePrice ? withPricesInventory : withoutPricesInventory }) return { columns } }