import { state } from '../state.js'; import { logger } from '../utils/logger.js'; import { t } from '../i18n.js'; import { makeDraggable } from '../ui/utils.js'; /** * initInventory - Initializes the real-time inventory counting panel */ export function initInventory() { const inventoryPanel = document.getElementById('inventory-panel'); const inventoryList = document.getElementById('inventory-list'); if (!inventoryPanel || !inventoryList) return; // Make Draggable makeDraggable(inventoryPanel, '.inventory-header'); // Initial update updateInventory(inventoryList); // Listen for graph changes if (state.graph) { state.graph.on('node:added', () => updateInventory(inventoryList)); state.graph.on('node:removed', () => updateInventory(inventoryList)); state.graph.on('cell:changed', ({ cell }) => { if (cell.isNode()) updateInventory(inventoryList); }); // project:restored 이벤트 수신 (복구 시점) state.graph.on('project:restored', () => { logger.info("Project restored. Updating inventory."); updateInventory(inventoryList); }); } } /** * toggleInventory - Toggles the visibility of the inventory panel */ export function toggleInventory() { const panel = document.getElementById('inventory-panel'); if (!panel) return; // Use getComputedStyle for more reliable check const currentDisplay = window.getComputedStyle(panel).display; if (currentDisplay === 'none') { panel.style.display = 'flex'; panel.classList.add('animate-up'); } else { panel.style.display = 'none'; } } /** * updateInventory - Aggregates node counts by type and updates the UI */ export function updateInventory(container) { if (!state.graph) return; // Use default container if not provided if (!container) { container = document.getElementById('inventory-list'); } if (!container) return; const nodes = state.graph.getNodes(); const counts = {}; nodes.forEach(node => { const data = node.getData() || {}; const type = data.type || 'Unknown'; counts[type] = (counts[type] || 0) + 1; }); // Render list container.innerHTML = ''; const sortedTypes = Object.keys(counts).sort(); if (sortedTypes.length === 0) { container.innerHTML = `