import api from '@/composables/IvyFormAPI.ts' import type { ContextMenuAction } from '@/views/_components/context-menu/context-menu-action' import { ContextMenuActionType, createContextMenuAction, } from '@/views/_components/context-menu/kit/ContextMenuActionType.ts' export interface EntryContextMenuActionsContext { entryId: number formId?: number | null /** When true, Pro starts edit on the current entry detail page. */ onDetailPage?: boolean /** List source for Pro navigation (do not infer from formId — all entries also have formId). */ context?: 'all-entries' | 'form-results' } /** * Merge extension-provided entry row context menu actions (Pro registers via filter). */ export function applyEntryContextMenuActionsFilter( actions: ContextMenuAction[], context: EntryContextMenuActionsContext, ): ContextMenuAction[] { return api.hooks.applyFilters( 'ivyforms/entry/context_menu_actions', actions, context, ) as ContextMenuAction[] } export interface EditEntryContextMenuActionOptions { /** When true, action shows Pro badge and does not run the handler. */ locked?: boolean | (() => boolean) } export function createEditEntryContextMenuAction( handler: (entryId: number | null) => void, options: EditEntryContextMenuActionOptions = {}, ): ContextMenuAction { const resolveLocked = () => { const locked = options.locked ?? false return typeof locked === 'function' ? locked() : locked } return createContextMenuAction(ContextMenuActionType.EditEntry, { secondary: true, iconColor: 'var(--map-base-purple-symbol-0)', isProLocked: resolveLocked, proRequiredPlan: 'essentials', value: 'ivyforms-edit-entry', handler: (entryId) => { if (resolveLocked()) { return } handler(entryId) }, }) }