import { AXPSessionService, AXP_PERMISSION_DEFINITION_PROVIDER } from '@acorex/platform/auth';
import { AXPSearchCommandProvider, AXPWorkflowNavigateAction, AXP_MENU_PROVIDER, AXP_SETTING_DEFINITION_PROVIDER, AXP_SEARCH_PROVIDER } from '@acorex/platform/common';
import * as i1 from '@acorex/platform/layout/widget-core';
import { AXPValueWidgetComponent, AXPWidgetCoreModule, AXPLayoutBaseWidgetComponent, createStringProperty, AXPWidgetGroupEnum, AXP_WIDGETS_ADVANCE_CATEGORY, AXP_WIDGETS_LAYOUT_CATEGORY, AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { AXPDesignerConnector, AXPDesignerService, AXPWidgetDesignerRendererDirective, AXPDesignerAddWidgetMiniButtonComponent, AXPDesignerMessageKeys } from '@acorex/platform/layout/designer';
import { AXMEntityCrudServiceImpl, AXPEntityService, AXP_ENTITY_DEFINITION_LOADER } from '@acorex/platform/layout/entity';
import { AXP_NAME_PROPERTY, AXP_DATA_PATH_PROPERTY, AXP_BEHAVIOR_PROPERTY_GROUP, AXPWidgetsModule } from '@acorex/platform/layout/widgets';
import * as i2$1 from '@acorex/platform/workflow';
import { AXPWorkflowService, AXPWorkflowAction, AXPWorkflowModule } from '@acorex/platform/workflow';
import * as i0 from '@angular/core';
import { Injectable, NgModule, inject, Injector, runInInjectionContext, InjectionToken, computed, signal, effect, ChangeDetectionStrategy, Component, HostBinding } from '@angular/core';
import { ROUTES } from '@angular/router';
import { firstValueFrom } from 'rxjs';
import { get, sortBy } from 'lodash-es';
import { AXPDataGenerator, AXPBroadcastEventService, AXP_DATASOURCE_DEFINITION_PROVIDER } from '@acorex/platform/core';
import * as i3 from '@acorex/core/translation';
import { AXTranslationService, AXTranslationModule } from '@acorex/core/translation';
import * as i2 from '@angular/common';
import { CommonModule } from '@angular/common';
import { AXPopupService } from '@acorex/components/popup';
import { AXDataSource } from '@acorex/cdk/common';
import { AXPTemplateViewerService } from '@acorex/platform/layout/components';
import { AXP_IDENTIFIER_RULES } from '@acorex/modules/identifier-management';

const config = {
    i18n: 'form-template-management',
    module: 'FormTemplateManagement',
};
const RootConfig = {
    config,
    module: {
        route: 'form-template-management',
        name: 'FormTemplateManagement',
        title: `t('module-name', {scope:"${config.i18n}"})`,
        icon: 'fa-light fa-file-invoice'
    },
    entities: {
        template: {
            name: 'Template',
            title: `t("template",{scope:"${config.i18n}"})`,
            source: `${config.module}.Template`,
            icon: 'fa-light fa-file-code'
        }
    },
};

class AXMFormTemplateManagementTemplateEntityService extends AXMEntityCrudServiceImpl {
}
class AXMFormTemplateManagementTemplateEntityServiceImpl extends AXMFormTemplateManagementTemplateEntityService {
    constructor() {
        super(`${RootConfig.module.name}.${RootConfig.entities.template.name}`);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMFormTemplateManagementTemplateEntityServiceImpl, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMFormTemplateManagementTemplateEntityServiceImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMFormTemplateManagementTemplateEntityServiceImpl, decorators: [{
            type: Injectable
        }], ctorParameters: () => [] });

class AXMFormTemplateManagementTemplateEntityModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMFormTemplateManagementTemplateEntityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.4", ngImport: i0, type: AXMFormTemplateManagementTemplateEntityModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMFormTemplateManagementTemplateEntityModule, providers: [
            {
                provide: AXMFormTemplateManagementTemplateEntityService,
                useClass: AXMFormTemplateManagementTemplateEntityServiceImpl,
            },
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMFormTemplateManagementTemplateEntityModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [],
                    exports: [],
                    declarations: [],
                    providers: [
                        {
                            provide: AXMFormTemplateManagementTemplateEntityService,
                            useClass: AXMFormTemplateManagementTemplateEntityServiceImpl,
                        },
                    ],
                }]
        }] });

const AXMFormTemplateTypes = {
    Form: { id: 10, title: 'Form Template' },
    Widget: { id: 20, title: 'Widget Template' },
    Report: { id: 30, title: 'Report Template' },
};

class AXMEntityProvider {
    constructor() {
        this.injector = inject(Injector);
    }
    preload() {
        const module = RootConfig.module.name;
        return Array.from(Object.values(RootConfig.entities)).map((entity) => ({
            module: module,
            entity: entity.name,
        }));
    }
    async get(moduleName, entityName) {
        if (moduleName == RootConfig.module.name) {
            switch (entityName) {
                case RootConfig.entities.template.name:
                    return (await import('./acorex-modules-form-template-management-template.entity-CqEvewsA.mjs')).factory(this.injector);
            }
        }
        return null;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMEntityProvider, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMEntityProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMEntityProvider, decorators: [{
            type: Injectable
        }] });

const AXMPermissionsKeys = {
    FormTemplate: {
        Management: 'form-template:manage',
        Templates: {
            Management: 'form-template:templates:manage',
            View: 'form-template:templates:view',
            Edit: 'form-template:templates:edit',
            Delete: 'form-template:templates:delete',
            Create: 'form-template:templates:create',
        },
        Categories: {
            Management: 'form-template:categories:manage',
            View: 'form-template:categories:view',
            Edit: 'form-template:categories:edit',
            Delete: 'form-template:categories:delete',
            Create: 'form-template:categories:create',
        },
    },
};

const AXPFormTemplateManagementMenuKeys = {
    Root: 'form-template-management:menu',
    Templates: 'form-template-management:menu:templates',
};

class AXMMenuProvider {
    constructor() {
        this.entityService = inject(AXPEntityService);
        this.sessionService = inject(AXPSessionService);
    }
    async provide(context) {
        const isAuthorized = await firstValueFrom(this.sessionService.isAuthorized$);
        if (!isAuthorized) {
            return;
        }
        //
        const scope = RootConfig.config.i18n;
        const module = RootConfig.module;
        context.addItems([
            {
                name: AXPFormTemplateManagementMenuKeys.Root,
                priority: 9001,
                text: `t('root-menu', {scope:"${scope}"})`,
                icon: module.icon,
                data: {
                    requiredPermission: [AXMPermissionsKeys.FormTemplate.Management]
                },
                children: [
                    {
                        name: AXPFormTemplateManagementMenuKeys.Templates,
                        text: `t('templates', {scope:"${scope}"})`,
                        path: this.entityService.createPath(module.name, RootConfig.entities.template.name),
                        icon: RootConfig.entities.template.icon,
                        priority: 2,
                        data: {
                            requiredPermission: [AXMPermissionsKeys.FormTemplate.Templates.Management]
                        },
                    },
                ],
            },
        ]);
    }
}

