"use client";
import { useEffect, useState } from "react";
import { cn } from "@/lib/utils";
// ---------------------------------------------------------------------------
// OPTIONS / ADVANCED (lane/ui-simplify, 5 Nov; the operator: "focus on the
// happy path and have options/advanced panels for everything else, keeping all
// current features exposed").
//
// A page shows ONE primary row for the happy path's next step; everything else
// sits in an Options disclosure (common, secondary) or an Advanced one (rare,
// expert). One shell for every page, so they look and behave the same:
//
// … …
//
// A ``: what is inside stays in the page (a link keeps its address, a
// spec finds it by its data-*), only folded. Whether it is open is remembered
// per viewer and per panel (`umtool.panel..` in localStorage,
// wrapped: a private window just starts folded). e2e opens one through
// e2e/panels.ts openPanel(page, kind, id).
// ---------------------------------------------------------------------------
export type PanelKind = "options" | "advanced";
const keyOf = (id: string, kind: PanelKind) => `umtool.panel.${id}.${kind}`;
export function Disclosure({
kind,
id,
label,
hint,
defaultOpen = false,
className,
bodyClassName,
children,
}: {
kind: PanelKind;
/** The page or panel this belongs to (`cut`, `take-card`, `play`): the remembered state's key. */
id: string;
label?: React.ReactNode;
/** A few words after the label, folded or not (what is inside: "voices · fetch · tighten"). */
hint?: React.ReactNode;
defaultOpen?: boolean;
className?: string;
bodyClassName?: string;
children: React.ReactNode;
}) {
const [open, setOpen] = useState(defaultOpen);
useEffect(() => {
try {
const v = window.localStorage.getItem(keyOf(id, kind));
if (v === "1" || v === "0") setOpen(v === "1");
} catch {
// storage refused: folded as the page drew it
}
}, [id, kind]);
return (
{
const now = (e.currentTarget as HTMLDetailsElement).open;
setOpen(now);
try {
window.localStorage.setItem(keyOf(id, kind), now ? "1" : "0");
} catch {
// not remembered; still toggles
}
}}
className={cn("group/disclosure min-w-0", className)}
>
▸
{label ?? (kind === "options" ? "Options" : "Advanced")}
{hint && {hint}}
{children}
);
}
export function Options(props: Omit, "kind">) {
return ;
}
export function Advanced(props: Omit, "kind">) {
return ;
}
/**
* A marked place for a control another lane owns (lane/vertical's vertical and side-tweet knobs): empty
* here, `data-panel-slot=""` so it is found and filled there.
*/
export function PanelSlot({ name }: { name: string }) {
return ;
}