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

export const withHostCommand: Command<never, 'host'> = (ctx, next) => {
  const host = ctx.std.host;
  assertInstanceOf(host, EditorHost);

  next({ host });
};

declare global {
  namespace BlockEditor {
    interface CommandContext {
      host?: EditorHost;
    }

    interface Commands {
      withHost: typeof withHostCommand;
    }
  }
}
