/**
 * @fileoverview Classify · Content Item Drilldown (Phase 4 audit/analytics).
 *
 * Given a content item (by ID), renders an auditable view of:
 *   (A) basic rendered content / fields,
 *   (B) its tags WITH weight + LLM Reasoning, plus a provenance link to the
 *       AI Prompt Run (`AIPromptRunID`) that produced each tag,
 *   (C) provenance facts (source / entity doc / prompt run), and
 *   (D) a simple audit list (created / last tagged / last embedded).
 *
 * Read-only: all loads use `ResultType:'simple'` + narrow `Fields`. Tags are read
 * from `MJ: Content Item Tags` filtered by `ItemID`. This component owns NO
 * navigation — record-open intents bubble UP via `(OpenRecordRequested)` so the
 * host (which owns NavigationService) opens the full entity form.
 */
import { Component, Input, Output, EventEmitter, ChangeDetectorRef, inject, } from '@angular/core';
import { RunView } from '@memberjunction/core';
import { BaseAngularComponent } from '@memberjunction/ng-base-types';
import { deriveDisplayName, formatWeight, tagFontSize, formatDate } 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";
const _forTrack0 = ($index, $item) => $item.Label + $item.Value;
const _forTrack1 = ($index, $item) => $item.Tag + $item.CreatedAt;
const _forTrack2 = ($index, $item) => $item.Label;
function ClassifyItemDrilldownComponent_Conditional_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 0);
    i0.ɵɵelement(1, "i", 3);
    i0.ɵɵelementStart(2, "p");
    i0.ɵɵtext(3, "Select an item to inspect its tags, reasoning, and provenance.");
    i0.ɵɵelementEnd()();
} }
function ClassifyItemDrilldownComponent_Conditional_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-loading", 1);
} }
function ClassifyItemDrilldownComponent_Conditional_2_Conditional_15_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 11)(1, "span", 12);
    i0.ɵɵtext(2, "URL");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "a", 23);
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("href", ctx_r1.URL, i0.ɵɵsanitizeUrl);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(ctx_r1.URL);
} }
function ClassifyItemDrilldownComponent_Conditional_2_Conditional_16_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 14);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(ctx_r1.TextPreview);
} }
function ClassifyItemDrilldownComponent_Conditional_2_Conditional_21_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "p", 16);
    i0.ɵɵtext(1, "No tags applied to this item.");
    i0.ɵɵelementEnd();
} }
function ClassifyItemDrilldownComponent_Conditional_2_Conditional_22_For_2_Conditional_6_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 31);
    i0.ɵɵlistener("click", function ClassifyItemDrilldownComponent_Conditional_2_Conditional_22_For_2_Conditional_6_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r3); const tag_r4 = i0.ɵɵnextContext().$implicit; const ctx_r1 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r1.OpenPromptRun(tag_r4)); });
    i0.ɵɵelement(1, "i", 32);
    i0.ɵɵtext(2, " Prompt Run ");
    i0.ɵɵelementEnd();
} }
function ClassifyItemDrilldownComponent_Conditional_2_Conditional_22_For_2_Conditional_7_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 29);
    i0.ɵɵelement(1, "i", 33);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const tag_r4 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", tag_r4.Reasoning, " ");
} }
function ClassifyItemDrilldownComponent_Conditional_2_Conditional_22_For_2_Conditional_8_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 30);
    i0.ɵɵtext(1, "No reasoning captured.");
    i0.ɵɵelementEnd();
} }
function ClassifyItemDrilldownComponent_Conditional_2_Conditional_22_For_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 24)(1, "div", 25)(2, "span", 26);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "span", 27);
    i0.ɵɵtext(5);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(6, ClassifyItemDrilldownComponent_Conditional_2_Conditional_22_For_2_Conditional_6_Template, 3, 0, "button", 28);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(7, ClassifyItemDrilldownComponent_Conditional_2_Conditional_22_For_2_Conditional_7_Template, 3, 1, "div", 29)(8, ClassifyItemDrilldownComponent_Conditional_2_Conditional_22_For_2_Conditional_8_Template, 2, 0, "div", 30);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const tag_r4 = ctx.$implicit;
    const ctx_r1 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(2);
    i0.ɵɵstyleProp("font-size", ctx_r1.TagFontSize(tag_r4.Weight));
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(tag_r4.Tag);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r1.FormatWeight(tag_r4.Weight));
    i0.ɵɵadvance();
    i0.ɵɵconditional(tag_r4.AIPromptRunID ? 6 : -1);
    i0.ɵɵadvance();
    i0.ɵɵconditional(tag_r4.Reasoning ? 7 : 8);
} }
function ClassifyItemDrilldownComponent_Conditional_2_Conditional_22_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 17);
    i0.ɵɵrepeaterCreate(1, ClassifyItemDrilldownComponent_Conditional_2_Conditional_22_For_2_Template, 9, 6, "div", 24, _forTrack1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵrepeater(ctx_r1.Tags);
} }
function ClassifyItemDrilldownComponent_Conditional_2_For_29_Conditional_4_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 38);
    i0.ɵɵlistener("click", function ClassifyItemDrilldownComponent_Conditional_2_For_29_Conditional_4_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r5); const fact_r6 = i0.ɵɵnextContext().$implicit; const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.OpenProvenanceRecord(fact_r6)); });
    i0.ɵɵtext(1);
    i0.ɵɵelement(2, "i", 9);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const fact_r6 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", fact_r6.Value, " ");
} }
function ClassifyItemDrilldownComponent_Conditional_2_For_29_Conditional_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 37);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const fact_r6 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(fact_r6.Value);
} }
function ClassifyItemDrilldownComponent_Conditional_2_For_29_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 20);
    i0.ɵɵelement(1, "i", 34);
    i0.ɵɵelementStart(2, "span", 35);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(4, ClassifyItemDrilldownComponent_Conditional_2_For_29_Conditional_4_Template, 3, 1, "button", 36)(5, ClassifyItemDrilldownComponent_Conditional_2_For_29_Conditional_5_Template, 2, 1, "span", 37);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const fact_r6 = ctx.$implicit;
    i0.ɵɵadvance();
    i0.ɵɵclassMap(fact_r6.Icon);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(fact_r6.Label);
    i0.ɵɵadvance();
    i0.ɵɵconditional(fact_r6.RecordEntity && fact_r6.RecordID ? 4 : 5);
} }
function ClassifyItemDrilldownComponent_Conditional_2_Conditional_34_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "p", 16);
    i0.ɵɵtext(1, "No audit events recorded.");
    i0.ɵɵelementEnd();
} }
function ClassifyItemDrilldownComponent_Conditional_2_Conditional_35_For_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "li", 39);
    i0.ɵɵelement(1, "i", 40);
    i0.ɵɵelementStart(2, "span", 41);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "span", 42);
    i0.ɵɵtext(5);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const entry_r7 = ctx.$implicit;
    i0.ɵɵadvance();
    i0.ɵɵclassMap(entry_r7.Icon);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(entry_r7.Label);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(entry_r7.Timestamp);
} }
function ClassifyItemDrilldownComponent_Conditional_2_Conditional_35_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "ul", 22);
    i0.ɵɵrepeaterCreate(1, ClassifyItemDrilldownComponent_Conditional_2_Conditional_35_For_2_Template, 6, 4, "li", 39, _forTrack2);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵrepeater(ctx_r1.Audit);
} }
function ClassifyItemDrilldownComponent_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 2)(1, "section", 4)(2, "div", 5)(3, "h4", 6);
    i0.ɵɵelement(4, "i", 7);
    i0.ɵɵtext(5);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(6, "button", 8);
    i0.ɵɵlistener("click", function ClassifyItemDrilldownComponent_Conditional_2_Template_button_click_6_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OpenItemRecord()); });
    i0.ɵɵelement(7, "i", 9);
    i0.ɵɵtext(8, " Open Record ");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(9, "div", 10)(10, "div", 11)(11, "span", 12);
    i0.ɵɵtext(12, "Source");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(13, "span", 13);
    i0.ɵɵtext(14);
    i0.ɵɵelementEnd()();
    i0.ɵɵconditionalCreate(15, ClassifyItemDrilldownComponent_Conditional_2_Conditional_15_Template, 5, 2, "div", 11);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(16, ClassifyItemDrilldownComponent_Conditional_2_Conditional_16_Template, 2, 1, "div", 14);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(17, "section", 4)(18, "h4", 6);
    i0.ɵɵelement(19, "i", 15);
    i0.ɵɵtext(20);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(21, ClassifyItemDrilldownComponent_Conditional_2_Conditional_21_Template, 2, 0, "p", 16)(22, ClassifyItemDrilldownComponent_Conditional_2_Conditional_22_Template, 3, 0, "div", 17);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(23, "section", 4)(24, "h4", 6);
    i0.ɵɵelement(25, "i", 18);
    i0.ɵɵtext(26, " Provenance");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(27, "div", 19);
    i0.ɵɵrepeaterCreate(28, ClassifyItemDrilldownComponent_Conditional_2_For_29_Template, 6, 4, "div", 20, _forTrack0);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(30, "section", 4)(31, "h4", 6);
    i0.ɵɵelement(32, "i", 21);
    i0.ɵɵtext(33, " Audit");
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(34, ClassifyItemDrilldownComponent_Conditional_2_Conditional_34_Template, 2, 0, "p", 16)(35, ClassifyItemDrilldownComponent_Conditional_2_Conditional_35_Template, 3, 0, "ul", 22);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate1(" ", ctx_r1.DisplayName);
    i0.ɵɵadvance(9);
    i0.ɵɵtextInterpolate(ctx_r1.SourceName);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.URL ? 15 : -1);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.TextPreview ? 16 : -1);
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate1(" Tags (", ctx_r1.Tags.length, ")");
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.Tags.length === 0 ? 21 : 22);
    i0.ɵɵadvance(7);
    i0.ɵɵrepeater(ctx_r1.Provenance);
    i0.ɵɵadvance(6);
    i0.ɵɵconditional(ctx_r1.Audit.length === 0 ? 34 : 35);
} }
export class ClassifyItemDrilldownComponent extends BaseAngularComponent {
    cdr = inject(ChangeDetectorRef);
    /** The content item to drill into, by ID. Re-loads on change (setter pattern). */
    _itemID = null;
    set ItemID(value) {
        if (value === this._itemID)
            return;
        this._itemID = value;
        if (value)
            void this.load(value);
        else
            this.reset();
    }
    get ItemID() {
        return this._itemID;
    }
    /** Emitted when the user wants to open a related record (entity + id). */
    OpenRecordRequested = new EventEmitter();
    IsLoading = false;
    DisplayName = '';
    SourceName = '';
    URL = '';
    TextPreview = '';
    Tags = [];
    Provenance = [];
    Audit = [];
    // Template-facing formatters
    FormatWeight = formatWeight;
    TagFontSize = tagFontSize;
    /** Max characters of item text shown in the rendered-content preview. */
    static TEXT_PREVIEW_MAX = 1200;
    OpenPromptRun(tag) {
        if (tag.AIPromptRunID) {
            this.OpenRecordRequested.emit({ entityName: 'MJ: AI Prompt Runs', recordID: tag.AIPromptRunID });
        }
    }
    OpenProvenanceRecord(fact) {
        if (fact.RecordEntity && fact.RecordID) {
            this.OpenRecordRequested.emit({ entityName: fact.RecordEntity, recordID: fact.RecordID });
        }
    }
    OpenItemRecord() {
        if (this._itemID) {
            this.OpenRecordRequested.emit({ entityName: 'MJ: Content Items', recordID: this._itemID });
        }
    }
    reset() {
        this.DisplayName = '';
        this.SourceName = '';
        this.URL = '';
        this.TextPreview = '';
        this.Tags = [];
        this.Provenance = [];
        this.Audit = [];
        this.cdr.detectChanges();
    }
    async load(itemID) {
        this.reset();
        this.IsLoading = true;
        this.cdr.detectChanges();
        const rv = RunView.FromMetadataProvider(this.ProviderToUse);
        const [itemResult, tagsResult] = await rv.RunViews([
            {
                EntityName: 'MJ: Content Items',
                ExtraFilter: `ID='${itemID}'`,
                Fields: ['ID', 'Name', 'Description', 'ContentSource', 'ContentSourceID', 'URL', 'Text',
                    'EntityRecordDocumentID', 'EmbeddingStatus', 'TaggingStatus', 'LastTaggedAt',
                    'LastEmbeddedAt', '__mj_CreatedAt'],
                ResultType: 'simple',
            },
            {
                EntityName: 'MJ: Content Item Tags',
                ExtraFilter: `ItemID='${itemID}'`,
                OrderBy: 'Weight DESC',
                Fields: ['ID', 'Tag', 'Weight', 'Reasoning', 'AIPromptRunID', '__mj_CreatedAt'],
                ResultType: 'simple',
            },
        ], this.ProviderToUse.CurrentUser);
        const item = itemResult.Success && itemResult.Results.length > 0
            ? itemResult.Results[0]
            : null;
        if (item) {
            this.applyItem(item);
        }
        this.applyTags(tagsResult.Success ? tagsResult.Results : []);
        this.IsLoading = false;
        this.cdr.detectChanges();
    }
    applyItem(item) {
        this.DisplayName = deriveDisplayName({ Name: item['Name'], Description: item['Description'] });
        this.SourceName = item['ContentSource'] ?? 'Unknown';
        this.URL = item['URL'] ?? '';
        const text = item['Text'] ?? '';
        this.TextPreview = text.length > ClassifyItemDrilldownComponent.TEXT_PREVIEW_MAX
            ? `${text.slice(0, ClassifyItemDrilldownComponent.TEXT_PREVIEW_MAX)}…`
            : text;
        this.buildProvenance(item);
        this.buildAudit(item);
    }
    applyTags(rows) {
        this.Tags = rows.map(r => ({
            Tag: r['Tag'] ?? '',
            Weight: Number(r['Weight'] ?? 0),
            Reasoning: r['Reasoning'] ?? null,
            AIPromptRunID: r['AIPromptRunID'] ?? null,
            CreatedAt: r['__mj_CreatedAt'] ?? '',
        }));
    }
    buildProvenance(item) {
        const facts = [];
        const sourceID = item['ContentSourceID'];
        facts.push({
            Label: 'Content Source',
            Value: this.SourceName,
            Icon: 'fa-solid fa-database',
            ...(sourceID ? { RecordEntity: 'MJ: Content Sources', RecordID: sourceID } : {}),
        });
        const docID = item['EntityRecordDocumentID'];
        if (docID) {
            facts.push({
                Label: 'Entity Record Document',
                Value: docID,
                Icon: 'fa-solid fa-file-lines',
                RecordEntity: 'MJ: Entity Record Documents',
                RecordID: docID,
            });
        }
        // Distinct AI Prompt Runs across this item's tags (provenance to the LLM runs).
        const promptRunIDs = new Set();
        for (const t of this.Tags) {
            if (t.AIPromptRunID)
                promptRunIDs.add(t.AIPromptRunID);
        }
        for (const runID of promptRunIDs) {
            facts.push({
                Label: 'AI Prompt Run',
                Value: runID,
                Icon: 'fa-solid fa-robot',
                RecordEntity: 'MJ: AI Prompt Runs',
                RecordID: runID,
            });
        }
        this.Provenance = facts;
    }
    buildAudit(item) {
        const entries = [];
        const created = item['__mj_CreatedAt'];
        const lastTagged = item['LastTaggedAt'];
        const lastEmbedded = item['LastEmbeddedAt'];
        if (created)
            entries.push({ Label: 'Item created', Timestamp: formatDate(created), Icon: 'fa-solid fa-plus' });
        if (lastTagged)
            entries.push({ Label: 'Last tagged', Timestamp: formatDate(lastTagged), Icon: 'fa-solid fa-tags' });
        if (lastEmbedded)
            entries.push({ Label: 'Last embedded', Timestamp: formatDate(lastEmbedded), Icon: 'fa-solid fa-vector-square' });
        this.Audit = entries;
    }
    static ɵfac = /*@__PURE__*/ (() => { let ɵClassifyItemDrilldownComponent_BaseFactory; return function ClassifyItemDrilldownComponent_Factory(__ngFactoryType__) { return (ɵClassifyItemDrilldownComponent_BaseFactory || (ɵClassifyItemDrilldownComponent_BaseFactory = i0.ɵɵgetInheritedFactory(ClassifyItemDrilldownComponent)))(__ngFactoryType__ || ClassifyItemDrilldownComponent); }; })();
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ClassifyItemDrilldownComponent, selectors: [["classify-item-drilldown"]], inputs: { ItemID: "ItemID" }, outputs: { OpenRecordRequested: "OpenRecordRequested" }, standalone: false, features: [i0.ɵɵInheritDefinitionFeature], decls: 3, vars: 1, consts: [[1, "cid-empty"], ["text", "Loading item detail...", "size", "small"], [1, "cid-wrap"], [1, "fa-solid", "fa-arrow-pointer"], [1, "cid-section"], [1, "cid-section-head"], [1, "cid-title"], [1, "fa-solid", "fa-file-lines"], ["mjButton", "", "variant", "secondary", "size", "sm", 3, "click"], [1, "fa-solid", "fa-up-right-from-square"], [1, "cid-fields"], [1, "cid-field"], [1, "cid-field-label"], [1, "cid-field-value"], [1, "cid-text-preview"], [1, "fa-solid", "fa-tags"], [1, "cid-muted"], [1, "cid-tag-list"], [1, "fa-solid", "fa-diagram-project"], [1, "cid-provenance-list"], [1, "cid-provenance-row"], [1, "fa-solid", "fa-clock-rotate-left"], [1, "cid-audit-list"], ["target", "_blank", "rel", "noopener", 1, "cid-field-link", 3, "href"], [1, "cid-tag-card"], [1, "cid-tag-head"], [1, "cid-tag-name"], [1, "cid-tag-weight"], ["title", "Open the AI Prompt Run that produced this tag", 1, "cid-provenance-link"], [1, "cid-tag-reasoning"], [1, "cid-tag-reasoning", "cid-muted"], ["title", "Open the AI Prompt Run that produced this tag", 1, "cid-provenance-link", 3, "click"], [1, "fa-solid", "fa-robot"], [1, "fa-solid", "fa-quote-left"], [1, "cid-provenance-icon"], [1, "cid-provenance-label"], [1, "cid-provenance-value", "cid-provenance-clickable"], [1, "cid-provenance-value"], [1, "cid-provenance-value", "cid-provenance-clickable", 3, "click"], [1, "cid-audit-row"], [1, "cid-audit-icon"], [1, "cid-audit-label"], [1, "cid-audit-time"]], template: function ClassifyItemDrilldownComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵconditionalCreate(0, ClassifyItemDrilldownComponent_Conditional_0_Template, 4, 0, "div", 0)(1, ClassifyItemDrilldownComponent_Conditional_1_Template, 1, 0, "mj-loading", 1)(2, ClassifyItemDrilldownComponent_Conditional_2_Template, 36, 7, "div", 2);
        } if (rf & 2) {
            i0.ɵɵconditional(!ctx.ItemID ? 0 : ctx.IsLoading ? 1 : 2);
        } }, dependencies: [i1.LoadingComponent, i2.MJButtonDirective], styles: [".cid-wrap[_ngcontent-%COMP%] {\n    display: flex;\n    flex-direction: column;\n    gap: 16px;\n}\n\n.cid-section[_ngcontent-%COMP%] {\n    background: var(--mj-bg-surface);\n    border: 1px solid var(--mj-border-default);\n    border-radius: var(--mj-radius-sm);\n    padding: 12px 14px;\n}\n\n.cid-section-head[_ngcontent-%COMP%] {\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    gap: 12px;\n    margin-bottom: 8px;\n}\n\n.cid-title[_ngcontent-%COMP%] {\n    margin: 0 0 8px 0;\n    font-size: 0.9rem;\n    font-weight: 600;\n    color: var(--mj-text-primary);\n    display: flex;\n    align-items: center;\n    gap: 6px;\n}\n\n.cid-title[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n    color: var(--mj-brand-primary);\n}\n\n.cid-section-head[_ngcontent-%COMP%]   .cid-title[_ngcontent-%COMP%] {\n    margin-bottom: 0;\n}\n\n.cid-fields[_ngcontent-%COMP%] {\n    display: flex;\n    flex-direction: column;\n    gap: 6px;\n}\n\n.cid-field[_ngcontent-%COMP%] {\n    display: flex;\n    gap: 10px;\n    font-size: 0.82rem;\n}\n\n.cid-field-label[_ngcontent-%COMP%] {\n    color: var(--mj-text-muted);\n    min-width: 60px;\n}\n\n.cid-field-value[_ngcontent-%COMP%] {\n    color: var(--mj-text-primary);\n}\n\n.cid-field-link[_ngcontent-%COMP%] {\n    color: var(--mj-text-link);\n    text-decoration: none;\n    word-break: break-all;\n}\n\n.cid-field-link[_ngcontent-%COMP%]:hover {\n    text-decoration: underline;\n}\n\n.cid-text-preview[_ngcontent-%COMP%] {\n    margin-top: 10px;\n    padding: 10px;\n    background: var(--mj-bg-surface-sunken);\n    border-radius: var(--mj-radius-sm);\n    font-size: 0.8rem;\n    line-height: 1.45;\n    color: var(--mj-text-secondary);\n    white-space: pre-wrap;\n    max-height: 220px;\n    overflow-y: auto;\n}\n\n.cid-muted[_ngcontent-%COMP%] {\n    color: var(--mj-text-muted);\n    font-size: 0.8rem;\n    margin: 0;\n}\n\n\n\n.cid-tag-list[_ngcontent-%COMP%] {\n    display: flex;\n    flex-direction: column;\n    gap: 8px;\n}\n\n.cid-tag-card[_ngcontent-%COMP%] {\n    border: 1px solid var(--mj-border-subtle);\n    border-radius: var(--mj-radius-sm);\n    padding: 8px 10px;\n    background: var(--mj-bg-surface-card);\n}\n\n.cid-tag-head[_ngcontent-%COMP%] {\n    display: flex;\n    align-items: center;\n    gap: 10px;\n    flex-wrap: wrap;\n}\n\n.cid-tag-name[_ngcontent-%COMP%] {\n    font-weight: 600;\n    color: var(--mj-text-primary);\n}\n\n.cid-tag-weight[_ngcontent-%COMP%] {\n    font-size: 0.72rem;\n    font-weight: 600;\n    color: var(--mj-brand-primary);\n    background: color-mix(in srgb, var(--mj-brand-primary) 12%, var(--mj-bg-surface));\n    border-radius: var(--mj-radius-full, 999px);\n    padding: 1px 8px;\n}\n\n.cid-provenance-link[_ngcontent-%COMP%] {\n    margin-left: auto;\n    border: 1px solid var(--mj-border-default);\n    background: var(--mj-bg-surface);\n    color: var(--mj-text-link);\n    border-radius: var(--mj-radius-sm);\n    font-size: 0.72rem;\n    padding: 2px 8px;\n    cursor: pointer;\n    display: inline-flex;\n    align-items: center;\n    gap: 4px;\n}\n\n.cid-provenance-link[_ngcontent-%COMP%]:hover {\n    background: var(--mj-bg-surface-hover);\n}\n\n.cid-tag-reasoning[_ngcontent-%COMP%] {\n    margin-top: 6px;\n    font-size: 0.8rem;\n    line-height: 1.4;\n    color: var(--mj-text-secondary);\n}\n\n.cid-tag-reasoning[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n    color: var(--mj-text-disabled);\n    margin-right: 4px;\n}\n\n\n\n.cid-provenance-list[_ngcontent-%COMP%], \n.cid-audit-list[_ngcontent-%COMP%] {\n    display: flex;\n    flex-direction: column;\n    gap: 6px;\n    margin: 0;\n    padding: 0;\n    list-style: none;\n}\n\n.cid-provenance-row[_ngcontent-%COMP%], \n.cid-audit-row[_ngcontent-%COMP%] {\n    display: flex;\n    align-items: center;\n    gap: 10px;\n    font-size: 0.82rem;\n}\n\n.cid-provenance-icon[_ngcontent-%COMP%], \n.cid-audit-icon[_ngcontent-%COMP%] {\n    color: var(--mj-text-muted);\n    width: 16px;\n    text-align: center;\n}\n\n.cid-provenance-label[_ngcontent-%COMP%], \n.cid-audit-label[_ngcontent-%COMP%] {\n    color: var(--mj-text-secondary);\n    min-width: 150px;\n}\n\n.cid-provenance-value[_ngcontent-%COMP%] {\n    color: var(--mj-text-primary);\n    word-break: break-all;\n}\n\n.cid-provenance-clickable[_ngcontent-%COMP%] {\n    border: none;\n    background: none;\n    color: var(--mj-text-link);\n    cursor: pointer;\n    padding: 0;\n    font: inherit;\n    display: inline-flex;\n    align-items: center;\n    gap: 4px;\n}\n\n.cid-provenance-clickable[_ngcontent-%COMP%]:hover {\n    text-decoration: underline;\n}\n\n.cid-audit-time[_ngcontent-%COMP%] {\n    margin-left: auto;\n    color: var(--mj-text-muted);\n    font-size: 0.78rem;\n}\n\n\n\n.cid-empty[_ngcontent-%COMP%] {\n    display: flex;\n    flex-direction: column;\n    align-items: center;\n    gap: 8px;\n    padding: 40px 16px;\n    color: var(--mj-text-muted);\n    text-align: center;\n}\n\n.cid-empty[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n    font-size: 1.6rem;\n    color: var(--mj-text-disabled);\n}\n\n.cid-empty[_ngcontent-%COMP%]   p[_ngcontent-%COMP%] {\n    margin: 0;\n    font-size: 0.85rem;\n}"] });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ClassifyItemDrilldownComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'classify-item-drilldown', template: "@if (!ItemID) {\n  <div class=\"cid-empty\">\n    <i class=\"fa-solid fa-arrow-pointer\"></i>\n    <p>Select an item to inspect its tags, reasoning, and provenance.</p>\n  </div>\n} @else if (IsLoading) {\n  <mj-loading text=\"Loading item detail...\" size=\"small\"></mj-loading>\n} @else {\n  <div class=\"cid-wrap\">\n\n    <!-- (A) Rendered content / fields -->\n    <section class=\"cid-section\">\n      <div class=\"cid-section-head\">\n        <h4 class=\"cid-title\"><i class=\"fa-solid fa-file-lines\"></i> {{ DisplayName }}</h4>\n        <button mjButton variant=\"secondary\" size=\"sm\" (click)=\"OpenItemRecord()\">\n          <i class=\"fa-solid fa-up-right-from-square\"></i> Open Record\n        </button>\n      </div>\n      <div class=\"cid-fields\">\n        <div class=\"cid-field\"><span class=\"cid-field-label\">Source</span><span class=\"cid-field-value\">{{ SourceName }}</span></div>\n        @if (URL) {\n          <div class=\"cid-field\">\n            <span class=\"cid-field-label\">URL</span>\n            <a class=\"cid-field-link\" [href]=\"URL\" target=\"_blank\" rel=\"noopener\">{{ URL }}</a>\n          </div>\n        }\n      </div>\n      @if (TextPreview) {\n        <div class=\"cid-text-preview\">{{ TextPreview }}</div>\n      }\n    </section>\n\n    <!-- (B) Tags with weight + reasoning + provenance link -->\n    <section class=\"cid-section\">\n      <h4 class=\"cid-title\"><i class=\"fa-solid fa-tags\"></i> Tags ({{ Tags.length }})</h4>\n      @if (Tags.length === 0) {\n        <p class=\"cid-muted\">No tags applied to this item.</p>\n      } @else {\n        <div class=\"cid-tag-list\">\n          @for (tag of Tags; track tag.Tag + tag.CreatedAt) {\n            <div class=\"cid-tag-card\">\n              <div class=\"cid-tag-head\">\n                <span class=\"cid-tag-name\" [style.fontSize]=\"TagFontSize(tag.Weight)\">{{ tag.Tag }}</span>\n                <span class=\"cid-tag-weight\">{{ FormatWeight(tag.Weight) }}</span>\n                @if (tag.AIPromptRunID) {\n                  <button class=\"cid-provenance-link\" (click)=\"OpenPromptRun(tag)\"\n                          title=\"Open the AI Prompt Run that produced this tag\">\n                    <i class=\"fa-solid fa-robot\"></i> Prompt Run\n                  </button>\n                }\n              </div>\n              @if (tag.Reasoning) {\n                <div class=\"cid-tag-reasoning\">\n                  <i class=\"fa-solid fa-quote-left\"></i> {{ tag.Reasoning }}\n                </div>\n              } @else {\n                <div class=\"cid-tag-reasoning cid-muted\">No reasoning captured.</div>\n              }\n            </div>\n          }\n        </div>\n      }\n    </section>\n\n    <!-- (C) Provenance -->\n    <section class=\"cid-section\">\n      <h4 class=\"cid-title\"><i class=\"fa-solid fa-diagram-project\"></i> Provenance</h4>\n      <div class=\"cid-provenance-list\">\n        @for (fact of Provenance; track fact.Label + fact.Value) {\n          <div class=\"cid-provenance-row\">\n            <i [class]=\"fact.Icon\" class=\"cid-provenance-icon\"></i>\n            <span class=\"cid-provenance-label\">{{ fact.Label }}</span>\n            @if (fact.RecordEntity && fact.RecordID) {\n              <button class=\"cid-provenance-value cid-provenance-clickable\" (click)=\"OpenProvenanceRecord(fact)\">\n                {{ fact.Value }} <i class=\"fa-solid fa-up-right-from-square\"></i>\n              </button>\n            } @else {\n              <span class=\"cid-provenance-value\">{{ fact.Value }}</span>\n            }\n          </div>\n        }\n      </div>\n    </section>\n\n    <!-- (D) Audit -->\n    <section class=\"cid-section\">\n      <h4 class=\"cid-title\"><i class=\"fa-solid fa-clock-rotate-left\"></i> Audit</h4>\n      @if (Audit.length === 0) {\n        <p class=\"cid-muted\">No audit events recorded.</p>\n      } @else {\n        <ul class=\"cid-audit-list\">\n          @for (entry of Audit; track entry.Label) {\n            <li class=\"cid-audit-row\">\n              <i [class]=\"entry.Icon\" class=\"cid-audit-icon\"></i>\n              <span class=\"cid-audit-label\">{{ entry.Label }}</span>\n              <span class=\"cid-audit-time\">{{ entry.Timestamp }}</span>\n            </li>\n          }\n        </ul>\n      }\n    </section>\n\n  </div>\n}\n", styles: [".cid-wrap {\n    display: flex;\n    flex-direction: column;\n    gap: 16px;\n}\n\n.cid-section {\n    background: var(--mj-bg-surface);\n    border: 1px solid var(--mj-border-default);\n    border-radius: var(--mj-radius-sm);\n    padding: 12px 14px;\n}\n\n.cid-section-head {\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    gap: 12px;\n    margin-bottom: 8px;\n}\n\n.cid-title {\n    margin: 0 0 8px 0;\n    font-size: 0.9rem;\n    font-weight: 600;\n    color: var(--mj-text-primary);\n    display: flex;\n    align-items: center;\n    gap: 6px;\n}\n\n.cid-title i {\n    color: var(--mj-brand-primary);\n}\n\n.cid-section-head .cid-title {\n    margin-bottom: 0;\n}\n\n.cid-fields {\n    display: flex;\n    flex-direction: column;\n    gap: 6px;\n}\n\n.cid-field {\n    display: flex;\n    gap: 10px;\n    font-size: 0.82rem;\n}\n\n.cid-field-label {\n    color: var(--mj-text-muted);\n    min-width: 60px;\n}\n\n.cid-field-value {\n    color: var(--mj-text-primary);\n}\n\n.cid-field-link {\n    color: var(--mj-text-link);\n    text-decoration: none;\n    word-break: break-all;\n}\n\n.cid-field-link:hover {\n    text-decoration: underline;\n}\n\n.cid-text-preview {\n    margin-top: 10px;\n    padding: 10px;\n    background: var(--mj-bg-surface-sunken);\n    border-radius: var(--mj-radius-sm);\n    font-size: 0.8rem;\n    line-height: 1.45;\n    color: var(--mj-text-secondary);\n    white-space: pre-wrap;\n    max-height: 220px;\n    overflow-y: auto;\n}\n\n.cid-muted {\n    color: var(--mj-text-muted);\n    font-size: 0.8rem;\n    margin: 0;\n}\n\n/* Tags */\n.cid-tag-list {\n    display: flex;\n    flex-direction: column;\n    gap: 8px;\n}\n\n.cid-tag-card {\n    border: 1px solid var(--mj-border-subtle);\n    border-radius: var(--mj-radius-sm);\n    padding: 8px 10px;\n    background: var(--mj-bg-surface-card);\n}\n\n.cid-tag-head {\n    display: flex;\n    align-items: center;\n    gap: 10px;\n    flex-wrap: wrap;\n}\n\n.cid-tag-name {\n    font-weight: 600;\n    color: var(--mj-text-primary);\n}\n\n.cid-tag-weight {\n    font-size: 0.72rem;\n    font-weight: 600;\n    color: var(--mj-brand-primary);\n    background: color-mix(in srgb, var(--mj-brand-primary) 12%, var(--mj-bg-surface));\n    border-radius: var(--mj-radius-full, 999px);\n    padding: 1px 8px;\n}\n\n.cid-provenance-link {\n    margin-left: auto;\n    border: 1px solid var(--mj-border-default);\n    background: var(--mj-bg-surface);\n    color: var(--mj-text-link);\n    border-radius: var(--mj-radius-sm);\n    font-size: 0.72rem;\n    padding: 2px 8px;\n    cursor: pointer;\n    display: inline-flex;\n    align-items: center;\n    gap: 4px;\n}\n\n.cid-provenance-link:hover {\n    background: var(--mj-bg-surface-hover);\n}\n\n.cid-tag-reasoning {\n    margin-top: 6px;\n    font-size: 0.8rem;\n    line-height: 1.4;\n    color: var(--mj-text-secondary);\n}\n\n.cid-tag-reasoning i {\n    color: var(--mj-text-disabled);\n    margin-right: 4px;\n}\n\n/* Provenance */\n.cid-provenance-list,\n.cid-audit-list {\n    display: flex;\n    flex-direction: column;\n    gap: 6px;\n    margin: 0;\n    padding: 0;\n    list-style: none;\n}\n\n.cid-provenance-row,\n.cid-audit-row {\n    display: flex;\n    align-items: center;\n    gap: 10px;\n    font-size: 0.82rem;\n}\n\n.cid-provenance-icon,\n.cid-audit-icon {\n    color: var(--mj-text-muted);\n    width: 16px;\n    text-align: center;\n}\n\n.cid-provenance-label,\n.cid-audit-label {\n    color: var(--mj-text-secondary);\n    min-width: 150px;\n}\n\n.cid-provenance-value {\n    color: var(--mj-text-primary);\n    word-break: break-all;\n}\n\n.cid-provenance-clickable {\n    border: none;\n    background: none;\n    color: var(--mj-text-link);\n    cursor: pointer;\n    padding: 0;\n    font: inherit;\n    display: inline-flex;\n    align-items: center;\n    gap: 4px;\n}\n\n.cid-provenance-clickable:hover {\n    text-decoration: underline;\n}\n\n.cid-audit-time {\n    margin-left: auto;\n    color: var(--mj-text-muted);\n    font-size: 0.78rem;\n}\n\n/* Empty state */\n.cid-empty {\n    display: flex;\n    flex-direction: column;\n    align-items: center;\n    gap: 8px;\n    padding: 40px 16px;\n    color: var(--mj-text-muted);\n    text-align: center;\n}\n\n.cid-empty i {\n    font-size: 1.6rem;\n    color: var(--mj-text-disabled);\n}\n\n.cid-empty p {\n    margin: 0;\n    font-size: 0.85rem;\n}\n"] }]
    }], null, { ItemID: [{
            type: Input
        }], OpenRecordRequested: [{
            type: Output
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ClassifyItemDrilldownComponent, { className: "ClassifyItemDrilldownComponent", filePath: "src/AI/components/autotagging/components/classify-item-drilldown.component.ts", lineNumber: 39 }); })();
//# sourceMappingURL=classify-item-drilldown.component.js.map