import { UmbEntityTrashedEvent } from '../../entity-action/trash/index.js';
import { UmbDefaultTreeItemContext } from '../../../tree/index.js';
import { UMB_ACTION_EVENT_CONTEXT } from '../../../action/index.js';
import { debounce } from '../../../utils/index.js';
export class UmbRecycleBinTreeItemContext extends UmbDefaultTreeItemContext {
    #actionEventContext;
    constructor(host) {
        super(host);
        this.consumeContext(UMB_ACTION_EVENT_CONTEXT, (instance) => {
            this.#removeEventListener();
            this.#actionEventContext = instance;
            this.#actionEventContext?.addEventListener(UmbEntityTrashedEvent.TYPE, this.#onEntityTrashed);
        });
    }
    #debounceLoadChildren = debounce(() => this.loadChildren(), 100);
    #onEntityTrashed = (event) => {
        const entityType = event.getEntityType();
        if (!entityType)
            throw new Error('Entity type is required');
        const supportedEntityTypes = this.manifest?.meta.supportedEntityTypes;
        if (!supportedEntityTypes) {
            throw new Error('Entity types are missing from the manifest (manifest.meta.supportedEntityTypes).');
        }
        if (supportedEntityTypes.includes(entityType)) {
            this.#debounceLoadChildren();
        }
    };
    #removeEventListener = () => {
        this.#actionEventContext?.removeEventListener(UmbEntityTrashedEvent.TYPE, this.#onEntityTrashed);
    };
    destroy() {
        this.#removeEventListener();
        super.destroy();
    }
}
export { UmbRecycleBinTreeItemContext as api };
