import { UmbMediaItemRepository } from '../../repository/index.js';
import { UMB_MEDIA_CREATE_OPTIONS_MODAL } from './media-create-options-modal.token.js';
import { umbOpenModal } from '../../../../core/modal/index.js';
import { UmbEntityActionBase } from '../../../../core/entity-action/index.js';
export class UmbCreateMediaEntityAction extends UmbEntityActionBase {
    constructor(host, args) {
        super(host, args);
    }
    async execute() {
        // default to root
        let mediaItem = null;
        if (this.args.unique) {
            // get media item to get the doc type id
            const itemRepository = new UmbMediaItemRepository(this._host);
            const { data, error } = await itemRepository.requestItems([this.args.unique]);
            if (error || !data)
                throw new Error(`Failed to load media item`);
            mediaItem = data[0];
        }
        await umbOpenModal(this, UMB_MEDIA_CREATE_OPTIONS_MODAL, {
            data: {
                parent: { unique: this.args.unique, entityType: this.args.entityType },
                mediaType: mediaItem ? { unique: mediaItem.mediaType.unique } : null,
            },
        });
    }
}
export { UmbCreateMediaEntityAction as api };
