import { defineStore } from 'pinia'; import { ref } from 'vue'; import type { ServerInfo, SettingsResponse, UpdateSettingsRequest } from '@arboretum/shared'; import { api } from '../lib/api'; // Réglages serveur + intégrations. `giteaUrl` alimente l'item de nav Gitea (affiché si défini). // Les préférences purement client (langue) restent gérées par l'i18n/localStorage. export const useSettingsStore = defineStore('settings', () => { const server = ref(null); const giteaUrl = ref(null); const scanRoots = ref([]); const scanIntervalMin = ref(0); const loaded = ref(false); const saving = ref(false); function apply(res: SettingsResponse): void { server.value = res.server; giteaUrl.value = res.settings.giteaUrl; scanRoots.value = res.settings.scanRoots; scanIntervalMin.value = res.settings.scanIntervalMin; loaded.value = true; } async function fetch(): Promise { apply(await api.get('/api/v1/settings')); } async function save(patch: UpdateSettingsRequest): Promise { saving.value = true; try { apply(await api.patch('/api/v1/settings', patch)); } finally { saving.value = false; } } return { server, giteaUrl, scanRoots, scanIntervalMin, loaded, saving, fetch, save }; });