var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
/**
 * @module database-designer-dashboard.component
 * @description Root dashboard for the Database Designer feature area.
 *
 * Registered as 'DatabaseDesignerDashboard' via `@RegisterClass(BaseDashboard, ...)`.
 * Registered as a navigation item via metadata (metadata/applications/).
 *
 * Lifecycle:
 *  - `initDashboard()` — sync ?entity= URL param (deep-link support), initialize slide-panel state
 *  - `loadData()` — delegate to DatabaseDesignerEngine singleton; pass result to EntityListComponent
 *
 * The wizard and modify panels open as MjSlidePanel drawers so the entity
 * list remains visible behind them.  The dashboard orchestrates all state
 * transitions; child components communicate only via @Output events.
 */
import { Component, ChangeDetectionStrategy, ChangeDetectorRef, inject, ViewChild, } from '@angular/core';
import { BaseDashboard, BaseResourceComponent } from '@memberjunction/ng-shared';
import { RegisterClass } from '@memberjunction/global';
import { DatabaseDesignerEngine } from '../services/database-designer.engine.js';
import { DatabaseDesignerService } from '../services/database-designer.service.js';
import { DatabaseModifyComponent } from './modify/database-modify.component.js';
import * as i0 from "@angular/core";
import * as i1 from "@memberjunction/ng-ui-components";
import * as i2 from "./entity-list.component";
import * as i3 from "./create-wizard/database-create-wizard.component";
import * as i4 from "./modify/database-modify.component";
function DatabaseDesignerDashboardComponent_Conditional_1_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "mj-slide-panel", 3);
    i0.ɵɵlistener("Closed", function DatabaseDesignerDashboardComponent_Conditional_1_Template_mj_slide_panel_Closed_0_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnWizardClosed()); });
    i0.ɵɵelementStart(1, "mj-database-create-wizard", 4);
    i0.ɵɵlistener("EntityCreated", function DatabaseDesignerDashboardComponent_Conditional_1_Template_mj_database_create_wizard_EntityCreated_1_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnEntityCreated()); })("Cancelled", function DatabaseDesignerDashboardComponent_Conditional_1_Template_mj_database_create_wizard_Cancelled_1_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnWizardClosed()); });
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("Visible", ctx_r1.ShowCreateWizard)("Resizable", true)("WidthPx", 9999)("MaxWidthRatio", 1)("MinWidthPx", 960);
} }
function DatabaseDesignerDashboardComponent_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "mj-slide-panel", 5);
    i0.ɵɵlistener("Closed", function DatabaseDesignerDashboardComponent_Conditional_2_Template_mj_slide_panel_Closed_0_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnModifyPanelClosed()); });
    i0.ɵɵelementStart(1, "mj-database-modify", 6);
    i0.ɵɵlistener("EntityModified", function DatabaseDesignerDashboardComponent_Conditional_2_Template_mj_database_modify_EntityModified_1_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnEntityModified()); })("Cancelled", function DatabaseDesignerDashboardComponent_Conditional_2_Template_mj_database_modify_Cancelled_1_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnModifyPanelClosed()); });
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("Visible", !!ctx_r1.ModifyEntityId)("Resizable", true)("WidthPx", 9999)("MaxWidthRatio", 1)("MinWidthPx", 960)("CanClose", ctx_r1.ModifyPanelCanClose);
    i0.ɵɵadvance();
    i0.ɵɵproperty("EntityId", ctx_r1.ModifyEntityId);
} }
let DatabaseDesignerDashboardComponent = class DatabaseDesignerDashboardComponent extends BaseDashboard {
    // ─── Injected services ─────────────────────────────────────────────────
    /** Angular DI: write operations (create, modify, validate). */
    designerService = inject(DatabaseDesignerService);
    /** Change detection ref for OnPush updates. */
    cdr = inject(ChangeDetectorRef);
    // ─── ViewChild ─────────────────────────────────────────────────────────
    /** Reference to the active modify component — used for close-guard state. */
    modifyRef;
    // ─── Slide-panel close guard ───────────────────────────────────────────
    /**
     * Passed as `[CanClose]` to the modify slide panel.
     * Prevents the panel from closing while a pipeline is running and prompts the user
     * for confirmation.  Defined as an arrow function so `this` is captured correctly
     * when called by `MjSlidePanelComponent` (no angular binding issues).
     */
    ModifyPanelCanClose = () => {
        if (!this.modifyRef?.IsPipelineRunning)
            return true;
        return window.confirm('A pipeline operation is in progress. Closing will hide the progress panel ' +
            'but the operation will continue running on the server.\n\nAre you sure?');
    };
    // ─── Entity list ───────────────────────────────────────────────────────
    /** Entities displayed in EntityListComponent — set by loadData(). */
    Entities = [];
    IsLoadingEntities = false;
    LoadError = null;
    // ─── Slide panel state ─────────────────────────────────────────────────
    /** Whether the Create Wizard drawer is open. */
    ShowCreateWizard = false;
    /** ID of the entity currently being modified; null if panel is closed. */
    ModifyEntityId = null;
    /** ID to deep-link into on first load (from ?entity= query param). */
    _deepLinkEntityId = null;
    // ─── BaseDashboard implementation ──────────────────────────────────────
    async GetResourceDisplayName(_data) {
        return 'Database Designer';
    }
    /** Sync ?entity=<id> URL param; set initial slide-panel state. */
    initDashboard() {
        const params = this.GetQueryParams();
        if (params['entity']) {
            this._deepLinkEntityId = params['entity'];
        }
    }
    /** Load accessible entities from the engine's cached store. */
    async loadData() {
        this.IsLoadingEntities = true;
        this.LoadError = null;
        this.cdr.markForCheck();
        try {
            this.Entities = await DatabaseDesignerEngine.Instance.loadAccessibleEntities();
            // Honor deep-link: open modify panel if the entity exists in the list.
            if (this._deepLinkEntityId) {
                const target = this.Entities.find(e => e.entityId === this._deepLinkEntityId);
                if (target) {
                    this.openModifyPanel(target);
                }
                this._deepLinkEntityId = null;
            }
        }
        catch (err) {
            this.LoadError = err instanceof Error ? err.message : String(err);
        }
        finally {
            this.IsLoadingEntities = false;
            this.cdr.markForCheck();
        }
    }
    // ─── Entity list event handlers ────────────────────────────────────────
    /** Opens the Create Wizard drawer. */
    OnNewEntity() {
        this.ShowCreateWizard = true;
        this.cdr.markForCheck();
    }
    /** Opens the Modify panel for an existing entity. */
    OnEditEntity(entity) {
        this.openModifyPanel(entity);
    }
    /** Opens the Modify panel (read-only view) for an existing entity. */
    OnViewEntity(entity) {
        this.openModifyPanel(entity);
    }
    // ─── Slide-panel event handlers ────────────────────────────────────────
    /** Called when the Create Wizard drawer closes (cancel or success). */
    OnWizardClosed() {
        this.ShowCreateWizard = false;
        this.cdr.markForCheck();
    }
    /** Called when the wizard successfully creates an entity. */
    OnEntityCreated() {
        this.ShowCreateWizard = false;
        DatabaseDesignerEngine.Instance.invalidateCache();
        this.loadData();
    }
    /** Called when the Modify panel drawer closes. */
    OnModifyPanelClosed() {
        this.ModifyEntityId = null;
        this.UpdateQueryParams({ entity: null });
        this.cdr.markForCheck();
    }
    /** Called when the modify wizard successfully alters an entity. */
    OnEntityModified() {
        this.ModifyEntityId = null;
        DatabaseDesignerEngine.Instance.invalidateCache();
        this.loadData();
    }
    /**
     * React to ?entity= changes that arrive after initial load — e.g. clicking a Home pin
     * for a specific entity, or browser back/forward — when this tab is re-focused rather
     * than freshly mounted (so initDashboard() does not run again). Without this, the modify
     * panel would not open for the pinned/linked entity. (initDashboard handles the very
     * first load via _deepLinkEntityId.)
     */
    OnQueryParamsChanged(params, _source) {
        const entityId = params['entity'] || null;
        if (entityId) {
            if (entityId !== this.ModifyEntityId) {
                const target = this.Entities.find(e => e.entityId === entityId);
                if (target) {
                    this.openModifyPanel(target);
                }
            }
        }
        else if (this.ModifyEntityId) {
            this.OnModifyPanelClosed();
        }
    }
    // ─── Helpers ───────────────────────────────────────────────────────────
    openModifyPanel(entity) {
        this.ModifyEntityId = entity.entityId;
        this.UpdateQueryParams({ entity: entity.entityId });
        this.cdr.markForCheck();
    }
    static ɵfac = /*@__PURE__*/ (() => { let ɵDatabaseDesignerDashboardComponent_BaseFactory; return function DatabaseDesignerDashboardComponent_Factory(__ngFactoryType__) { return (ɵDatabaseDesignerDashboardComponent_BaseFactory || (ɵDatabaseDesignerDashboardComponent_BaseFactory = i0.ɵɵgetInheritedFactory(DatabaseDesignerDashboardComponent)))(__ngFactoryType__ || DatabaseDesignerDashboardComponent); }; })();
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: DatabaseDesignerDashboardComponent, selectors: [["mj-database-designer-dashboard"]], viewQuery: function DatabaseDesignerDashboardComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(DatabaseModifyComponent, 5);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.modifyRef = _t.first);
        } }, standalone: false, features: [i0.ɵɵInheritDefinitionFeature], decls: 3, vars: 2, consts: [[3, "NewEntity", "EditEntity", "ViewEntity"], ["Mode", "slide", "Title", "New Entity", 3, "Visible", "Resizable", "WidthPx", "MaxWidthRatio", "MinWidthPx"], ["Mode", "slide", "Title", "Edit Entity", 3, "Visible", "Resizable", "WidthPx", "MaxWidthRatio", "MinWidthPx", "CanClose"], ["Mode", "slide", "Title", "New Entity", 3, "Closed", "Visible", "Resizable", "WidthPx", "MaxWidthRatio", "MinWidthPx"], [3, "EntityCreated", "Cancelled"], ["Mode", "slide", "Title", "Edit Entity", 3, "Closed", "Visible", "Resizable", "WidthPx", "MaxWidthRatio", "MinWidthPx", "CanClose"], [3, "EntityModified", "Cancelled", "EntityId"]], template: function DatabaseDesignerDashboardComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "mj-database-entity-list", 0);
            i0.ɵɵlistener("NewEntity", function DatabaseDesignerDashboardComponent_Template_mj_database_entity_list_NewEntity_0_listener() { return ctx.OnNewEntity(); })("EditEntity", function DatabaseDesignerDashboardComponent_Template_mj_database_entity_list_EditEntity_0_listener($event) { return ctx.OnEditEntity($event); })("ViewEntity", function DatabaseDesignerDashboardComponent_Template_mj_database_entity_list_ViewEntity_0_listener($event) { return ctx.OnViewEntity($event); });
            i0.ɵɵelementEnd();
            i0.ɵɵconditionalCreate(1, DatabaseDesignerDashboardComponent_Conditional_1_Template, 2, 5, "mj-slide-panel", 1);
            i0.ɵɵconditionalCreate(2, DatabaseDesignerDashboardComponent_Conditional_2_Template, 2, 7, "mj-slide-panel", 2);
        } if (rf & 2) {
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.ShowCreateWizard ? 1 : -1);
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.ModifyEntityId ? 2 : -1);
        } }, dependencies: [i1.MjSlidePanelComponent, i2.EntityListComponent, i3.DatabaseCreateWizardComponent, i4.DatabaseModifyComponent], styles: ["\n\n\n\n\n\n\n[_nghost-%COMP%] {\n  display: flex;\n  flex-direction: column;\n  height: 100%;\n  overflow: hidden;\n  background: var(--mj-bg-page);\n  position: relative;\n}\n\nmj-database-entity-list[_ngcontent-%COMP%] {\n  display: block;\n  flex: 1;\n  min-height: 0;\n}\n\n\n\n\n.panel-placeholder[_ngcontent-%COMP%] {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  gap: 16px;\n  padding: 60px 32px;\n  text-align: center;\n  color: var(--mj-text-muted);\n}\n\n.panel-placeholder[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  font-size: 2rem;\n}\n\n.panel-placeholder[_ngcontent-%COMP%]   p[_ngcontent-%COMP%] {\n  margin: 0;\n  font-size: 0.95rem;\n}"], changeDetection: 0 });
};
DatabaseDesignerDashboardComponent = __decorate([
    RegisterClass(BaseResourceComponent, 'DatabaseDesignerDashboard')
], DatabaseDesignerDashboardComponent);
export { DatabaseDesignerDashboardComponent };
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DatabaseDesignerDashboardComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'mj-database-designer-dashboard', changeDetection: ChangeDetectionStrategy.OnPush, template: "<!--\n  Thin wrapper \u2014 the entity-list component owns the interior chrome card\n  (<mj-page-header-interior>) and the scrollable body. The dashboard's role is\n  to host the slide-over panels (create-wizard, modify) and route their lifecycle.\n-->\n<mj-database-entity-list\n  (NewEntity)=\"OnNewEntity()\"\n  (EditEntity)=\"OnEditEntity($event)\"\n  (ViewEntity)=\"OnViewEntity($event)\">\n</mj-database-entity-list>\n\n  <!-- \u2500\u2500 Create Wizard slide-over panel \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n  @if (ShowCreateWizard) {\n    <mj-slide-panel\n      Mode=\"slide\"\n      Title=\"New Entity\"\n      [Visible]=\"ShowCreateWizard\"\n      [Resizable]=\"true\"\n      [WidthPx]=\"9999\"\n      [MaxWidthRatio]=\"1\"\n      [MinWidthPx]=\"960\"\n      (Closed)=\"OnWizardClosed()\">\n      <mj-database-create-wizard\n        (EntityCreated)=\"OnEntityCreated()\"\n        (Cancelled)=\"OnWizardClosed()\">\n      </mj-database-create-wizard>\n    </mj-slide-panel>\n  }\n\n  <!-- \u2500\u2500 Modify slide-over panel \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n  @if (ModifyEntityId) {\n    <mj-slide-panel\n      Mode=\"slide\"\n      Title=\"Edit Entity\"\n      [Visible]=\"!!ModifyEntityId\"\n      [Resizable]=\"true\"\n      [WidthPx]=\"9999\"\n      [MaxWidthRatio]=\"1\"\n      [MinWidthPx]=\"960\"\n      [CanClose]=\"ModifyPanelCanClose\"\n      (Closed)=\"OnModifyPanelClosed()\">\n      <mj-database-modify\n        [EntityId]=\"ModifyEntityId!\"\n        (EntityModified)=\"OnEntityModified()\"\n        (Cancelled)=\"OnModifyPanelClosed()\">\n      </mj-database-modify>\n    </mj-slide-panel>\n  }\n", styles: ["/*\n  Database Designer dashboard root \u2014 thin wrapper that hosts the entity-list\n  child + slide-over panels. The entity-list owns its own interior chrome\n  (<mj-page-header-interior>) so this component is a flex column that just\n  lets the child fill the body. See Section 10 of plans/explorer-chrome-conventions.md.\n*/\n:host {\n  display: flex;\n  flex-direction: column;\n  height: 100%;\n  overflow: hidden;\n  background: var(--mj-bg-page);\n  position: relative;\n}\n\nmj-database-entity-list {\n  display: block;\n  flex: 1;\n  min-height: 0;\n}\n\n/* \u2500\u2500 Placeholder (pre-Phase 5d/5e wiring) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n.panel-placeholder {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  gap: 16px;\n  padding: 60px 32px;\n  text-align: center;\n  color: var(--mj-text-muted);\n}\n\n.panel-placeholder i {\n  font-size: 2rem;\n}\n\n.panel-placeholder p {\n  margin: 0;\n  font-size: 0.95rem;\n}\n"] }]
    }], null, { modifyRef: [{
            type: ViewChild,
            args: [DatabaseModifyComponent]
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(DatabaseDesignerDashboardComponent, { className: "DatabaseDesignerDashboardComponent", filePath: "src/DatabaseDesigner/components/database-designer-dashboard.component.ts", lineNumber: 38 }); })();
/** Tree-shaking prevention — called from module's public-api.ts. */
export function LoadDatabaseDesignerDashboard() { }
//# sourceMappingURL=database-designer-dashboard.component.js.map