import { AXActionSheetModule } from '@acorex/components/action-sheet';
import { AXBreadcrumbsModule } from '@acorex/components/breadcrumbs';
import * as i3$1 from '@acorex/components/button';
import { AXButtonModule } from '@acorex/components/button';
import * as i2 from '@acorex/components/decorators';
import { AXDecoratorModule } from '@acorex/components/decorators';
import { AXDialogModule } from '@acorex/components/dialog';
import { AXDrawerModule } from '@acorex/components/drawer';
import { AXDropdownModule } from '@acorex/components/dropdown';
import * as i1 from '@acorex/components/form';
import { AXFormModule } from '@acorex/components/form';
import { AXLoadingModule } from '@acorex/components/loading';
import { AXPopoverModule } from '@acorex/components/popover';
import * as i3 from '@acorex/components/tabs';
import { AXTabsModule } from '@acorex/components/tabs';
import * as i10 from '@acorex/core/translation';
import { AXTranslationModule } from '@acorex/core/translation';
import { AXPAuthModule } from '@acorex/platform/auth';
import { AXPReloadEvent, AXPRefreshEvent } from '@acorex/platform/common';
import { AXPGridLayoutDirective, AXPContextStore } from '@acorex/platform/core';
import * as i7 from '@acorex/platform/layout/widget-core';
import { AXPWidgetContainerComponent, AXPWidgetCoreModule } from '@acorex/platform/layout/widget-core';
import * as i1$2 from '@acorex/platform/layout/components';
import { AXPThemeLayoutBlockComponent, AXPComponentSlotModule } from '@acorex/platform/layout/components';
import { AXPEntityService } from '@acorex/platform/layout/entity';
import { AXPPageLayoutBaseComponent, AXPPageLayoutComponent, AXPPageLayoutBase } from '@acorex/platform/layout/views';
import { AXPLayoutThemeService } from '@acorex/platform/themes/shared';
import { AXPWidgetsModule } from '@acorex/platform/layout/widgets';
import { AXPWorkflowEventService, AXPWorkflowService, ofType } from '@acorex/platform/workflow';
import * as i1$1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { inject, viewChild, signal, effect, ChangeDetectionStrategy, Component, untracked } from '@angular/core';
import { ActivatedRoute, RouterModule, Router } from '@angular/router';
import { Subject, takeUntil } from 'rxjs';
import { AXPEntityDetailListViewComponent } from './acorex-platform-themes-default.mjs';

