import { UmbArrayState } from '../../../../libs/observable-api/index.js';
import { UmbBlockManagerContext } from '../../block/index.js';
import '../components/block-rte-entry/index.js';
/**
 * A implementation of the Block Manager specifically for the Rich Text Editor.
 */
export class UmbBlockRteManagerContext extends UmbBlockManagerContext {
    constructor() {
        super(...arguments);
        /**
         * Pending deletions are used to support undo for block deletions.
         * When a block is deleted via the delete button, the contentKey is added to this list.
         * The Tiptap API observes this and removes the HTML element, which triggers
         * the _filterUnusedBlocks mechanism that stores block data for undo and removes from manager.
         */
        this.#pendingDeletions = new UmbArrayState([], (x) => x);
        this.pendingDeletions = this.#pendingDeletions.asObservable();
    }
    /**
     * Pending deletions are used to support undo for block deletions.
     * When a block is deleted via the delete button, the contentKey is added to this list.
     * The Tiptap API observes this and removes the HTML element, which triggers
     * the _filterUnusedBlocks mechanism that stores block data for undo and removes from manager.
     */
    #pendingDeletions;
    /**
     * Request a block to be deleted. This adds the contentKey to pending deletions,
     * which will be processed by the Tiptap API to remove the HTML element first,
     * enabling undo support.
     * @param {string} contentKey - The content key of the block to delete.
     */
    requestPendingDeletion(contentKey) {
        this.#pendingDeletions.appendOne(contentKey);
    }
    /**
     * Clear a pending deletion after it has been processed.
     * @param {string} contentKey - The content key to clear from pending deletions.
     */
    clearPendingDeletion(contentKey) {
        this.#pendingDeletions.removeOne(contentKey);
    }
    removeOneLayout(contentKey) {
        this._layouts.removeOne(contentKey);
    }
    removeManyLayouts(contentKeys) {
        this._layouts.remove(contentKeys);
    }
    /**
     * @param contentElementTypeKey
     * @param partialLayoutEntry
     * @param _originData
     */
    async createWithPresets(contentElementTypeKey, partialLayoutEntry, 
    // This property is used by some implementations, but not used in this, do not remove. [NL]
    _originData) {
        const data = await super._createBlockData(contentElementTypeKey, partialLayoutEntry);
        // Find block type.
        const blockType = this.getBlockTypes().find((x) => x.contentElementTypeKey === contentElementTypeKey);
        if (!blockType) {
            throw new Error(`Cannot create block, missing block type for ${contentElementTypeKey}`);
        }
        return data;
    }
    insert(layoutEntry, content, settings, originData) {
        this._layouts.appendOne(layoutEntry);
        this.insertBlockData(layoutEntry, content, settings, originData);
        this.notifyBlockInserted(layoutEntry, originData);
        return true;
    }
    /**
     * @param contentKey
     * @internal
     */
    deleteLayoutElement(contentKey) {
        this.removeBlockKey(contentKey);
    }
}
