import {
useLongPress,
useVisibility,
} from "@charcuterie/logic"
import { playgroundParameters } from "@charcuterie/storybook-config/story-parameters"
import type { ControlSize } from "@charcuterie/tokens"
import type { Meta, StoryObj } from "@storybook/react"
import type { ReactNode } from "react"
import { useRef } from "react"
import {
controlSizeArgType,
placementArgType,
} from "../argTypes.storyHelpers.ts"
import { Button } from "../Button/Button.tsx"
import {
StoryCell,
StoryGrid,
} from "../board.storyHelpers.tsx"
import {
RedoIcon,
SettingsIcon,
UndoIcon,
} from "../icons.storyHelpers.tsx"
import type { AnchoredOverlayAnchor } from "../Overlay/useAnchoredOverlay.ts"
import { Tooltip } from "../Tooltip/Tooltip.tsx"
import type { MenuEntry, MenuItem } from "./Menu.tsx"
import { Menu } from "./Menu.tsx"
const noop = () => undefined
const BAY_ACTIONS: MenuItem[] = [
{
icon: ,
key: "retry",
label: "Retry title",
onSelect: noop,
},
{
icon: ,
key: "skip",
label: "Skip title",
onSelect: noop,
},
{
icon: ,
isDisabled: true,
key: "eject",
label: "Eject disc",
onSelect: noop,
},
]
const GROUPED_ACTIONS: MenuEntry[] = [
{
items: [
{
key: "retry",
label: "Retry title",
onSelect: noop,
},
{ key: "skip", label: "Skip title", onSelect: noop },
],
key: "disc",
label: "Disc",
type: "group",
},
{ key: "sep", type: "separator" },
{
items: [
{
icon: ,
key: "eject",
label: "Eject disc",
onSelect: noop,
},
],
key: "danger",
label: "Danger",
type: "group",
},
]
/**
* A menu's visibility belongs to the app, exactly like `Popover`'s —
* so the stories hold it in a `useVisibility`, which is what a
* consumer writes too.
*/
const MenuHarness = ({
emptyState,
isInitiallyVisible = false,
itemSize,
items = BAY_ACTIONS,
triggerLabel,
}: {
emptyState?: ReactNode
isInitiallyVisible?: boolean
itemSize?: ControlSize
items?: MenuEntry[]
triggerLabel: string
}): ReactNode => {
const { hide, isVisible, toggle } = useVisibility({
isVisible: isInitiallyVisible,
})
return (