class AXPEntitySingleOverviewComponent {
    constructor() {
        this.activeRoute = inject(ActivatedRoute);
        this.vm = this.activeRoute.snapshot.data['vm'];
        this.widgetContainer = viewChild(AXPWidgetContainerComponent, ...(ngDevMode ? [{ debugName: "widgetContainer" }] : []));
        this.selectedRelatedIEntityTabIndex = signal(0, ...(ngDevMode ? [{ debugName: "selectedRelatedIEntityTabIndex" }] : []));
        this.#refresh = effect(() => {
            if (this.vm.updateTrigger()) {
                this.widgetContainer()?.refresh();
            }
        }, ...(ngDevMode ? [{ debugName: "#refresh" }] : []));
    }
    handleActiveRelatedEntityChanged(e) {
        this.selectedRelatedIEntityTabIndex.set(e.index);
    }
    #refresh;
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPEntitySingleOverviewComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.16", type: AXPEntitySingleOverviewComponent, isStandalone: true, selector: "axp-entity-single-overview", viewQueries: [{ propertyName: "widgetContainer", first: true, predicate: AXPWidgetContainerComponent, descendants: true, isSignal: true }], ngImport: i0, template: "<div class=\"ax-grid ax-grid-cols-12 ax-gap-4\">\n  <axp-widgets-container [context]=\"vm.context()\">\n    @for (section of vm.sections(); track section.name()) {\n      <div class=\"ax-card ax-mt-2\" [axp-grid-layout]=\"section.layout()\">\n        <ax-form #form>\n          <div class=\"ax-card-header !ax-py-2 !ax-px-4\">\n            <p>\n              <span class=\"!ax-text-lg ax-font-semibold\">{{ section.title() | translate | async }}</span>\n              <br />\n              @if (section.description()) {\n                <span class=\"ax-text-sm ax-font-normal ax-opacity-75\">{{ section.description() }}</span>\n              }\n            </p>\n            @if (section.editable()) {\n              <ax-button\n                class=\"ax-xs\"\n                [color]=\"'default'\"\n                [look]=\"'blank'\"\n                (onClick)=\"vm.executeCommand('modify-entity-section', section)\"\n              >\n                <ax-icon class=\"fa-solid fa-pen ax-text-gray-600\"> </ax-icon>\n              </ax-button>\n            }\n          </div>\n          <div class=\"ax-card-body !ax-grid !ax-grid-cols-12 !ax-gap-4\">\n            @for (attr of section.props(); track $index) {\n              <div\n                class=\"ax-flex ax-flex-col ax-gap-1\"\n                [axp-grid-layout]=\"attr.layout()\"\n                [class.ax-hidden]=\"widget.options()['visibility'] == false\"\n              >\n                <div>\n                  @if (attr.showLabel()) {\n                    <div class=\"ax-font-semibold ax-mb-1\">\n                      <span>{{ attr.title() | translate | async }}</span>\n                    </div>\n                  }\n                </div>\n                <div>\n                  <ng-container\n                    axp-widget-renderer\n                    [node]=\"attr.node()\"\n                    [mode]=\"'view'\"\n                    #widget=\"widgetRenderer\"\n                  ></ng-container>\n                </div>\n              </div>\n            }\n          </div>\n        </ax-form>\n      </div>\n    }\n  </axp-widgets-container>\n</div>\n\n@if ((vm.relatedEntities() | async)?.length) {\n  <ax-tabs\n    [look]=\"'classic'\"\n    class=\"ax-mt-4 ax-font-semibold\"\n    #tab\n    (onActiveTabChanged)=\"handleActiveRelatedEntityChanged($event)\"\n  >\n    @for (e of vm.relatedEntities() | async; track $index; let index = $index) {\n      <ax-tab-item [text]=\"(e.title() | translate | async)!\" [key]=\"index.toString()\"> </ax-tab-item>\n    }\n  </ax-tabs>\n  @for (e of vm.relatedEntities() | async; track $index; let index = $index) {\n    <div [class.ax-hidden]=\"$index != selectedRelatedIEntityTabIndex()\">\n      <axp-entity-detail-list-view [viewModel]=\"e\"></axp-entity-detail-list-view>\n    </div>\n  }\n}\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: RouterModule }, { kind: "ngmodule", type: AXDecoratorModule }, { kind: "component", type: i2.AXDecoratorIconComponent, selector: "ax-icon", inputs: ["icon"] }, { kind: "ngmodule", type: AXDropdownModule }, { kind: "ngmodule", type: AXPopoverModule }, { kind: "ngmodule", type: AXFormModule }, { kind: "component", type: i1.AXFormComponent, selector: "ax-form", inputs: ["disabled", "readonly", "labelMode", "look", "messageStyle", "updateOn", "inUserInteractionActive"], outputs: ["onValidate", "updateOnChange"] }, { kind: "ngmodule", type: AXActionSheetModule }, { kind: "ngmodule", type: AXDrawerModule }, { kind: "ngmodule", type: AXDialogModule }, { kind: "ngmodule", type: AXLoadingModule }, { kind: "ngmodule", type: AXTabsModule }, { kind: "component", type: i3.AXTabsComponent, selector: "ax-tabs", inputs: ["look", "location", "fitParent", "minWidth", "content"], outputs: ["onActiveTabChanged"] }, { kind: "component", type: i3.AXTabItemComponent, selector: "ax-tab-item", inputs: ["disabled", "text", "key", "headerTemplate", "active"], outputs: ["disabledChange", "onClick", "onBlur", "onFocus", "activeChange"] }, { kind: "ngmodule", type: AXButtonModule }, { kind: "component", type: i3$1.AXButtonComponent, selector: "ax-button", inputs: ["disabled", "size", "tabIndex", "color", "look", "text", "toggleable", "selected", "iconOnly", "type", "loadingText"], outputs: ["onBlur", "onFocus", "onClick", "selectedChange", "toggleableChange", "lookChange", "colorChange", "disabledChange", "loadingTextChange"] }, { kind: "ngmodule", type: AXBreadcrumbsModule }, { kind: "ngmodule", type: 
                //
                AXPWidgetCoreModule }, { kind: "component", type: i7.AXPWidgetContainerComponent, selector: "axp-widgets-container", inputs: ["context", "functions"], outputs: ["onContextChanged"] }, { kind: "directive", type: i7.AXPWidgetRendererDirective, selector: "[axp-widget-renderer]", inputs: ["parentNode", "index", "mode", "node"], outputs: ["onOptionsChanged", "onValueChanged", "onLoad"], exportAs: ["widgetRenderer"] }, { kind: "ngmodule", type: AXPWidgetsModule }, { kind: "directive", type: AXPGridLayoutDirective, selector: "[axp-grid-layout]", inputs: ["axp-grid-layout"] }, { kind: "component", type: AXPEntityDetailListViewComponent, selector: "axp-entity-detail-list-view", inputs: ["viewModel"] }, { kind: "ngmodule", type: 
                //
                AXTranslationModule }, { kind: "pipe", type: i1$1.AsyncPipe, name: "async" }, { kind: "pipe", type: i10.AXTranslatorPipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPEntitySingleOverviewComponent, decorators: [{
            type: Component,
            args: [{ selector: 'axp-entity-single-overview', imports: [
                        CommonModule,
                        RouterModule,
                        AXDecoratorModule,
                        AXDropdownModule,
                        AXPopoverModule,
                        AXFormModule,
                        AXActionSheetModule,
                        AXDrawerModule,
                        AXDialogModule,
                        AXLoadingModule,
                        AXTabsModule,
                        AXButtonModule,
                        AXBreadcrumbsModule,
                        //
                        AXPWidgetCoreModule,
                        AXPWidgetsModule,
                        AXPGridLayoutDirective,
                        AXPEntityDetailListViewComponent,
                        //
                        AXTranslationModule,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"ax-grid ax-grid-cols-12 ax-gap-4\">\n  <axp-widgets-container [context]=\"vm.context()\">\n    @for (section of vm.sections(); track section.name()) {\n      <div class=\"ax-card ax-mt-2\" [axp-grid-layout]=\"section.layout()\">\n        <ax-form #form>\n          <div class=\"ax-card-header !ax-py-2 !ax-px-4\">\n            <p>\n              <span class=\"!ax-text-lg ax-font-semibold\">{{ section.title() | translate | async }}</span>\n              <br />\n              @if (section.description()) {\n                <span class=\"ax-text-sm ax-font-normal ax-opacity-75\">{{ section.description() }}</span>\n              }\n            </p>\n            @if (section.editable()) {\n              <ax-button\n                class=\"ax-xs\"\n                [color]=\"'default'\"\n                [look]=\"'blank'\"\n                (onClick)=\"vm.executeCommand('modify-entity-section', section)\"\n              >\n                <ax-icon class=\"fa-solid fa-pen ax-text-gray-600\"> </ax-icon>\n              </ax-button>\n            }\n          </div>\n          <div class=\"ax-card-body !ax-grid !ax-grid-cols-12 !ax-gap-4\">\n            @for (attr of section.props(); track $index) {\n              <div\n                class=\"ax-flex ax-flex-col ax-gap-1\"\n                [axp-grid-layout]=\"attr.layout()\"\n                [class.ax-hidden]=\"widget.options()['visibility'] == false\"\n              >\n                <div>\n                  @if (attr.showLabel()) {\n                    <div class=\"ax-font-semibold ax-mb-1\">\n                      <span>{{ attr.title() | translate | async }}</span>\n                    </div>\n                  }\n                </div>\n                <div>\n                  <ng-container\n                    axp-widget-renderer\n                    [node]=\"attr.node()\"\n                    [mode]=\"'view'\"\n                    #widget=\"widgetRenderer\"\n                  ></ng-container>\n                </div>\n              </div>\n            }\n          </div>\n        </ax-form>\n      </div>\n    }\n  </axp-widgets-container>\n</div>\n\n@if ((vm.relatedEntities() | async)?.length) {\n  <ax-tabs\n    [look]=\"'classic'\"\n    class=\"ax-mt-4 ax-font-semibold\"\n    #tab\n    (onActiveTabChanged)=\"handleActiveRelatedEntityChanged($event)\"\n  >\n    @for (e of vm.relatedEntities() | async; track $index; let index = $index) {\n      <ax-tab-item [text]=\"(e.title() | translate | async)!\" [key]=\"index.toString()\"> </ax-tab-item>\n    }\n  </ax-tabs>\n  @for (e of vm.relatedEntities() | async; track $index; let index = $index) {\n    <div [class.ax-hidden]=\"$index != selectedRelatedIEntityTabIndex()\">\n      <axp-entity-detail-list-view [viewModel]=\"e\"></axp-entity-detail-list-view>\n    </div>\n  }\n}\n" }]
        }], propDecorators: { widgetContainer: [{ type: i0.ViewChild, args: [i0.forwardRef(() => AXPWidgetContainerComponent), { isSignal: true }] }] } });