class AXMSearchCommandProvider extends AXPSearchCommandProvider {
    constructor() {
        super(...arguments);
        this.commands = [
            {
                group: 'command',
                title: 'New Form Template',
                icon: RootConfig.entities.template.icon,
                description: 'Create a new form template for designing reusable forms.', // Added description
                command: {
                    // 'create-entity': {
                    //   entity: `${RootConfig.module.name}.${RootConfig.entities.template.name}`,
                    // },
                    name: 'create-entity',
                    options: {
                        entity: `${RootConfig.module.name}.${RootConfig.entities.template.name}`
                    }
                },
            },
        ];
    }
}

class AXPTemplateWidgetProviderImpl {
    constructor() {
        this.service = inject(AXMFormTemplateManagementTemplateEntityService);
    }
    async items(query) {
        const result = (await this.service.query(query)).items.map((c) => ({
            id: c.id,
            title: c.title,
            group: {
                name: c.categoryIds[0],
                order: 2,
                title: get(c, 'category.title') ?? 'Custom',
            },
            description: c.description,
        }));
        return result;
    }
    async get(id) {
        const item = await this.service.getOne(id);
        if (item) {
            const document = JSON.parse(item.template);
            const page = document?.children?.[0];
            return {
                id: item.id,
                nodes: page?.children ?? [],
                title: item.title,
            };
        }
        else {
            throw Error('Invalid Id');
        }
    }
}

