import { UmbEnableUserRepository } from '../../repository/enable/enable-user.repository.js';
import { UmbUserItemRepository } from '../../repository/item/user-item.repository.js';
import { UmbEntityActionBase } from '../../../../core/entity-action/index.js';
import { umbConfirmModal } from '../../../../core/modal/index.js';
export class UmbEnableUserEntityAction extends UmbEntityActionBase {
    constructor(host, args) {
        super(host, args);
    }
    async execute() {
        if (!this.args.unique)
            throw new Error('Unique is not available');
        const itemRepository = new UmbUserItemRepository(this);
        const { data } = await itemRepository.requestItems([this.args.unique]);
        if (!data?.length) {
            throw new Error('Item not found.');
        }
        const item = data[0];
        await umbConfirmModal(this._host, {
            headline: `Enable ${item.name}`,
            content: 'Are you sure you want to enable this user?',
            confirmLabel: 'Enable',
        });
        const enableRepository = new UmbEnableUserRepository(this);
        const { error } = await enableRepository.enable([this.args.unique]);
        if (error) {
            throw error;
        }
    }
}
export { UmbEnableUserEntityAction as api };