class AXPEntityMasterSingleViewComponent extends AXPPageLayoutBaseComponent {
    constructor() {
        super(...arguments);
        this.activeRoute = inject(ActivatedRoute);
        this.router = inject(Router);
        this.vm = this.activeRoute.snapshot.data['vm'];
        this.store = inject(AXPLayoutThemeService);
        this.contextStore = inject(AXPContextStore);
        this.eventService = inject(AXPWorkflowEventService);
        this.workflow = inject(AXPWorkflowService);
        this.entityService = inject(AXPEntityService);
        this.destroyed = new Subject();
        this.#syncContext = effect(() => {
            // TODO: this is a hack to sync the context with the vm
            untracked(() => {
                this.contextStore.patch({
                    entity: this.vm.context(),
                });
            });
        }, ...(ngDevMode ? [{ debugName: "#syncContext" }] : []));
    }
    async ngOnInit() {
        await super.ngOnInit();
        this.workflow.events$
            .pipe(ofType(AXPReloadEvent))
            .pipe(takeUntil(this.destroyed))
            .subscribe(async (event) => {
            if (event.payload.entity == `${this.vm.entityDef.module}.${this.vm.entityDef.name}`) {
                const fn = this.vm.entityDef.queries?.byKey?.execute;
                if (fn) {
                    const data = await fn(this.vm.context().id);
                    this.vm.context.set(data);
                }
                if (this.vm.entityDef.relatedEntities?.length) {
                    for (const relatedEntity of this.vm.entityDef.relatedEntities) {
                        this.eventService.dispatch(AXPRefreshEvent({ entity: relatedEntity.entity }));
                    }
                }
            }
        });
    }
    #syncContext;
    getPageTitle() {
        return this.vm.title();
    }
    getPageDescription() {
        return this.vm.description() ?? '';
    }
    getPageBreadcrumbs() {
        return this.vm.beardcrumbs();
    }
    getPrimaryMenuItems() {
        return Promise.all(this.vm.primaryActions().map(async (tr) => {
            const hidden = await this.vm.evaluateExpressions(tr.hidden, this.vm.context());
            if (hidden)
                return null;
            const disabled = await this.vm.evaluateExpressions(tr.disabled, this.vm.context());
            return {
                name: tr.name,
                title: tr.title,
                icon: tr.icon,
                color: tr.color,
                disabled,
                command: {
                    name: tr.name,
                    options: tr.options,
                    metadata: tr.metadata,
                },
            };
        })).then((items) => items.filter(Boolean));
    }
    getSecondaryMenuItems() {
        return Promise.all(this.vm.secondaryActions().map(async (tr) => {
            const hidden = await this.vm.evaluateExpressions(tr.hidden, this.vm.context());
            if (hidden)
                return null;
            const disabled = await this.vm.evaluateExpressions(tr.disabled, this.vm.context());
            return {
                name: tr.name,
                title: tr.title,
                icon: tr.icon,
                color: tr.color,
                disabled,
                separated: tr.separated,
                command: {
                    name: tr.name,
                    options: tr.options,
                    metadata: tr.metadata,
                },
            };
        })).then((items) => items.filter(Boolean));
    }
    execute(command) {
        if (command) {
            this.vm.execute(command);
        }
    }
    async getBackButton() {
        return {
            title: await this.translateService.translateAsync(this.vm.title()),
        };
    }
    onBackButtonClick() {
        this.vm.navigateToUp();
    }
    ngOnDestroy() {
        this.vm.destroy();
        this.destroyed.next();
        this.destroyed.complete();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPEntityMasterSingleViewComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.16", type: AXPEntityMasterSingleViewComponent, isStandalone: true, selector: "ng-component", providers: [
            {
                provide: AXPPageLayoutBase,
                useExisting: AXPEntityMasterSingleViewComponent,
            },
        ], usesInheritance: true, ngImport: i0, template: "<axp-page-layout *translate=\"let t\">\n  <axp-page-content>\n    <axp-component-slot name=\"entity-detail-header\"></axp-component-slot>\n    <axp-entity-single-overview></axp-entity-single-overview>\n    <axp-component-slot name=\"entity-detail-footer\"></axp-component-slot>\n  </axp-page-content>\n</axp-page-layout>", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: RouterModule }, { kind: "ngmodule", type: 
                //
                AXDecoratorModule }, { kind: "ngmodule", type: AXDropdownModule }, { kind: "ngmodule", type: AXPopoverModule }, { kind: "ngmodule", type: AXFormModule }, { kind: "ngmodule", type: AXActionSheetModule }, { kind: "ngmodule", type: AXPAuthModule }, { kind: "ngmodule", type: AXTranslationModule }, { kind: "directive", type: i10.AXTranslatorDirective, selector: "[translate]" }, { kind: "ngmodule", type: AXDrawerModule }, { kind: "ngmodule", type: AXDialogModule }, { kind: "ngmodule", type: AXLoadingModule }, { kind: "ngmodule", type: AXTabsModule }, { kind: "ngmodule", type: AXButtonModule }, { kind: "ngmodule", type: AXBreadcrumbsModule }, { kind: "ngmodule", type: 
                //
                AXPWidgetCoreModule }, { kind: "ngmodule", type: AXPWidgetsModule }, { kind: "component", type: AXPEntitySingleOverviewComponent, selector: "axp-entity-single-overview" }, { kind: "component", type: AXPPageLayoutComponent, selector: "axp-page-layout" }, { kind: "component", type: AXPThemeLayoutBlockComponent, selector: "    axp-page-content,     axp-page-footer-container,    axp-page-footer,    axp-page-header,    axp-page-header-container,    axp-page-toolbar,    axp-layout-content,     axp-layout-page-content,     axp-layout-sections,    axp-layout-body,    axp-layout-page-body,    axp-layout-prefix,    axp-layout-suffix,    axp-layout-title-bar,    axp-layout-title,     axp-layout-title-actions,     axp-layout-nav-button,     axp-layout-description,     axp-layout-breadcrumbs,    axp-layout-list-action,    " }, { kind: "ngmodule", type: AXPComponentSlotModule }, { kind: "directive", type: i1$2.AXPComponentSlotDirective, selector: "axp-component-slot", inputs: ["name", "host", "context"], exportAs: ["slot"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPEntityMasterSingleViewComponent, decorators: [{
            type: Component,
            args: [{ imports: [
                        CommonModule,
                        RouterModule,
                        //
                        AXDecoratorModule,
                        AXDropdownModule,
                        AXPopoverModule,
                        AXFormModule,
                        AXActionSheetModule,
                        AXPAuthModule,
                        AXTranslationModule,
                        AXDrawerModule,
                        AXDialogModule,
                        AXLoadingModule,
                        AXTabsModule,
                        AXButtonModule,
                        AXBreadcrumbsModule,
                        //
                        AXPWidgetCoreModule,
                        AXPWidgetsModule,
                        AXPEntitySingleOverviewComponent,
                        AXPPageLayoutComponent,
                        AXPThemeLayoutBlockComponent,
                        AXPComponentSlotModule,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, providers: [
                        {
                            provide: AXPPageLayoutBase,
                            useExisting: AXPEntityMasterSingleViewComponent,
                        },
                    ], template: "<axp-page-layout *translate=\"let t\">\n  <axp-page-content>\n    <axp-component-slot name=\"entity-detail-header\"></axp-component-slot>\n    <axp-entity-single-overview></axp-entity-single-overview>\n    <axp-component-slot name=\"entity-detail-footer\"></axp-component-slot>\n  </axp-page-content>\n</axp-page-layout>" }]
        }] });

export { AXPEntityMasterSingleViewComponent };
//# sourceMappingURL=acorex-platform-themes-default-entity-master-single-view.component-CwHHYmiK.mjs.map
