import { AXPopupService } from '@acorex/components/popup';
import { AXTranslationService } from '@acorex/core/translation';
import { AXPSettingService } from '@acorex/platform/common';
import { AXPBroadcastEventService, AXPPlatformScope } from '@acorex/platform/core';
import { AXPEntityDefinitionRegistryService } from '@acorex/platform/layout/entity';
import * as i0 from '@angular/core';
import { inject, signal, Injectable } from '@angular/core';

class AXPManageExtraPropertiesCommand {
    constructor() {
        this.settingsService = inject(AXPSettingService);
        this.popupService = inject(AXPopupService);
        this.translateService = inject(AXTranslationService);
        this.entityDefinitionRegistryService = inject(AXPEntityDefinitionRegistryService);
        this.eventService = inject(AXPBroadcastEventService);
    }
    async execute(ctx) {
        const entityName = ctx.target;
        const schema = (await this.settingsService.scope(AXPPlatformScope.Tenant).get(`extra-properties.schema.${entityName}`)) ?? [];
        const component = await import('./acorex-modules-common-manage-extra-properties-popup.component-Cp2ggAfC.mjs').then((m) => m.AXPManageExtraPropertiesPopupComponent);
        const result = await this.popupService.open(component, {
            title: await this.translateService.translateAsync('@extra-properties:actions.manage'),
            size: 'lg',
            data: {
                schema: signal(schema),
            },
        });
        if (result && result.data?.schema) {
            await this.settingsService
                .scope(AXPPlatformScope.Tenant)
                .set(`extra-properties.schema.${entityName}`, result.data.schema);
            //Dispatch definition-updated for immediate same-tab refresh (cross-tab covered by bridge)
            await this.entityDefinitionRegistryService.refresh(entityName);
            this.eventService.publish('REFRESH_LAYOUT', {
                name: entityName,
            });
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPManageExtraPropertiesCommand, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPManageExtraPropertiesCommand, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPManageExtraPropertiesCommand, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }] });

export { AXPManageExtraPropertiesCommand };
//# sourceMappingURL=acorex-modules-common-manage-extra-properties.command-2LcIbEWj.mjs.map
