import type { HTMLAttributes, ReactNode } from "react";
import { Alert } from "../components/alert.js";
import { Button } from "../components/button.js";
import { Status } from "../components/status.js";
import { cn } from "../lib/cn.js";
import { EmptyState } from "./empty-state.js";
/** A step the person takes to finish setup. */
export type SetupNoticeAction = Readonly<{
label: string;
/** Called when the step is chosen. */
onSelect: () => void;
}>;
/** The required fix; `pending` means it opened Settings and is waiting. */
export type SetupNoticeFix = SetupNoticeAction &
Readonly<{ pending?: boolean }>;
/** Props accepted by SetupNotice. */
export type SetupNoticeProps = Omit<
HTMLAttributes,
"title" | "children"
> & {
/** The title, such as "Connect a model to start chatting". */
need: ReactNode;
/** One sentence naming the real cause. */
cause: ReactNode;
/** The one primary fix; never a dead CTA. */
fix: SetupNoticeFix;
secondary?: SetupNoticeAction;
/** What still works meanwhile, such as "Uploads work now". */
available?: ReactNode;
/** The panel's own glyph (an App icon, say) in place of the warning bead; ignored by `banner` and `inline`. */
visual?: Exclude;
/** Names what is awaited while pending, after "Waiting for". */
waitingFor?: string;
/** `panel` replaces an empty state; `banner` and `inline` sit above or in content. */
variant: "panel" | "inline" | "banner";
};
/**
* Missing setup, named with its fix. Render it only while the setup fact is
* missing; when the fact turns ready the host unmounts it (and may toast).
*/
export function SetupNotice({
available,
cause,
className,
fix,
need,
secondary,
variant,
visual,
waitingFor = "setup",
...props
}: SetupNoticeProps) {
const pending = fix.pending === true;
const label = pending ? `Waiting for ${waitingFor}…` : fix.label;
const detail = available ? (
<>
{cause} {available}
>
) : (
cause
);
if (variant === "panel") {
return (
{secondary.label}
) : undefined
}
className={cn("caps-setup-notice", className)}
data-variant="panel"
description={detail}
primaryAction={{
label,
onSelect: fix.onSelect,
pending,
}}
title={need}
variant="panel"
visual={
visual ?? (
)
}
/>
);
}
return (