import { UmbDocumentItemRepository } from '../../item/index.js';
import { UmbDocumentTypeDetailRepository, UmbDocumentTypeStructureRepository, } from '../../../document-types/index.js';
import { UmbMoveToEntityAction } from '../../../../core/tree/index.js';
class UmbDocumentMoveToEntityAction extends UmbMoveToEntityAction {
    async _getPickableFilter(unique) {
        const itemRepository = new UmbDocumentItemRepository(this);
        const { data } = await itemRepository.requestItems([unique]);
        const item = data?.[0];
        if (!item)
            throw new Error('Item is not available');
        const documentTypeUnique = item.documentType.unique;
        const structureRepository = new UmbDocumentTypeStructureRepository(this);
        const typeDetailRepository = new UmbDocumentTypeDetailRepository(this);
        const [{ data: allowedParents }, { data: documentType }] = await Promise.all([
            structureRepository.requestAllowedParentsOf(documentTypeUnique),
            typeDetailRepository.requestByUnique(documentTypeUnique),
        ]);
        const isAllowedAtRoot = documentType?.allowedAtRoot ?? false;
        if (!allowedParents)
            return undefined;
        return (treeItem) => this.#isPickable(treeItem, unique, isAllowedAtRoot, allowedParents);
    }
    #isPickable(treeItem, unique, isAllowedAtRoot, allowedParents) {
        if (treeItem.unique === unique)
            return false;
        if (treeItem.unique === null)
            return isAllowedAtRoot;
        return allowedParents.some((parent) => parent.unique === treeItem.documentType?.unique);
    }
}
export { UmbDocumentMoveToEntityAction as api };
