import type { LogicNode } from './strategyTypes'; import type { EdgeHandleBinding } from './strategyFlowLayout'; export type SignalFlowLayoutSnapshot = { positions: Record; edgeHandles: Record; orphans?: LogicNode[]; }; export type FlowLayoutChangePayload = Omit & { tab: 'buy' | 'sell'; }; export type StrategyFlowLayoutStore = { buy: SignalFlowLayoutSnapshot; sell: SignalFlowLayoutSnapshot; }; const STORAGE_KEY = 'gc_se_flow_layout_v1'; export function emptySignalFlowLayout(): SignalFlowLayoutSnapshot { return { positions: {}, edgeHandles: {}, orphans: [] }; } export function emptyStrategyFlowLayout(): StrategyFlowLayoutStore { return { buy: emptySignalFlowLayout(), sell: emptySignalFlowLayout() }; } export function loadStrategyFlowLayout(strategyKey: string): StrategyFlowLayoutStore | null { try { const raw = localStorage.getItem(STORAGE_KEY); if (!raw) return null; const all = JSON.parse(raw) as Record; return all[strategyKey] ?? null; } catch { return null; } } export function saveStrategyFlowLayout(strategyKey: string, layout: StrategyFlowLayoutStore): void { try { const raw = localStorage.getItem(STORAGE_KEY); const all: Record = raw ? JSON.parse(raw) : {}; all[strategyKey] = layout; localStorage.setItem(STORAGE_KEY, JSON.stringify(all)); } catch { /* ignore quota / private mode */ } } export function deleteStrategyFlowLayout(strategyKey: string): void { try { const raw = localStorage.getItem(STORAGE_KEY); if (!raw) return; const all = JSON.parse(raw) as Record; delete all[strategyKey]; localStorage.setItem(STORAGE_KEY, JSON.stringify(all)); } catch { /* ignore */ } } export function migrateStrategyFlowLayout(fromKey: string, toKey: string): void { if (fromKey === toKey) return; const layout = loadStrategyFlowLayout(fromKey); if (!layout) return; saveStrategyFlowLayout(toKey, layout); deleteStrategyFlowLayout(fromKey); }