/**
 * @fileoverview Classify · Run History tab.
 *
 * Self-contained sub-page: owns its header-interior, the run table, filters,
 * and the per-run detail panel. Receives the shared raw run list from the host
 * via `[Runs]` (the host is the data orchestrator); loads per-run detail rows
 * on demand itself. Cross-tab navigation (none today) would bubble via @Output.
 */
import { Component, ChangeDetectorRef, EventEmitter, Input, Output, inject } from '@angular/core';
import { RunView } from '@memberjunction/core';
import { BaseAngularComponent } from '@memberjunction/ng-base-types';
import { formatNumber, formatDate, computeDuration, displayStatus, formatTokenCount, mapRunDetailRecords } 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-item-grid.component";
const _forTrack0 = ($index, $item) => $item.ID;
const _forTrack1 = ($index, $item) => $item.SourceName;
function ClassifyHistoryTabComponent_Conditional_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 15);
    i0.ɵɵelementStart(1, "span", 16);
    i0.ɵɵtext(2, "Refreshing\u2026");
    i0.ɵɵelementEnd();
} }
function ClassifyHistoryTabComponent_Conditional_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 17);
    i0.ɵɵelementStart(1, "span", 16);
    i0.ɵɵtext(2, "Refresh");
    i0.ɵɵelementEnd();
} }
function ClassifyHistoryTabComponent_For_32_Conditional_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 20);
} }
function ClassifyHistoryTabComponent_For_32_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "tr", 18);
    i0.ɵɵlistener("click", function ClassifyHistoryTabComponent_For_32_Template_tr_click_0_listener() { const row_r2 = i0.ɵɵrestoreView(_r1).$implicit; const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OpenRunDetail(row_r2.ID)); });
    i0.ɵɵelementStart(1, "td")(2, "span", 19);
    i0.ɵɵconditionalCreate(3, ClassifyHistoryTabComponent_For_32_Conditional_3_Template, 1, 0, "i", 20);
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(5, "td", 21);
    i0.ɵɵtext(6);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(7, "td");
    i0.ɵɵtext(8);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(9, "td", 22);
    i0.ɵɵtext(10);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(11, "td");
    i0.ɵɵtext(12);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(13, "td");
    i0.ɵɵtext(14);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(15, "td");
    i0.ɵɵtext(16);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const row_r2 = ctx.$implicit;
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵclassProp("at-run-row-selected", ctx_r2.SelectedRunID === row_r2.ID);
    i0.ɵɵadvance(2);
    i0.ɵɵclassMap(row_r2.StatusClass);
    i0.ɵɵadvance();
    i0.ɵɵconditional(row_r2.StatusClass === "running" ? 3 : -1);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", row_r2.Status, " ");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(row_r2.SourceName);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(row_r2.StartedDisplay);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(row_r2.Duration);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(row_r2.Items);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(row_r2.Tags);
    i0.ɵɵadvance();
    i0.ɵɵclassMap(row_r2.ErrorClass);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(row_r2.Errors);
} }
function ClassifyHistoryTabComponent_Conditional_33_Conditional_3_Conditional_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 15);
    i0.ɵɵtext(1, " Loading\u2026 ");
} }
function ClassifyHistoryTabComponent_Conditional_33_Conditional_3_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 25);
    i0.ɵɵtext(1, " Load more ");
} }
function ClassifyHistoryTabComponent_Conditional_33_Conditional_3_Template(rf, ctx) { if (rf & 1) {
    const _r4 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 2);
    i0.ɵɵlistener("click", function ClassifyHistoryTabComponent_Conditional_33_Conditional_3_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r4); const ctx_r2 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r2.onLoadMore()); });
    i0.ɵɵconditionalCreate(1, ClassifyHistoryTabComponent_Conditional_33_Conditional_3_Conditional_1_Template, 2, 0)(2, ClassifyHistoryTabComponent_Conditional_33_Conditional_3_Conditional_2_Template, 2, 0);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("disabled", ctx_r2.IsLoadingMore);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r2.IsLoadingMore ? 1 : 2);
} }
function ClassifyHistoryTabComponent_Conditional_33_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 13)(1, "span", 23);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(3, ClassifyHistoryTabComponent_Conditional_33_Conditional_3_Template, 3, 2, "button", 24);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate2("Showing ", ctx_r2.FilteredRunRows.length, " of ", ctx_r2.TotalRunCount, " runs");
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r2.HasMoreRuns ? 3 : -1);
} }
function ClassifyHistoryTabComponent_Conditional_34_Conditional_9_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-loading", 32);
} }
function ClassifyHistoryTabComponent_Conditional_34_Conditional_10_For_25_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "tr")(1, "td", 21);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "td");
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(5, "td")(6, "span", 19);
    i0.ɵɵtext(7);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(8, "td");
    i0.ɵɵtext(9);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(10, "td");
    i0.ɵɵtext(11);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(12, "td");
    i0.ɵɵtext(13);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(14, "td");
    i0.ɵɵtext(15);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(16, "td");
    i0.ɵɵtext(17);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(18, "td");
    i0.ɵɵtext(19);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(20, "td", 22);
    i0.ɵɵtext(21);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const detail_r6 = ctx.$implicit;
    const ctx_r2 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(detail_r6.SourceName);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(detail_r6.SourceType);
    i0.ɵɵadvance(2);
    i0.ɵɵclassMap(detail_r6.StatusClass);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(detail_r6.Status);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(detail_r6.ItemsProcessed);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(detail_r6.ItemsTagged);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(detail_r6.ItemsVectorized);
    i0.ɵɵadvance();
    i0.ɵɵclassProp("run-error-text", detail_r6.ErrorCount > 0);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(detail_r6.ErrorCount);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r2.FormatTokenCount(detail_r6.TotalTokens));
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(detail_r6.TotalCost > 0 ? "$" + detail_r6.TotalCost.toFixed(4) : "$0.00");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(detail_r6.Duration);
} }
function ClassifyHistoryTabComponent_Conditional_34_Conditional_10_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "table", 11)(1, "thead")(2, "tr")(3, "th");
    i0.ɵɵtext(4, "Source");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(5, "th");
    i0.ɵɵtext(6, "Source Type");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(7, "th");
    i0.ɵɵtext(8, "Status");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(9, "th");
    i0.ɵɵtext(10, "Items");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(11, "th");
    i0.ɵɵtext(12, "Tagged");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(13, "th");
    i0.ɵɵtext(14, "Vectorized");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(15, "th");
    i0.ɵɵtext(16, "Errors");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(17, "th");
    i0.ɵɵtext(18, "Tokens");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(19, "th");
    i0.ɵɵtext(20, "Cost");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(21, "th");
    i0.ɵɵtext(22, "Duration");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(23, "tbody");
    i0.ɵɵrepeaterCreate(24, ClassifyHistoryTabComponent_Conditional_34_Conditional_10_For_25_Template, 22, 14, "tr", null, _forTrack1);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(24);
    i0.ɵɵrepeater(ctx_r2.RunDetailRows);
} }
function ClassifyHistoryTabComponent_Conditional_34_Conditional_11_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-empty-state", 33);
} }
function ClassifyHistoryTabComponent_Conditional_34_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 14)(1, "div", 26)(2, "span", 27);
    i0.ɵɵelement(3, "i", 28);
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(5, "button", 29);
    i0.ɵɵlistener("click", function ClassifyHistoryTabComponent_Conditional_34_Template_button_click_5_listener() { i0.ɵɵrestoreView(_r5); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.CloseRunDetail()); });
    i0.ɵɵelement(6, "i", 30);
    i0.ɵɵtext(7, " Close ");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(8, "div", 31);
    i0.ɵɵconditionalCreate(9, ClassifyHistoryTabComponent_Conditional_34_Conditional_9_Template, 1, 0, "mj-loading", 32)(10, ClassifyHistoryTabComponent_Conditional_34_Conditional_10_Template, 26, 0, "table", 11)(11, ClassifyHistoryTabComponent_Conditional_34_Conditional_11_Template, 1, 0, "mj-empty-state", 33);
    i0.ɵɵelementStart(12, "div", 34)(13, "div", 35)(14, "span", 27);
    i0.ɵɵelement(15, "i", 36);
    i0.ɵɵtext(16, " Items in this run ");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(17, "classify-item-grid", 37);
    i0.ɵɵlistener("ItemSelected", function ClassifyHistoryTabComponent_Conditional_34_Template_classify_item_grid_ItemSelected_17_listener($event) { i0.ɵɵrestoreView(_r5); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.onItemSelected($event)); });
    i0.ɵɵelementEnd()()()();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate1(" Run Detail: ", ctx_r2.SelectedRunID.slice(0, 14), "... ");
    i0.ɵɵadvance(5);
    i0.ɵɵconditional(ctx_r2.IsLoadingRunDetail ? 9 : ctx_r2.RunDetailRows.length > 0 ? 10 : 11);
    i0.ɵɵadvance(8);
    i0.ɵɵproperty("RunID", ctx_r2.SelectedRunID)("Provider", ctx_r2.Provider);
} }
export class ClassifyHistoryTabComponent extends BaseAngularComponent {
    cdr = inject(ChangeDetectorRef);
    /** Shared raw `MJ: Content Process Runs` rows, supplied by the host orchestrator. */
    _runs = [];
    set Runs(value) {
        this._runs = value ?? [];
        this.buildRunHistoryRows();
        this.buildHistorySourceOptions();
        this.FilterRunHistory();
        // A fresh Runs binding (from the host reload) ends any in-flight refresh.
        this.IsLoading = false;
        this.cdr.detectChanges();
    }
    get Runs() {
        return this._runs;
    }
    /** Total run count in the DB (from TotalRowCount) — drives the "Showing X of Y" line. */
    TotalRunCount = 0;
    /** True while the host is fetching the next page in response to LoadMoreRequested. */
    IsLoadingMore = false;
    /** Bubble a "load more" request to the host, which widens the loaded window. */
    LoadMoreRequested = new EventEmitter();
    /**
     * Bubble a content-item selection (from the per-run item grid) up to the host,
     * which owns NavigationService + the drilldown slide-in.
     */
    ItemSelected = new EventEmitter();
    onItemSelected(itemID) {
        this.ItemSelected.emit(itemID);
    }
    /** Whether more runs exist in the DB than are currently loaded. */
    get HasMoreRuns() {
        return this.TotalRunCount > this._runs.length;
    }
    onLoadMore() {
        this.LoadMoreRequested.emit();
    }
    /** Shown while the host reloads the run list in response to RefreshRequested. */
    IsLoading = false;
    /**
     * Bubble a refresh request up to the host, which owns the run-history data
     * (`MJ: Content Process Runs`). The host reloads and re-binds `[Runs]`, whose
     * setter rebuilds the rows; the host also clears IsLoading via [Loading].
     */
    RefreshRequested = new EventEmitter();
    RunHistoryRows = [];
    FilteredRunRows = [];
    HistorySourceFilter = '';
    HistoryStatusFilter = '';
    HistorySourceOptions = [];
    // Per-run detail panel
    SelectedRunID = null;
    RunDetailRows = [];
    IsLoadingRunDetail = false;
    // Template-facing formatters
    FormatTokenCount = formatTokenCount;
    /**
     * Ask the host to reload the run history. Data is host-owned, so we surface a
     * loading state and emit; the new `[Runs]` binding clears IsLoading.
     */
    Refresh() {
        this.IsLoading = true;
        this.cdr.detectChanges();
        this.RefreshRequested.emit();
    }
    buildRunHistoryRows() {
        this.RunHistoryRows = this._runs.map(run => {
            const status = run['Status'] ?? 'Unknown';
            const startTime = run['StartTime'];
            const endTime = run['EndTime'];
            const duration = computeDuration(startTime, endTime);
            const processedItems = run['ProcessedItems'];
            const errorCount = run['ErrorCount'];
            const statusLower = status.toLowerCase();
            const isFailed = statusLower === 'error' || statusLower === 'failed';
            const isRunning = statusLower === 'running' || statusLower === 'processing';
            const hasErrors = (errorCount ?? 0) > 0;
            return {
                ID: run['ID'],
                Status: displayStatus(status),
                StatusClass: isFailed ? 'failed' : isRunning ? 'running' : 'complete',
                SourceName: run['Source'] ?? 'Unknown',
                StartedDisplay: startTime ? formatDate(startTime) : '—',
                Duration: duration,
                Items: processedItems != null ? formatNumber(processedItems) : '—',
                Tags: '—',
                Errors: hasErrors ? formatNumber(errorCount) : (isFailed ? status : '0'),
                ErrorClass: isFailed || hasErrors ? 'run-error-text' : ''
            };
        });
    }
    buildHistorySourceOptions() {
        const sources = new Set();
        for (const run of this._runs) {
            const s = run['Source'];
            if (s)
                sources.add(s);
        }
        this.HistorySourceOptions = Array.from(sources).sort();
    }
    FilterRunHistory() {
        this.FilteredRunRows = this.RunHistoryRows.filter(row => {
            if (this.HistorySourceFilter && row.SourceName !== this.HistorySourceFilter)
                return false;
            if (this.HistoryStatusFilter && row.StatusClass !== this.HistoryStatusFilter)
                return false;
            return true;
        });
        this.cdr.detectChanges();
    }
    /**
     * Filter fields for the Run History section, rendered inside an
     * `<mj-filter-popover>` (many values, single-select → popover with dropdown).
     */
    get historyFilterFields() {
        return [
            {
                key: 'source',
                type: 'dropdown',
                label: 'Source',
                placeholder: 'All Sources',
                filterable: this.HistorySourceOptions.length > 10,
                options: [
                    { text: 'All Sources', value: '' },
                    ...this.HistorySourceOptions.map(s => ({ text: s, value: s }))
                ]
            },
            {
                key: 'status',
                type: 'dropdown',
                label: 'Status',
                placeholder: 'All Status',
                options: [
                    { text: 'All Status', value: '' },
                    { text: 'Complete', value: 'complete' },
                    { text: 'Failed', value: 'failed' },
                    { text: 'Running', value: 'running' }
                ]
            }
        ];
    }
    get historyFilterValues() {
        return { source: this.HistorySourceFilter, status: this.HistoryStatusFilter };
    }
    get historyActiveFilterCount() {
        return (this.HistorySourceFilter ? 1 : 0) + (this.HistoryStatusFilter ? 1 : 0);
    }
    onHistoryFilterChange(values) {
        this.HistorySourceFilter = values['source'] ?? '';
        this.HistoryStatusFilter = values['status'] ?? '';
        this.FilterRunHistory();
    }
    onHistoryFilterReset() {
        this.HistorySourceFilter = '';
        this.HistoryStatusFilter = '';
        this.FilterRunHistory();
    }
    /** Open (or toggle closed) the detail view for a run, loading its per-source detail rows. */
    async OpenRunDetail(runID) {
        if (this.SelectedRunID === runID) {
            this.CloseRunDetail();
            return;
        }
        this.SelectedRunID = runID;
        this.IsLoadingRunDetail = true;
        this.RunDetailRows = [];
        this.cdr.detectChanges();
        await this.loadRunDetailRows(runID);
        this.IsLoadingRunDetail = false;
        this.cdr.detectChanges();
    }
    CloseRunDetail() {
        this.SelectedRunID = null;
        this.RunDetailRows = [];
        this.IsLoadingRunDetail = false;
        this.cdr.detectChanges();
    }
    async loadRunDetailRows(runID) {
        const rv = RunView.FromMetadataProvider(this.ProviderToUse);
        const result = await rv.RunView({
            EntityName: 'MJ: Content Process Run Details',
            ExtraFilter: `ContentProcessRunID='${runID}'`,
            OrderBy: 'ContentSource',
            ResultType: 'simple',
        });
        if (result.Success) {
            this.RunDetailRows = mapRunDetailRecords(result.Results);
        }
    }
    static ɵfac = /*@__PURE__*/ (() => { let ɵClassifyHistoryTabComponent_BaseFactory; return function ClassifyHistoryTabComponent_Factory(__ngFactoryType__) { return (ɵClassifyHistoryTabComponent_BaseFactory || (ɵClassifyHistoryTabComponent_BaseFactory = i0.ɵɵgetInheritedFactory(ClassifyHistoryTabComponent)))(__ngFactoryType__ || ClassifyHistoryTabComponent); }; })();
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ClassifyHistoryTabComponent, selectors: [["classify-history-tab"]], inputs: { Runs: "Runs", TotalRunCount: "TotalRunCount", IsLoadingMore: "IsLoadingMore" }, outputs: { LoadMoreRequested: "LoadMoreRequested", ItemSelected: "ItemSelected", RefreshRequested: "RefreshRequested" }, standalone: false, features: [i0.ɵɵInheritDefinitionFeature], decls: 35, vars: 10, consts: [["Title", "Run History", "Subtitle", "Pipeline execution history and per-source run detail"], ["actions", ""], ["mjButton", "", "variant", "secondary", "size", "sm", 3, "click", "disabled"], ["toolbar", ""], [3, "ClearAllRequested", "ActiveCount", "ShowClearAll"], [3, "ValuesChange", "Reset", "Fields", "Values"], [3, "Padding", "Flex"], [1, "at-main-area"], [1, "at-page-body"], [1, "at-card"], [1, "at-card-body", 2, "max-height", "600px", "overflow-y", "auto"], [1, "at-run-table"], [1, "at-run-row-clickable", 3, "at-run-row-selected"], [1, "at-load-more-bar"], [1, "at-card", 2, "margin-top", "12px"], [1, "fa-solid", "fa-spinner", "fa-spin"], [1, "mj-action-label"], [1, "fa-solid", "fa-arrows-rotate"], [1, "at-run-row-clickable", 3, "click"], [1, "at-run-status-badge"], [1, "fa-solid", "fa-spinner", "fa-spin", 2, "font-size", "0.55rem"], [1, "at-run-source-name"], [1, "at-run-duration"], [1, "at-load-more-count"], ["mjButton", "", "variant", "secondary", "size", "sm", 3, "disabled"], [1, "fa-solid", "fa-chevron-down"], [1, "at-card-header"], [1, "at-card-title"], [1, "fa-solid", "fa-magnifying-glass-chart"], [1, "at-action-btn", "at-secondary-btn", 2, "font-size", "11px", "padding", "3px 8px", 3, "click"], [1, "fa-solid", "fa-times"], [1, "at-card-body"], ["text", "Loading run details...", "size", "small"], ["Size", "compact", "Icon", "fa-solid fa-info-circle", "Title", "No per-source detail records found for this run."], [1, "at-run-items-section"], [1, "at-card-header", 2, "padding-left", "0", "padding-right", "0"], [1, "fa-solid", "fa-list-check"], [3, "ItemSelected", "RunID", "Provider"]], template: function ClassifyHistoryTabComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "mj-page-header-interior", 0)(1, "div", 1)(2, "button", 2);
            i0.ɵɵlistener("click", function ClassifyHistoryTabComponent_Template_button_click_2_listener() { return ctx.Refresh(); });
            i0.ɵɵconditionalCreate(3, ClassifyHistoryTabComponent_Conditional_3_Template, 3, 0)(4, ClassifyHistoryTabComponent_Conditional_4_Template, 3, 0);
            i0.ɵɵelementEnd()();
            i0.ɵɵelementStart(5, "div", 3)(6, "mj-filter-popover", 4);
            i0.ɵɵlistener("ClearAllRequested", function ClassifyHistoryTabComponent_Template_mj_filter_popover_ClearAllRequested_6_listener() { return ctx.onHistoryFilterReset(); });
            i0.ɵɵelementStart(7, "mj-filter-panel", 5);
            i0.ɵɵlistener("ValuesChange", function ClassifyHistoryTabComponent_Template_mj_filter_panel_ValuesChange_7_listener($event) { return ctx.onHistoryFilterChange($event); })("Reset", function ClassifyHistoryTabComponent_Template_mj_filter_panel_Reset_7_listener() { return ctx.onHistoryFilterReset(); });
            i0.ɵɵelementEnd()()()();
            i0.ɵɵelementStart(8, "mj-page-body-interior", 6)(9, "div", 7)(10, "div", 8)(11, "div", 9)(12, "div", 10)(13, "table", 11)(14, "thead")(15, "tr")(16, "th");
            i0.ɵɵtext(17, "Status");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(18, "th");
            i0.ɵɵtext(19, "Source");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(20, "th");
            i0.ɵɵtext(21, "Started");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(22, "th");
            i0.ɵɵtext(23, "Duration");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(24, "th");
            i0.ɵɵtext(25, "Items");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(26, "th");
            i0.ɵɵtext(27, "Tags");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(28, "th");
            i0.ɵɵtext(29, "Errors");
            i0.ɵɵelementEnd()()();
            i0.ɵɵelementStart(30, "tbody");
            i0.ɵɵrepeaterCreate(31, ClassifyHistoryTabComponent_For_32_Template, 17, 14, "tr", 12, _forTrack0);
            i0.ɵɵelementEnd()()();
            i0.ɵɵconditionalCreate(33, ClassifyHistoryTabComponent_Conditional_33_Template, 4, 3, "div", 13);
            i0.ɵɵelementEnd();
            i0.ɵɵconditionalCreate(34, ClassifyHistoryTabComponent_Conditional_34_Template, 18, 4, "div", 14);
            i0.ɵɵelementEnd()()();
        } if (rf & 2) {
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("disabled", ctx.IsLoading);
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.IsLoading ? 3 : 4);
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("ActiveCount", ctx.historyActiveFilterCount)("ShowClearAll", ctx.historyActiveFilterCount > 0);
            i0.ɵɵadvance();
            i0.ɵɵproperty("Fields", ctx.historyFilterFields)("Values", ctx.historyFilterValues);
            i0.ɵɵadvance();
            i0.ɵɵproperty("Padding", false)("Flex", true);
            i0.ɵɵadvance(23);
            i0.ɵɵrepeater(ctx.FilteredRunRows);
            i0.ɵɵadvance(2);
            i0.ɵɵconditional(ctx.TotalRunCount > 0 ? 33 : -1);
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.SelectedRunID ? 34 : -1);
        } }, dependencies: [i1.LoadingComponent, i2.MJButtonDirective, i2.MJPageHeaderInteriorComponent, i2.MJPageBodyInteriorComponent, i2.MJFilterPopoverComponent, i2.MJFilterPanelComponent, i2.MJEmptyStateComponent, i3.ClassifyItemGridComponent], styles: ["\n\n\n\n\n\n\n\n\n\n.at-run-items-section[_ngcontent-%COMP%] {\n    margin-top: 16px;\n    border-top: 1px solid var(--mj-border-subtle);\n    padding-top: 12px;\n}"] });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ClassifyHistoryTabComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'classify-history-tab', template: "<mj-page-header-interior\n    Title=\"Run History\"\n    Subtitle=\"Pipeline execution history and per-source run detail\">\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  </div>\n  <div toolbar>\n    <mj-filter-popover\n        [ActiveCount]=\"historyActiveFilterCount\"\n        [ShowClearAll]=\"historyActiveFilterCount > 0\"\n        (ClearAllRequested)=\"onHistoryFilterReset()\">\n      <mj-filter-panel\n          [Fields]=\"historyFilterFields\"\n          [Values]=\"historyFilterValues\"\n          (ValuesChange)=\"onHistoryFilterChange($event)\"\n          (Reset)=\"onHistoryFilterReset()\">\n      </mj-filter-panel>\n    </mj-filter-popover>\n  </div>\n</mj-page-header-interior>\n\n<mj-page-body-interior [Padding]=\"false\" [Flex]=\"true\">\n  <div class=\"at-main-area\">\n    <div class=\"at-page-body\">\n      <div class=\"at-card\">\n        <div class=\"at-card-body\" style=\"max-height: 600px; overflow-y: auto;\">\n          <table class=\"at-run-table\">\n            <thead>\n              <tr>\n                <th>Status</th>\n                <th>Source</th>\n                <th>Started</th>\n                <th>Duration</th>\n                <th>Items</th>\n                <th>Tags</th>\n                <th>Errors</th>\n              </tr>\n            </thead>\n            <tbody>\n              @for (row of FilteredRunRows; track row.ID) {\n                <tr class=\"at-run-row-clickable\"\n                    [class.at-run-row-selected]=\"SelectedRunID === row.ID\"\n                    (click)=\"OpenRunDetail(row.ID)\">\n                  <td>\n                    <span class=\"at-run-status-badge\" [class]=\"row.StatusClass\">\n                      @if (row.StatusClass === 'running') {\n                        <i class=\"fa-solid fa-spinner fa-spin\" style=\"font-size: 0.55rem\"></i>\n                      }\n                      {{ row.Status }}\n                    </span>\n                  </td>\n                  <td class=\"at-run-source-name\">{{ row.SourceName }}</td>\n                  <td>{{ row.StartedDisplay }}</td>\n                  <td class=\"at-run-duration\">{{ row.Duration }}</td>\n                  <td>{{ row.Items }}</td>\n                  <td>{{ row.Tags }}</td>\n                  <td [class]=\"row.ErrorClass\">{{ row.Errors }}</td>\n                </tr>\n              }\n            </tbody>\n          </table>\n        </div>\n        @if (TotalRunCount > 0) {\n          <div class=\"at-load-more-bar\">\n            <span class=\"at-load-more-count\">Showing {{ FilteredRunRows.length }} of {{ TotalRunCount }} runs</span>\n            @if (HasMoreRuns) {\n              <button mjButton variant=\"secondary\" size=\"sm\" (click)=\"onLoadMore()\" [disabled]=\"IsLoadingMore\">\n                @if (IsLoadingMore) {\n                  <i class=\"fa-solid fa-spinner fa-spin\"></i> Loading\u2026\n                } @else {\n                  <i class=\"fa-solid fa-chevron-down\"></i> Load more\n                }\n              </button>\n            }\n          </div>\n        }\n      </div>\n\n      <!-- Per-run detail panel -->\n      @if (SelectedRunID) {\n        <div class=\"at-card\" style=\"margin-top: 12px;\">\n          <div class=\"at-card-header\">\n            <span class=\"at-card-title\">\n              <i class=\"fa-solid fa-magnifying-glass-chart\"></i>\n              Run Detail: {{ SelectedRunID.slice(0, 14) }}...\n            </span>\n            <button class=\"at-action-btn at-secondary-btn\" style=\"font-size: 11px; padding: 3px 8px;\" (click)=\"CloseRunDetail()\">\n              <i class=\"fa-solid fa-times\"></i> Close\n            </button>\n          </div>\n          <div class=\"at-card-body\">\n            @if (IsLoadingRunDetail) {\n              <mj-loading text=\"Loading run details...\" size=\"small\"></mj-loading>\n            } @else if (RunDetailRows.length > 0) {\n              <table class=\"at-run-table\">\n                <thead>\n                  <tr>\n                    <th>Source</th>\n                    <th>Source Type</th>\n                    <th>Status</th>\n                    <th>Items</th>\n                    <th>Tagged</th>\n                    <th>Vectorized</th>\n                    <th>Errors</th>\n                    <th>Tokens</th>\n                    <th>Cost</th>\n                    <th>Duration</th>\n                  </tr>\n                </thead>\n                <tbody>\n                  @for (detail of RunDetailRows; track detail.SourceName) {\n                    <tr>\n                      <td class=\"at-run-source-name\">{{ detail.SourceName }}</td>\n                      <td>{{ detail.SourceType }}</td>\n                      <td>\n                        <span class=\"at-run-status-badge\" [class]=\"detail.StatusClass\">{{ detail.Status }}</span>\n                      </td>\n                      <td>{{ detail.ItemsProcessed }}</td>\n                      <td>{{ detail.ItemsTagged }}</td>\n                      <td>{{ detail.ItemsVectorized }}</td>\n                      <td [class.run-error-text]=\"detail.ErrorCount > 0\">{{ detail.ErrorCount }}</td>\n                      <td>{{ FormatTokenCount(detail.TotalTokens) }}</td>\n                      <td>{{ detail.TotalCost > 0 ? '$' + detail.TotalCost.toFixed(4) : '$0.00' }}</td>\n                      <td class=\"at-run-duration\">{{ detail.Duration }}</td>\n                    </tr>\n                  }\n                </tbody>\n              </table>\n            } @else {\n              <mj-empty-state Size=\"compact\" Icon=\"fa-solid fa-info-circle\"\n                Title=\"No per-source detail records found for this run.\" />\n            }\n\n            <!-- Phase 4: content items processed in this run -->\n            <div class=\"at-run-items-section\">\n              <div class=\"at-card-header\" style=\"padding-left: 0; padding-right: 0;\">\n                <span class=\"at-card-title\">\n                  <i class=\"fa-solid fa-list-check\"></i> Items in this run\n                </span>\n              </div>\n              <classify-item-grid\n                  [RunID]=\"SelectedRunID\"\n                  [Provider]=\"Provider\"\n                  (ItemSelected)=\"onItemSelected($event)\"></classify-item-grid>\n            </div>\n          </div>\n        </div>\n      }\n    </div>\n  </div>\n</mj-page-body-interior>\n", styles: ["/*\n * Run History 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-run-items-section {\n    margin-top: 16px;\n    border-top: 1px solid var(--mj-border-subtle);\n    padding-top: 12px;\n}\n"] }]
    }], null, { Runs: [{
            type: Input
        }], TotalRunCount: [{
            type: Input
        }], IsLoadingMore: [{
            type: Input
        }], LoadMoreRequested: [{
            type: Output
        }], ItemSelected: [{
            type: Output
        }], RefreshRequested: [{
            type: Output
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ClassifyHistoryTabComponent, { className: "ClassifyHistoryTabComponent", filePath: "src/AI/components/autotagging/tabs/history-tab.component.ts", lineNumber: 22 }); })();
//# sourceMappingURL=history-tab.component.js.map