import { HardwareAsset, SoftwareAsset, SWUser, HardwareLog } from './excelHandler'; // --- State Definitions --- export interface MasterAssetData { pc: HardwareAsset[]; server: HardwareAsset[]; storage: HardwareAsset[]; equip: HardwareAsset[]; subSw: SoftwareAsset[]; permSw: SoftwareAsset[]; swUsers: SWUser[]; logs: HardwareLog[]; } export interface AppState { activeCategory: 'dashboard' | 'hw' | 'sw'; activeSubTab: string; // '대시보드', '개인PC', '서버', '스토리지', '전산비품', '구독SW', '영구SW' masterData: MasterAssetData; } // 초기 상태 export const state: AppState = { activeCategory: 'dashboard', activeSubTab: '대시보드', masterData: { pc: [], server: [], storage: [], equip: [], subSw: [], permSw: [], swUsers: [], logs: [] } }; /** * 전용 API 엔드포인트들로부터 데이터 로드 */ export async function loadMasterDataFromDB() { try { const endpoints = [ { key: 'pc', url: 'http://localhost:3000/api/pc' }, { key: 'server', url: 'http://localhost:3000/api/server' }, { key: 'storage', url: 'http://localhost:3000/api/storage' }, { key: 'equip', url: 'http://localhost:3000/api/equip' }, { key: 'subSw', url: 'http://localhost:3000/api/sw/sub' }, { key: 'permSw', url: 'http://localhost:3000/api/sw/perm' }, { key: 'swUsers', url: 'http://localhost:3000/api/sw-users' } ]; const results = await Promise.all(endpoints.map(e => fetch(e.url))); for (let i = 0; i < endpoints.length; i++) { if (results[i].ok) { const data = await results[i].json(); (state.masterData as any)[endpoints[i].key] = data || []; } } console.log('✅ 6개 테이블 데이터 로드 완료'); return true; } catch (err) { console.warn('⚠️ 백엔드 서버 연결 실패. 로컬 데이터를 유지합니다.'); } return false; } // --- State Helpers --- export function updateState(newState: Partial) { Object.assign(state, newState); }