import { RemoveChildrenAction } from '../../actions/remove-child-action';
import { RemoveNestListAction } from '../../actions/remove-nest-list-action';
import { RemoveChildrenStrategy } from './remove-children-strategy';
/**
 * List remove list item strategy.
 */
export class ListRemoveListItemStrategy extends RemoveChildrenStrategy {
  /**
   * Remove the list item, check the list item and remove self if the list item is empty.
   *
   * @param {RemoveChildrenAction} action - The remove action instance.
   * @param {RTEListBlock} target - The list block.
   */
  handleAction(action, target) {
    super.handleAction(action, target);
    const parent = target.parent;
    if (target.children.length === 0 && parent) {
      // The parent is a list item mean the current block is a nest list, so we need to use RemoveNestListAction to remove the item
      if (parent['type'] === 'list-item') {
        parent.apply(new RemoveNestListAction(target));
      }
      else {
        parent.apply(new RemoveChildrenAction(target));
      }
    }
  }
}
