import { defineStore } from "pinia"; import { ref, computed } from "vue"; export interface FactureFournisseurLine { id?: number; designation: string; quantity: number; priceHt: number; totalHt: number; } export interface FactureFournisseur { id: number; number: string; supplierId: string; supplierName: string; date: string; status: string; totalHt: number; totalTva: number; totalTtc: number; lines: FactureFournisseurLine[]; } export const useFactureFournisseurStore = defineStore("factureFournisseur", () => { // State const factures = ref([ { id: 1, number: "FF-2026-0001", supplierId: "1", supplierName: "Produits FunĂ©raires Pro", date: "2026-01-15", status: "payee", totalHt: 1250.0, totalTva: 250.0, totalTtc: 1500.0, lines: [ { id: 1, designation: "Cercueils ChĂȘne Prestige", quantity: 2, priceHt: 625.0, totalHt: 1250.0 } ] }, { id: 2, number: "FF-2026-0002", supplierId: "2", supplierName: "Thanatos Supply", date: "2026-01-20", status: "en_attente", totalHt: 450.0, totalTva: 90.0, totalTtc: 540.0, lines: [ { id: 2, designation: "Urnes Granit Noir", quantity: 5, priceHt: 90.0, totalHt: 450.0 } ] } ]); const currentFacture = ref(null); const loading = ref(false); const error = ref(null); // Getters const allFactures = computed(() => factures.value); const isLoading = computed(() => loading.value); // Actions const fetchFactures = async () => { loading.value = true; // Mock API call await new Promise(resolve => setTimeout(resolve, 500)); loading.value = false; }; const fetchFacture = async (id: number) => { loading.value = true; await new Promise(resolve => setTimeout(resolve, 300)); const found = factures.value.find(f => f.id === id); currentFacture.value = found || null; loading.value = false; }; const createFacture = async (payload: any) => { loading.value = true; await new Promise(resolve => setTimeout(resolve, 800)); const newFacture = { ...payload, id: factures.value.length + 1, }; factures.value.push(newFacture); loading.value = false; return newFacture; }; const deleteFacture = async (id: number) => { factures.value = factures.value.filter(f => f.id !== id); }; return { factures, currentFacture, loading, error, allFactures, isLoading, fetchFactures, fetchFacture, createFacture, deleteFacture }; });