import { ActionHandleStrategy } from '../action-handle-strategy.abstract';
/**
 * Remove list item nest list block strategy.
 */
export class ListItemRemoveNestListStrategy extends ActionHandleStrategy {
  /**
   * Remove the nest list block from the list item, clear the property children when the children is empty.
   *
   * @param {RemoveNestListAction} action - The action instance.
   * @param {RTEListItemBlock} target - The list item block.
   */
  handleAction(action, target) {
    if (target.nestList) {
      if (target.nestList.length > 1) {
        target.nestList = target.nestList.filter((child) => child !== action.nestListBlockToBeRemoved);
      }
      else {
        target.nestList = undefined;
      }
    }
  }
}
