/**
 * @fileoverview Classify · Content Types tab.
 *
 * Self-contained sub-page: owns its header-interior and the content-type cards
 * grid. Receives the shared raw data needed to build the cards from the host
 * orchestrator (content types, sources, items, and the accurate total item
 * count). The slide-in CRUD form stays in the host — this tab emits
 * Add/Edit intents up via @Output and the host opens its existing form.
 */
import { Component, ChangeDetectorRef, EventEmitter, Input, Output, inject } from '@angular/core';
import { BaseAngularComponent } from '@memberjunction/ng-base-types';
import { formatNumber } from '../shared/classify.format';
import * as i0 from "@angular/core";
import * as i1 from "@memberjunction/ng-shared-generic";
import * as i2 from "@memberjunction/ng-ui-components";
import * as i3 from "../components/classify-org-context-editor.component";
const _forTrack0 = ($index, $item) => $item.ID;
function ClassifyTypesTabComponent_Conditional_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 18);
    i0.ɵɵelementStart(1, "span", 5);
    i0.ɵɵtext(2, "Refreshing\u2026");
    i0.ɵɵelementEnd();
} }
function ClassifyTypesTabComponent_Conditional_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 19);
    i0.ɵɵelementStart(1, "span", 5);
    i0.ɵɵtext(2, "Refresh");
    i0.ɵɵelementEnd();
} }
function ClassifyTypesTabComponent_Conditional_11_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 8);
    i0.ɵɵelement(1, "mj-loading", 20);
    i0.ɵɵelementEnd();
} }
function ClassifyTypesTabComponent_For_17_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 13)(1, "div", 21)(2, "span", 22);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "span", 23);
    i0.ɵɵtext(5);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(6, "div", 24)(7, "span", 25);
    i0.ɵɵtext(8, "Description");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(9, "span", 26);
    i0.ɵɵtext(10);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(11, "div", 24)(12, "span", 25);
    i0.ɵɵtext(13, "Sources Using");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(14, "span", 26);
    i0.ɵɵtext(15);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(16, "div", 24)(17, "span", 25);
    i0.ɵɵtext(18, "Items Tagged");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(19, "span", 26);
    i0.ɵɵtext(20);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(21, "div", 27);
    i0.ɵɵelement(22, "i", 28);
    i0.ɵɵelementStart(23, "span");
    i0.ɵɵtext(24);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(25, "div", 29);
    i0.ɵɵelement(26, "div", 30);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(27, "span");
    i0.ɵɵtext(28);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(29, "span", 31);
    i0.ɵɵtext(30, "tags/item");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(31, "div", 32)(32, "button", 33);
    i0.ɵɵlistener("click", function ClassifyTypesTabComponent_For_17_Template_button_click_32_listener() { const card_r2 = i0.ɵɵrestoreView(_r1).$implicit; const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.onEditType(card_r2)); });
    i0.ɵɵelement(33, "i", 34);
    i0.ɵɵtext(34, " Edit");
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const card_r2 = ctx.$implicit;
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate(card_r2.Name);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(card_r2.AIModelName);
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate(card_r2.Description || "\u2014");
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate(card_r2.SourcesUsing);
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate(ctx_r2.formatNumber(card_r2.ItemsTagged));
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate(card_r2.MinTags);
    i0.ɵɵadvance(2);
    i0.ɵɵstyleProp("left", card_r2.RangeLeftPct, "%")("right", card_r2.RangeRightPct, "%");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(card_r2.MaxTags);
} }
export class ClassifyTypesTabComponent extends BaseAngularComponent {
    cdr = inject(ChangeDetectorRef);
    /** Shown while a manual Refresh() recomputes the content-type cards. */
    IsLoading = false;
    /** Raw `MJ: Content Types` rows — the primary source for the cards. */
    _contentTypes = [];
    set ContentTypes(value) {
        this._contentTypes = value ?? [];
        this.rebuild();
    }
    get ContentTypes() {
        return this._contentTypes;
    }
    /** Raw `MJ: Content Sources` rows — used to count sources per content type. */
    _sources = [];
    set Sources(value) {
        this._sources = value ?? [];
        this.rebuild();
    }
    get Sources() {
        return this._sources;
    }
    /** Raw `MJ: Content Items` rows — used to count items per content type. */
    _items = [];
    set Items(value) {
        this._items = value ?? [];
        this.rebuild();
    }
    get Items() {
        return this._items;
    }
    /** Accurate total item count from TotalRowCount (used when a single content type exists). */
    _totalItemCount = 0;
    set TotalItemCount(value) {
        this._totalItemCount = value ?? 0;
        this.rebuild();
    }
    get TotalItemCount() {
        return this._totalItemCount;
    }
    ContentTypeCards = [];
    /** Template-facing formatter (exposed so `formatNumber(...)` resolves in the view). */
    formatNumber = formatNumber;
    /** Bubble Add/Edit intents to the host, which owns the slide-in CRUD form. */
    AddTypeRequested = new EventEmitter();
    EditTypeRequested = new EventEmitter();
    /**
     * Recompute the content-type cards from the current host-supplied inputs. The
     * data is host-owned (flows in via @Input); Refresh rebuilds the view models
     * and surfaces a brief loading state for user feedback.
     */
    async Refresh() {
        this.IsLoading = true;
        this.cdr.detectChanges();
        this.rebuild();
        this.IsLoading = false;
        this.cdr.detectChanges();
    }
    onAddType() {
        this.AddTypeRequested.emit();
    }
    onEditType(card) {
        this.EditTypeRequested.emit(card);
    }
    /** Rebuild the card view models from the current inputs. */
    rebuild() {
        const sourcesUsingByType = this.countSourcesByContentType();
        // When items are capped by MaxRows, countItemsByContentType undercounts.
        // For a single content type, use the accurate TotalItemCount.
        const singleType = this._contentTypes.length === 1;
        const itemsByType = singleType ? null : this.countItemsByContentType();
        this.ContentTypeCards = this._contentTypes.map(ct => {
            const id = ct['ID'];
            const minTags = ct['MinTags'] ?? 1;
            const maxTags = ct['MaxTags'] ?? 10;
            const range = 15; // max possible
            return {
                ID: id,
                Name: ct['Name'] ?? 'Unnamed',
                Description: ct['Description'] ?? '',
                AIModelName: ct['AIModel'] ?? 'Default Model',
                AIModelID: ct['AIModelID'] ?? '',
                MinTags: minTags,
                MaxTags: maxTags,
                SourcesUsing: sourcesUsingByType.get(id) ?? 0,
                ItemsTagged: singleType ? this._totalItemCount : (itemsByType.get(id) ?? 0),
                RangeLeftPct: Math.round((minTags / range) * 100),
                RangeRightPct: Math.round(100 - (maxTags / range) * 100),
                EmbeddingModelID: ct['EmbeddingModelID'] ?? '',
                VectorIndexID: ct['VectorIndexID'] ?? ''
            };
        });
    }
    countSourcesByContentType() {
        const counts = new Map();
        for (const source of this._sources) {
            const typeId = source['ContentTypeID'];
            if (typeId)
                counts.set(typeId, (counts.get(typeId) ?? 0) + 1);
        }
        return counts;
    }
    countItemsByContentType() {
        const counts = new Map();
        for (const item of this._items) {
            const typeId = item['ContentTypeID'];
            if (typeId)
                counts.set(typeId, (counts.get(typeId) ?? 0) + 1);
        }
        return counts;
    }
    static ɵfac = /*@__PURE__*/ (() => { let ɵClassifyTypesTabComponent_BaseFactory; return function ClassifyTypesTabComponent_Factory(__ngFactoryType__) { return (ɵClassifyTypesTabComponent_BaseFactory || (ɵClassifyTypesTabComponent_BaseFactory = i0.ɵɵgetInheritedFactory(ClassifyTypesTabComponent)))(__ngFactoryType__ || ClassifyTypesTabComponent); }; })();
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ClassifyTypesTabComponent, selectors: [["classify-types-tab"]], inputs: { ContentTypes: "ContentTypes", Sources: "Sources", Items: "Items", TotalItemCount: "TotalItemCount" }, outputs: { AddTypeRequested: "AddTypeRequested", EditTypeRequested: "EditTypeRequested" }, standalone: false, features: [i0.ɵɵInheritDefinitionFeature], decls: 24, vars: 6, consts: [["Title", "Content Types", "Subtitle", "Configure AI tagging rules per content category"], ["actions", ""], ["mjButton", "", "variant", "secondary", "size", "sm", 3, "click", "disabled"], ["mjButton", "", "variant", "primary", "size", "sm", 3, "click"], [1, "fa-solid", "fa-plus"], [1, "mj-action-label"], [3, "Padding", "Flex"], [1, "at-main-area"], [1, "at-loading-overlay"], [1, "at-page-body"], [1, "at-org-ctx-wrap"], [3, "Provider"], [1, "at-ct-grid"], [1, "at-ct-card"], [1, "at-add-type-card", 3, "click"], [1, "fa-solid", "fa-plus-circle"], [2, "font-size", "0.85rem", "font-weight", "600"], [2, "font-size", "0.72rem"], [1, "fa-solid", "fa-spinner", "fa-spin"], [1, "fa-solid", "fa-arrows-rotate"], ["text", "Refreshing content types\u2026"], [1, "at-ct-card-header"], [1, "at-ct-card-name"], [1, "at-ct-card-model"], [1, "at-ct-field"], [1, "at-ct-field-label"], [1, "at-ct-field-value"], [1, "at-ct-tag-range"], [1, "fa-solid", "fa-tags"], [1, "at-ct-tag-range-bar"], [1, "at-ct-tag-range-fill"], [1, "at-ct-range-suffix"], [1, "at-source-card-actions", 2, "margin-top", "10px"], [1, "at-source-action-btn", 3, "click"], [1, "fa-solid", "fa-pen"]], template: function ClassifyTypesTabComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "mj-page-header-interior", 0)(1, "div", 1)(2, "button", 2);
            i0.ɵɵlistener("click", function ClassifyTypesTabComponent_Template_button_click_2_listener() { return ctx.Refresh(); });
            i0.ɵɵconditionalCreate(3, ClassifyTypesTabComponent_Conditional_3_Template, 3, 0)(4, ClassifyTypesTabComponent_Conditional_4_Template, 3, 0);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(5, "button", 3);
            i0.ɵɵlistener("click", function ClassifyTypesTabComponent_Template_button_click_5_listener() { return ctx.onAddType(); });
            i0.ɵɵelement(6, "i", 4);
            i0.ɵɵelementStart(7, "span", 5);
            i0.ɵɵtext(8, "Add Type");
            i0.ɵɵelementEnd()()()();
            i0.ɵɵelementStart(9, "mj-page-body-interior", 6)(10, "div", 7);
            i0.ɵɵconditionalCreate(11, ClassifyTypesTabComponent_Conditional_11_Template, 2, 0, "div", 8);
            i0.ɵɵelementStart(12, "div", 9)(13, "div", 10);
            i0.ɵɵelement(14, "classify-org-context-editor", 11);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(15, "div", 12);
            i0.ɵɵrepeaterCreate(16, ClassifyTypesTabComponent_For_17_Template, 35, 11, "div", 13, _forTrack0);
            i0.ɵɵelementStart(18, "div", 14);
            i0.ɵɵlistener("click", function ClassifyTypesTabComponent_Template_div_click_18_listener() { return ctx.onAddType(); });
            i0.ɵɵelement(19, "i", 15);
            i0.ɵɵelementStart(20, "span", 16);
            i0.ɵɵtext(21, "Add Content Type");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(22, "span", 17);
            i0.ɵɵtext(23, "Configure tagging rules");
            i0.ɵɵelementEnd()()()()()();
        } if (rf & 2) {
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("disabled", ctx.IsLoading);
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.IsLoading ? 3 : 4);
            i0.ɵɵadvance(6);
            i0.ɵɵproperty("Padding", false)("Flex", true);
            i0.ɵɵadvance(2);
            i0.ɵɵconditional(ctx.IsLoading ? 11 : -1);
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("Provider", ctx.Provider);
            i0.ɵɵadvance(2);
            i0.ɵɵrepeater(ctx.ContentTypeCards);
        } }, dependencies: [i1.LoadingComponent, i2.MJButtonDirective, i2.MJPageHeaderInteriorComponent, i2.MJPageBodyInteriorComponent, i3.ClassifyOrgContextEditorComponent], styles: ["\n\n\n\n\n\n\n\n\n\n.at-org-ctx-wrap[_ngcontent-%COMP%] {\n    margin-bottom: 16px;\n}"] });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ClassifyTypesTabComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'classify-types-tab', template: "<mj-page-header-interior\n    Title=\"Content Types\"\n    Subtitle=\"Configure AI tagging rules per content category\">\n  <div actions>\n    <button mjButton variant=\"secondary\" size=\"sm\" (click)=\"Refresh()\" [disabled]=\"IsLoading\">\n      @if (IsLoading) {\n        <i class=\"fa-solid fa-spinner fa-spin\"></i> <span class=\"mj-action-label\">Refreshing\u2026</span>\n      } @else {\n        <i class=\"fa-solid fa-arrows-rotate\"></i> <span class=\"mj-action-label\">Refresh</span>\n      }\n    </button>\n    <button mjButton variant=\"primary\" size=\"sm\" (click)=\"onAddType()\">\n      <i class=\"fa-solid fa-plus\"></i> <span class=\"mj-action-label\">Add Type</span>\n    </button>\n  </div>\n</mj-page-header-interior>\n\n<mj-page-body-interior [Padding]=\"false\" [Flex]=\"true\">\n  <div class=\"at-main-area\">\n    @if (IsLoading) {\n      <div class=\"at-loading-overlay\">\n        <mj-loading text=\"Refreshing content types\u2026\"></mj-loading>\n      </div>\n    }\n    <div class=\"at-page-body\">\n      <!-- Org-level domain context (broadest classification-context scope) -->\n      <div class=\"at-org-ctx-wrap\">\n        <classify-org-context-editor [Provider]=\"Provider\"></classify-org-context-editor>\n      </div>\n\n      <div class=\"at-ct-grid\">\n        @for (card of ContentTypeCards; track card.ID) {\n          <div class=\"at-ct-card\">\n            <div class=\"at-ct-card-header\">\n              <span class=\"at-ct-card-name\">{{ card.Name }}</span>\n              <span class=\"at-ct-card-model\">{{ card.AIModelName }}</span>\n            </div>\n            <div class=\"at-ct-field\">\n              <span class=\"at-ct-field-label\">Description</span>\n              <span class=\"at-ct-field-value\">{{ card.Description || '\u2014' }}</span>\n            </div>\n            <div class=\"at-ct-field\">\n              <span class=\"at-ct-field-label\">Sources Using</span>\n              <span class=\"at-ct-field-value\">{{ card.SourcesUsing }}</span>\n            </div>\n            <div class=\"at-ct-field\">\n              <span class=\"at-ct-field-label\">Items Tagged</span>\n              <span class=\"at-ct-field-value\">{{ formatNumber(card.ItemsTagged) }}</span>\n            </div>\n            <div class=\"at-ct-tag-range\">\n              <i class=\"fa-solid fa-tags\"></i>\n              <span>{{ card.MinTags }}</span>\n              <div class=\"at-ct-tag-range-bar\">\n                <div class=\"at-ct-tag-range-fill\" [style.left.%]=\"card.RangeLeftPct\" [style.right.%]=\"card.RangeRightPct\"></div>\n              </div>\n              <span>{{ card.MaxTags }}</span>\n              <span class=\"at-ct-range-suffix\">tags/item</span>\n            </div>\n            <div class=\"at-source-card-actions\" style=\"margin-top: 10px;\">\n              <button class=\"at-source-action-btn\" (click)=\"onEditType(card)\"><i class=\"fa-solid fa-pen\"></i> Edit</button>\n            </div>\n          </div>\n        }\n        <!-- Add Content Type Card -->\n        <div class=\"at-add-type-card\" (click)=\"onAddType()\">\n          <i class=\"fa-solid fa-plus-circle\"></i>\n          <span style=\"font-size: 0.85rem; font-weight: 600;\">Add Content Type</span>\n          <span style=\"font-size: 0.72rem;\">Configure tagging rules</span>\n        </div>\n      </div>\n    </div>\n  </div>\n</mj-page-body-interior>\n", styles: ["/*\n * Content Types tab styles.\n *\n * The host (AutotaggingPipelineResourceComponent) uses ViewEncapsulation.None,\n * so its `.at-*` rules are global and already style this tab's markup while it\n * renders inside the host shell. Tab-specific rules live here as the shared CSS\n * is partitioned during the host-slim step.\n */\n\n.at-org-ctx-wrap {\n    margin-bottom: 16px;\n}\n"] }]
    }], null, { ContentTypes: [{
            type: Input
        }], Sources: [{
            type: Input
        }], Items: [{
            type: Input
        }], TotalItemCount: [{
            type: Input
        }], AddTypeRequested: [{
            type: Output
        }], EditTypeRequested: [{
            type: Output
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ClassifyTypesTabComponent, { className: "ClassifyTypesTabComponent", filePath: "src/AI/components/autotagging/tabs/types-tab.component.ts", lineNumber: 21 }); })();
//# sourceMappingURL=types-tab.component.js.map