/* eslint-disable @typescript-eslint/no-explicit-any */
import { omit } from "lodash-es"
import { getActionList } from "@/redux/currentApp/action/actionSelector"
import { DisplayNameGenerator } from "@/utils/generators/generateDisplayName"
import { ActionContent, ActionItem } from "@/redux/currentApp/action/interface"

export const addActionItemWhenUndoRedo = async (
    action: ActionItem<ActionContent>,
) => {

    omit(action, ["displayName", "actionID"])
    DisplayNameGenerator.isAlreadyGenerate(action.displayName)
        ? DisplayNameGenerator.generateDisplayName(action.actionType)
        : DisplayNameGenerator.updateOrGenerateDisplayName(action.displayName)

}

export const removeActionItemWhenUndoRedo = async (displayName: string,aaaStore:any) => {
    const actionList = getActionList(aaaStore.getState())
    const targetAction = actionList.find(
        (item) => item.displayName === displayName,
    )
    if (!targetAction) {
        throw new Error("action not found")
    }

}

export const updateActionItemReducerWhenUndoRedo = async (
    action: ActionItem<ActionContent>,aaaStore:any
) => {
    const actionList = getActionList(aaaStore.getState())
    const targetAction = actionList.find(
        (item) => action.displayName === item.displayName,
    )
    if (!targetAction) {
        throw new Error("action not found")
    }

}

export const updateActionDisplayNameReducerWhenUndoRedo = async (
    oldDisplayName: string,
    newDisplayName: string,
    aaaStore,
) => {

    const actionList = getActionList(aaaStore.getState())
    actionList.find(
        (action) => action.displayName === oldDisplayName,
    )

}