/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { Extension } from '@tiptap/core';

declare module '@tiptap/core' {
  interface Commands<ReturnType> {
    iframe: {
      setIframe: (options: { src?: string; srcdoc?: string }) => ReturnType;
    };
  }
}

const Iframe = Extension.create({
  name: 'iframe',

  addCommands() {
    return {
      setIframe:
        (options: { src?: string; srcdoc?: string }) =>
        ({ commands }) =>
          commands.insertContent([
            {
              type: 'resizable-media',
              attrs: {
                tag: 'iframe',
                src: options.src,
                srcdoc: options.srcdoc,
              },
            },
            { type: 'paragraph' },
          ]),
    };
  },
});

export default Iframe;