class AXPDesignerConnectorImpl extends AXPDesignerConnector {
    constructor() {
        super(...arguments);
        this.workflow = inject(AXPWorkflowService);
        this.injector = inject(Injector);
        this.templateEntityService = inject(AXMFormTemplateManagementTemplateEntityService);
        this.categoryEntityService = runInInjectionContext(this.injector, () => new AXMEntityCrudServiceImpl(`${RootConfig.module.name}.${RootConfig.entities.template.name}Category`));
    }
    //#region Save and load Widgets
    async save(id, content) {
        const item = await this.templateEntityService.getOne(id);
        if (item) {
            await this.templateEntityService.updateOne(id, { template: content.json });
            return true;
        }
        else {
            throw Error("Invalid Id");
        }
    }
    async saveAs(content) {
        const result = await this.workflow.execute('create-entity', {
            redirect: false,
            entity: `${RootConfig.module.name}.${RootConfig.entities.template.name}`,
            canCreateNewOne: false,
            data: {
                name: AXPDataGenerator.alphanumeric(10),
                type: AXMFormTemplateTypes.Widget,
                template: content.json,
                categoryId: (await this.categoryEntityService.query()).items[0]?.id
            }
        });
        return result.getOutput('result');
    }
    async load(id) {
        const item = await this.templateEntityService.getOne(id);
        if (item) {
            return item.template;
        }
        else {
            throw Error("Invalid Id");
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPDesignerConnectorImpl, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPDesignerConnectorImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPDesignerConnectorImpl, decorators: [{
            type: Injectable
        }] });

const AXMCreateFormTemplateWorkflow = {
    startStepId: 'create-form-template',
    steps: {
        "create-form-template": {
            action: 'start-workflow',
            input: {
                workflow: "create-entity",
                context: {
                    redirect: true,
                    entity: `${RootConfig.module.name}.${RootConfig.entities.template.name}`,
                },
                options: {
                    process: {
                        redirect: false,
                    }
                }
            },
            // nextSteps: [
            //     {
            //         conditions: [{ type: 'SINGLE', expression: 'context.getOutput("result") == true' }],
            //         nextStepId: 'get-template-confirmaton',
            //     },
            // ],
        },
        "get-template-confirmaton": {
            action: 'show-prompt-dialog',
            input: {
                title: 'Confirm Action',
                message: `Would you like to proceed with starting template design?`,
                type: 'primary',
            },
            nextSteps: [
                {
                    conditions: [{ type: 'SINGLE', expression: 'context.getOutput("result") == true' }],
                    nextStepId: 'template-design',
                },
            ],
        },
        "template-design": {
            action: 'open-form-template-designer',
        },
    },
};

const AXMDesignFormTemplateWorkflow = {
    startStepId: 'open',
    steps: {
        "open": {
            action: 'decide',
            nextSteps: [
                {
                    conditions: [{ type: 'SINGLE', expression: '  context.getVariable("embedded") == true' }],
                    nextStepId: 'embedded',
                },
                {
                    conditions: [{ type: 'SINGLE', expression: ' !context.getVariable("embedded")' }],
                    nextStepId: 'form',
                },
            ],
        },
        'embedded': {
            action: 'open-embedded-template-designer',
            nextSteps: [
                {
                    conditions: [{ type: 'SINGLE', expression: '  context.getOutput("result") == true' }],
                    nextStepId: 'save-embedded',
                },
            ],
        },
        'form': {
            action: 'open-form-template-designer',
        },
        'save-embedded': {
            action: 'save-embedded-template-designer',
        },
    },
};

const AXP_TEMPLATE_WIDGET_PROVIDER = new InjectionToken('AXP_TEMPLATE_WIDGET_PROVIDER');
class AXPTemplateWidgetProviderService {
    constructor() {
        this.popupService = inject(AXPopupService);
        this.translate = inject(AXTranslationService);
        this.providers = inject(AXP_TEMPLATE_WIDGET_PROVIDER, { optional: true });
    }
    async items(query) {
        if (Array.isArray(this.providers)) {
            const result = [];
            for (const provider of this.providers) {
                const items = await provider.items(query);
                if (items) {
                    result.push(...items);
                }
            }
            return result;
        }
        else {
            return [];
        }
    }
    async get(id) {
        if (Array.isArray(this.providers)) {
            for (const provider of this.providers) {
                const node = await provider.get(id);
                if (node) {
                    return node;
                }
            }
        }
        return null;
    }
    async chooseTemplate() {
        const com = await import('./acorex-modules-form-template-management-template-picker.component-B_3DSrcW.mjs').then((c) => c.AXPTemplateWidgetPickerComponent);
        const widgets = await this.items({
            skip: 0,
            take: 100,
            filter: {
                field: 'type.id',
                value: 20,
                operator: {
                    type: 'equal',
                },
            },
        });
        const result = await this.popupService.open(com, {
            title: await this.translate.translateAsync('@form-template-management:template-picker.title'),
            size: 'lg',
            closeButton: true,
            data: {
                widgets: sortBy(widgets, (c) => c.title),
            },
        });
        if (result.data) {
            const selected = result.data?.widgets;
            return selected[0];
        }
        return null;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPTemplateWidgetProviderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPTemplateWidgetProviderService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPTemplateWidgetProviderService, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

class AXPTemplateWidgetViewComponent extends AXPValueWidgetComponent {
    constructor() {
        super();
        this.metaKey = '__meta__';
        this.templateProvider = inject(AXPTemplateWidgetProviderService);
        this.templateId = computed(() => this.options()['templateId'], ...(ngDevMode ? [{ debugName: "templateId" }] : []));
        this.nodes = signal([], ...(ngDevMode ? [{ debugName: "nodes" }] : []));
        //
        effect(async () => {
            this.nodes.set([]);
            const value = this.getValue();
            const templateId = get(value, `${this.metaKey}.templateId`) ?? this.templateId();
            if (templateId) {
                const item = await this.templateProvider.get(templateId);
                if (item) {
                    this.nodes.set(item.nodes);
                }
            }
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPTemplateWidgetViewComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.4", type: AXPTemplateWidgetViewComponent, isStandalone: true, selector: "axp-template-widget-view", usesInheritance: true, ngImport: i0, template: `
    @for (node of nodes(); track $index) {
      <ng-container axp-widget-renderer [node]="node" [parentNode]="this" [mode]="this.mode"> </ng-container>
    } @empty {
      <span class="ax-underline ax-decoration-dotted  ax-underline-offset-8 ax-text-gray-400">
        {{ 'empty-template' | translate: { scope: 'form-template-management' } | async }}
      </span>
    }
  `, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: AXPWidgetCoreModule }, { kind: "directive", type: i1.AXPWidgetRendererDirective, selector: "[axp-widget-renderer]", inputs: ["parentNode", "index", "mode", "node"], outputs: ["onOptionsChanged", "onValueChanged"], exportAs: ["widgetRenderer"] }, { kind: "ngmodule", type: AXTranslationModule }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }, { kind: "pipe", type: i3.AXTranslatorPipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPTemplateWidgetViewComponent, decorators: [{
            type: Component,
            args: [{
                    selector: 'axp-template-widget-view',
                    template: `
    @for (node of nodes(); track $index) {
      <ng-container axp-widget-renderer [node]="node" [parentNode]="this" [mode]="this.mode"> </ng-container>
    } @empty {
      <span class="ax-underline ax-decoration-dotted  ax-underline-offset-8 ax-text-gray-400">
        {{ 'empty-template' | translate: { scope: 'form-template-management' } | async }}
      </span>
    }
  `,
                    changeDetection: ChangeDetectionStrategy.OnPush,
                    imports: [CommonModule, AXPWidgetCoreModule, AXTranslationModule],
                }]
        }], ctorParameters: () => [] });

var templateWidgetView_component = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXPTemplateWidgetViewComponent: AXPTemplateWidgetViewComponent
});

const AXP_DESIGNER_TEMPLATE_WIDGET_CHOOSE_MENU = {
    text: 'Choose Template',
    name: 'choose',
    icon: 'fa-solid fa-folder-open',
};
class AXPTemplateWidgetDesignerComponent extends AXPValueWidgetComponent {
    constructor() {
        super();
        this.templateProvider = inject(AXPTemplateWidgetProviderService);
        this.designerService = inject(AXPDesignerService);
        this.templateId = computed(() => this.options()['templateId'], ...(ngDevMode ? [{ debugName: "templateId" }] : []));
        this.nodes = signal([], ...(ngDevMode ? [{ debugName: "nodes" }] : []));
        this.title = signal(null, ...(ngDevMode ? [{ debugName: "title" }] : []));
        //
        effect(async () => {
            this.nodes.set([]);
            if (this.templateId()) {
                const item = await this.templateProvider.get(this.templateId());
                if (item && item.nodes?.length > 0) {
                    this.title.set(item.title);
                    this.nodes.set(item.nodes);
                }
            }
        });
    }
    async handleChooseWidget() {
        const result = await this.templateProvider.chooseTemplate();
        if (result) {
            this.designerService.update({
                mode: 'update',
                values: { options: { templateId: result.id } },
                widget: this.node,
            });
        }
    }
    get __class() {
        const cls = {};
        //
        cls[`ax-w-full`] = true;
        cls[`ax-widget-outline`] = true;
        //
        cls[`ax-block`] = true;
        return cls;
    }
    onContextMenu(context) {
        const items = [AXP_DESIGNER_TEMPLATE_WIDGET_CHOOSE_MENU];
        items[items.length - 1].break = true;
        context.items.unshift(...items);
    }
    async executeCommand(command) {
        switch (command.name) {
            case AXP_DESIGNER_TEMPLATE_WIDGET_CHOOSE_MENU.name:
                await this.handleChooseWidget();
                break;
        }
        return Promise.resolve();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPTemplateWidgetDesignerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.4", type: AXPTemplateWidgetDesignerComponent, isStandalone: true, selector: "axp-template-widget-designer", host: { properties: { "class": "this.__class" } }, providers: [
            {
                provide: AXPLayoutBaseWidgetComponent,
                useExisting: AXPTemplateWidgetDesignerComponent,
            },
        ], usesInheritance: true, ngImport: i0, template: `
    @if (nodes().length) {
      <div class="ax-relative ax-block ax-w-full ax-pointer-events-none">
        @for (node of nodes(); track $index) {
          <ng-container
            axp-widget-designer-renderer
            [locked]="true"
            [node]="node"
            [parentNode]="this"
            [mode]="this.mode"
          >
          </ng-container>
        }
        <div
          class="ax-absolute ax-top-0 ax-bottom-0 ax-left-0 ax-right-0 ax-bg-blue-400 ax-opacity-30 ax-flex ax-justify-center ax-items-center ax-z-[400]"
        >
          <span class="ax-capitalize ax-font-semibold ax-text-primary-700"> {{ title() }}</span>
        </div>
      </div>
    } @else {
      <axp-designer-add-widget-mini-button
        class="ax-flex-1 ax-self-center ax-place-self-end"
        (onClick)="handleChooseWidget()"
      >
      </axp-designer-add-widget-mini-button>
    }
  `, isInline: true, dependencies: [{ kind: "ngmodule", type: AXPWidgetCoreModule }, { kind: "directive", type: AXPWidgetDesignerRendererDirective, selector: "[axp-widget-designer-renderer]", inputs: ["parentNode", "parentElement", "parentComponent", "index", "locked", "mode", "node"] }, { kind: "component", type: AXPDesignerAddWidgetMiniButtonComponent, selector: "axp-designer-add-widget-mini-button", outputs: ["onClick"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPTemplateWidgetDesignerComponent, decorators: [{
            type: Component,
            args: [{
                    selector: 'axp-template-widget-designer',
                    template: `
    @if (nodes().length) {
      <div class="ax-relative ax-block ax-w-full ax-pointer-events-none">
        @for (node of nodes(); track $index) {
          <ng-container
            axp-widget-designer-renderer
            [locked]="true"
            [node]="node"
            [parentNode]="this"
            [mode]="this.mode"
          >
          </ng-container>
        }
        <div
          class="ax-absolute ax-top-0 ax-bottom-0 ax-left-0 ax-right-0 ax-bg-blue-400 ax-opacity-30 ax-flex ax-justify-center ax-items-center ax-z-[400]"
        >
          <span class="ax-capitalize ax-font-semibold ax-text-primary-700"> {{ title() }}</span>
        </div>
      </div>
    } @else {
      <axp-designer-add-widget-mini-button
        class="ax-flex-1 ax-self-center ax-place-self-end"
        (onClick)="handleChooseWidget()"
      >
      </axp-designer-add-widget-mini-button>
    }
  `,
                    changeDetection: ChangeDetectionStrategy.OnPush,
                    imports: [
                        AXPWidgetCoreModule,
                        AXPWidgetDesignerRendererDirective,
                        AXPDesignerAddWidgetMiniButtonComponent
                    ],
                    providers: [
                        {
                            provide: AXPLayoutBaseWidgetComponent,
                            useExisting: AXPTemplateWidgetDesignerComponent,
                        },
                    ],
                }]
        }], ctorParameters: () => [], propDecorators: { __class: [{
                type: HostBinding,
                args: ['class']
            }] } });

var templateWidgetDesigner_component = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXPTemplateWidgetDesignerComponent: AXPTemplateWidgetDesignerComponent,
    AXP_DESIGNER_TEMPLATE_WIDGET_CHOOSE_MENU: AXP_DESIGNER_TEMPLATE_WIDGET_CHOOSE_MENU
});

const AXPTemplateWidget = {
    name: 'template',
    title: 'Template',
    type: 'container',
    icon: 'fa-light fa-file-invoice',
    categories: [AXP_WIDGETS_ADVANCE_CATEGORY],
    groups: [AXPWidgetGroupEnum.FormElement],
    designer: {
        canInsert: false,
    },
    properties: [
        AXP_NAME_PROPERTY,
        AXP_DATA_PATH_PROPERTY,
        createStringProperty({
            name: 'options.templateId',
            title: 'Template',
            group: AXP_BEHAVIOR_PROPERTY_GROUP,
            visible: false,
        }),
    ],
    components: {
        view: {
            component: () => Promise.resolve().then(function () { return templateWidgetView_component; }).then((c) => c.AXPTemplateWidgetViewComponent),
        },
        edit: {
            component: () => import('./acorex-modules-form-template-management-template-widget-edit.component-CvEqpmfa.mjs').then((c) => c.AXPTemplateWidgetEditComponent),
        },
        print: {
            component: () => Promise.resolve().then(function () { return templateWidgetView_component; }).then((c) => c.AXPTemplateWidgetViewComponent),
        },
        designer: {
            component: () => Promise.resolve().then(function () { return templateWidgetDesigner_component; }).then((c) => c.AXPTemplateWidgetDesignerComponent),
        },
    },
};

class AXPTemplateDesignerWidgetViewComponent extends AXPValueWidgetComponent {
    constructor() {
        super(...arguments);
        this.workflow = inject(AXPWorkflowService);
        this.embedded = computed(() => this.options()['embedded'] ?? false, ...(ngDevMode ? [{ debugName: "embedded" }] : []));
    }
    async handleClick() {
        if (this.embedded()) {
            const context = await this.workflow.execute('design-form-template', { embedded: true, content: this.getValue() });
            const content = context.getVariable('content');
            this.setValue(content);
        }
        else {
            const id = this.extractValue('id');
            const context = await this.workflow.execute('design-form-template', { id });
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPTemplateDesignerWidgetViewComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.4", type: AXPTemplateDesignerWidgetViewComponent, isStandalone: true, selector: "ng-component", usesInheritance: true, ngImport: i0, template: `
    <span
      class="ax-underline ax-decoration-dotted  ax-underline-offset-8 hover:ax-text-primary-500 ax-cursor-pointer"
      (click)="handleClick()" *translate="let t"
    >
      {{ t("edit-template",{ scope:"form-template-management" })   | async }}
    </span>
  `, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: AXTranslationModule }, { kind: "directive", type: i3.AXTranslatorDirective, selector: "[translate]" }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPTemplateDesignerWidgetViewComponent, decorators: [{
            type: Component,
            args: [{
                    template: `
    <span
      class="ax-underline ax-decoration-dotted  ax-underline-offset-8 hover:ax-text-primary-500 ax-cursor-pointer"
      (click)="handleClick()" *translate="let t"
    >
      {{ t("edit-template",{ scope:"form-template-management" })   | async }}
    </span>
  `,
                    changeDetection: ChangeDetectionStrategy.OnPush,
                    imports: [CommonModule, AXTranslationModule]
                }]
        }] });

var templateDesignerWidgetView_component = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXPTemplateDesignerWidgetViewComponent: AXPTemplateDesignerWidgetViewComponent
});

const AXPTemplateDesignerWidget = {
    name: "template-designer",
    title: "Template Designer",
    icon: "fa-solid fa-square",
    type: 'editor',
    categories: AXP_WIDGETS_LAYOUT_CATEGORY,
    properties: [
        AXP_NAME_PROPERTY,
        AXP_DATA_PATH_PROPERTY,
    ],
    components: {
        view: {
            component: () => Promise.resolve().then(function () { return templateDesignerWidgetView_component; }).then((c) => c.AXPTemplateDesignerWidgetViewComponent),
        },
        edit: {
            component: () => Promise.resolve().then(function () { return templateDesignerWidgetView_component; }).then((c) => c.AXPTemplateDesignerWidgetViewComponent),
        }
    }
};

class AXMQuestionnaireDataSourceDefinition {
    constructor() {
        //#region ----   Yes/No Options   ----
        this.yesNoOptions = {
            name: 'yes-no-options',
            title: '@questionnaire:datasources.yes-no-options.title',
            columns: [
                {
                    name: 'value',
                    title: '@questionnaire:datasources.yes-no-options.columns.value.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
                {
                    name: 'title',
                    title: '@questionnaire:datasources.yes-no-options.columns.title.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
            ],
            filters: [],
            textField: { name: 'title', title: '@questionnaire:datasources.yes-no-options.columns.title.title' },
            valueField: { name: 'value', title: '@questionnaire:datasources.yes-no-options.columns.value.title' },
            samples: [
                { value: 'yes', title: '@questionnaire:datasources.yes-no-options.samples.yes' },
                { value: 'no', title: '@questionnaire:datasources.yes-no-options.samples.no' },
            ],
            source: () => {
                return new AXDataSource({
                    pageSize: 10,
                    key: 'value',
                    load: async () => {
                        return {
                            items: [
                                { value: 'yes', title: '@questionnaire:datasources.yes-no-options.samples.yes' },
                                { value: 'no', title: '@questionnaire:datasources.yes-no-options.samples.no' },
                            ],
                            total: 2,
                        };
                    },
                    byKey: async (key) => {
                        const items = [
                            { value: 'yes', title: '@questionnaire:datasources.yes-no-options.samples.yes' },
                            { value: 'no', title: '@questionnaire:datasources.yes-no-options.samples.no' },
                        ];
                        return items.find(item => item.value === key);
                    },
                });
            },
        };
        //#endregion
        //#region ----   Rating Scale Options   ----
        this.ratingScaleOptions = {
            name: 'rating-scale-options',
            title: '@questionnaire:datasources.rating-scale-options.title',
            columns: [
                {
                    name: 'value',
                    title: '@questionnaire:datasources.rating-scale-options.columns.value.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'number',
                },
                {
                    name: 'title',
                    title: '@questionnaire:datasources.rating-scale-options.columns.title.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
                {
                    name: 'description',
                    title: '@questionnaire:datasources.rating-scale-options.columns.description.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
            ],
            filters: [],
            textField: { name: 'title', title: '@questionnaire:datasources.rating-scale-options.columns.title.title' },
            valueField: { name: 'value', title: '@questionnaire:datasources.rating-scale-options.columns.value.title' },
            samples: [
                { value: 1, title: '@questionnaire:datasources.rating-scale-options.samples.1', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.1' },
                { value: 2, title: '@questionnaire:datasources.rating-scale-options.samples.2', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.2' },
                { value: 3, title: '@questionnaire:datasources.rating-scale-options.samples.3', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.3' },
                { value: 4, title: '@questionnaire:datasources.rating-scale-options.samples.4', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.4' },
                { value: 5, title: '@questionnaire:datasources.rating-scale-options.samples.5', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.5' },
            ],
            source: () => {
                return new AXDataSource({
                    pageSize: 10,
                    key: 'value',
                    load: async () => {
                        return {
                            items: [
                                { value: 1, title: '@questionnaire:datasources.rating-scale-options.samples.1', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.1' },
                                { value: 2, title: '@questionnaire:datasources.rating-scale-options.samples.2', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.2' },
                                { value: 3, title: '@questionnaire:datasources.rating-scale-options.samples.3', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.3' },
                                { value: 4, title: '@questionnaire:datasources.rating-scale-options.samples.4', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.4' },
                                { value: 5, title: '@questionnaire:datasources.rating-scale-options.samples.5', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.5' },
                            ],
                            total: 5,
                        };
                    },
                    byKey: async (key) => {
                        const items = [
                            { value: 1, title: '@questionnaire:datasources.rating-scale-options.samples.1', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.1' },
                            { value: 2, title: '@questionnaire:datasources.rating-scale-options.samples.2', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.2' },
                            { value: 3, title: '@questionnaire:datasources.rating-scale-options.samples.3', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.3' },
                            { value: 4, title: '@questionnaire:datasources.rating-scale-options.samples.4', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.4' },
                            { value: 5, title: '@questionnaire:datasources.rating-scale-options.samples.5', description: '@questionnaire:datasources.rating-scale-options.samples.descriptions.5' },
                        ];
                        return items.find(item => item.value === key);
                    },
                });
            },
        };
        //#endregion
        //#region ----   Agreement Scale Options   ----
        this.agreementScaleOptions = {
            name: 'agreement-scale-options',
            title: '@questionnaire:datasources.agreement-scale-options.title',
            columns: [
                {
                    name: 'value',
                    title: '@questionnaire:datasources.agreement-scale-options.columns.value.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
                {
                    name: 'title',
                    title: '@questionnaire:datasources.agreement-scale-options.columns.title.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
            ],
            filters: [],
            textField: { name: 'title', title: '@questionnaire:datasources.agreement-scale-options.columns.title.title' },
            valueField: { name: 'value', title: '@questionnaire:datasources.agreement-scale-options.columns.value.title' },
            samples: [
                { value: 'strongly-disagree', title: '@questionnaire:datasources.agreement-scale-options.samples.strongly-disagree' },
                { value: 'disagree', title: '@questionnaire:datasources.agreement-scale-options.samples.disagree' },
                { value: 'neutral', title: '@questionnaire:datasources.agreement-scale-options.samples.neutral' },
                { value: 'agree', title: '@questionnaire:datasources.agreement-scale-options.samples.agree' },
                { value: 'strongly-agree', title: '@questionnaire:datasources.agreement-scale-options.samples.strongly-agree' },
            ],
            source: () => {
                return new AXDataSource({
                    pageSize: 10,
                    key: 'value',
                    load: async () => {
                        return {
                            items: [
                                { value: 'strongly-disagree', title: '@questionnaire:datasources.agreement-scale-options.samples.strongly-disagree' },
                                { value: 'disagree', title: '@questionnaire:datasources.agreement-scale-options.samples.disagree' },
                                { value: 'neutral', title: '@questionnaire:datasources.agreement-scale-options.samples.neutral' },
                                { value: 'agree', title: '@questionnaire:datasources.agreement-scale-options.samples.agree' },
                                { value: 'strongly-agree', title: '@questionnaire:datasources.agreement-scale-options.samples.strongly-agree' },
                            ],
                            total: 5,
                        };
                    },
                    byKey: async (key) => {
                        const items = [
                            { value: 'strongly-disagree', title: '@questionnaire:datasources.agreement-scale-options.samples.strongly-disagree' },
                            { value: 'disagree', title: '@questionnaire:datasources.agreement-scale-options.samples.disagree' },
                            { value: 'neutral', title: '@questionnaire:datasources.agreement-scale-options.samples.neutral' },
                            { value: 'agree', title: '@questionnaire:datasources.agreement-scale-options.samples.agree' },
                            { value: 'strongly-agree', title: '@questionnaire:datasources.agreement-scale-options.samples.strongly-agree' },
                        ];
                        return items.find(item => item.value === key);
                    },
                });
            },
        };
        //#endregion
        //#region ----   Frequency Options   ----
        this.frequencyOptions = {
            name: 'frequency-options',
            title: '@questionnaire:datasources.frequency-options.title',
            columns: [
                {
                    name: 'value',
                    title: '@questionnaire:datasources.frequency-options.columns.value.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
                {
                    name: 'title',
                    title: '@questionnaire:datasources.frequency-options.columns.title.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
            ],
            filters: [],
            textField: { name: 'title', title: '@questionnaire:datasources.frequency-options.columns.title.title' },
            valueField: { name: 'value', title: '@questionnaire:datasources.frequency-options.columns.value.title' },
            samples: [
                { value: 'never', title: '@questionnaire:datasources.frequency-options.samples.never' },
                { value: 'rarely', title: '@questionnaire:datasources.frequency-options.samples.rarely' },
                { value: 'sometimes', title: '@questionnaire:datasources.frequency-options.samples.sometimes' },
                { value: 'often', title: '@questionnaire:datasources.frequency-options.samples.often' },
                { value: 'always', title: '@questionnaire:datasources.frequency-options.samples.always' },
            ],
            source: () => {
                return new AXDataSource({
                    pageSize: 10,
                    key: 'value',
                    load: async () => {
                        return {
                            items: [
                                { value: 'never', title: '@questionnaire:datasources.frequency-options.samples.never' },
                                { value: 'rarely', title: '@questionnaire:datasources.frequency-options.samples.rarely' },
                                { value: 'sometimes', title: '@questionnaire:datasources.frequency-options.samples.sometimes' },
                                { value: 'often', title: '@questionnaire:datasources.frequency-options.samples.often' },
                                { value: 'always', title: '@questionnaire:datasources.frequency-options.samples.always' },
                            ],
                            total: 5,
                        };
                    },
                    byKey: async (key) => {
                        const items = [
                            { value: 'never', title: '@questionnaire:datasources.frequency-options.samples.never' },
                            { value: 'rarely', title: '@questionnaire:datasources.frequency-options.samples.rarely' },
                            { value: 'sometimes', title: '@questionnaire:datasources.frequency-options.samples.sometimes' },
                            { value: 'often', title: '@questionnaire:datasources.frequency-options.samples.often' },
                            { value: 'always', title: '@questionnaire:datasources.frequency-options.samples.always' },
                        ];
                        return items.find(item => item.value === key);
                    },
                });
            },
        };
        //#endregion
        //#region ----   Satisfaction Options   ----
        this.satisfactionOptions = {
            name: 'satisfaction-options',
            title: '@questionnaire:datasources.satisfaction-options.title',
            columns: [
                {
                    name: 'value',
                    title: '@questionnaire:datasources.satisfaction-options.columns.value.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
                {
                    name: 'title',
                    title: '@questionnaire:datasources.satisfaction-options.columns.title.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
            ],
            filters: [],
            textField: { name: 'title', title: '@questionnaire:datasources.satisfaction-options.columns.title.title' },
            valueField: { name: 'value', title: '@questionnaire:datasources.satisfaction-options.columns.value.title' },
            samples: [
                { value: 'very-dissatisfied', title: '@questionnaire:datasources.satisfaction-options.samples.very-dissatisfied' },
                { value: 'dissatisfied', title: '@questionnaire:datasources.satisfaction-options.samples.dissatisfied' },
                { value: 'neutral', title: '@questionnaire:datasources.satisfaction-options.samples.neutral' },
                { value: 'satisfied', title: '@questionnaire:datasources.satisfaction-options.samples.satisfied' },
                { value: 'very-satisfied', title: '@questionnaire:datasources.satisfaction-options.samples.very-satisfied' },
            ],
            source: () => {
                return new AXDataSource({
                    pageSize: 10,
                    key: 'value',
                    load: async () => {
                        return {
                            items: [
                                { value: 'very-dissatisfied', title: '@questionnaire:datasources.satisfaction-options.samples.very-dissatisfied' },
                                { value: 'dissatisfied', title: '@questionnaire:datasources.satisfaction-options.samples.dissatisfied' },
                                { value: 'neutral', title: '@questionnaire:datasources.satisfaction-options.samples.neutral' },
                                { value: 'satisfied', title: '@questionnaire:datasources.satisfaction-options.samples.satisfied' },
                                { value: 'very-satisfied', title: '@questionnaire:datasources.satisfaction-options.samples.very-satisfied' },
                            ],
                            total: 5,
                        };
                    },
                    byKey: async (key) => {
                        const items = [
                            { value: 'very-dissatisfied', title: '@questionnaire:datasources.satisfaction-options.samples.very-dissatisfied' },
                            { value: 'dissatisfied', title: '@questionnaire:datasources.satisfaction-options.samples.dissatisfied' },
                            { value: 'neutral', title: '@questionnaire:datasources.satisfaction-options.samples.neutral' },
                            { value: 'satisfied', title: '@questionnaire:datasources.satisfaction-options.samples.satisfied' },
                            { value: 'very-satisfied', title: '@questionnaire:datasources.satisfaction-options.samples.very-satisfied' },
                        ];
                        return items.find(item => item.value === key);
                    },
                });
            },
        };
        //#endregion
        //#region ----   Priority Options   ----
        this.priorityOptions = {
            name: 'priority-options',
            title: '@questionnaire:datasources.priority-options.title',
            columns: [
                {
                    name: 'value',
                    title: '@questionnaire:datasources.priority-options.columns.value.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
                {
                    name: 'title',
                    title: '@questionnaire:datasources.priority-options.columns.title.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
            ],
            filters: [],
            textField: { name: 'title', title: '@questionnaire:datasources.priority-options.columns.title.title' },
            valueField: { name: 'value', title: '@questionnaire:datasources.priority-options.columns.value.title' },
            samples: [
                { value: 'low', title: '@questionnaire:datasources.priority-options.samples.low' },
                { value: 'medium', title: '@questionnaire:datasources.priority-options.samples.medium' },
                { value: 'high', title: '@questionnaire:datasources.priority-options.samples.high' },
                { value: 'critical', title: '@questionnaire:datasources.priority-options.samples.critical' },
            ],
            source: () => {
                return new AXDataSource({
                    pageSize: 10,
                    key: 'value',
                    load: async () => {
                        return {
                            items: [
                                { value: 'low', title: '@questionnaire:datasources.priority-options.samples.low' },
                                { value: 'medium', title: '@questionnaire:datasources.priority-options.samples.medium' },
                                { value: 'high', title: '@questionnaire:datasources.priority-options.samples.high' },
                                { value: 'critical', title: '@questionnaire:datasources.priority-options.samples.critical' },
                            ],
                            total: 4,
                        };
                    },
                    byKey: async (key) => {
                        const items = [
                            { value: 'low', title: '@questionnaire:datasources.priority-options.samples.low' },
                            { value: 'medium', title: '@questionnaire:datasources.priority-options.samples.medium' },
                            { value: 'high', title: '@questionnaire:datasources.priority-options.samples.high' },
                            { value: 'critical', title: '@questionnaire:datasources.priority-options.samples.critical' },
                        ];
                        return items.find(item => item.value === key);
                    },
                });
            },
        };
    }
    //#endregion
    async items() {
        return [
            this.yesNoOptions,
            this.ratingScaleOptions,
            this.agreementScaleOptions,
            this.frequencyOptions,
            this.satisfactionOptions,
            this.priorityOptions,
        ];
    }
}

class AXPFormTemplateViewerConnector {
}
class AXPFormTemplateViewerConnectorImpl extends AXPFormTemplateViewerConnector {
    constructor() {
        super(...arguments);
        this.templateEntityService = inject(AXMFormTemplateManagementTemplateEntityService);
    }
    //#region Save and load Widgets
    async submit(id, context, metadeta) {
        return Promise.resolve(true);
    }
    async load(id) {
        const item = await this.templateEntityService.getOne(id);
        if (item) {
            return item.template;
        }
        else {
            throw Error('Invalid Id');
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPFormTemplateViewerConnectorImpl, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPFormTemplateViewerConnectorImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPFormTemplateViewerConnectorImpl, decorators: [{
            type: Injectable
        }] });

class AXMOpenFormTemplateViewerAction extends AXPWorkflowAction {
    constructor() {
        super(...arguments);
        //#region ----   Services & Dependencies   ----
        this.templateViewerService = inject(AXPTemplateViewerService);
        this.connector = inject(AXPFormTemplateViewerConnector);
    }
    //#endregion
    //#region ----   Workflow Execution   ----
    async execute(context) {
        const { id, template } = context.getVariable('data');
        const metadata = context.getVariable('metadata');
        let templateData;
        if (id) {
            // Load template from database using connector
            templateData = await this.connector.load(id) || '';
        }
        else if (template) {
            // Use provided template string
            templateData = template;
        }
        else {
            throw new Error('Either template ID or template data must be provided');
        }
        const result = await this.templateViewerService.showTemplate({
            template: templateData,
            title: 'Form Template Viewer',
            context: {},
            metadata,
            readOnly: false,
            showActions: true
        });
        context.setOutput('result', !result.cancelled);
        if (!result.cancelled && result.context) {
            context.setOutput('form-context', result.context);
            // If we have an ID, submit the form data using the connector
            if (id) {
                await this.connector.submit(id, result.context, metadata);
            }
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMOpenFormTemplateViewerAction, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMOpenFormTemplateViewerAction }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMOpenFormTemplateViewerAction, decorators: [{
            type: Injectable
        }] });
//#region ----   Workflow Definition   ----
const AXMOpenFormTemplateViewerWorkflow = {
    startStepId: 'open-form',
    steps: {
        "open-form": {
            action: 'open-form-template-viewer',
        },
    },
};

class AXMOpenFormTemplateDesignerAction extends AXPWorkflowAction {
    constructor() {
        super(...arguments);
        this.navigation = inject(AXPWorkflowNavigateAction);
    }
    async execute(context) {
        const id = context.getVariable('id') ?? context.getVariable('data.id') ?? AXPDataGenerator.uuid();
        context.setVariable('payload', {
            commands: `forms/designer?id=${id}`,
            target: 'blank'
        });
        await this.navigation.execute(context);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMOpenFormTemplateDesignerAction, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMOpenFormTemplateDesignerAction }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMOpenFormTemplateDesignerAction, decorators: [{
            type: Injectable
        }] });
Injectable();
class AXMOpenEmbeddedTemplateDesignerAction extends AXPWorkflowAction {
    constructor() {
        super(...arguments);
        this.navigation = inject(AXPWorkflowNavigateAction);
        this.broadcastService = inject(AXPBroadcastEventService);
    }
    async execute(context) {
        const id = context.getVariable('id') ?? context.getVariable('data.id') ?? AXPDataGenerator.uuid();
        context.setVariable('payload', {
            commands: `forms/designer?id=${id}&strategy=Broadcast`,
            target: 'blank'
        });
        await this.navigation.execute(context);
        return new Promise((resolve, reject) => {
            this.broadcastService.listen(AXPDesignerMessageKeys.RequestFormContent).subscribe(async (event) => {
                if (event.requestId && event.data.formId == id) {
                    const content = context.getVariable('content') ?? null;
                    this.broadcastService.respondToRequest(event.requestId, content);
                    context.setOutput("result", true);
                    resolve();
                }
                else {
                    context.setOutput("result", false);
                    reject('No valid requestId found in the event.');
                }
            });
        });
    }
}
Injectable();
class AXMSaveEmbeddedTemplateDesignerAction extends AXPWorkflowAction {
    constructor() {
        super(...arguments);
        this.broadcastService = inject(AXPBroadcastEventService);
    }
    async execute(context) {
        return new Promise((resolve, reject) => {
            this.broadcastService.listen(AXPDesignerMessageKeys.SaveForm).subscribe(async (event) => {
                if (event.data.success) {
                    this.broadcastService.respondToRequest(event.requestId, { success: true });
                    context.setVariable('content', event.data.content);
                    context.setOutput('result', true);
                }
                else {
                    context.setOutput('result', false);
                }
                resolve();
            });
        });
    }
}

const AXM_FORM_TEMPLATE_CODE_IDENTIFIER_RULE = {
    id: 'form-template',
    title: 'Form Template Code',
    entity: RootConfig.entities.template.source,
    pattern: 'FT-{date:YYYYMMDD}-{seq:4}',
    enabled: true,
    priority: 1,
    scopeConfig: { byTenant: false, period: 'monthly', minValue: 0, blockSize: 0 },
};

function routesFacory() {
    const routes = [
        {
            path: 'forms',
            children: [
                {
                    path: 'designer',
                    loadComponent: () => import('./acorex-modules-form-template-management-designer.page-DmN4rBrf.mjs').then((c) => c.AXMFormTemplateManagementModuleDesignerPage),
                },
                {
                    path: 'preview',
                    loadComponent: () => import('@acorex/platform/layout/designer').then((c) => c.AXPLayoutDesignerPreviewComponent),
                },
                {
                    path: 'viewer',
                    loadComponent: () => import('@acorex/platform/layout/designer').then((c) => c.AXPLayoutDesignerPreviewViewerComponent),
                },
            ],
        },
    ];
    return routes;
}
class AXMFormTemplateManagementModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMFormTemplateManagementModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.4", ngImport: i0, type: AXMFormTemplateManagementModule, imports: [AXPWidgetsModule,
            AXMFormTemplateManagementTemplateEntityModule, i1.AXPWidgetCoreModule, i2$1.AXPWorkflowModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMFormTemplateManagementModule, providers: [
            {
                provide: ROUTES,
                multi: true,
                useFactory: routesFacory,
            },
            {
                provide: AXP_ENTITY_DEFINITION_LOADER,
                useClass: AXMEntityProvider,
                multi: true,
            },
            {
                provide: AXP_MENU_PROVIDER,
                useClass: AXMMenuProvider,
                multi: true,
            },
            {
                provide: AXPDesignerConnector,
                useClass: AXPDesignerConnectorImpl,
            },
            {
                provide: AXPFormTemplateViewerConnector,
                useClass: AXPFormTemplateViewerConnectorImpl,
            },
            {
                provide: AXP_TEMPLATE_WIDGET_PROVIDER,
                useClass: AXPTemplateWidgetProviderImpl,
                multi: true,
            },
            {
                provide: AXP_SETTING_DEFINITION_PROVIDER,
                useFactory: async () => {
                    const injector = inject(Injector);
                    const provider = (await import('./acorex-modules-form-template-management-settings.provider-Ds18e881.mjs')).AXMSettingProvider;
                    return new provider(injector);
                },
                multi: true,
            },
            {
                provide: AXP_SEARCH_PROVIDER,
                useClass: AXMSearchCommandProvider,
                multi: true,
            },
            {
                provide: AXP_PERMISSION_DEFINITION_PROVIDER,
                useFactory: async () => {
                    const injector = inject(Injector);
                    const provider = (await import('./acorex-modules-form-template-management-permission-definition.provider-BSARsii9.mjs')).AXMPermissionDefinitionProvider;
                    return new provider(injector);
                },
                multi: true,
            },
            {
                provide: AXP_IDENTIFIER_RULES,
                multi: true,
                useValue: AXM_FORM_TEMPLATE_CODE_IDENTIFIER_RULE,
            },
            {
                provide: AXP_DATASOURCE_DEFINITION_PROVIDER,
                useClass: AXMQuestionnaireDataSourceDefinition,
                multi: true,
            },
        ], imports: [AXPWidgetsModule,
            AXMFormTemplateManagementTemplateEntityModule,
            AXPWidgetCoreModule.forChild({
                widgets: [AXPTemplateDesignerWidget, AXPTemplateWidget],
            }),
            AXPWorkflowModule.forChild({
                actions: {
                    'open-form-template-viewer': AXMOpenFormTemplateViewerAction,
                    //
                    'open-form-template-designer': AXMOpenFormTemplateDesignerAction,
                    'open-embedded-template-designer': AXMOpenEmbeddedTemplateDesignerAction,
                    //
                    'save-embedded-template-designer': AXMSaveEmbeddedTemplateDesignerAction
                },
                workflows: {
                    'create-form-template': AXMCreateFormTemplateWorkflow,
                    'design-form-template': AXMDesignFormTemplateWorkflow,
                    'open-form-template': AXMOpenFormTemplateViewerWorkflow
                },
            })] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMFormTemplateManagementModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        AXPWidgetsModule,
                        AXMFormTemplateManagementTemplateEntityModule,
                        AXPWidgetCoreModule.forChild({
                            widgets: [AXPTemplateDesignerWidget, AXPTemplateWidget],
                        }),
                        AXPWorkflowModule.forChild({
                            actions: {
                                'open-form-template-viewer': AXMOpenFormTemplateViewerAction,
                                //
                                'open-form-template-designer': AXMOpenFormTemplateDesignerAction,
                                'open-embedded-template-designer': AXMOpenEmbeddedTemplateDesignerAction,
                                //
                                'save-embedded-template-designer': AXMSaveEmbeddedTemplateDesignerAction
                            },
                            workflows: {
                                'create-form-template': AXMCreateFormTemplateWorkflow,
                                'design-form-template': AXMDesignFormTemplateWorkflow,
                                'open-form-template': AXMOpenFormTemplateViewerWorkflow
                            },
                        }),
                    ],
                    exports: [],
                    declarations: [],
                    providers: [
                        {
                            provide: ROUTES,
                            multi: true,
                            useFactory: routesFacory,
                        },
                        {
                            provide: AXP_ENTITY_DEFINITION_LOADER,
                            useClass: AXMEntityProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_MENU_PROVIDER,
                            useClass: AXMMenuProvider,
                            multi: true,
                        },
                        {
                            provide: AXPDesignerConnector,
                            useClass: AXPDesignerConnectorImpl,
                        },
                        {
                            provide: AXPFormTemplateViewerConnector,
                            useClass: AXPFormTemplateViewerConnectorImpl,
                        },
                        {
                            provide: AXP_TEMPLATE_WIDGET_PROVIDER,
                            useClass: AXPTemplateWidgetProviderImpl,
                            multi: true,
                        },
                        {
                            provide: AXP_SETTING_DEFINITION_PROVIDER,
                            useFactory: async () => {
                                const injector = inject(Injector);
                                const provider = (await import('./acorex-modules-form-template-management-settings.provider-Ds18e881.mjs')).AXMSettingProvider;
                                return new provider(injector);
                            },
                            multi: true,
                        },
                        {
                            provide: AXP_SEARCH_PROVIDER,
                            useClass: AXMSearchCommandProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_PERMISSION_DEFINITION_PROVIDER,
                            useFactory: async () => {
                                const injector = inject(Injector);
                                const provider = (await import('./acorex-modules-form-template-management-permission-definition.provider-BSARsii9.mjs')).AXMPermissionDefinitionProvider;
                                return new provider(injector);
                            },
                            multi: true,
                        },
                        {
                            provide: AXP_IDENTIFIER_RULES,
                            multi: true,
                            useValue: AXM_FORM_TEMPLATE_CODE_IDENTIFIER_RULE,
                        },
                        {
                            provide: AXP_DATASOURCE_DEFINITION_PROVIDER,
                            useClass: AXMQuestionnaireDataSourceDefinition,
                            multi: true,
                        },
                    ],
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { AXMPermissionsKeys as A, RootConfig as R, AXMFormTemplateManagementTemplateEntityService as a, AXMFormTemplateTypes as b, AXPTemplateWidgetProviderService as c, AXMFormTemplateManagementModule as d, AXMFormTemplateManagementTemplateEntityModule as e, AXMFormTemplateManagementTemplateEntityServiceImpl as f };
//# sourceMappingURL=acorex-modules-form-template-management-acorex-modules-form-template-management-DCKQMU5_.mjs.map
