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