import { Component } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "../../services/component-studio-state.service";
import * as i2 from "../editors/spec-editor.component";
import * as i3 from "../editors/code-editor-panel.component";
import * as i4 from "../editors/requirements-editor.component";
import * as i5 from "../editors/data-requirements-editor.component";
import * as i6 from "../form-builder/form-builder-tab.component";
function EditorTabsComponent_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 3);
    i0.ɵɵlistener("click", function EditorTabsComponent_Conditional_2_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.SelectTab(5)); });
    i0.ɵɵelement(1, "i", 12);
    i0.ɵɵtext(2, " Form Builder ");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵclassProp("active", ctx_r1.state.ActiveTab === 5);
} }
function EditorTabsComponent_Case_20_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-spec-editor");
} }
function EditorTabsComponent_Case_21_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-code-editor-panel");
} }
function EditorTabsComponent_Case_22_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-requirements-editor", 11);
} if (rf & 2) {
    i0.ɵɵproperty("Field", "functionalRequirements")("Title", "Functional Requirements");
} }
function EditorTabsComponent_Case_23_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-requirements-editor", 11);
} if (rf & 2) {
    i0.ɵɵproperty("Field", "technicalDesign")("Title", "Technical Design");
} }
function EditorTabsComponent_Case_24_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-data-requirements-editor");
} }
function EditorTabsComponent_Case_25_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "mj-form-builder-tab", 13);
    i0.ɵɵlistener("RequestCodeTab", function EditorTabsComponent_Case_25_Template_mj_form_builder_tab_RequestCodeTab_0_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.SelectTab(1)); });
    i0.ɵɵelementEnd();
} }
/**
 * Tab index constants. The Form Builder tab is conditional — it only shows
 * up for form-role components — so we key tabs by stable index rather than
 * position-in-array. State service stores ActiveTab as the numeric index.
 */
