import { useCallback as a } from "react";
import { TextSelection as h } from "@tiptap/pm/state";
function A(t) {
  const s = a(
    (e) => {
      if (!t) return;
      const { src: n, alt: m, alignment: o, width: i, height: r } = e;
      if (!n.trim())
        return;
      t.chain().focus().insertContent({
        type: "image",
        attrs: {
          src: n,
          alt: m ?? "",
          alignment: o ?? "left",
          width: i ?? null,
          height: r ?? null
        }
      }).run();
      const { $to: f } = t.state.selection, g = t.state.doc.resolve(Math.min(f.pos, t.state.doc.content.size));
      t.commands.setTextSelection(h.near(g).from);
    },
    [t]
  ), c = a(
    (e) => {
      if (!t) return;
      const { alignment: n } = e;
      t.chain().focus().updateAttributes("image", { alignment: n }).run();
    },
    [t]
  ), l = a(
    (e) => {
      if (!t) return;
      const { alt: n } = e;
      t.chain().focus().updateAttributes("image", { alt: n }).run();
    },
    [t]
  ), u = a(() => {
    t && t.chain().focus().deleteNode("image").run();
  }, [t]);
  return { handleInsertImage: s, handleUpdateImageAlignment: c, handleUpdateImageAlt: l, handleDeleteImage: u };
}
export {
  A as default
};
//# sourceMappingURL=useHtmlEditorImageAction.js.map
