/** * StitchStepControl Component * * Compact stitch position control shown when machine is paused/stopped/interrupted. * Allows stepping forward/backward by 1, 10, or 100 stitches, * jumping to thread color boundaries, and resetting to current position. */ import { ChevronLeftIcon, ChevronRightIcon, ChevronDoubleLeftIcon, ChevronDoubleRightIcon, SwatchIcon, ArrowUturnLeftIcon, } from "@heroicons/react/24/solid"; import { Button } from "@/components/ui/button"; import { getErrorStitchRollback, getErrorMessage, } from "../../utils/errorCodeHelpers"; import type { ColorBlock } from "./types"; import { findCurrentBlockIndex } from "../../utils/colorBlockHelpers"; interface StitchStepControlProps { currentStitch: number; adjustedStitchIndex: number | null; pausedStitchIndex: number | null; totalStitches: number; lastRolledBackError: number | null; colorBlocks: ColorBlock[]; onAdjustPosition: (offset: number) => void; onSetPosition: (index: number) => void; } export function StitchStepControl({ currentStitch, adjustedStitchIndex, pausedStitchIndex, totalStitches, lastRolledBackError, colorBlocks, onAdjustPosition, onSetPosition, }: StitchStepControlProps) { const displayStitch = adjustedStitchIndex ?? currentStitch; const handleGoToThreadStart = () => { const blockIndex = findCurrentBlockIndex(colorBlocks, displayStitch); if (blockIndex >= 0) { onSetPosition(colorBlocks[blockIndex].startStitch); } }; const handleGoToPausedStitch = () => { if (pausedStitchIndex !== null) { onSetPosition(pausedStitchIndex); } }; const rollbackAmount = lastRolledBackError ? getErrorStitchRollback(lastRolledBackError) : null; const rollbackErrorName = lastRolledBackError ? getErrorMessage(lastRolledBackError) : null; const showGoToPaused = pausedStitchIndex !== null && displayStitch !== pausedStitchIndex; return (
{/* Header: label + stitch count on one line */}
Stitch Position {displayStitch.toLocaleString()} / {totalStitches.toLocaleString()}
{/* Rollback info */} {rollbackAmount !== null && rollbackErrorName && (
Moved back {rollbackAmount} stitches ( {rollbackErrorName.toLowerCase()})
)} {/* Step buttons + navigation in one row */}
{colorBlocks.length > 0 && ( )}
); }