import { DndContext, DragOverlay, PointerSensor, useSensor, useSensors } from '@dnd-kit/core' import { useState } from 'react' import { VariablePalette } from '../components/VariablePalette.jsx' import { Workspace } from '../components/Workspace.jsx' import { ResultsPanel } from '../components/ResultsPanel.jsx' import { PaletteCard } from '../components/VariableCard.jsx' import { PropellantModal } from '../components/PropellantModal.jsx' import { EquationBrowser } from '../components/EquationBrowser.jsx' import { useSolver } from '../hooks/useSolver.js' import { EQUATIONS } from '../engine/equations.js' import { buildExportData, exportJSON, parseImport, downloadBlob } from '../engine/exportImport.js' import { generateOdt } from '../engine/exportOdt.js' export default function Solver() { const { workspaceVarIds, userValues, solved, missingReport, allKnown, unitSelections, getUnit, setUnit, sciNotation, areaRatioBranch, toggleSciNotation, toggleAreaRatioBranch, addVariable, addVariables, removeVariable, reorderVariable, setValue, addPreset, applyPropellant, clearWorkspace, importWorkspace, } = useSolver() const [activeVarId, setActiveVarId] = useState(null) const [showPropellants, setShowPropellants] = useState(false) const [showEquations, setShowEquations] = useState(false) const sensors = useSensors( useSensor(PointerSensor, { activationConstraint: { distance: 6 } }) ) function handleDragStart(event) { const { varId } = event.active.data.current ?? {} if (varId) setActiveVarId(varId) } function handleDragEnd(event) { const { over, active } = event if (!over) { setActiveVarId(null) return } // Palette → workspace drop if (over.id === 'workspace') { const { varId } = active.data.current ?? {} if (varId) addVariable(varId) } // Workspace → workspace reorder else if (workspaceVarIds.includes(active.id) && workspaceVarIds.includes(over.id)) { reorderVariable(active.id, over.id) } setActiveVarId(null) } async function handleExportOdt() { const data = buildExportData(workspaceVarIds, userValues, solved, unitSelections, getUnit, sciNotation) const blob = await generateOdt(data) downloadBlob(blob, 'rocketry-workspace.odt') } function handleExportJSON() { const data = buildExportData(workspaceVarIds, userValues, solved, unitSelections, getUnit, sciNotation) const blob = exportJSON(data, workspaceVarIds, userValues, unitSelections) downloadBlob(blob, 'rocketry-workspace.json') } function handleImportJSON(jsonString) { try { const workspace = parseImport(jsonString) importWorkspace(workspace) } catch (err) { alert(`Import failed: ${err.message}`) } } return (
{/* Solver sub-header */}

Add variables, enter known values, and unknowns solve automatically.

{/* Three-panel layout */}
{showPropellants && ( setShowPropellants(false)} onApply={applyPropellant} /> )} {showEquations && ( addVariables(varIds)} onClose={() => setShowEquations(false)} /> )} {activeVarId ? (
) : null}
) }