import { useEffect, useState } from "react"; import { Minus, Plus } from "lucide-react"; import { DXF_BEND_DIRECTION, normalizeDxfBendAngleDeg, normalizeDxfBendDirection, normalizeDxfPreviewThicknessMm } from "../../lib/dxf/buildPreviewMesh"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "../ui/accordion"; import { Button } from "../ui/button"; import { Input } from "../ui/input"; import { ToggleGroup, ToggleGroupItem } from "../ui/toggle-group"; import FileSheet from "./FileSheet"; const fieldLabelClasses = "block text-xs font-medium text-muted-foreground"; const compactInputClasses = "h-8 text-xs font-medium tabular-nums"; const compactIconButtonClasses = "size-8"; function formatThicknessInput(valueMm) { const numericValue = Number(valueMm); if (!Number.isFinite(numericValue)) { return ""; } return numericValue.toFixed(4).replace(/\.?0+$/, ""); } function formatAngleInput(valueDeg) { const rounded = Math.round(Number(valueDeg) * 10) / 10; return Number.isFinite(rounded) ? String(rounded) : ""; } function DxfBendRow({ index, setting, onChange }) { const [draftAngle, setDraftAngle] = useState(() => formatAngleInput(setting?.angleDeg)); useEffect(() => { setDraftAngle(formatAngleInput(setting?.angleDeg)); }, [setting?.angleDeg]); const commitAngle = (nextValue) => { const normalizedAngle = normalizeDxfBendAngleDeg(nextValue, setting?.angleDeg); onChange(index, { angleDeg: normalizedAngle }); setDraftAngle(formatAngleInput(normalizedAngle)); }; const direction = normalizeDxfBendDirection(setting?.direction); return (
B{index + 1}
Direction { if (!nextDirection) { return; } onChange(index, { direction: nextDirection }); }} className="grid h-8 w-full min-w-0 grid-cols-2" aria-label={`Bend ${index + 1} direction`} > Up Down
); } export default function DxfFileSheet({ open, isDesktop, width, valueMm, bendSettings, hasDxfData, viewerLoading, onThicknessChange, onBendChange }) { const [draftValue, setDraftValue] = useState(() => formatThicknessInput(valueMm)); const normalizedBendSettings = Array.isArray(bendSettings) ? bendSettings : []; useEffect(() => { setDraftValue(formatThicknessInput(valueMm)); }, [valueMm]); const commitValue = (nextValue) => { const normalizedValue = normalizeDxfPreviewThicknessMm(nextValue, valueMm); onThicknessChange(normalizedValue); setDraftValue(formatThicknessInput(normalizedValue)); }; return ( Plate Bends {normalizedBendSettings.length ? normalizedBendSettings.map((setting, index) => ( )) : (

{viewerLoading ? "Loading bends..." : "No bends are available."}

)}
); }