// Production - The Idle Game: Desktop Inspector & Supply Chain Analytics Panel import { PRODUCTS, SECTORS, getProduct } from '../data/products.js'; import { fmtCurrency, fmtNum } from '../core/formatters.js'; export function renderInspector(container, state, onAction) { const selectedId = state.selectedProductId || 'wheat'; const product = getProduct(selectedId) || PRODUCTS[0]; const pState = state.products[product.id] || { stock: 0, lines: 0, logistics: 0, unlocked: false }; const sector = SECTORS.find(s => s.id === product.sector); // Find downstream products that consume this product const downstream = PRODUCTS.filter(p => p.inputs && p.inputs.some(inp => inp.id === product.id)); // Calculate liquidation value const totalLiquidationValue = (pState.stock || 0) * product.basePrice; const halfLiquidationValue = totalLiquidationValue * 0.5; let html = `
${sector?.name} Tier ${product.tier}

${product.name}

${product.description}

Warehouse Stock: ${fmtNum(pState.stock, 0)} ${product.unit}
Wholesale Price: ${fmtCurrency(product.basePrice)}
Production Lines: ${pState.lines} active
Logistics Fleets: ${pState.logistics || 0} active

Instant Wholesale Liquidation

Liquidate stockpiles immediately onto the wholesale spot market.

Supply Chain Dependencies

Direct Inputs: ${(!product.inputs || product.inputs.length === 0) ? `
Primary commodity • Direct extraction from natural deposits.
` : `
${product.inputs.map(inp => { const parent = getProduct(inp.id); const parentStock = state.products[inp.id]?.stock || 0; return `
${parent.name}
${inp.amount} per unit (${fmtNum(parentStock, 0)} on hand)
`; }).join('')}
`}
Downstream Consumers: ${downstream.length === 0 ? `
End-tier consumer or industrial finished product.
` : `
${downstream.map(child => { const isUnlocked = state.products[child.id]?.unlocked; return `
${child.name}
${isUnlocked ? 'Active' : 'Locked'}
`; }).join('')}
`}
`; container.innerHTML = html; const halfBtn = container.querySelector('.btn-liquidate-half'); if (halfBtn) { halfBtn.onclick = () => onAction({ type: 'LIQUIDATE_STOCK', productId: product.id, ratio: 0.5 }); } const allBtn = container.querySelector('.btn-liquidate-all'); if (allBtn) { allBtn.onclick = () => onAction({ type: 'LIQUIDATE_STOCK', productId: product.id, ratio: 1.0 }); } container.querySelectorAll('.chain-item-row').forEach(row => { row.onclick = () => onAction({ type: 'SELECT_PRODUCT', productId: row.dataset.product }); }); }