import { UmbMediaItemRepository } from '../../repository/index.js';
import { UmbMediaTypeDetailRepository, UmbMediaTypeStructureRepository } from '../../../media-types/index.js';
import { UmbMoveToEntityAction } from '../../../../core/tree/index.js';
class UmbMediaMoveToEntityAction extends UmbMoveToEntityAction {
    async _getPickableFilter(unique) {
        const itemRepository = new UmbMediaItemRepository(this);
        const { data } = await itemRepository.requestItems([unique]);
        const item = data?.[0];
        if (!item)
            throw new Error('Item is not available');
        const mediaTypeUnique = item.mediaType.unique;
        const structureRepository = new UmbMediaTypeStructureRepository(this);
        const typeDetailRepository = new UmbMediaTypeDetailRepository(this);
        const [{ data: allowedParents }, { data: mediaType }] = await Promise.all([
            structureRepository.requestAllowedParentsOf(mediaTypeUnique),
            typeDetailRepository.requestByUnique(mediaTypeUnique),
        ]);
        const isAllowedAtRoot = mediaType?.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.mediaType?.unique);
    }
}
export { UmbMediaMoveToEntityAction as api };
