import { defineStore } from 'pinia' import { ref } from 'vue' import type { EditableFile, ImpactResult } from '@/shared/types/api' import * as editorApi from '../api' export const useEditorStore = defineStore('editor', () => { const currentFile = ref(null) const impactResult = ref(null) const saving = ref(false) const error = ref(null) async function loadFile(projectId: string, path: string) { try { currentFile.value = await editorApi.getFile(projectId, path) } catch (e: any) { error.value = e.message } } async function saveFile(projectId: string, path: string, content: string) { saving.value = true try { await editorApi.saveFile(projectId, path, content) } catch (e: any) { error.value = e.message } finally { saving.value = false } } async function analyzeImpact(projectId: string, path: string) { try { impactResult.value = await editorApi.getFileImpact(projectId, path) } catch (e: any) { error.value = e.message } } return { currentFile, impactResult, saving, error, loadFile, saveFile, analyzeImpact } })