import { computed } from 'vue' import { pluginManager } from '@/core/plugin-manager' import type { QuickAction } from '@/core/types' /** * Composable for dynamic quick actions based on enabled modules * * Quick actions are module-provided action buttons that appear in the floating * action button (FAB) menu. Each module can register its own quick actions * for common tasks like composing notes, sending payments, adding expenses, etc. * * @example * ```typescript * const { quickActions, getActionsByCategory } = useQuickActions() * * // Get all actions * const actions = quickActions.value * * // Get actions by category * const composeActions = getActionsByCategory('compose') * ``` */ export function useQuickActions() { /** * Get all quick actions from installed modules * Actions are sorted by order (lower = higher priority) */ const quickActions = computed(() => { const actions: QuickAction[] = [] // Iterate through installed modules const installedModules = pluginManager.getInstalledModules() for (const moduleName of installedModules) { const module = pluginManager.getModule(moduleName) if (module?.plugin.quickActions) { actions.push(...module.plugin.quickActions) } } // Sort by order (lower = higher priority), then by label return actions.sort((a, b) => { const orderA = a.order ?? 999 const orderB = b.order ?? 999 if (orderA !== orderB) { return orderA - orderB } return a.label.localeCompare(b.label) }) }) /** * Get actions filtered by category */ const getActionsByCategory = (category: string) => { return computed(() => { return quickActions.value.filter(action => action.category === category) }) } /** * Get a specific action by ID */ const getActionById = (id: string) => { return computed(() => { return quickActions.value.find(action => action.id === id) }) } /** * Check if any actions are available */ const hasActions = computed(() => quickActions.value.length > 0) /** * Get all unique categories */ const categories = computed(() => { const cats = new Set() quickActions.value.forEach(action => { if (action.category) { cats.add(action.category) } }) return Array.from(cats).sort() }) return { quickActions, getActionsByCategory, getActionById, hasActions, categories } }