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