"use client"; import { useState } from "react"; import { Copy, MoreVertical, Trash2, type LucideIcon } from "lucide-react"; import { cn } from "@/lib/utils"; import { canApplyComponentLayerAction, type ComponentLayerAction, } from "@/components/slide-editor/selection/layering"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; export type ComponentActionsMenuActions = { canUngroup: boolean; componentIndex: number; componentCount: number; onDelete: () => void; onDuplicate: () => void; onLayerAction: (action: ComponentLayerAction) => void; onUngroup: () => void; }; const COMPONENT_LAYER_ACTIONS: Array<{ action: ComponentLayerAction; label: string; shortcut: string; }> = [ { action: "bring-to-front", label: "Bring to Front", shortcut: "⌥⌘]", }, { action: "bring-forward", label: "Bring Forward", shortcut: "⌘]", }, { action: "send-backward", label: "Send Backward", shortcut: "⌘[", }, { action: "send-to-back", label: "Send Back", shortcut: "⌥⌘[", }, ]; export function ComponentActionsMenu({ actions, open, onOpenChange, }: { actions: ComponentActionsMenuActions; open?: boolean; onOpenChange?: (open: boolean) => void; }) { const [uncontrolledOpen, setUncontrolledOpen] = useState(false); const menuOpen = open ?? uncontrolledOpen; const setMenuOpen = onOpenChange ?? setUncontrolledOpen; return ( event.stopPropagation()} onPointerDown={(event) => event.stopPropagation()} className="z-[10001] box-border w-[206px] rounded-[12px] border border-[#EDEEEF] bg-white py-2 font-syne text-[14px] font-normal leading-normal tracking-[0.14px] text-[#191919] shadow-[0_6px_18px_rgba(16,24,40,0.08)]" > {COMPONENT_LAYER_ACTIONS.map(({ action, label, shortcut }) => { const disabled = !canApplyComponentLayerAction( actions.componentIndex, actions.componentCount, action, ); return ( actions.onLayerAction(action)} /> ); })} ); } export function ComponentUngroupButton({ actions, }: { actions: ComponentActionsMenuActions; }) { if (!actions.canUngroup) return null; return ( ); } function ComponentActionsMenuItem({ disabled, icon: Icon = undefined, label, shortcut, strong, onClick, }: { disabled?: boolean; icon?: LucideIcon; label: string; shortcut?: string; strong?: boolean; onClick: () => void; }) { return ( {Icon ? : null} {label} {shortcut ? ( {shortcut} ) : null} ); }