/**
 * @module database-create-wizard.component
 * @description Multi-step wizard for creating a new Database Designer entity.
 *
 * Rendered inside an `mj-slide-panel` by the dashboard.  Manages step routing
 * and owns one `EntityWizardStateService` instance for the duration the panel
 * is open.
 *
 * Wizard steps:
 *   1  Basics       — entity name, table name, schema, description
 *   2  Fields       — column definitions (EntityFieldsGridComponent)
 *   3  Relationships — optional foreign keys
 *   4  Review       — read-only schema preview + server-side validation
 *   5  Create       — pipeline execution + result (EntityPipelinePanelComponent)
 *
 * Step 5 is terminal — once the pipeline starts there is no Back navigation.
 */
import { Component, Output, EventEmitter, ChangeDetectionStrategy, ChangeDetectorRef, inject, ViewChild, } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { DatabaseDesignerService } from '../../services/database-designer.service.js';
import { EntityWizardStateService } from '../../services/entity-wizard-state.service.js';
import { DatabaseDesignerEngine } from '../../services/database-designer.engine.js';
import { StepPipelineComponent } from './steps/step-pipeline.component.js';
import * as i0 from "@angular/core";
import * as i1 from "@memberjunction/ng-ui-components";
import * as i2 from "angular-split";
import * as i3 from "../shared/wizard-step-indicator.component";
import * as i4 from "../shared/database-preview-pane.component";
import * as i5 from "./steps/step-basics.component";
import * as i6 from "./steps/step-fields.component";
import * as i7 from "./steps/step-relationships.component";
import * as i8 from "./steps/step-review.component";
import * as i9 from "./steps/step-pipeline.component";
import * as i10 from "@angular/common";
const _c0 = () => ({});
const _c1 = () => [];
function DatabaseCreateWizardComponent_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 2)(1, "mj-entity-step-pipeline", 5);
    i0.ɵɵlistener("PipelineCompleted", function DatabaseCreateWizardComponent_Conditional_2_Template_mj_entity_step_pipeline_PipelineCompleted_1_listener($event) { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnPipelineCompleted($event)); })("CreateAnother", function DatabaseCreateWizardComponent_Conditional_2_Template_mj_entity_step_pipeline_CreateAnother_1_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnCreateAnother()); });
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵproperty("TableDefinition", ctx_r1.TableDefinition);
} }
function DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Conditional_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵtext(0, " We hit a problem ");
} }
function DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Conditional_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵtext(0);
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(3);
    i0.ɵɵtextInterpolate1(" We hit ", ctx_r1.ValidationErrors.length, " problems ");
} }
function DatabaseCreateWizardComponent_Conditional_3_Conditional_3_For_8_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "li");
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const err_r4 = ctx.$implicit;
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(err_r4);
} }
function DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Conditional_10_Conditional_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 23);
    i0.ɵɵtext(1, " Retrying\u2026 ");
} }
function DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Conditional_10_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 24);
    i0.ɵɵtext(1, " Retry ");
} }
function DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Conditional_10_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 22);
    i0.ɵɵlistener("click", function DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Conditional_10_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r5); const ctx_r1 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r1.OnRetryValidation()); });
    i0.ɵɵconditionalCreate(1, DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Conditional_10_Conditional_1_Template, 2, 0)(2, DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Conditional_10_Conditional_2_Template, 2, 0);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(3);
    i0.ɵɵproperty("disabled", ctx_r1.IsValidating);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.IsValidating ? 1 : 2);
} }
function DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 8);
    i0.ɵɵelement(1, "i", 14);
    i0.ɵɵelementStart(2, "div", 15)(3, "div", 16);
    i0.ɵɵconditionalCreate(4, DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Conditional_4_Template, 1, 0)(5, DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Conditional_5_Template, 1, 1);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(6, "ul", 17);
    i0.ɵɵrepeaterCreate(7, DatabaseCreateWizardComponent_Conditional_3_Conditional_3_For_8_Template, 2, 1, "li", null, i0.ɵɵrepeaterTrackByIndex);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(9, "div", 18);
    i0.ɵɵconditionalCreate(10, DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Conditional_10_Template, 3, 2, "button", 19);
    i0.ɵɵelementStart(11, "button", 20);
    i0.ɵɵlistener("click", function DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Template_button_click_11_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.OnDismissErrors()); });
    i0.ɵɵelement(12, "i", 21);
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(4);
    i0.ɵɵconditional(ctx_r1.ValidationErrors.length === 1 ? 4 : 5);
    i0.ɵɵadvance(3);
    i0.ɵɵrepeater(ctx_r1.ValidationErrors);
    i0.ɵɵadvance(3);
    i0.ɵɵconditional(ctx_r1.CurrentStep === "relationships" || ctx_r1.CurrentStep === "review" ? 10 : -1);
} }
function DatabaseCreateWizardComponent_Conditional_3_Conditional_4_Template(rf, ctx) { if (rf & 1) {
    const _r6 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "mj-entity-step-basics", 25);
    i0.ɵɵlistener("ValueChanged", function DatabaseCreateWizardComponent_Conditional_3_Conditional_4_Template_mj_entity_step_basics_ValueChanged_0_listener($event) { i0.ɵɵrestoreView(_r6); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.OnBasicsChanged($event)); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("AvailableSchemas", ctx_r1.AvailableSchemas);
} }
function DatabaseCreateWizardComponent_Conditional_3_Conditional_5_Template(rf, ctx) { if (rf & 1) {
    const _r7 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "mj-entity-step-fields", 26);
    i0.ɵɵlistener("ColumnsChanged", function DatabaseCreateWizardComponent_Conditional_3_Conditional_5_Template_mj_entity_step_fields_ColumnsChanged_0_listener($event) { i0.ɵɵrestoreView(_r7); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.OnFieldsChanged($event)); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("InitialColumns", ctx_r1.TableDefinition.Columns ?? i0.ɵɵpureFunction0(1, _c1));
} }
function DatabaseCreateWizardComponent_Conditional_3_Conditional_6_Template(rf, ctx) { if (rf & 1) {
    const _r8 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "mj-entity-step-relationships", 27);
    i0.ɵɵlistener("ForeignKeysChanged", function DatabaseCreateWizardComponent_Conditional_3_Conditional_6_Template_mj_entity_step_relationships_ForeignKeysChanged_0_listener($event) { i0.ɵɵrestoreView(_r8); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.OnRelationshipsChanged($event)); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("InitialForeignKeys", ctx_r1.TableDefinition.ForeignKeys ?? i0.ɵɵpureFunction0(2, _c1))("AvailableColumns", ctx_r1.TableDefinition.Columns ?? i0.ɵɵpureFunction0(3, _c1));
} }
function DatabaseCreateWizardComponent_Conditional_3_Conditional_7_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-entity-step-review", 12);
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("TableDefinition", ctx_r1.TableDefinition)("ValidationErrors", ctx_r1.ValidationErrors)("IsValidating", ctx_r1.IsValidating);
} }
function DatabaseCreateWizardComponent_Conditional_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "as-split", 3)(1, "as-split-area", 6)(2, "div", 7);
    i0.ɵɵconditionalCreate(3, DatabaseCreateWizardComponent_Conditional_3_Conditional_3_Template, 13, 2, "div", 8);
    i0.ɵɵconditionalCreate(4, DatabaseCreateWizardComponent_Conditional_3_Conditional_4_Template, 1, 1, "mj-entity-step-basics", 9);
    i0.ɵɵconditionalCreate(5, DatabaseCreateWizardComponent_Conditional_3_Conditional_5_Template, 1, 2, "mj-entity-step-fields", 10);
    i0.ɵɵconditionalCreate(6, DatabaseCreateWizardComponent_Conditional_3_Conditional_6_Template, 1, 4, "mj-entity-step-relationships", 11);
    i0.ɵɵconditionalCreate(7, DatabaseCreateWizardComponent_Conditional_3_Conditional_7_Template, 1, 3, "mj-entity-step-review", 12);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(8, "as-split-area", 6);
    i0.ɵɵelement(9, "mj-database-preview-pane", 13);
    i0.ɵɵpipe(10, "async");
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵproperty("size", 55)("minSize", 40);
    i0.ɵɵadvance(2);
    i0.ɵɵconditional(ctx_r1.ValidationErrors.length > 0 ? 3 : -1);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.CurrentStep === "basics" ? 4 : -1);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.CurrentStep === "fields" ? 5 : -1);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.CurrentStep === "relationships" ? 6 : -1);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.CurrentStep === "review" ? 7 : -1);
    i0.ɵɵadvance();
    i0.ɵɵproperty("size", 45)("minSize", 25);
    i0.ɵɵadvance();
    i0.ɵɵproperty("TableDefinition", i0.ɵɵpipeBind1(10, 10, ctx_r1.WizardState.tableDefinition$) ?? i0.ɵɵpureFunction0(12, _c0));
} }
function DatabaseCreateWizardComponent_Conditional_4_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    const _r10 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 33);
    i0.ɵɵlistener("click", function DatabaseCreateWizardComponent_Conditional_4_Conditional_2_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r10); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.OnBack()); });
    i0.ɵɵelement(1, "i", 34);
    i0.ɵɵtext(2, " Back ");
    i0.ɵɵelementEnd();
} }
function DatabaseCreateWizardComponent_Conditional_4_Conditional_7_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 23);
    i0.ɵɵtext(1, " Validating\u2026 ");
} }
function DatabaseCreateWizardComponent_Conditional_4_Conditional_8_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵtext(0, " Create Entity ");
    i0.ɵɵelement(1, "i", 35);
} }
function DatabaseCreateWizardComponent_Conditional_4_Conditional_9_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵtext(0, " Next ");
    i0.ɵɵelement(1, "i", 36);
} }
function DatabaseCreateWizardComponent_Conditional_4_Template(rf, ctx) { if (rf & 1) {
    const _r9 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 4)(1, "div", 28);
    i0.ɵɵconditionalCreate(2, DatabaseCreateWizardComponent_Conditional_4_Conditional_2_Template, 3, 0, "button", 29);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "div", 30)(4, "button", 31);
    i0.ɵɵlistener("click", function DatabaseCreateWizardComponent_Conditional_4_Template_button_click_4_listener() { i0.ɵɵrestoreView(_r9); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnCancel()); });
    i0.ɵɵtext(5, " Cancel ");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(6, "button", 32);
    i0.ɵɵlistener("click", function DatabaseCreateWizardComponent_Conditional_4_Template_button_click_6_listener() { i0.ɵɵrestoreView(_r9); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnNext()); });
    i0.ɵɵconditionalCreate(7, DatabaseCreateWizardComponent_Conditional_4_Conditional_7_Template, 2, 0)(8, DatabaseCreateWizardComponent_Conditional_4_Conditional_8_Template, 2, 0)(9, DatabaseCreateWizardComponent_Conditional_4_Conditional_9_Template, 2, 0);
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(2);
    i0.ɵɵconditional(!ctx_r1.IsFirstStep ? 2 : -1);
    i0.ɵɵadvance(4);
    i0.ɵɵproperty("disabled", ctx_r1.IsValidating);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.IsValidating ? 7 : ctx_r1.CurrentStep === "review" ? 8 : 9);
} }
const WIZARD_STEP_DEFS = [
    { id: 'basics', label: 'Basics' },
    { id: 'fields', label: 'Fields' },
    { id: 'relationships', label: 'Relationships' },
    { id: 'review', label: 'Review & Create' },
];
const STEP_ORDER = ['basics', 'fields', 'relationships', 'review'];
export class DatabaseCreateWizardComponent {
    // ─── Injected ──────────────────────────────────────────────────────────
    designerService = inject(DatabaseDesignerService);
    cdr = inject(ChangeDetectorRef);
    // ─── Per-instance wizard state service ────────────────────────────────
    WizardState = new EntityWizardStateService(this.designerService);
    // ─── Outputs ───────────────────────────────────────────────────────────
    /** Emitted when the wizard completes successfully. */
    EntityCreated = new EventEmitter();
    /** Emitted when the user cancels or clicks "Create Another". */
    Cancelled = new EventEmitter();
    // ─── Pipeline step ref ─────────────────────────────────────────────────
    // StepPipelineComponent is rendered directly in the wizard's own template
    // (via <mj-entity-step-pipeline>) so this ViewChild resolves correctly,
    // unlike @ViewChild(EntityPipelinePanelComponent) which lives one level
    // deeper inside StepPipelineComponent's own view.
    stepPipelineRef;
    // ─── View state ────────────────────────────────────────────────────────
    CurrentStep = 'basics';
    StepDefs = [];
    IsValidating = false;
    ValidationErrors = [];
    /** True once the user has clicked "Create Entity" — pipeline runs inline on the review step. */
    IsExecuting = false;
    get StepIndex() {
        return STEP_ORDER.indexOf(this.CurrentStep);
    }
    get IsFirstStep() { return this.StepIndex === 0; }
    get IsLastStep() { return this.CurrentStep === 'review'; }
    // ─── Lifecycle ─────────────────────────────────────────────────────────
    destroy$ = new Subject();
    AvailableSchemas = [];
    constructor() {
        this.WizardState.currentStep$
            .pipe(takeUntil(this.destroy$))
            .subscribe(step => {
            this.CurrentStep = step;
            this.rebuildStepDefs(step);
            this.cdr.markForCheck();
        });
        this.WizardState.isValidating$
            .pipe(takeUntil(this.destroy$))
            .subscribe(v => { this.IsValidating = v; this.cdr.markForCheck(); });
        this.WizardState.stepErrors$
            .pipe(takeUntil(this.destroy$))
            .subscribe(errors => {
            this.ValidationErrors = Object.values(errors);
            this.cdr.markForCheck();
        });
        // Build initial step defs
        this.rebuildStepDefs('basics');
        // Load available schemas asynchronously — wizard renders synchronously but
        // the schema dropdown populates when the async result arrives
        DatabaseDesignerEngine.Instance.loadAvailableSchemas().then(schemas => {
            this.AvailableSchemas = schemas;
            this.cdr.markForCheck();
        });
    }
    ngOnDestroy() {
        this.destroy$.next();
        this.destroy$.complete();
        this.WizardState.Destroy();
    }
    // ─── Step data handlers (called by child step components) ─────────────
    OnBasicsChanged(value) {
        this.WizardState.UpdateBasics(value);
    }
    OnFieldsChanged(columns) {
        this.WizardState.UpdateFields(columns);
    }
    OnRelationshipsChanged(fks) {
        this.WizardState.UpdateRelationshipsAndAutoColumns(fks);
    }
    // ─── Navigation ────────────────────────────────────────────────────────
    async OnNext() {
        const currentStep = this.CurrentStep;
        // Synchronous validation for the current step
        if (!this.WizardState.ValidateStep(currentStep))
            return;
        // Entering Review (step 4): run server-side validation first
        if (currentStep === 'relationships') {
            const result = await this.WizardState.ValidateSchema();
            if (!result.Valid)
                return;
        }
        // Review is the last step — "Create Entity" button triggers inline pipeline execution.
        if (currentStep === 'review') {
            this.IsExecuting = true;
            this.cdr.markForCheck();
            // @ViewChild(StepPipelineComponent) resolves after the @if block renders on the
            // next CD cycle. The setTimeout gives Angular that cycle before we call StartPipeline().
            // StepPipelineComponent.ngAfterViewInit() is also wired up as a belt-and-suspenders
            // trigger — if it fires first, StartPipeline() is a no-op (idempotent guard inside).
            setTimeout(() => this.stepPipelineRef?.StartPipeline());
            return;
        }
        this.advanceToStep(STEP_ORDER[this.StepIndex + 1]);
    }
    OnBack() {
        if (this.IsFirstStep || this.IsExecuting)
            return;
        this.advanceToStep(STEP_ORDER[this.StepIndex - 1]);
    }
    OnCancel() {
        this.Cancelled.emit();
    }
    /** Re-run server-side schema validation without advancing the step. */
    async OnRetryValidation() {
        await this.WizardState.ValidateSchema();
    }
    /** Clear the current validation errors without re-running validation. */
    OnDismissErrors() {
        this.ValidationErrors = [];
        this.cdr.markForCheck();
    }
    // ─── Pipeline events ───────────────────────────────────────────────────
    OnPipelineCompleted(result) {
        DatabaseDesignerEngine.Instance.invalidateCache();
        this.EntityCreated.emit(result);
    }
    OnPipelineErrored(_msg) {
        // Panel handles the error UI inline — nothing extra needed here
        this.cdr.markForCheck();
    }
    OnCreateAnother() {
        this.Cancelled.emit(); // Parent will re-open a fresh wizard if needed
    }
    // ─── Template helpers ──────────────────────────────────────────────────
    get TableDefinition() { return this.WizardState.TableDefinition; }
    TrackByStep(_, def) { return def.id; }
    // ─── Private helpers ───────────────────────────────────────────────────
    advanceToStep(step) {
        this.ValidationErrors = [];
        this.WizardState.GoToStep(step);
    }
    rebuildStepDefs(activeStep) {
        const activeIndex = STEP_ORDER.indexOf(activeStep);
        this.StepDefs = WIZARD_STEP_DEFS.map((def, i) => ({
            ...def,
            isActive: def.id === activeStep,
            isComplete: i < activeIndex,
        }));
    }
    static ɵfac = function DatabaseCreateWizardComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || DatabaseCreateWizardComponent)(); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: DatabaseCreateWizardComponent, selectors: [["mj-database-create-wizard"]], viewQuery: function DatabaseCreateWizardComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(StepPipelineComponent, 5);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.stepPipelineRef = _t.first);
        } }, outputs: { EntityCreated: "EntityCreated", Cancelled: "Cancelled" }, standalone: false, decls: 5, vars: 4, consts: [[1, "wizard-root"], [3, "Steps", "CurrentStep"], [1, "wizard-body", "wizard-body-full"], ["direction", "horizontal", "gutterSize", "6", 1, "wizard-split"], [1, "wizard-footer"], [3, "PipelineCompleted", "CreateAnother", "TableDefinition"], [3, "size", "minSize"], [1, "wizard-body"], ["role", "alert", 1, "wizard-banner", "wizard-banner-error"], [3, "AvailableSchemas"], [3, "InitialColumns"], [3, "InitialForeignKeys", "AvailableColumns"], [3, "TableDefinition", "ValidationErrors", "IsValidating"], [1, "wizard-preview", 3, "TableDefinition"], [1, "fa-solid", "fa-triangle-exclamation"], [1, "wizard-banner-body"], [1, "wizard-banner-title"], [1, "wizard-banner-list"], [1, "wizard-banner-actions"], ["mjButton", "", "buttonStyle", "secondary", "type", "button", 3, "disabled"], ["type", "button", "title", "Dismiss", 1, "wizard-banner-dismiss", 3, "click"], [1, "fa-solid", "fa-xmark"], ["mjButton", "", "buttonStyle", "secondary", "type", "button", 3, "click", "disabled"], [1, "fa-solid", "fa-spinner", "fa-spin"], [1, "fa-solid", "fa-rotate-right"], [3, "ValueChanged", "AvailableSchemas"], [3, "ColumnsChanged", "InitialColumns"], [3, "ForeignKeysChanged", "InitialForeignKeys", "AvailableColumns"], [1, "footer-left"], ["mjButton", "", "buttonStyle", "ghost", "type", "button"], [1, "footer-right"], ["mjButton", "", "buttonStyle", "secondary", "type", "button", 3, "click"], ["mjButton", "", "buttonStyle", "primary", "type", "button", 3, "click", "disabled"], ["mjButton", "", "buttonStyle", "ghost", "type", "button", 3, "click"], [1, "fa-solid", "fa-arrow-left"], [1, "fa-solid", "fa-rocket-launch"], [1, "fa-solid", "fa-arrow-right"]], template: function DatabaseCreateWizardComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0);
            i0.ɵɵelement(1, "mj-entity-wizard-step-indicator", 1);
            i0.ɵɵconditionalCreate(2, DatabaseCreateWizardComponent_Conditional_2_Template, 2, 1, "div", 2)(3, DatabaseCreateWizardComponent_Conditional_3_Template, 11, 13, "as-split", 3);
            i0.ɵɵconditionalCreate(4, DatabaseCreateWizardComponent_Conditional_4_Template, 10, 3, "div", 4);
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵadvance();
            i0.ɵɵproperty("Steps", ctx.StepDefs)("CurrentStep", ctx.StepIndex);
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.IsExecuting ? 2 : 3);
            i0.ɵɵadvance(2);
            i0.ɵɵconditional(!ctx.IsExecuting ? 4 : -1);
        } }, dependencies: [i1.MJButtonDirective, i2.SplitComponent, i2.SplitAreaComponent, i3.WizardStepIndicatorComponent, i4.DatabasePreviewPaneComponent, i5.StepBasicsComponent, i6.StepFieldsComponent, i7.StepRelationshipsComponent, i8.StepReviewComponent, i9.StepPipelineComponent, i10.AsyncPipe], styles: [".wizard-root[_ngcontent-%COMP%] {\n  display: flex;\n  flex-direction: column;\n  height: 100%;\n  overflow: hidden;\n}\n\n\n\n\n.wizard-split[_ngcontent-%COMP%] {\n  flex: 1;\n  min-height: 0;\n  width: 100%;\n}\n\n.wizard-split[_ngcontent-%COMP%]   as-split-area[_ngcontent-%COMP%] {\n  display: flex;\n  flex-direction: column;\n  min-width: 0;\n  min-height: 0;\n}\n\n.wizard-preview[_ngcontent-%COMP%] {\n  display: block;\n  height: 100%;\n  min-width: 0;\n}\n\n\n\n\n.wizard-body[_ngcontent-%COMP%] {\n  flex: 1;\n  overflow-y: auto;\n  overflow-x: hidden;\n  min-height: 0;\n}\n\n.wizard-body-full[_ngcontent-%COMP%] {\n  width: 100%;\n}\n\n\n\n\n.wizard-banner[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: flex-start;\n  gap: 12px;\n  padding: 12px 16px;\n  margin: 16px 20px 0;\n  border-radius: 8px;\n  border: 1px solid var(--mj-status-error-border);\n  background: var(--mj-status-error-bg);\n  color: var(--mj-status-error-text);\n  flex-shrink: 0;\n}\n\n.wizard-banner[_ngcontent-%COMP%]    > i[_ngcontent-%COMP%] {\n  font-size: 16px;\n  margin-top: 2px;\n  flex-shrink: 0;\n}\n\n.wizard-banner-body[_ngcontent-%COMP%] {\n  flex: 1;\n  min-width: 0;\n  display: flex;\n  flex-direction: column;\n  gap: 4px;\n}\n\n.wizard-banner-title[_ngcontent-%COMP%] {\n  font-weight: 600;\n  font-size: 0.9375rem;\n}\n\n.wizard-banner-list[_ngcontent-%COMP%] {\n  margin: 0;\n  padding-left: 18px;\n  font-size: 0.875rem;\n  line-height: 1.5;\n  display: flex;\n  flex-direction: column;\n  gap: 2px;\n}\n\n.wizard-banner-list[_ngcontent-%COMP%]   li[_ngcontent-%COMP%] {\n  word-break: break-word;\n}\n\n.wizard-banner-actions[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  flex-shrink: 0;\n}\n\n.wizard-banner-dismiss[_ngcontent-%COMP%] {\n  background: transparent;\n  border: 0;\n  color: var(--mj-status-error-text);\n  cursor: pointer;\n  padding: 4px 8px;\n  border-radius: 4px;\n  opacity: 0.7;\n  transition: opacity 120ms, background-color 120ms;\n}\n\n.wizard-banner-dismiss[_ngcontent-%COMP%]:hover {\n  opacity: 1;\n  background: color-mix(in srgb, var(--mj-status-error) 15%, transparent);\n}\n\n\n\n\n.wizard-footer[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  padding: 14px 20px;\n  border-top: 1px solid var(--mj-border-subtle);\n  background: var(--mj-bg-surface-card);\n  flex-shrink: 0;\n}\n\n.footer-right[_ngcontent-%COMP%] {\n  display: flex;\n  gap: 12px;\n  align-items: center;\n}"], changeDetection: 0 });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DatabaseCreateWizardComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'mj-database-create-wizard', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"wizard-root\">\n\n  <!-- \u2500\u2500 Step indicator \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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n  <mj-entity-wizard-step-indicator\n    [Steps]=\"StepDefs\"\n    [CurrentStep]=\"StepIndex\">\n  </mj-entity-wizard-step-indicator>\n\n  <!-- \u2500\u2500 Split body: steps (left) + live preview (right) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n  @if (IsExecuting) {\n\n    <!-- Pipeline takes the full width while it runs -->\n    <div class=\"wizard-body wizard-body-full\">\n      <mj-entity-step-pipeline\n        [TableDefinition]=\"TableDefinition\"\n        (PipelineCompleted)=\"OnPipelineCompleted($event)\"\n        (CreateAnother)=\"OnCreateAnother()\">\n      </mj-entity-step-pipeline>\n    </div>\n\n  } @else {\n\n    <as-split direction=\"horizontal\" class=\"wizard-split\" gutterSize=\"6\">\n\n      <as-split-area [size]=\"55\" [minSize]=\"40\">\n        <div class=\"wizard-body\">\n\n          <!-- \u2500\u2500 Inline validation banner (replaces bottom-floating error bar) \u2500\u2500\u2500 -->\n          @if (ValidationErrors.length > 0) {\n            <div class=\"wizard-banner wizard-banner-error\" role=\"alert\">\n              <i class=\"fa-solid fa-triangle-exclamation\"></i>\n              <div class=\"wizard-banner-body\">\n                <div class=\"wizard-banner-title\">\n                  @if (ValidationErrors.length === 1) {\n                    We hit a problem\n                  } @else {\n                    We hit {{ ValidationErrors.length }} problems\n                  }\n                </div>\n                <ul class=\"wizard-banner-list\">\n                  @for (err of ValidationErrors; track $index) {\n                    <li>{{ err }}</li>\n                  }\n                </ul>\n              </div>\n              <div class=\"wizard-banner-actions\">\n                @if (CurrentStep === 'relationships' || CurrentStep === 'review') {\n                  <button\n                    mjButton\n                    buttonStyle=\"secondary\"\n                    type=\"button\"\n                    [disabled]=\"IsValidating\"\n                    (click)=\"OnRetryValidation()\">\n                    @if (IsValidating) {\n                      <i class=\"fa-solid fa-spinner fa-spin\"></i>\n                      Retrying\u2026\n                    } @else {\n                      <i class=\"fa-solid fa-rotate-right\"></i>\n                      Retry\n                    }\n                  </button>\n                }\n                <button\n                  type=\"button\"\n                  class=\"wizard-banner-dismiss\"\n                  title=\"Dismiss\"\n                  (click)=\"OnDismissErrors()\">\n                  <i class=\"fa-solid fa-xmark\"></i>\n                </button>\n              </div>\n            </div>\n          }\n\n          <!-- Step 1: Basics -->\n          @if (CurrentStep === 'basics') {\n            <mj-entity-step-basics\n              [AvailableSchemas]=\"AvailableSchemas\"\n              (ValueChanged)=\"OnBasicsChanged($event)\">\n            </mj-entity-step-basics>\n          }\n\n          <!-- Step 2: Fields -->\n          @if (CurrentStep === 'fields') {\n            <mj-entity-step-fields\n              [InitialColumns]=\"TableDefinition.Columns ?? []\"\n              (ColumnsChanged)=\"OnFieldsChanged($event)\">\n            </mj-entity-step-fields>\n          }\n\n          <!-- Step 3: Relationships -->\n          @if (CurrentStep === 'relationships') {\n            <mj-entity-step-relationships\n              [InitialForeignKeys]=\"TableDefinition.ForeignKeys ?? []\"\n              [AvailableColumns]=\"TableDefinition.Columns ?? []\"\n              (ForeignKeysChanged)=\"OnRelationshipsChanged($event)\">\n            </mj-entity-step-relationships>\n          }\n\n          <!-- Step 4: Review & Create -->\n          @if (CurrentStep === 'review') {\n            <mj-entity-step-review\n              [TableDefinition]=\"TableDefinition\"\n              [ValidationErrors]=\"ValidationErrors\"\n              [IsValidating]=\"IsValidating\">\n            </mj-entity-step-review>\n          }\n\n        </div>\n      </as-split-area>\n\n      <as-split-area [size]=\"45\" [minSize]=\"25\">\n        <mj-database-preview-pane\n          class=\"wizard-preview\"\n          [TableDefinition]=\"(WizardState.tableDefinition$ | async) ?? {}\">\n        </mj-database-preview-pane>\n      </as-split-area>\n\n    </as-split>\n\n  }\n\n  <!-- \u2500\u2500 Footer navigation \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\u2500\u2500\u2500\u2500\u2500\u2500 -->\n  @if (!IsExecuting) {\n    <div class=\"wizard-footer\">\n      <div class=\"footer-left\">\n        @if (!IsFirstStep) {\n          <button\n            mjButton\n            buttonStyle=\"ghost\"\n            type=\"button\"\n            (click)=\"OnBack()\">\n            <i class=\"fa-solid fa-arrow-left\"></i>\n            Back\n          </button>\n        }\n      </div>\n      <div class=\"footer-right\">\n        <button\n          mjButton\n          buttonStyle=\"secondary\"\n          type=\"button\"\n          (click)=\"OnCancel()\">\n          Cancel\n        </button>\n        <button\n          mjButton\n          buttonStyle=\"primary\"\n          type=\"button\"\n          [disabled]=\"IsValidating\"\n          (click)=\"OnNext()\">\n          @if (IsValidating) {\n            <i class=\"fa-solid fa-spinner fa-spin\"></i>\n            Validating\u2026\n          } @else if (CurrentStep === 'review') {\n            Create Entity\n            <i class=\"fa-solid fa-rocket-launch\"></i>\n          } @else {\n            Next\n            <i class=\"fa-solid fa-arrow-right\"></i>\n          }\n        </button>\n      </div>\n    </div>\n  }\n\n</div>\n", styles: [".wizard-root {\n  display: flex;\n  flex-direction: column;\n  height: 100%;\n  overflow: hidden;\n}\n\n/* \u2500\u2500 Split body \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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n.wizard-split {\n  flex: 1;\n  min-height: 0;\n  width: 100%;\n}\n\n.wizard-split as-split-area {\n  display: flex;\n  flex-direction: column;\n  min-width: 0;\n  min-height: 0;\n}\n\n.wizard-preview {\n  display: block;\n  height: 100%;\n  min-width: 0;\n}\n\n/* \u2500\u2500 Body \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\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.wizard-body {\n  flex: 1;\n  overflow-y: auto;\n  overflow-x: hidden;\n  min-height: 0;\n}\n\n.wizard-body-full {\n  width: 100%;\n}\n\n/* \u2500\u2500 Inline banner (at top of step content) \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.wizard-banner {\n  display: flex;\n  align-items: flex-start;\n  gap: 12px;\n  padding: 12px 16px;\n  margin: 16px 20px 0;\n  border-radius: 8px;\n  border: 1px solid var(--mj-status-error-border);\n  background: var(--mj-status-error-bg);\n  color: var(--mj-status-error-text);\n  flex-shrink: 0;\n}\n\n.wizard-banner > i {\n  font-size: 16px;\n  margin-top: 2px;\n  flex-shrink: 0;\n}\n\n.wizard-banner-body {\n  flex: 1;\n  min-width: 0;\n  display: flex;\n  flex-direction: column;\n  gap: 4px;\n}\n\n.wizard-banner-title {\n  font-weight: 600;\n  font-size: 0.9375rem;\n}\n\n.wizard-banner-list {\n  margin: 0;\n  padding-left: 18px;\n  font-size: 0.875rem;\n  line-height: 1.5;\n  display: flex;\n  flex-direction: column;\n  gap: 2px;\n}\n\n.wizard-banner-list li {\n  word-break: break-word;\n}\n\n.wizard-banner-actions {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  flex-shrink: 0;\n}\n\n.wizard-banner-dismiss {\n  background: transparent;\n  border: 0;\n  color: var(--mj-status-error-text);\n  cursor: pointer;\n  padding: 4px 8px;\n  border-radius: 4px;\n  opacity: 0.7;\n  transition: opacity 120ms, background-color 120ms;\n}\n\n.wizard-banner-dismiss:hover {\n  opacity: 1;\n  background: color-mix(in srgb, var(--mj-status-error) 15%, transparent);\n}\n\n/* \u2500\u2500 Footer \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\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.wizard-footer {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  padding: 14px 20px;\n  border-top: 1px solid var(--mj-border-subtle);\n  background: var(--mj-bg-surface-card);\n  flex-shrink: 0;\n}\n\n.footer-right {\n  display: flex;\n  gap: 12px;\n  align-items: center;\n}\n"] }]
    }], () => [], { EntityCreated: [{
            type: Output
        }], Cancelled: [{
            type: Output
        }], stepPipelineRef: [{
            type: ViewChild,
            args: [StepPipelineComponent]
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(DatabaseCreateWizardComponent, { className: "DatabaseCreateWizardComponent", filePath: "src/DatabaseDesigner/components/create-wizard/database-create-wizard.component.ts", lineNumber: 51 }); })();
//# sourceMappingURL=database-create-wizard.component.js.map