import type { Command } from '@blockeditor/block-std';
import { assertExists } from '@blockeditor/global/utils';

export const deleteSelectedModelsCommand: Command<'selectedModels'> = (
  ctx,
  next
) => {
  const models = ctx.selectedModels;
  assertExists(
    models,
    '`selectedModels` is required, you need to use `getSelectedModels` command before adding this command to the pipeline.'
  );

  models.forEach(model => {
    ctx.std.page.deleteBlock(model);
  });

  return next();
};

declare global {
  namespace BlockEditor {
    interface Commands {
      deleteSelectedModels: typeof deleteSelectedModelsCommand;
    }
  }
}
