import { loadSettings, saveSettings } from "./storage.js"; const state = { settings: loadSettings(), selectedRepoPath: "", selectedRepoName: "", repoSearch: "", localRepoPathInput: "", localRepoScanRootInput: "", localRepoScanResults: [], localRepoScanLoading: false, localRepoScanError: "", cloneUrlInput: "", cloneDestinationInput: "", commitMessage: "", viewer: { source: "", repoName: "", repoPath: "", cloneUrl: "", defaultBranch: "", branch: "", branches: [], path: "", entries: [], selectedFile: null, readmeFile: null, loading: false, error: "", }, }; export function getState() { return state; } export function setSettings(nextSettings) { state.settings = nextSettings; saveSettings(state.settings); } export function updateSettings(patch) { setSettings({ ...state.settings, ...patch }); } export function addRecentRepo(path) { if (!path) return; const current = state.settings.recentRepositories.filter((item) => item !== path); const next = [path, ...current].slice(0, 15); updateSettings({ recentRepositories: next }); } export function getActiveServer() { const { activeServerId, servers } = state.settings; return servers.find((server) => server.id === activeServerId) ?? null; }