// frontend/src/stores/fabrications.ts import { defineStore } from 'pinia' import { ref } from 'vue' import { fabricationsApi, type Fabrication } from '@/api/fabrications' export const useFabricationsStore = defineStore('fabrications', () => { const fabrications = ref([]) const loading = ref(false) async function fetchAll(params?: { type?: string; statut?: string }) { loading.value = true try { fabrications.value = await fabricationsApi.list(params) } finally { loading.value = false } } async function create(f: Partial) { const created = await fabricationsApi.create(f) fabrications.value.unshift(created) return created } async function updateStatut(id: number, statut: string) { const updated = await fabricationsApi.updateStatut(id, statut) const idx = fabrications.value.findIndex(f => f.id === id) if (idx !== -1) fabrications.value[idx] = updated return updated } async function remove(id: number) { await fabricationsApi.delete(id) fabrications.value = fabrications.value.filter(f => f.id !== id) } return { fabrications, loading, fetchAll, create, updateStatut, remove } })