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, UUIDsEqual } from '@memberjunction/global';
import { CompositeKey, Metadata } from '@memberjunction/core';
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 { EntityListComponent } from './entity-list.component.js';
import { buildDatabaseDesignerAgentContext, buildEntityNotFoundError, entityDisplayName, resolveEntityByIdOrName, } from '../database-designer-agent-context.js';
import { validateStringParam } from '../../shared/agent-tool-validation.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;
    /** Reference to the entity list — used to drive the agent's read-only search/refresh. */
    entityListRef;
    // ─── 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;
    /**
     * Loaded field/column detail for the currently selected entity, used ONLY to enrich the
     * agent context (the modify panel loads its own detail independently). Cleared when the
     * panel closes; refreshed (best-effort) when an entity is selected.
     */
    _selectedEntityDetail = null;
    // ─── BaseDashboard implementation ──────────────────────────────────────
    async GetResourceDisplayName(_data) {
        return 'Database Designer';
    }
    /**
     * After the view initializes, publish the initial agent context and register the
     * (read-only) client tools the AI agent can invoke against this surface. The ongoing
     * context re-emit happens from {@link loadData} and the slide-panel handlers as the
     * browse state changes.
     */
    ngAfterViewInit() {
        this.publishAgentContext();
        this.registerAgentClientTools();
    }
    /** 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();
            // Keep the agent's view of the entity list in sync after each (re)load.
            this.publishAgentContext();
        }
    }
    // ─── 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._selectedEntityDetail = null;
        this.UpdateQueryParams({ entity: null });
        this.cdr.markForCheck();
        this.publishAgentContext();
    }
    /** 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._selectedEntityDetail = null;
        this.UpdateQueryParams({ entity: entity.entityId });
        this.cdr.markForCheck();
        this.publishAgentContext();
        // Best-effort: load the field detail so the agent context can include the selected
        // entity's field/relationship summary. Fire-and-forget — a failure just leaves the
        // summary absent (never throws into the open path).
        void this.loadSelectedEntityDetailForContext(entity.entityId);
    }
    /**
     * Load the selected entity's field detail (read-only) purely to enrich the agent
     * context. Guarded against a newer selection superseding this load. Re-publishes context
     * once the detail is available.
     */
    async loadSelectedEntityDetailForContext(entityId) {
        try {
            const detail = await DatabaseDesignerEngine.Instance.loadEntityDetail(entityId);
            // Only apply if this entity is still the selected one.
            if (this.ModifyEntityId === entityId) {
                this._selectedEntityDetail = detail;
                this.publishAgentContext();
            }
        }
        catch {
            // Read-only enrichment — ignore failures, the summary simply stays absent.
        }
    }
    // ========================================
    // AI AGENT CONTEXT & CLIENT TOOLS
    //
    // 🔒 SAFETY BOUNDARY: The Database Designer surface CAN MUTATE the database
    // schema — it creates entities (Create Wizard), alters tables, adds/removes
    // fields, and runs the DDL pipeline (modify panel). EVERYTHING published and
    // registered below is STRICTLY READ-ONLY / SCHEMA-BROWSE:
    //   - context reports only the accessible-entity list, search, selection, and
    //     whether the detail panel is open;
    //   - tools only search the list, open an entity's detail panel for VIEWING,
    //     and refresh the list.
    // NONE of the following is exposed to the agent, and NONE may ever be added
    // here: OpenCreateWizard / CreateNewEntity, ModifyEntitySchema,
    // AddField / RemoveField / ChangeFieldType, DeleteEntity, ApplyDatabaseChanges,
    // RunDatabasePipeline — or any other schema mutation. The agent browses the
    // schema; the USER makes changes from the wizard / modify panel.
    //
    // NOTE on SelectEntity: the modify panel it opens is the SAME drawer the user
    // edits in, but the agent only OPENS it (read/browse context). It never applies,
    // saves, or runs the pipeline — there is no tool that can.
    // ========================================
    /**
     * Registered Name of the entity whose detail panel is open, resolved from the loaded
     * list. Null when nothing is selected or the id is not (yet) in the list.
     */
    get SelectedEntityName() {
        if (!this.ModifyEntityId) {
            return null;
        }
        return this.Entities.find(e => e.entityId === this.ModifyEntityId)?.entityName ?? null;
    }
    /** Current free-text search term applied to the entity list (reads the child list's state). */
    get currentSearchText() {
        return this.entityListRef?.SearchTerm ?? '';
    }
    /** Active schema filter applied to the entity list (reads the child list's state). */
    get currentSchemaFilter() {
        return this.entityListRef?.SelectedSchema ?? '';
    }
    /** Count of entities visible after the child list's search + schema filter. */
    get filteredEntityCount() {
        return this.entityListRef?.FilteredEntities.length ?? this.Entities.length;
    }
    /**
     * Build the resolver candidate list: every accessible entity as an
     * {@link EntityNameCandidate}, enriched with the entity's `DisplayName` from `EntityInfo`
     * metadata when available (so display-name resolution matches what the user reads).
     */
    buildEntityCandidates() {
        return this.Entities.map(e => ({
            ID: e.entityId,
            Name: e.entityName,
            DisplayName: this.lookupEntityInfo(e.entityName)?.DisplayName ?? null,
        }));
    }
    /** Resolve the `EntityInfo` for a registered entity name (for DisplayName + RelatedEntities). */
    lookupEntityInfo(entityName) {
        return new Metadata().EntityByName(entityName); // global-provider-ok: client-side Angular dashboard, single provider; metadata-only read.
    }
    /** The on-screen DISPLAY label for an accessible entity (DisplayName, else prefix-stripped Name). */
    displayNameForEntity(entity) {
        return entityDisplayName(entity.entityName, this.lookupEntityInfo(entity.entityName)?.DisplayName);
    }
    /** Bounded-by-the-helper list of the DISPLAY names of the currently-filtered entities. */
    get availableEntityDisplayNames() {
        const rows = this.entityListRef?.FilteredEntities ?? this.Entities;
        return rows.map(e => this.displayNameForEntity(e));
    }
    /** Schema → entity-count groupings across all accessible entities. */
    buildSchemaGroups() {
        const counts = new Map();
        for (const e of this.Entities) {
            counts.set(e.schemaName, (counts.get(e.schemaName) ?? 0) + 1);
        }
        return Array.from(counts.entries())
            .map(([SchemaName, EntityCount]) => ({ SchemaName, EntityCount }))
            .sort((a, b) => a.SchemaName.localeCompare(b.SchemaName));
    }
    /** Field summaries for the selected entity (from the loaded detail), for the agent context. */
    buildSelectedEntityFields() {
        const cols = this._selectedEntityDetail?.columns ?? [];
        return cols.map(c => ({
            Name: c.Name,
            Type: c.RawSqlType ?? c.Type ?? 'unknown',
            IsNullable: c.IsNullable,
        }));
    }
    /** Related-entity summaries for the selected entity (from EntityInfo.RelatedEntities). */
    buildSelectedRelatedEntities() {
        const name = this.SelectedEntityName;
        if (!name) {
            return [];
        }
        const info = this.lookupEntityInfo(name);
        if (!info) {
            return [];
        }
        return info.RelatedEntities.map(r => ({
            Name: r.DisplayName || r.RelatedEntity || '(unnamed)',
            RelationshipType: r.Type ?? 'unknown',
        }));
    }
    /**
     * Publish the current Database Designer schema-browse state to the AI agent via
     * NavigationService. Reports the accessible-entity count + filtered count, the current
     * search/schema filters, the open selection (id + registered name + DISPLAY name +
     * schema + table + field count + bounded field/relationship summary), whether the
     * modify/detail panel is open, the loading flag, the bounded available-entity DISPLAY
     * names, and the schema-grouping landscape. The shaping lives in the pure
     * {@link buildDatabaseDesignerAgentContext} helper so it stays unit-testable. Called on
     * init (ngAfterViewInit) and on every browse-state change (load, filter, open/close
     * panel, detail load).
     */
    publishAgentContext() {
        const selectedEntity = this.ModifyEntityId
            ? this.Entities.find(e => e.entityId === this.ModifyEntityId) ?? null
            : null;
        const context = buildDatabaseDesignerAgentContext({
            EntityCount: this.Entities.length,
            FilteredEntityCount: this.filteredEntityCount,
            SearchText: this.currentSearchText,
            SchemaFilter: this.currentSchemaFilter,
            SelectedEntityId: this.ModifyEntityId,
            SelectedEntityName: this.SelectedEntityName,
            SelectedEntityDisplayName: selectedEntity ? this.displayNameForEntity(selectedEntity) : null,
            SelectedEntitySchema: selectedEntity?.schemaName ?? null,
            SelectedEntityTable: selectedEntity?.tableName ?? null,
            SelectedEntityFieldCount: this._selectedEntityDetail?.fieldCount ?? null,
            SelectedEntityFields: this.buildSelectedEntityFields(),
            RelatedEntities: this.buildSelectedRelatedEntities(),
            ShowModifyPanel: !!this.ModifyEntityId,
            IsLoading: this.IsLoadingEntities,
            AvailableEntityNames: this.availableEntityDisplayNames,
            SchemaGroups: this.buildSchemaGroups(),
        });
        this.navigationService.SetAgentContext(this, context);
    }
    /**
     * Register the READ-ONLY (schema-browse) client tools the AI agent can invoke against
     * the Database Designer. Each handler delegates to the same read-only path a user
     * interaction would take and returns `{ Success: true }` on success or
     * `{ Success: false, ErrorMessage }` on failure. Handlers never throw.
     *
     * Tools (browse only — see SAFETY BOUNDARY above):
     * - SearchEntities: filter the accessible-entity list by a search string.
     * - SelectEntity: open an entity's detail panel by its ID OR name/display-name (VIEW).
     * - FilterBySchema: narrow the entity list to a schema (empty string clears the filter).
     * - RefreshEntityList: reload the accessible-entity list.
     * - NavigateToEntityRecord: open the `MJ: Entities` record for an entity to VIEW it.
     *
     * Intentionally NOT exposed (mutations — see SAFETY BOUNDARY): create wizard,
     * modify-schema, add/remove/change fields, delete entity, apply changes, run pipeline.
     */
    registerAgentClientTools() {
        this.navigationService.SetAgentClientTools(this, [
            {
                Name: 'SearchEntities',
                Description: 'Filter the accessible-entity list by a free-text search string (matches entity name, table, or schema). Read-only.',
                ParameterSchema: { type: 'object', properties: { searchText: { type: 'string' } }, required: ['searchText'] },
                Handler: async (params) => this.toolSearchEntities(params),
            },
            {
                Name: 'SelectEntity',
                Description: "Open an entity's detail panel to VIEW its schema. Accepts the entity ID, the registered name, or the on-screen DISPLAY name (e.g. \"AI Models\" — the \"MJ: \" prefix is not required). Read-only — opens the panel but never applies, saves, or runs any change.",
                ParameterSchema: { type: 'object', properties: { entity: { type: 'string', description: 'Entity ID, registered name, or display name.' } }, required: ['entity'] },
                Handler: async (params) => this.toolSelectEntity(params),
            },
            {
                Name: 'FilterBySchema',
                Description: 'Narrow the accessible-entity list to a single SQL schema (e.g. "__mj_UDT"). Pass an empty string to clear the schema filter. Read-only.',
                ParameterSchema: { type: 'object', properties: { schema: { type: 'string' } }, required: ['schema'] },
                Handler: async (params) => this.toolFilterBySchema(params),
            },
            {
                Name: 'RefreshEntityList',
                Description: 'Reload the accessible-entity list (no schema is modified).',
                ParameterSchema: { type: 'object', properties: {} },
                Handler: async () => this.toolRefreshEntityList(),
            },
            {
                Name: 'NavigateToEntityRecord',
                Description: "Open the `MJ: Entities` record for an entity (by ID, registered name, or display name) in a tab to VIEW its full metadata. Read-only navigation — does not edit.",
                ParameterSchema: { type: 'object', properties: { entity: { type: 'string', description: 'Entity ID, registered name, or display name.' } }, required: ['entity'] },
                Handler: async (params) => this.toolNavigateToEntityRecord(params),
            },
        ]);
    }
    /** Apply a read-only search filter to the entity list via the child list component. */
    toolSearchEntities(params) {
        const validated = validateStringParam(params['searchText'], 'searchText');
        if (!validated.ok) {
            return validated.result;
        }
        if (!this.entityListRef) {
            return { Success: false, ErrorMessage: 'The entity list is not ready yet.' };
        }
        this.entityListRef.SearchTerm = validated.value;
        this.cdr.markForCheck();
        this.publishAgentContext();
        return { Success: true };
    }
    /**
     * Open an entity's detail panel to VIEW its schema. Resolves the agent's reference by ID,
     * registered name, or DISPLAY name. This opens the SAME panel the user edits in, but the
     * agent only opens it for browsing — it applies nothing.
     */
    toolSelectEntity(params) {
        const validated = validateStringParam(params['entity'], 'entity');
        if (!validated.ok) {
            return validated.result;
        }
        const candidate = resolveEntityByIdOrName(validated.value, this.buildEntityCandidates());
        if (!candidate) {
            return { Success: false, ErrorMessage: buildEntityNotFoundError(validated.value, this.buildEntityCandidates()) };
        }
        const entity = this.Entities.find(e => UUIDsEqual(e.entityId, candidate.ID));
        if (!entity) {
            return { Success: false, ErrorMessage: buildEntityNotFoundError(validated.value, this.buildEntityCandidates()) };
        }
        this.openModifyPanel(entity);
        return { Success: true };
    }
    /** Narrow the entity list to a schema (empty string clears it). Read-only. */
    toolFilterBySchema(params) {
        const validated = validateStringParam(params['schema'], 'schema');
        if (!validated.ok) {
            return validated.result;
        }
        if (!this.entityListRef) {
            return { Success: false, ErrorMessage: 'The entity list is not ready yet.' };
        }
        const schema = validated.value.trim();
        const available = this.entityListRef.AvailableFilterSchemas;
        if (schema && !available.includes(schema)) {
            return { Success: false, ErrorMessage: `Schema "${schema}" is not present in the accessible entities. Available schemas: ${available.join(', ') || '(none)'}.` };
        }
        this.entityListRef.SelectedSchema = schema;
        this.cdr.markForCheck();
        this.publishAgentContext();
        return { Success: true };
    }
    /** Reload the accessible-entity list (read-only). */
    async toolRefreshEntityList() {
        await this.loadData();
        return { Success: true };
    }
    /**
     * Open the `MJ: Entities` record for an entity in a tab to VIEW its full metadata.
     * Resolves by ID / registered name / display name. Read-only navigation.
     */
    toolNavigateToEntityRecord(params) {
        const validated = validateStringParam(params['entity'], 'entity');
        if (!validated.ok) {
            return validated.result;
        }
        const candidate = resolveEntityByIdOrName(validated.value, this.buildEntityCandidates());
        if (!candidate) {
            return { Success: false, ErrorMessage: buildEntityNotFoundError(validated.value, this.buildEntityCandidates()) };
        }
        this.navigationService.OpenEntityRecord('MJ: Entities', CompositeKey.FromID(candidate.ID));
        return { Success: true };
    }
    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)(EntityListComponent, 5);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.modifyRef = _t.first);
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.entityListRef = _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]
        }], entityListRef: [{
            type: ViewChild,
            args: [EntityListComponent]
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(DatabaseDesignerDashboardComponent, { className: "DatabaseDesignerDashboardComponent", filePath: "src/DatabaseDesigner/components/database-designer-dashboard.component.ts", lineNumber: 51 }); })();
/** Tree-shaking prevention — called from module's public-api.ts. */
export function LoadDatabaseDesignerDashboard() { }
//# sourceMappingURL=database-designer-dashboard.component.js.map