import { SwitchMiiInstructions } from "@/types"; import { useState } from "react"; import ColorPicker from "../color-picker"; import TypeSelector from "../type-selector"; interface Props { instructions: React.RefObject; } type Tab = "sets" | "bangs" | "back"; export default function HairTab({ instructions }: Props) { const [tab, setTab] = useState("sets"); const [setsType, setSetsType] = useState(0); const [bangsType, setBangsType] = useState(0); const [backType, setBackType] = useState(0); const [color, setColor] = useState(0); const [subColor, setSubColor] = useState(null); const [isFlipped, setIsFlipped] = useState(false); const type = tab === "sets" ? setsType : tab === "bangs" ? bangsType : backType; const setType = (value: number) => { if (tab === "sets") { setSetsType(value); instructions.current.hair.setType = value; } else if (tab === "bangs") { setBangsType(value); instructions.current.hair.bangsType = value; } else { setBackType(value); instructions.current.hair.backType = value; } }; return (

Hair

{ setType(i); // Update ref if (tab === "sets") { instructions.current.hair.setType = i; } else if (tab === "bangs") { instructions.current.hair.bangsType = i; } else if (tab === "back") { instructions.current.hair.backType = i; } }} />
{ setColor(i); instructions.current.hair.color = i; }} />
setSubColor(e.target.checked ? 0 : null)} />
{ setSubColor(i); instructions.current.hair.subColor = i; }} />
setIsFlipped(e.target.checked)} />
); }