// @ts-check
/**
* @import {treeAction} from './../../types.js'
*/
import { errorLoggerUpdate } from '../../utils/requestLogger.js'
import { removeDlistFilterAction, removeVisibilityFilterAction } from './treeRemove.filterActions.js'
import { removeListEntryAction } from './treeRemove.listAction.js'
import { removeFamilyAction } from './treeRemove.familyAction.js'
import { removeMemberAction } from './treeRemove.memberAction.js'
/**
* Handles various removal actions in the tree structure.
* Delegates to type-specific submodules.
*
* Note on dispatch order: the filter-type guards (include/exclude/intersect and
* visible/changeable) use plain `if` blocks and are not mutually exclusive with
* the final `else` branch of the listMember/list/family chain. This matches the
* original logic exactly.
*
* @async
* @function removeAction
* @param {treeAction} action
* @returns {Promise<void>}
*/
export const removeAction = async (action) => {
try {
// ── Filter-type removals (plain if – can run alongside the else block) ──
if (['include', 'exclude', 'intersect'].includes(action.Type)) {
await removeDlistFilterAction(action)
}
if (['visible', 'changeable'].includes(action.Type)) {
await removeVisibilityFilterAction(action)
}
// ── List / family / member dispatch ──────────────────────────────────
if (action.Type === 'listMember') {
// stub – logic commented out in original (resetRecursive / undoObjectsLists)
} else if (action.Type === 'list') {
await removeListEntryAction(action)
} else if (action.Type === 'family') {
await removeFamilyAction(action)
} else {
// Handles: job, guest, groupGuest, group, person, extern, event, eventJob, achievement
// Also fires for filter types (include/exclude/intersect/visible/changeable) –
// those sub-type checks inside removeMemberAction are all false, so it is a no-op.
await removeMemberAction(action)
}
}
catch (e) {
errorLoggerUpdate(e || new Error('treeRemove: Unknown error occurred'))
}
}