import { SwitchMiiInstructions } from "@/types"; import { useState } from "react"; import ColorPicker from "../color-picker"; import NumberInputs from "../number-inputs"; interface Props { instructions: React.RefObject; } const TABS: { name: keyof SwitchMiiInstructions["other"]; length: number; defaultColor?: number }[] = [ { name: "wrinkles1", length: 9 }, { name: "wrinkles2", length: 15 }, { name: "beard", length: 15 }, { name: "moustache", length: 16 }, { name: "goatee", length: 14 }, { name: "mole", length: 2 }, { name: "eyeShadow", length: 4, defaultColor: 139 }, { name: "blush", length: 8 }, ]; export default function OtherTab({ instructions }: Props) { const [tab, setTab] = useState(0); const [isFlipped, setIsFlipped] = useState(false); const [colors, setColors] = useState(() => TABS.map((t) => { const entry = instructions.current.other[t.name] ?? {}; const color = entry && "color" in entry ? entry.color : null; return color ?? t.defaultColor ?? 0; }), ); const currentTab = TABS[tab]; const setColor = (value: number) => { setColors((prev) => { const copy = [...prev]; copy[tab] = value; return copy; }); const target = instructions.current.other[currentTab.name]; if ("color" in target) { target.color = value; } }; return ( <>

Other

{TABS.map((_, i) => ( ))}
{tab === 3 && (
{ setIsFlipped(e.target.checked); instructions.current.other.moustache.isFlipped = e.target.checked; }} />
)}
); }