import { defineStore } from 'pinia';
import { ref } from 'vue';
import { varietiesApi } from '@/api/varieties';
export const useVarietiesStore = defineStore('varieties', () => {
    const varieties = ref([]);
    const loading = ref(false);
    async function fetchAll() {
        loading.value = true;
        varieties.value = await varietiesApi.list();
        loading.value = false;
    }
    async function create(v) {
        const created = await varietiesApi.create(v);
        varieties.value.push(created);
        return created;
    }
    async function remove(id) {
        await varietiesApi.delete(id);
        varieties.value = varieties.value.filter(v => v.id !== id);
    }
    return { varieties, loading, fetchAll, create, remove };
});
