import { expect, fn, screen, userEvent, waitFor, within } from "storybook/test"; import type { Meta, StoryObj } from "@storybook/react-vite"; import { QuestionRegularIcon } from "alouette-icons/phosphor-icons/Question"; import { TrashRegularIcon } from "alouette-icons/phosphor-icons/Trash"; import { type ReactNode, useState } from "react"; import type { Accent } from "../../core/AlouetteConfig"; import { Button } from "../actions/Button"; import { FormItem } from "../forms/FormItem"; import { InputText } from "../inputs/InputText"; import { Story, accentsWithoutNeutral } from "../story-components/Story"; import { StoryGrid } from "../story-components/StoryGrid"; import { AlertDialog, type AlertDialogProps, type AlertDialogUsageProps, InfoAlertDialog, QuestionAlertDialog, SuccessAlertDialog, WarningAlertDialog, } from "./AlertDialog"; type ThisStory = StoryObj; // Loose superset of every variant's props: a demo helper accepts any // combination and forwards a cast-back union to the component under test. The // spread through JSX loses the discriminated correlation the props already // satisfy at each call site. interface AlertDialogDemoProps { triggerLabel?: string; variant?: AlertDialogProps["variant"]; title: string; children?: ReactNode; accent?: AlertDialogProps["accent"]; icon?: AlertDialogProps["icon"]; size?: AlertDialogProps["size"]; testID?: string; onConfirm?: () => void; onCancel?: () => void; onClose?: () => void; confirmText?: ReactNode; cancelText?: ReactNode; closeText?: ReactNode; confirmDisabled?: boolean; primaryAction?: "cancel" | "confirm"; } // Stateful demo wrapper: a trigger button that opens the dialog and manages the // open/close state, closing it whenever any of its actions fire. function AlertDialogDemo({ triggerLabel = "Open", accent, icon = , ...props }: AlertDialogDemoProps): ReactNode { const [visible, setVisible] = useState(false); const close = () => { setVisible(false); }; const wrapped = (handler?: () => void) => () => { close(); handler?.(); }; const actions = (() => { switch (props.variant) { case "alert": return { onClose: wrapped(props.onClose) }; case "required": return { onConfirm: wrapped(props.onConfirm) }; case "confirm": case undefined: default: return { onConfirm: wrapped(props.onConfirm), onCancel: wrapped(props.onCancel), }; } })(); return ( <>