var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _EdenEditorUi_add;
import EdenAddSection from "../block/eden-add-block.js";
import template from "./eden-editor-ui.template.js";
import styles from "./eden-editor-ui.styles.js";
import { isContentNotValidForPaste } from "../../services/clipboard.js";
class EdenEditorUi extends HTMLElement {
    constructor(editor, callbacks, templates) {
        super();
        this.hidePaste = false;
        _EdenEditorUi_add.set(this, async (e) => {
            this.hidePaste = await isContentNotValidForPaste(this.editor);
            if (this.hidePaste && this.templates?.length === 1) {
                this.callbacks.addBlock(this.templates[0]);
                return;
            }
            document.body.prepend(new EdenAddSection(e, {
                addBlock: this.callbacks.addBlock,
                paste: this.callbacks.paste,
            }, this.templates, this.hidePaste));
        });
        this.editor = editor;
        this.callbacks = callbacks;
        this.templates = templates;
        const shadowRoot = this.attachShadow({ mode: "open" });
        shadowRoot.innerHTML = template();
        const sheet = new CSSStyleSheet();
        sheet.replaceSync(styles);
        shadowRoot.adoptedStyleSheets = [sheet];
    }
    connectedCallback() {
        if (!this.shadowRoot) {
            return;
        }
        this.addButton = this.shadowRoot.querySelector(".button") ?? undefined;
        this.addButton?.addEventListener("click", __classPrivateFieldGet(this, _EdenEditorUi_add, "f"));
    }
    disconnectedCallback() {
        this.addButton?.removeEventListener("click", __classPrivateFieldGet(this, _EdenEditorUi_add, "f"));
        this.addButton = undefined;
    }
}
_EdenEditorUi_add = new WeakMap();
export default EdenEditorUi;
if (!customElements.get("eden-editor-ui")) {
    customElements.define("eden-editor-ui", EdenEditorUi);
}