const TAB_SPEC = 0;
const TAB_CODE = 1;
const TAB_REQUIREMENTS = 2;
const TAB_DESIGN = 3;
const TAB_DATA = 4;
const TAB_FORM_BUILDER = 5;
export class EditorTabsComponent {
    state;
    cdr;
    stateChangedSub = null;
    /** Tracked so we can default to the Form Builder tab the first time a form-role component loads. */
    lastFormRole = false;
    constructor(state, cdr) {
        this.state = state;
        this.cdr = cdr;
    }
    ngOnInit() {
        this.lastFormRole = this.IsFormRoleComponent;
        this.maybeAutoSelectFormBuilder();
        this.stateChangedSub = this.state.StateChanged.subscribe(() => {
            this.maybeAutoSelectFormBuilder();
            this.cdr.detectChanges();
        });
    }
    ngOnDestroy() {
        if (this.stateChangedSub) {
            this.stateChangedSub.unsubscribe();
            this.stateChangedSub = null;
        }
    }
    SelectTab(index) {
        this.state.ActiveTab = index;
        this.cdr.detectChanges();
    }
    /** True iff the current spec declares itself form-role. */
    get IsFormRoleComponent() {
        const spec = this.state.GetCurrentSpec();
        return spec?.componentRole === 'form' || spec?.type === 'form';
    }
    /**
     * Auto-select the Form Builder tab the first time a form-role component
     * appears in state. Don't fight the user after that — if they switched
     * to Code or Spec, leave them there on subsequent state updates.
     */
    maybeAutoSelectFormBuilder() {
        const isForm = this.IsFormRoleComponent;
        if (isForm && !this.lastFormRole) {
            this.state.ActiveTab = TAB_FORM_BUILDER;
        }
        else if (!isForm && this.lastFormRole) {
            // If we leave a form-role component, drop back to Spec.
            if (this.state.ActiveTab === TAB_FORM_BUILDER) {
                this.state.ActiveTab = TAB_SPEC;
            }
        }
        this.lastFormRole = isForm;
    }
    static ɵfac = function EditorTabsComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || EditorTabsComponent)(i0.ɵɵdirectiveInject(i1.ComponentStudioStateService), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: EditorTabsComponent, selectors: [["mj-editor-tabs"]], standalone: false, decls: 26, vars: 12, consts: [[1, "editor-tabs-container"], [1, "tab-bar"], [1, "tab-pill", 3, "active"], [1, "tab-pill", 3, "click"], [1, "fa-solid", "fa-file-code"], [1, "fa-solid", "fa-code"], [1, "fa-solid", "fa-clipboard-list"], [1, "fa-solid", "fa-drafting-compass"], [1, "fa-solid", "fa-database"], [1, "tab-spacer"], [1, "tab-content"], [3, "Field", "Title"], [1, "fa-solid", "fa-table-list"], [3, "RequestCodeTab"]], template: function EditorTabsComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0)(1, "div", 1);
            i0.ɵɵconditionalCreate(2, EditorTabsComponent_Conditional_2_Template, 3, 2, "button", 2);
            i0.ɵɵelementStart(3, "button", 3);
            i0.ɵɵlistener("click", function EditorTabsComponent_Template_button_click_3_listener() { return ctx.SelectTab(0); });
            i0.ɵɵelement(4, "i", 4);
            i0.ɵɵtext(5, " Spec ");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(6, "button", 3);
            i0.ɵɵlistener("click", function EditorTabsComponent_Template_button_click_6_listener() { return ctx.SelectTab(1); });
            i0.ɵɵelement(7, "i", 5);
            i0.ɵɵtext(8, " Code ");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(9, "button", 3);
            i0.ɵɵlistener("click", function EditorTabsComponent_Template_button_click_9_listener() { return ctx.SelectTab(2); });
            i0.ɵɵelement(10, "i", 6);
            i0.ɵɵtext(11, " Requirements ");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(12, "button", 3);
            i0.ɵɵlistener("click", function EditorTabsComponent_Template_button_click_12_listener() { return ctx.SelectTab(3); });
            i0.ɵɵelement(13, "i", 7);
            i0.ɵɵtext(14, " Design ");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(15, "button", 3);
            i0.ɵɵlistener("click", function EditorTabsComponent_Template_button_click_15_listener() { return ctx.SelectTab(4); });
            i0.ɵɵelement(16, "i", 8);
            i0.ɵɵtext(17, " Data ");
            i0.ɵɵelementEnd();
            i0.ɵɵelement(18, "span", 9);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(19, "div", 10);
            i0.ɵɵconditionalCreate(20, EditorTabsComponent_Case_20_Template, 1, 0, "mj-spec-editor")(21, EditorTabsComponent_Case_21_Template, 1, 0, "mj-code-editor-panel")(22, EditorTabsComponent_Case_22_Template, 1, 2, "mj-requirements-editor", 11)(23, EditorTabsComponent_Case_23_Template, 1, 2, "mj-requirements-editor", 11)(24, EditorTabsComponent_Case_24_Template, 1, 0, "mj-data-requirements-editor")(25, EditorTabsComponent_Case_25_Template, 1, 0, "mj-form-builder-tab");
            i0.ɵɵelementEnd()();
        } if (rf & 2) {
            let tmp_6_0;
            i0.ɵɵadvance(2);
            i0.ɵɵconditional(ctx.IsFormRoleComponent ? 2 : -1);
            i0.ɵɵadvance();
            i0.ɵɵclassProp("active", ctx.state.ActiveTab === 0);
            i0.ɵɵadvance(3);
            i0.ɵɵclassProp("active", ctx.state.ActiveTab === 1);
            i0.ɵɵadvance(3);
            i0.ɵɵclassProp("active", ctx.state.ActiveTab === 2);
            i0.ɵɵadvance(3);
            i0.ɵɵclassProp("active", ctx.state.ActiveTab === 3);
            i0.ɵɵadvance(3);
            i0.ɵɵclassProp("active", ctx.state.ActiveTab === 4);
            i0.ɵɵadvance(5);
            i0.ɵɵconditional((tmp_6_0 = ctx.state.ActiveTab) === 0 ? 20 : tmp_6_0 === 1 ? 21 : tmp_6_0 === 2 ? 22 : tmp_6_0 === 3 ? 23 : tmp_6_0 === 4 ? 24 : tmp_6_0 === 5 ? 25 : -1);
        } }, dependencies: [i2.SpecEditorComponent, i3.CodeEditorPanelComponent, i4.RequirementsEditorComponent, i5.DataRequirementsEditorComponent, i6.FormBuilderTabComponent], styles: ["[_nghost-%COMP%] {\n      display: flex;\n      flex: 1;\n      overflow: hidden;\n    }\n\n    .editor-tabs-container[_ngcontent-%COMP%] {\n      display: flex;\n      flex-direction: column;\n      flex: 1;\n      overflow: hidden;\n    }\n\n    .tab-bar[_ngcontent-%COMP%] {\n      display: flex;\n      align-items: center;\n      padding: 0 8px;\n      height: 38px;\n      background: var(--mj-bg-surface-sunken);\n      border-bottom: 1px solid var(--mj-border-default);\n      flex-shrink: 0;\n      gap: 2px;\n    }\n\n    .tab-pill[_ngcontent-%COMP%] {\n      display: inline-flex;\n      align-items: center;\n      gap: 5px;\n      padding: 5px 12px;\n      border: none;\n      border-radius: 8px;\n      background: transparent;\n      color: var(--mj-text-secondary);\n      font-size: 12px;\n      font-weight: 500;\n      cursor: pointer;\n      transition: all 0.15s ease;\n      white-space: nowrap;\n      font-family: inherit;\n    }\n\n    .tab-pill[_ngcontent-%COMP%]:hover {\n      background: var(--mj-bg-surface-sunken);\n      color: var(--mj-text-primary);\n    }\n\n    .tab-pill.active[_ngcontent-%COMP%] {\n      background: var(--mj-bg-surface);\n      color: var(--mj-brand-primary);\n      font-weight: 600;\n      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);\n    }\n\n    .tab-pill[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n      font-size: 11px;\n    }\n\n    .tab-spacer[_ngcontent-%COMP%] {\n      flex: 1;\n    }\n\n    .tab-content[_ngcontent-%COMP%] {\n      flex: 1;\n      overflow: hidden;\n      display: flex;\n      flex-direction: column;\n    }\n\n    .tab-content[_ngcontent-%COMP%]    > *[_ngcontent-%COMP%] {\n      flex: 1;\n      overflow: hidden;\n    }"] });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(EditorTabsComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'mj-editor-tabs', template: `
    <div class="editor-tabs-container">
      <div class="tab-bar">
        @if (IsFormRoleComponent) {
          <button class="tab-pill" [class.active]="state.ActiveTab === ${TAB_FORM_BUILDER}" (click)="SelectTab(${TAB_FORM_BUILDER})">
            <i class="fa-solid fa-table-list"></i> Form Builder
          </button>
        }
        <button class="tab-pill" [class.active]="state.ActiveTab === ${TAB_SPEC}" (click)="SelectTab(${TAB_SPEC})">
          <i class="fa-solid fa-file-code"></i> Spec
        </button>
        <button class="tab-pill" [class.active]="state.ActiveTab === ${TAB_CODE}" (click)="SelectTab(${TAB_CODE})">
          <i class="fa-solid fa-code"></i> Code
        </button>
        <button class="tab-pill" [class.active]="state.ActiveTab === ${TAB_REQUIREMENTS}" (click)="SelectTab(${TAB_REQUIREMENTS})">
          <i class="fa-solid fa-clipboard-list"></i> Requirements
        </button>
        <button class="tab-pill" [class.active]="state.ActiveTab === ${TAB_DESIGN}" (click)="SelectTab(${TAB_DESIGN})">
          <i class="fa-solid fa-drafting-compass"></i> Design
        </button>
        <button class="tab-pill" [class.active]="state.ActiveTab === ${TAB_DATA}" (click)="SelectTab(${TAB_DATA})">
          <i class="fa-solid fa-database"></i> Data
        </button>
        <span class="tab-spacer"></span>
      </div>

      <div class="tab-content">
        @switch (state.ActiveTab) {
          @case (${TAB_SPEC}) {
            <mj-spec-editor></mj-spec-editor>
          }
          @case (${TAB_CODE}) {
            <mj-code-editor-panel></mj-code-editor-panel>
          }
          @case (${TAB_REQUIREMENTS}) {
            <mj-requirements-editor [Field]="'functionalRequirements'" [Title]="'Functional Requirements'"></mj-requirements-editor>
          }
          @case (${TAB_DESIGN}) {
            <mj-requirements-editor [Field]="'technicalDesign'" [Title]="'Technical Design'"></mj-requirements-editor>
          }
          @case (${TAB_DATA}) {
            <mj-data-requirements-editor></mj-data-requirements-editor>
          }
          @case (${TAB_FORM_BUILDER}) {
            <mj-form-builder-tab (RequestCodeTab)="SelectTab(${TAB_CODE})"></mj-form-builder-tab>
          }
        }
      </div>
    </div>
  `, styles: ["\n    :host {\n      display: flex;\n      flex: 1;\n      overflow: hidden;\n    }\n\n    .editor-tabs-container {\n      display: flex;\n      flex-direction: column;\n      flex: 1;\n      overflow: hidden;\n    }\n\n    .tab-bar {\n      display: flex;\n      align-items: center;\n      padding: 0 8px;\n      height: 38px;\n      background: var(--mj-bg-surface-sunken);\n      border-bottom: 1px solid var(--mj-border-default);\n      flex-shrink: 0;\n      gap: 2px;\n    }\n\n    .tab-pill {\n      display: inline-flex;\n      align-items: center;\n      gap: 5px;\n      padding: 5px 12px;\n      border: none;\n      border-radius: 8px;\n      background: transparent;\n      color: var(--mj-text-secondary);\n      font-size: 12px;\n      font-weight: 500;\n      cursor: pointer;\n      transition: all 0.15s ease;\n      white-space: nowrap;\n      font-family: inherit;\n    }\n\n    .tab-pill:hover {\n      background: var(--mj-bg-surface-sunken);\n      color: var(--mj-text-primary);\n    }\n\n    .tab-pill.active {\n      background: var(--mj-bg-surface);\n      color: var(--mj-brand-primary);\n      font-weight: 600;\n      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);\n    }\n\n    .tab-pill i {\n      font-size: 11px;\n    }\n\n    .tab-spacer {\n      flex: 1;\n    }\n\n    .tab-content {\n      flex: 1;\n      overflow: hidden;\n      display: flex;\n      flex-direction: column;\n    }\n\n    .tab-content > * {\n      flex: 1;\n      overflow: hidden;\n    }\n  "] }]
    }], () => [{ type: i1.ComponentStudioStateService }, { type: i0.ChangeDetectorRef }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(EditorTabsComponent, { className: "EditorTabsComponent", filePath: "src/ComponentStudio/components/workspace/editor-tabs.component.ts", lineNumber: 146 }); })();
//# sourceMappingURL=editor-tabs.component.js.map