import { router } from "@inertiajs/react";
import clsx from "clsx";
import {
ArrowDown,
ArrowLeft,
ArrowRight,
ArrowUp,
Check,
ChevronDown,
ChevronsDown,
ChevronsUp,
ChevronUp,
Home,
Lock,
} from "lucide-react";
import { useState, type FormEvent, type ReactNode } from "react";
import type { PageProps, PrinterState } from "@/types";
import { isBusy } from "./bed-view";
import { act, Button, Field, Instruction, inputClass } from "./ui";
type StepStatus = "done" | "current" | "locked";
function Step({
n,
title,
status,
summary,
open,
onToggle,
children,
}: {
n: number;
title: string;
status: StepStatus;
summary?: ReactNode;
open: boolean;
onToggle: () => void;
children: ReactNode;
}) {
return (
{open && status !== "locked" &&
{children}
}
);
}
export function SetupSteps({ props }: { props: PageProps }) {
const { printer } = props;
const paperMarked = Boolean(printer.paper_top_left && printer.paper_bottom_right);
const done = [printer.connected, printer.xy_homed, printer.z_zeroed, paperMarked];
const current = done.indexOf(false); // -1 when everything's ready
const status = (i: number): StepStatus =>
done[i] ? "done" : i === current ? "current" : current !== -1 && i > current ? "locked" : "current";
// Steps open on their own as you reach them; you can also reopen done ones.
const [manual, setManual] = useState>({});
const isOpen = (i: number) => manual[i] ?? i === current;
const toggle = (i: number) => setManual((m) => ({ ...m, [i]: !isOpen(i) }));
return (
toggle(0)}
summary={printer.connected ? `Connected to ${props.connection.ip}` : undefined}
>
toggle(1)}
summary="The printer knows where the pen is"
>
{printer.saved_calibration && (
Picking up where you left off? If the printer has stayed on and nobody has moved the head
or released the motors, you can keep the previous position
{printer.saved_calibration.z_zeroed && " and pen height"}.
)}
Pen: leave it out for now. Clear the bed, then press Home. The head lifts 10 mm, finds its
corner and comes back to the middle of the bed, so from now on the app knows exactly where it is.
toggle(2)}
summary={`Pen lifts ${printer.pen_up} mm between lines`}
>
Tape your paper to the bed. Its top edge should face the back of the printer.
Move the pen over the paper: click on the paper in the bed picture.
Now put the pen in the holder, with its tip a few millimetres above the paper.
Lower the head until the tip just touches the paper. Go slowly at the end.
This becomes the paper height. The pen then lifts {printer.pen_up} mm, and will only come down to draw.