import { TIPTAP_AUDIO_TYPE } from "./../../ricos-content/index.js";
import { NodeSelection } from "./../../tiptap/pm/state.js";
import generalStyles from "./../../editor-common/statics/styles/general-scss.js";
import { createRicosNodeExtension } from "./../../plugin-commons/index.js";
import { ROOT } from "../data-hooks.js";
import { Audio as Component } from "./component.js";
const name = TIPTAP_AUDIO_TYPE;
const tiptapExtensions = [
  createRicosNodeExtension({
    groups: [
      "overlay",
      "draggable",
      "not-overtypable",
      { group: "resizable", options: { minWidth: 90 } }
    ],
    type: "react-node",
    name,
    reconfigure: (config, _extensions, _props, settings) => ({
      ...config,
      addOptions: () => settings
    }),
    Component,
    renderingOptions: {
      onDragStart({ editor, dragHandle, target, event }) {
        if (!this.dom || !dragHandle || this.contentDOM?.contains(target)) {
          return;
        }
        const audioRoot = this.dom.querySelector(`[data-hook="${ROOT}"]`) ?? this.dom;
        const nativeEvent = "nativeEvent" in event ? event.nativeEvent : event;
        const rootBox = audioRoot.getBoundingClientRect();
        const clientX = nativeEvent.clientX;
        const clientY = nativeEvent.clientY;
        const x = Math.min(Math.max(clientX - rootBox.left, 0), rootBox.width - 1);
        const y = Math.min(Math.max(clientY - rootBox.top, 0), rootBox.height - 1);
        audioRoot.classList.add(generalStyles.dragImageView);
        audioRoot.style.overflow = "hidden";
        audioRoot.style.isolation = "isolate";
        event.dataTransfer?.setDragImage(audioRoot, x, y);
        setTimeout(() => {
          audioRoot.classList.remove(generalStyles.dragImageView);
          audioRoot.style.overflow = "";
          audioRoot.style.isolation = "";
        }, 0);
        const selection = NodeSelection.create(editor.view.state.doc, this.getPos());
        const transaction = editor.view.state.tr.setSelection(selection);
        editor.view.dispatch(transaction);
      }
    },
    createExtensionConfig() {
      return {
        name: this.name,
        group: "block smartBlockCellContent layoutCellContent collapsibleListItemBodyContent tableCellContent",
        selectable: true,
        draggable: true,
        addAttributes: () => ({
          containerData: null,
          audio: null,
          disableDownload: null,
          coverImage: null,
          name: null,
          authorName: null,
          html: null,
          loading: {
            default: false
          },
          error: null
        }),
        addCommands() {
          return {};
        }
      };
    }
  })
];
export {
  tiptapExtensions
};
//# sourceMappingURL=tiptap.js.map
