var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, inject } from '@angular/core';
import { RegisterClass, UUIDsEqual } from '@memberjunction/global';
import { LogError, RunView } from '@memberjunction/core';
import { MJEnvironmentEntityExtended } from '@memberjunction/core-entities';
import { AIEngineBase } from '@memberjunction/ai-engine-base';
import { trustDots, trustEvidenceLine } from '@memberjunction/predictive-studio-core';
import { BaseResourceComponent } from '@memberjunction/ng-shared';
import { PSResourceBase } from './ps-resource-base';
import { buildBusinessCatalog } from '../business-predictions.view-models';
import { parseAtRiskRows, topGlobalDrivers } from '../at-risk.view-models';
import * as i0 from "@angular/core";
import * as i1 from "@memberjunction/ng-ui-components";
import * as i2 from "@memberjunction/ng-shared-generic";
import * as i3 from "@memberjunction/ng-conversations";
const _c0 = () => [1, 2, 3, 4, 5];
const _forTrack0 = ($index, $item) => $item.modelId;
const _forTrack1 = ($index, $item) => $item.recordId;
function PSPredictionsResourceComponent_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 6);
    i0.ɵɵlistener("click", function PSPredictionsResourceComponent_Conditional_2_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.newPrediction()); });
    i0.ɵɵelement(1, "i", 7);
    i0.ɵɵtext(2, " New prediction ");
    i0.ɵɵelementEnd();
} }
function PSPredictionsResourceComponent_Conditional_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-loading", 4);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_0_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 11);
    i0.ɵɵelement(1, "i", 13);
    i0.ɵɵelementStart(2, "h3");
    i0.ɵɵtext(3, "No predictions yet");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "p", 14);
    i0.ɵɵtext(5, "Ask the Model Dev Agent to build your first one.");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(6, "button", 15);
    i0.ɵɵlistener("click", function PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_0_Template_button_click_6_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r1.newPrediction()); });
    i0.ɵɵelement(7, "i", 7);
    i0.ɵɵtext(8, " New prediction");
    i0.ɵɵelementEnd()();
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_1_For_2_Conditional_10_Template(rf, ctx) { if (rf & 1) {
    const _r4 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 26);
    i0.ɵɵlistener("click", function PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_1_For_2_Conditional_10_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r4); const c_r5 = i0.ɵɵnextContext().$implicit; const ctx_r1 = i0.ɵɵnextContext(4); return i0.ɵɵresetView(ctx_r1.open(c_r5)); });
    i0.ɵɵtext(1, "Open ");
    i0.ɵɵelement(2, "i", 27);
    i0.ɵɵelementEnd();
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_1_For_2_Conditional_11_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "button", 25);
    i0.ɵɵelement(1, "i", 28);
    i0.ɵɵtext(2, " Needs an analyst");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    i0.ɵɵproperty("disabled", true);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_1_For_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 17)(1, "div", 18)(2, "span", 19);
    i0.ɵɵelement(3, "i", 20);
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(5, "h3", 21);
    i0.ɵɵtext(6);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(7, "p", 22);
    i0.ɵɵtext(8);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(9, "div", 23);
    i0.ɵɵconditionalCreate(10, PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_1_For_2_Conditional_10_Template, 3, 0, "button", 24)(11, PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_1_For_2_Conditional_11_Template, 3, 1, "button", 25);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const c_r5 = ctx.$implicit;
    i0.ɵɵclassProp("blocked", !c_r5.canOpen);
    i0.ɵɵadvance(2);
    i0.ɵɵclassMap("trust-" + c_r5.trust.grade.toLowerCase());
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", c_r5.canOpen ? c_r5.trust.grade : "Not ready", " ");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(c_r5.title);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(c_r5.canOpen ? c_r5.trust.oneLiner : c_r5.blockedReason);
    i0.ɵɵadvance(2);
    i0.ɵɵconditional(c_r5.canOpen ? 10 : 11);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 12);
    i0.ɵɵrepeaterCreate(1, PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_1_For_2_Template, 12, 8, "div", 16, _forTrack0);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance();
    i0.ɵɵrepeater(ctx_r1.cards);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵconditionalCreate(0, PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_0_Template, 9, 0, "div", 11)(1, PSPredictionsResourceComponent_Conditional_5_Conditional_2_Conditional_1_Template, 3, 0, "div", 12);
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵconditional(ctx_r1.cards.length === 0 ? 0 : 1);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_3_For_9_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 43);
} if (rf & 2) {
    const d_r7 = ctx.$implicit;
    const ctx_r1 = i0.ɵɵnextContext(3);
    i0.ɵɵclassProp("on", d_r7 <= ctx_r1.dots(ctx_r1.selected));
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_0_For_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 49);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const d_r8 = ctx.$implicit;
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(d_r8);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 44);
    i0.ɵɵelement(1, "i", 48);
    i0.ɵɵelementStart(2, "strong");
    i0.ɵɵtext(3, "What's driving this:");
    i0.ɵɵelementEnd();
    i0.ɵɵrepeaterCreate(4, PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_0_For_5_Template, 2, 1, "span", 49, i0.ɵɵrepeaterTrackByIdentity);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(4);
    i0.ɵɵadvance(4);
    i0.ɵɵrepeater(ctx_r1.drivers);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-loading", 45);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_2_For_8_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 52)(1, "span", 54);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "span", 55);
    i0.ɵɵelement(4, "span", 56);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(5, "span", 57);
    i0.ɵɵtext(6);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const r_r9 = ctx.$implicit;
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(r_r9.recordId);
    i0.ɵɵadvance(2);
    i0.ɵɵclassMap("risk-" + r_r9.band);
    i0.ɵɵstyleProp("width", r_r9.riskPct, "%");
    i0.ɵɵadvance();
    i0.ɵɵclassMap("risk-" + r_r9.band);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1("", r_r9.riskPct, "%");
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 46, 0)(2, "div", 50)(3, "span");
    i0.ɵɵtext(4, "Member");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(5, "span", 51);
    i0.ɵɵtext(6, "Likelihood");
    i0.ɵɵelementEnd()();
    i0.ɵɵrepeaterCreate(7, PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_2_For_8_Template, 7, 8, "div", 52, _forTrack1);
    i0.ɵɵelementStart(9, "div", 53);
    i0.ɵɵtext(10);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(4);
    i0.ɵɵadvance(7);
    i0.ɵɵrepeater(ctx_r1.atRiskRows.slice(0, 50));
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1("", ctx_r1.atRiskRows.length > 50 ? "Showing top 50 of " + ctx_r1.atRiskRows.length : ctx_r1.atRiskRows.length + " members", " \u00B7 highest first");
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 47);
    i0.ɵɵtext(1, "No results yet \u2014 run this prediction from ");
    i0.ɵɵelementStart(2, "strong");
    i0.ɵɵtext(3, "Models in Production");
    i0.ɵɵelementEnd();
    i0.ɵɵtext(4, " to see who's at risk.");
    i0.ɵɵelementEnd();
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵconditionalCreate(0, PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_0_Template, 6, 0, "div", 44);
    i0.ɵɵconditionalCreate(1, PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_1_Template, 1, 0, "mj-loading", 45)(2, PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_2_Template, 11, 1, "div", 46)(3, PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Conditional_3_Template, 5, 0, "div", 47);
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(3);
    i0.ɵɵconditional(ctx_r1.drivers.length > 0 ? 0 : -1);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.atRiskLoading ? 1 : ctx_r1.atRiskRows.length > 0 ? 2 : 3);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_22_Template(rf, ctx) { if (rf & 1) {
    const _r10 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 58);
    i0.ɵɵlistener("click", function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_22_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r10); const ctx_r1 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r1.scrollToList()); });
    i0.ɵɵelement(1, "i", 59);
    i0.ɵɵtext(2, " Review the call list");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "button", 60);
    i0.ɵɵlistener("click", function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_22_Template_button_click_3_listener() { i0.ɵɵrestoreView(_r10); const ctx_r1 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r1.askAgentTo("Save these renewal-risk scores onto the member records so my team can use them.")); });
    i0.ɵɵelement(4, "i", 61);
    i0.ɵɵtext(5, " Save scores to records");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(6, "button", 62);
    i0.ɵɵlistener("click", function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_22_Template_button_click_6_listener() { i0.ɵɵrestoreView(_r10); const ctx_r1 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r1.askAgentTo("Put these at-risk members into a list called \"At-Risk Renewals\" for outreach.")); });
    i0.ɵɵelement(7, "i", 63);
    i0.ɵɵtext(8, " Send to a list");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(9, "button", 64);
    i0.ɵɵlistener("click", function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_22_Template_button_click_9_listener() { i0.ɵɵrestoreView(_r10); const ctx_r1 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r1.exportList()); });
    i0.ɵɵelement(10, "i", 65);
    i0.ɵɵtext(11, " Share / export");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(9);
    i0.ɵɵproperty("disabled", ctx_r1.atRiskRows.length === 0);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_23_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 42);
    i0.ɵɵelement(1, "i", 28);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", ctx_r1.selected.trust.gateReason);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Template(rf, ctx) { if (rf & 1) {
    const _r6 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "nav", 29)(1, "a", 30);
    i0.ɵɵlistener("click", function PSPredictionsResourceComponent_Conditional_5_Conditional_3_Template_a_click_1_listener() { i0.ɵɵrestoreView(_r6); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.backToCatalog()); });
    i0.ɵɵtext(2, "Predictions");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(3, "i", 31);
    i0.ɵɵelementStart(4, "span");
    i0.ɵɵtext(5);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(6, "div", 32)(7, "div", 33);
    i0.ɵɵrepeaterCreate(8, PSPredictionsResourceComponent_Conditional_5_Conditional_3_For_9_Template, 1, 2, "i", 34, i0.ɵɵrepeaterTrackByIdentity);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(10, "div", 35)(11, "div", 36);
    i0.ɵɵtext(12);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(13, "div", 37);
    i0.ɵɵtext(14);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(15, "div", 38);
    i0.ɵɵtext(16);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(17, "div", 39);
    i0.ɵɵtext(18);
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(19, "div", 40);
    i0.ɵɵconditionalCreate(20, PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_20_Template, 4, 2);
    i0.ɵɵelementStart(21, "div", 41);
    i0.ɵɵconditionalCreate(22, PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_22_Template, 12, 1)(23, PSPredictionsResourceComponent_Conditional_5_Conditional_3_Conditional_23_Template, 3, 1, "div", 42);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate(ctx_r1.selected.title);
    i0.ɵɵadvance();
    i0.ɵɵclassMap("trust-" + ctx_r1.selected.trust.grade.toLowerCase());
    i0.ɵɵadvance(2);
    i0.ɵɵrepeater(i0.ɵɵpureFunction0(11, _c0));
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate(ctx_r1.selected.canOpen ? "You can rely on this \u2014 " + ctx_r1.selected.trust.grade : "Not reliable yet");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r1.selected.trust.oneLiner);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r1.selected.trust.explanation);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r1.evidence());
    i0.ɵɵadvance(2);
    i0.ɵɵconditional(ctx_r1.selected.canOpen ? 20 : -1);
    i0.ɵɵadvance();
    i0.ɵɵclassProp("locked", !ctx_r1.selected.canOpen);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.selected.canOpen ? 22 : 23);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_4_Conditional_8_Template(rf, ctx) { if (rf & 1) {
    const _r12 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "mj-conversation-chat-area", 74);
    i0.ɵɵlistener("conversationCreated", function PSPredictionsResourceComponent_Conditional_5_Conditional_4_Conditional_8_Template_mj_conversation_chat_area_conversationCreated_0_listener($event) { i0.ɵɵrestoreView(_r12); const ctx_r1 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r1.onChatConversationCreated($event)); })("pendingMessageConsumed", function PSPredictionsResourceComponent_Conditional_5_Conditional_4_Conditional_8_Template_mj_conversation_chat_area_pendingMessageConsumed_0_listener() { i0.ɵɵrestoreView(_r12); const ctx_r1 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r1.onChatPendingMessageConsumed()); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(3);
    i0.ɵɵproperty("Provider", ctx_r1.Provider)("environmentId", ctx_r1.chatEnvironmentId)("currentUser", ctx_r1.currentUser)("conversation", ctx_r1.chatConversation)("conversationId", ctx_r1.chatConversationId)("isNewConversation", ctx_r1.chatIsNewConversation)("suppressNewConversationEmptyState", true)("allowMentions", false)("overlayMode", true)("showExportButton", false)("showShareButton", false)("showArtifactIndicator", false)("showAgentPicker", false)("showAgentModePicker", false)("defaultAgentId", ctx_r1.modelDevAgentId)("pendingMessage", ctx_r1.pendingPrompt)("applicationScope", "Application")("applicationId", ctx_r1.applicationId)("appContext", ctx_r1.chatAppContext);
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_4_Conditional_9_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 73);
    i0.ɵɵelement(1, "mj-loading", 75);
    i0.ɵɵelementEnd();
} }
function PSPredictionsResourceComponent_Conditional_5_Conditional_4_Template(rf, ctx) { if (rf & 1) {
    const _r11 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "aside", 10)(1, "div", 66)(2, "div", 67);
    i0.ɵɵelement(3, "i", 68);
    i0.ɵɵtext(4, " New prediction");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(5, "button", 69);
    i0.ɵɵlistener("click", function PSPredictionsResourceComponent_Conditional_5_Conditional_4_Template_button_click_5_listener() { i0.ɵɵrestoreView(_r11); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.closeChat()); });
    i0.ɵɵelement(6, "i", 70);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(7, "div", 71);
    i0.ɵɵconditionalCreate(8, PSPredictionsResourceComponent_Conditional_5_Conditional_4_Conditional_8_Template, 1, 19, "mj-conversation-chat-area", 72)(9, PSPredictionsResourceComponent_Conditional_5_Conditional_4_Conditional_9_Template, 2, 0, "div", 73);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(8);
    i0.ɵɵconditional(ctx_r1.currentUser ? 8 : 9);
} }
function PSPredictionsResourceComponent_Conditional_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 8)(1, "div", 9);
    i0.ɵɵconditionalCreate(2, PSPredictionsResourceComponent_Conditional_5_Conditional_2_Template, 2, 1);
    i0.ɵɵconditionalCreate(3, PSPredictionsResourceComponent_Conditional_5_Conditional_3_Template, 24, 12);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(4, PSPredictionsResourceComponent_Conditional_5_Conditional_4_Template, 10, 1, "aside", 10);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵclassProp("chat-open", ctx_r1.chatOpen);
    i0.ɵɵadvance(2);
    i0.ɵɵconditional(ctx_r1.view === "catalog" ? 2 : -1);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.view === "workspace" && ctx_r1.selected ? 3 : -1);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.chatOpen ? 4 : -1);
} }
const PREDICTIVE_STUDIO_APP_ID = '299C9272-8D38-40CA-85D4-0980F2C9FAD1';
const MODEL_DEV_AGENT_NAME = 'Model Development Agent';
/**
 * **Predictions** — the business-user home for Predictive Studio (`option-b-refined` mockup). Reframes
 * published ML models as plain-language "predictions" in a catalog, each with a trust badge; opening one
 * goes to a workspace whose trust verdict GATES the actions (a Poor/unmeasured prediction can't be acted
 * on). "+ New prediction" opens the Model Development Agent (the deterministic builder) as a docked
 * co-pilot. Zero ML jargon — the analyst surfaces stay under the other nav items as "Advanced".
 */
let PSPredictionsResourceComponent = class PSPredictionsResourceComponent extends PSResourceBase {
    SectionKey = 'predictions';
    SectionLabel = 'Predictions';
    SectionIcon = 'fa-solid fa-wand-magic-sparkles';
    cdrLocal = inject(ChangeDetectorRef);
    /** catalog (the home grid) ↔ workspace (a selected prediction). */
    view = 'catalog';
    selected = null;
    chatOpen = false;
    pendingPrompt = null;
    _modelDevAgentId = null;
    /**
     * Embedded co-pilot conversation state. The chat-area starts in "new conversation" mode; on the first
     * send it creates the conversation and emits `conversationCreated`, at which point we capture the live
     * conversation and flip out of new-mode so subsequent sends append to the same thread. Without this
     * wiring the suppressed empty-state input has no valid conversation to write into and the first send
     * silently no-ops (matches the proven Form Builder co-pilot pattern).
     */
    chatConversation = null;
    chatConversationId = null;
    chatIsNewConversation = true;
    /** The ranked at-risk rows for the open prediction's latest run (empty until loaded / when no run yet). */
    atRiskRows = [];
    /** Plain-language "what's driving this" drivers for the open prediction (global feature importance). */
    drivers = [];
    /** Whether the at-risk list is loading for the open prediction. */
    atRiskLoading = false;
    /** The business catalog cards, most-trustworthy first, derived from the engine's published models. */
    get cards() {
        return buildBusinessCatalog(this.engine.PublishedModels.map((m) => ({
            modelId: m.ID,
            name: this.engine.ModelDisplayName(m),
            HoldoutMetrics: m.HoldoutMetrics,
            Metrics: m.Metrics,
            ProblemType: m.ProblemType,
            updatedAt: m.__mj_UpdatedAt ?? null,
        })));
    }
    dots(c) { return trustDots(c.trust.grade); }
    evidence() { return trustEvidenceLine({ noun: 'members' }); }
    open(c) {
        if (!c.canOpen)
            return;
        this.selected = c;
        this.view = 'workspace';
        this.atRiskRows = [];
        this.drivers = [];
        this.cdrLocal.detectChanges();
        void this.loadAtRisk(c);
    }
    /** Load the open prediction's plain-language drivers + its latest run's ranked at-risk rows. */
    async loadAtRisk(c) {
        const model = this.engine.PublishedModels.find((m) => UUIDsEqual(m.ID, c.modelId));
        this.drivers = topGlobalDrivers(model?.FeatureImportance ?? null, 3);
        this.atRiskLoading = true;
        this.cdrLocal.detectChanges();
        try {
            const provider = this.ProviderToUse;
            const user = provider.CurrentUser ?? undefined;
            const runs = await this.engine.LoadRecentRunsForModel(c.modelId, provider, user, { maxRows: 1 });
            const latest = runs[0];
            if (latest?.ID) {
                const res = await RunView.FromMetadataProvider(provider).RunView({ EntityName: 'MJ: Process Run Details', ExtraFilter: `ProcessRunID='${latest.ID}'`, MaxRows: 2137, ResultType: 'entity_object' }, user);
                if (res.Success && this.selected?.modelId === c.modelId) {
                    this.atRiskRows = parseAtRiskRows((res.Results ?? []).map((d) => ({ recordId: d.RecordID, ResultPayload: d.ResultPayload })));
                }
            }
        }
        catch (err) {
            LogError(`PSPredictionsResource.loadAtRisk: ${err instanceof Error ? err.message : String(err)}`);
        }
        finally {
            this.atRiskLoading = false;
            this.cdrLocal.detectChanges();
        }
    }
    backToCatalog() {
        this.view = 'catalog';
        this.selected = null;
        this.atRiskRows = [];
        this.drivers = [];
        this.cdrLocal.detectChanges();
    }
    /** "Review the call list" — scroll the ranked at-risk list into view. */
    scrollToList() {
        document.querySelector('[data-testid="ps-atrisk-list"]')?.scrollIntoView({ behavior: 'smooth', block: 'start' });
    }
    /** "Save scores" / "Send to a list" — open the docked co-pilot seeded with the request (the agent does it). */
    askAgentTo(prompt) {
        this.pendingPrompt = prompt;
        this.chatOpen = true;
        void this.ensureModelDevAgentResolved();
        this.cdrLocal.detectChanges();
    }
    /** "Share / export" — download the at-risk list as a CSV (dependency-free). */
    exportList() {
        if (this.atRiskRows.length === 0)
            return;
        const csv = ['Member,Likelihood %,Predicted', ...this.atRiskRows.map((r) => `${r.recordId},${r.riskPct},${r.class ?? ''}`)].join('\n');
        const url = URL.createObjectURL(new Blob([csv], { type: 'text/csv' }));
        const a = document.createElement('a');
        a.href = url;
        a.download = `${(this.selected?.title ?? 'prediction').replace(/[^a-z0-9]+/gi, '-').toLowerCase()}-at-risk.csv`;
        a.click();
        URL.revokeObjectURL(url);
    }
    newPrediction() {
        this.pendingPrompt = 'Help me build a new prediction. What do you want to know about your members?';
        this.chatOpen = true;
        void this.ensureModelDevAgentResolved();
        this.cdrLocal.detectChanges();
    }
    closeChat() {
        this.chatOpen = false;
        this.pendingPrompt = null;
        this.cdrLocal.detectChanges();
    }
    /**
     * The chat-area created its backing conversation after the user's first message — capture the live
     * conversation, re-feed the pending message in the same change-detection cycle, and leave new-mode so
     * the thread renders (mirrors the Form Builder co-pilot's atomic state-flip).
     */
    onChatConversationCreated(event) {
        this.pendingPrompt = event.pendingMessage ?? null;
        this.chatConversation = event.conversation;
        this.chatConversationId = event.conversation.ID;
        this.chatIsNewConversation = false;
        this.cdrLocal.detectChanges();
    }
    /** The chat-area delivered the seeded prompt — clear the buffer so a re-render doesn't resend it. */
    onChatPendingMessageConsumed() {
        this.pendingPrompt = null;
        this.cdrLocal.detectChanges();
    }
    get currentUser() { return this.ProviderToUse.CurrentUser ?? null; }
    get chatEnvironmentId() {
        return this.Data?.Configuration?.['environmentId'] || MJEnvironmentEntityExtended.DefaultEnvironmentID;
    }
    get applicationId() { return this.Data?.Configuration?.['applicationId'] ?? null; }
    get modelDevAgentId() { return this._modelDevAgentId; }
    get chatAppContext() {
        return { app: 'Predictive Studio', section: 'predictions', publishedModels: this.engine.PublishedModels.length };
    }
    async ensureModelDevAgentResolved() {
        if (this._modelDevAgentId)
            return;
        try {
            await AIEngineBase.Instance.Config(false, this.ProviderToUse.CurrentUser ?? undefined);
            this._modelDevAgentId =
                AIEngineBase.Instance.Agents?.find((a) => a.Name?.trim().toLowerCase() === MODEL_DEV_AGENT_NAME.toLowerCase())?.ID ?? null;
            if (!this._modelDevAgentId)
                LogError(`PSPredictionsResource: '${MODEL_DEV_AGENT_NAME}' not found — chat uses default-agent routing.`);
            this.cdrLocal.detectChanges();
        }
        catch (err) {
            LogError(`PSPredictionsResource.ensureModelDevAgentResolved: ${err instanceof Error ? err.message : String(err)}`);
        }
    }
    static ɵfac = /*@__PURE__*/ (() => { let ɵPSPredictionsResourceComponent_BaseFactory; return function PSPredictionsResourceComponent_Factory(__ngFactoryType__) { return (ɵPSPredictionsResourceComponent_BaseFactory || (ɵPSPredictionsResourceComponent_BaseFactory = i0.ɵɵgetInheritedFactory(PSPredictionsResourceComponent)))(__ngFactoryType__ || PSPredictionsResourceComponent); }; })();
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: PSPredictionsResourceComponent, selectors: [["mj-ps-predictions-resource"]], standalone: false, features: [i0.ɵɵInheritDefinitionFeature], decls: 6, vars: 4, consts: [["atriskList", ""], [3, "Title", "Subtitle"], ["actions", ""], ["mjButton", "", "variant", "primary", "size", "sm", "data-testid", "ps-new-prediction"], ["text", "Loading your predictions\u2026", "size", "medium"], [1, "ps-biz-host", 3, "chat-open"], ["mjButton", "", "variant", "primary", "size", "sm", "data-testid", "ps-new-prediction", 3, "click"], [1, "fa-solid", "fa-plus"], [1, "ps-biz-host"], [1, "ps-biz-main"], ["data-testid", "ps-predictions-copilot", 1, "ps-biz-copilot"], ["data-testid", "ps-predictions-empty", 1, "ps-biz-empty"], ["data-testid", "ps-predictions-grid", 1, "ps-biz-grid"], [1, "fa-solid", "fa-wand-magic-sparkles"], [1, "muted"], ["mjButton", "", "variant", "primary", "size", "md", 3, "click"], ["data-testid", "ps-prediction-card", 1, "ps-biz-card", 3, "blocked"], ["data-testid", "ps-prediction-card", 1, "ps-biz-card"], [1, "ps-biz-card-top"], ["data-testid", "ps-trust-badge", 1, "ps-trust-badge"], [1, "fa-solid", "fa-shield-halved"], [1, "ps-biz-card-title"], [1, "ps-biz-card-line"], [1, "ps-biz-card-foot"], ["mjButton", "", "variant", "secondary", "size", "sm", "data-testid", "ps-open-prediction"], ["mjButton", "", "variant", "secondary", "size", "sm", "data-testid", "ps-open-blocked", 3, "disabled"], ["mjButton", "", "variant", "secondary", "size", "sm", "data-testid", "ps-open-prediction", 3, "click"], [1, "fa-solid", "fa-arrow-right"], [1, "fa-solid", "fa-lock"], [1, "ps-biz-crumb"], ["data-testid", "ps-crumb-home", 3, "click"], [1, "fa-solid", "fa-chevron-right"], ["data-testid", "ps-trust-banner", 1, "ps-trust-banner"], [1, "ps-trust-dots"], [1, "fa-solid", "fa-star", 3, "on"], [1, "ps-trust-text"], [1, "ps-trust-grade"], [1, "ps-trust-line"], [1, "ps-trust-explain", "muted"], [1, "ps-trust-evidence", "muted"], ["data-testid", "ps-workspace-body", 1, "ps-biz-workspace-body"], ["data-testid", "ps-action-bar", 1, "ps-action-bar"], [1, "ps-action-locked"], [1, "fa-solid", "fa-star"], ["data-testid", "ps-drivers", 1, "ps-drivers"], ["text", "Loading who's at risk\u2026", "size", "small"], ["data-testid", "ps-atrisk-list", 1, "ps-atrisk"], ["data-testid", "ps-atrisk-empty", 1, "ps-atrisk-empty", "muted"], [1, "fa-solid", "fa-lightbulb"], [1, "ps-driver-chip"], [1, "ps-atrisk-head"], [1, "ps-atrisk-rcol"], ["data-testid", "ps-atrisk-row", 1, "ps-atrisk-row"], [1, "ps-atrisk-foot", "muted"], [1, "ps-atrisk-id", "mono"], [1, "ps-atrisk-bar"], [1, "ps-atrisk-fill"], [1, "ps-atrisk-pct"], ["mjButton", "", "variant", "primary", "size", "sm", "data-testid", "ps-act-review", 3, "click"], [1, "fa-solid", "fa-list-check"], ["mjButton", "", "variant", "secondary", "size", "sm", "data-testid", "ps-act-save", 3, "click"], [1, "fa-solid", "fa-floppy-disk"], ["mjButton", "", "variant", "secondary", "size", "sm", "data-testid", "ps-act-list", 3, "click"], [1, "fa-solid", "fa-paper-plane"], ["mjButton", "", "variant", "secondary", "size", "sm", "data-testid", "ps-act-export", 3, "click", "disabled"], [1, "fa-solid", "fa-file-export"], [1, "ps-biz-copilot-head"], [1, "ps-biz-copilot-title"], [1, "fa-solid", "fa-robot"], ["aria-label", "Close", 1, "ps-biz-copilot-close", 3, "click"], [1, "fa-solid", "fa-xmark"], [1, "ps-biz-copilot-body"], ["emptyStateGreeting", "What do you want to predict? Describe it in plain words.", 3, "Provider", "environmentId", "currentUser", "conversation", "conversationId", "isNewConversation", "suppressNewConversationEmptyState", "allowMentions", "overlayMode", "showExportButton", "showShareButton", "showArtifactIndicator", "showAgentPicker", "showAgentModePicker", "defaultAgentId", "pendingMessage", "applicationScope", "applicationId", "appContext"], [1, "ps-biz-copilot-empty"], ["emptyStateGreeting", "What do you want to predict? Describe it in plain words.", 3, "conversationCreated", "pendingMessageConsumed", "Provider", "environmentId", "currentUser", "conversation", "conversationId", "isNewConversation", "suppressNewConversationEmptyState", "allowMentions", "overlayMode", "showExportButton", "showShareButton", "showArtifactIndicator", "showAgentPicker", "showAgentModePicker", "defaultAgentId", "pendingMessage", "applicationScope", "applicationId", "appContext"], ["text", "Connecting\u2026", "size", "small"]], template: function PSPredictionsResourceComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "mj-page-header-interior", 1)(1, "div", 2);
            i0.ɵɵconditionalCreate(2, PSPredictionsResourceComponent_Conditional_2_Template, 3, 0, "button", 3);
            i0.ɵɵelementEnd()();
            i0.ɵɵelementStart(3, "mj-page-body-interior");
            i0.ɵɵconditionalCreate(4, PSPredictionsResourceComponent_Conditional_4_Template, 1, 0, "mj-loading", 4)(5, PSPredictionsResourceComponent_Conditional_5_Template, 5, 5, "div", 5);
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵproperty("Title", ctx.view === "workspace" ? (ctx.selected == null ? null : ctx.selected.title) ?? "Prediction" : "Predictions")("Subtitle", ctx.view === "workspace" ? "Who to focus on, how much to trust it, and what to do next" : "Ready-to-use predictions for your members");
            i0.ɵɵadvance(2);
            i0.ɵɵconditional(ctx.view === "catalog" ? 2 : -1);
            i0.ɵɵadvance(2);
            i0.ɵɵconditional(ctx.isLoading ? 4 : 5);
        } }, dependencies: [i1.MJButtonDirective, i1.MJPageHeaderInteriorComponent, i1.MJPageBodyInteriorComponent, i2.LoadingComponent, i3.ConversationChatAreaComponent], styles: ["[_nghost-%COMP%] { display: flex; flex-direction: column; width: 100%; height: 100%; min-height: 0; }\n      .ps-biz-host[_ngcontent-%COMP%] { display: flex; flex: 1; min-height: 0; overflow: hidden; }\n      .ps-biz-main[_ngcontent-%COMP%] { flex: 1; min-width: 0; overflow-y: auto; padding: 16px 18px 28px; }\n      .ps-biz-grid[_ngcontent-%COMP%] { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }\n      .ps-biz-card[_ngcontent-%COMP%] { background: var(--mj-bg-surface); border: 1px solid var(--mj-border-default); border-radius: var(--mj-radius-lg); padding: 18px; box-shadow: var(--mj-shadow-sm); display: flex; flex-direction: column; gap: 10px; transition: box-shadow .15s, transform .15s; }\n      .ps-biz-card[_ngcontent-%COMP%]:hover { box-shadow: var(--mj-shadow-md); transform: translateY(-2px); }\n      .ps-biz-card.blocked[_ngcontent-%COMP%] { opacity: .85; background: var(--mj-bg-surface-card); }\n      .ps-biz-card-title[_ngcontent-%COMP%] { font-size: var(--mj-text-lg); font-weight: 600; color: var(--mj-text-primary); margin: 0; }\n      .ps-biz-card-line[_ngcontent-%COMP%] { color: var(--mj-text-secondary); font-size: var(--mj-text-sm); margin: 0; flex: 1; }\n      .ps-biz-card-foot[_ngcontent-%COMP%] { display: flex; justify-content: flex-end; }\n      .ps-trust-badge[_ngcontent-%COMP%] { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--mj-radius-full); font-size: var(--mj-text-xs); font-weight: 600; }\n      .trust-good[_ngcontent-%COMP%], .trust-excellent[_ngcontent-%COMP%] { background: var(--mj-status-success-bg); color: var(--mj-status-success-text); }\n      .trust-fair[_ngcontent-%COMP%] { background: var(--mj-status-warning-bg); color: var(--mj-status-warning-text); }\n      .trust-poor[_ngcontent-%COMP%] { background: var(--mj-status-error-bg); color: var(--mj-status-error-text); }\n      .ps-biz-empty[_ngcontent-%COMP%] { text-align: center; padding: 64px 16px; color: var(--mj-text-secondary); }\n      .ps-biz-empty[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] { font-size: 40px; color: var(--mj-brand-primary); margin-bottom: 12px; }\n      .ps-biz-empty[_ngcontent-%COMP%]   h3[_ngcontent-%COMP%] { margin: 0 0 6px; color: var(--mj-text-primary); }\n      .ps-biz-empty[_ngcontent-%COMP%]   p[_ngcontent-%COMP%] { margin: 0 0 16px; }\n      .ps-biz-crumb[_ngcontent-%COMP%] { display: flex; align-items: center; gap: 8px; font-size: var(--mj-text-sm); color: var(--mj-text-muted); margin-bottom: 14px; }\n      .ps-biz-crumb[_ngcontent-%COMP%]   a[_ngcontent-%COMP%] { color: var(--mj-text-link); cursor: pointer; }\n      .ps-biz-crumb[_ngcontent-%COMP%]   a[_ngcontent-%COMP%]:hover { text-decoration: underline; }\n      .ps-biz-crumb[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] { font-size: 10px; }\n      .ps-trust-banner[_ngcontent-%COMP%] { display: flex; gap: 16px; align-items: center; padding: 18px 20px; border-radius: var(--mj-radius-lg); border: 1px solid; margin-bottom: 18px; }\n      .ps-trust-banner.trust-good[_ngcontent-%COMP%], .ps-trust-banner.trust-excellent[_ngcontent-%COMP%] { background: var(--mj-status-success-bg); border-color: var(--mj-status-success-border); }\n      .ps-trust-banner.trust-fair[_ngcontent-%COMP%] { background: var(--mj-status-warning-bg); border-color: var(--mj-status-warning-border); }\n      .ps-trust-banner.trust-poor[_ngcontent-%COMP%] { background: var(--mj-status-error-bg); border-color: var(--mj-status-error-border); }\n      .ps-trust-dots[_ngcontent-%COMP%] { display: flex; gap: 3px; font-size: 18px; }\n      .ps-trust-dots[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] { color: var(--mj-border-strong); } .ps-trust-dots[_ngcontent-%COMP%]   i.on[_ngcontent-%COMP%] { color: var(--mj-status-warning); }\n      .ps-trust-banner.trust-good[_ngcontent-%COMP%]   .ps-trust-dots[_ngcontent-%COMP%]   i.on[_ngcontent-%COMP%], .ps-trust-banner.trust-excellent[_ngcontent-%COMP%]   .ps-trust-dots[_ngcontent-%COMP%]   i.on[_ngcontent-%COMP%] { color: var(--mj-status-success); }\n      .ps-trust-grade[_ngcontent-%COMP%] { font-weight: 700; font-size: var(--mj-text-lg); color: var(--mj-text-primary); }\n      .ps-trust-line[_ngcontent-%COMP%] { font-weight: 600; color: var(--mj-text-primary); margin-top: 2px; }\n      .ps-trust-explain[_ngcontent-%COMP%], .ps-trust-evidence[_ngcontent-%COMP%] { font-size: var(--mj-text-sm); margin-top: 4px; }\n      .ps-action-bar[_ngcontent-%COMP%] { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-radius: var(--mj-radius-lg); background: var(--mj-bg-surface-card); border: 1px solid var(--mj-border-default); }\n      .ps-action-bar.locked[_ngcontent-%COMP%] { background: var(--mj-status-error-bg); border-color: var(--mj-status-error-border); }\n      .ps-action-locked[_ngcontent-%COMP%] { display: flex; align-items: center; gap: 8px; color: var(--mj-status-error-text); font-weight: 600; font-size: var(--mj-text-sm); }\n      .ps-drivers[_ngcontent-%COMP%] { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 0 0 16px; color: var(--mj-text-secondary); font-size: var(--mj-text-sm); }\n      .ps-drivers[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] { color: var(--mj-status-warning); }\n      .ps-driver-chip[_ngcontent-%COMP%] { background: var(--mj-bg-surface-card); border: 1px solid var(--mj-border-default); border-radius: var(--mj-radius-full); padding: 2px 10px; font-weight: 600; color: var(--mj-text-primary); }\n      .ps-atrisk[_ngcontent-%COMP%] { border: 1px solid var(--mj-border-default); border-radius: var(--mj-radius-lg); overflow: hidden; margin-bottom: 16px; background: var(--mj-bg-surface); }\n      .ps-atrisk-head[_ngcontent-%COMP%] { display: grid; grid-template-columns: 1fr 140px 52px; gap: 12px; padding: 8px 14px; background: var(--mj-bg-surface-card); border-bottom: 1px solid var(--mj-border-default); font-size: var(--mj-text-xs); font-weight: 600; color: var(--mj-text-muted); text-transform: uppercase; letter-spacing: .03em; }\n      .ps-atrisk-rcol[_ngcontent-%COMP%] { grid-column: 2 / span 2; text-align: right; }\n      .ps-atrisk-row[_ngcontent-%COMP%] { display: grid; grid-template-columns: 1fr 140px 52px; gap: 12px; align-items: center; padding: 9px 14px; border-bottom: 1px solid var(--mj-border-subtle); }\n      .ps-atrisk-row[_ngcontent-%COMP%]:last-child { border-bottom: none; }\n      .ps-atrisk-row[_ngcontent-%COMP%]:hover { background: var(--mj-bg-surface-hover); }\n      .ps-atrisk-id[_ngcontent-%COMP%] { font-size: var(--mj-text-xs); color: var(--mj-text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n      .ps-atrisk-bar[_ngcontent-%COMP%] { height: 8px; border-radius: var(--mj-radius-full); background: var(--mj-bg-surface-sunken); overflow: hidden; }\n      .ps-atrisk-fill[_ngcontent-%COMP%] { display: block; height: 100%; border-radius: var(--mj-radius-full); }\n      .ps-atrisk-pct[_ngcontent-%COMP%] { text-align: right; font-weight: 700; font-size: var(--mj-text-sm); font-variant-numeric: tabular-nums; }\n      .ps-atrisk-fill.risk-high[_ngcontent-%COMP%] { background: var(--mj-status-error); }\n      .ps-atrisk-fill.risk-medium[_ngcontent-%COMP%] { background: var(--mj-status-warning); }\n      .ps-atrisk-fill.risk-low[_ngcontent-%COMP%] { background: var(--mj-status-success); }\n      .ps-atrisk-pct.risk-high[_ngcontent-%COMP%] { color: var(--mj-status-error-text); }\n      .ps-atrisk-pct.risk-medium[_ngcontent-%COMP%] { color: var(--mj-status-warning-text); }\n      .ps-atrisk-pct.risk-low[_ngcontent-%COMP%] { color: var(--mj-status-success-text); }\n      .ps-atrisk-foot[_ngcontent-%COMP%] { padding: 8px 14px; font-size: var(--mj-text-xs); }\n      .ps-atrisk-empty[_ngcontent-%COMP%] { padding: 24px; text-align: center; border: 1px dashed var(--mj-border-default); border-radius: var(--mj-radius-lg); margin-bottom: 16px; }\n      .mono[_ngcontent-%COMP%] { font-family: var(--mj-font-family-mono); }\n      .ps-biz-copilot[_ngcontent-%COMP%] { width: 420px; max-width: 42vw; flex: none; border-left: 1px solid var(--mj-border-default); background: var(--mj-bg-surface); display: flex; flex-direction: column; min-height: 0; }\n      .ps-biz-copilot-head[_ngcontent-%COMP%] { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--mj-border-default); }\n      .ps-biz-copilot-title[_ngcontent-%COMP%] { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--mj-text-primary); }\n      .ps-biz-copilot-title[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] { color: var(--mj-brand-primary); }\n      .ps-biz-copilot-close[_ngcontent-%COMP%] { background: transparent; border: none; cursor: pointer; padding: 6px 8px; border-radius: 6px; color: var(--mj-text-muted); }\n      .ps-biz-copilot-close[_ngcontent-%COMP%]:hover { background: var(--mj-bg-surface-hover); color: var(--mj-text-secondary); }\n      .ps-biz-copilot-body[_ngcontent-%COMP%] { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }\n      .ps-biz-copilot-body[_ngcontent-%COMP%]   mj-conversation-chat-area[_ngcontent-%COMP%] { flex: 1; min-height: 0; display: block; }\n      .ps-biz-copilot-empty[_ngcontent-%COMP%] { display: flex; align-items: center; justify-content: center; flex: 1; }\n      @media (max-width: 1100px) { .ps-biz-host.chat-open[_ngcontent-%COMP%]   .ps-biz-main[_ngcontent-%COMP%] { display: none; } .ps-biz-copilot[_ngcontent-%COMP%] { width: 100%; max-width: none; border-left: none; } }"], changeDetection: 0 });
};
PSPredictionsResourceComponent = __decorate([
    RegisterClass(BaseResourceComponent, 'PredictiveStudioPredictionsResource')
], PSPredictionsResourceComponent);
export { PSPredictionsResourceComponent };
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PSPredictionsResourceComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'mj-ps-predictions-resource', template: `
    <mj-page-header-interior
      [Title]="view === 'workspace' ? (selected?.title ?? 'Prediction') : 'Predictions'"
      [Subtitle]="view === 'workspace' ? 'Who to focus on, how much to trust it, and what to do next' : 'Ready-to-use predictions for your members'">
      <div actions>
        @if (view === 'catalog') {
          <button mjButton variant="primary" size="sm" data-testid="ps-new-prediction" (click)="newPrediction()">
            <i class="fa-solid fa-plus"></i> New prediction
          </button>
        }
      </div>
    </mj-page-header-interior>
    <mj-page-body-interior>
      @if (isLoading) {
        <mj-loading text="Loading your predictions…" size="medium"></mj-loading>
      } @else {
        <div class="ps-biz-host" [class.chat-open]="chatOpen">
          <div class="ps-biz-main">
            <!-- ───────── CATALOG ───────── -->
            @if (view === 'catalog') {
              @if (cards.length === 0) {
                <div class="ps-biz-empty" data-testid="ps-predictions-empty">
                  <i class="fa-solid fa-wand-magic-sparkles"></i>
                  <h3>No predictions yet</h3>
                  <p class="muted">Ask the Model Dev Agent to build your first one.</p>
                  <button mjButton variant="primary" size="md" (click)="newPrediction()"><i class="fa-solid fa-plus"></i> New prediction</button>
                </div>
              } @else {
                <div class="ps-biz-grid" data-testid="ps-predictions-grid">
                  @for (c of cards; track c.modelId) {
                    <div class="ps-biz-card" [class.blocked]="!c.canOpen" data-testid="ps-prediction-card">
                      <div class="ps-biz-card-top">
                        <span class="ps-trust-badge" [class]="'trust-' + c.trust.grade.toLowerCase()" data-testid="ps-trust-badge">
                          <i class="fa-solid fa-shield-halved"></i> {{ c.canOpen ? c.trust.grade : 'Not ready' }}
                        </span>
                      </div>
                      <h3 class="ps-biz-card-title">{{ c.title }}</h3>
                      <p class="ps-biz-card-line">{{ c.canOpen ? c.trust.oneLiner : c.blockedReason }}</p>
                      <div class="ps-biz-card-foot">
                        @if (c.canOpen) {
                          <button mjButton variant="secondary" size="sm" data-testid="ps-open-prediction" (click)="open(c)">Open <i class="fa-solid fa-arrow-right"></i></button>
                        } @else {
                          <button mjButton variant="secondary" size="sm" [disabled]="true" data-testid="ps-open-blocked"><i class="fa-solid fa-lock"></i> Needs an analyst</button>
                        }
                      </div>
                    </div>
                  }
                </div>
              }
            }

            <!-- ───────── WORKSPACE (trust gate) ───────── -->
            @if (view === 'workspace' && selected) {
              <nav class="ps-biz-crumb">
                <a (click)="backToCatalog()" data-testid="ps-crumb-home">Predictions</a>
                <i class="fa-solid fa-chevron-right"></i> <span>{{ selected.title }}</span>
              </nav>

              <div class="ps-trust-banner" [class]="'trust-' + selected.trust.grade.toLowerCase()" data-testid="ps-trust-banner">
                <div class="ps-trust-dots">
                  @for (d of [1,2,3,4,5]; track d) { <i class="fa-solid fa-star" [class.on]="d <= dots(selected)"></i> }
                </div>
                <div class="ps-trust-text">
                  <div class="ps-trust-grade">{{ selected.canOpen ? 'You can rely on this — ' + selected.trust.grade : 'Not reliable yet' }}</div>
                  <div class="ps-trust-line">{{ selected.trust.oneLiner }}</div>
                  <div class="ps-trust-explain muted">{{ selected.trust.explanation }}</div>
                  <div class="ps-trust-evidence muted">{{ evidence() }}</div>
                </div>
              </div>

              <div class="ps-biz-workspace-body" data-testid="ps-workspace-body">
                @if (selected.canOpen) {
                  @if (drivers.length > 0) {
                    <div class="ps-drivers" data-testid="ps-drivers">
                      <i class="fa-solid fa-lightbulb"></i> <strong>What's driving this:</strong>
                      @for (d of drivers; track d) { <span class="ps-driver-chip">{{ d }}</span> }
                    </div>
                  }
                  @if (atRiskLoading) {
                    <mj-loading text="Loading who's at risk…" size="small"></mj-loading>
                  } @else if (atRiskRows.length > 0) {
                    <div class="ps-atrisk" data-testid="ps-atrisk-list" #atriskList>
                      <div class="ps-atrisk-head"><span>Member</span><span class="ps-atrisk-rcol">Likelihood</span></div>
                      @for (r of atRiskRows.slice(0, 50); track r.recordId) {
                        <div class="ps-atrisk-row" data-testid="ps-atrisk-row">
                          <span class="ps-atrisk-id mono">{{ r.recordId }}</span>
                          <span class="ps-atrisk-bar"><span class="ps-atrisk-fill" [class]="'risk-' + r.band" [style.width.%]="r.riskPct"></span></span>
                          <span class="ps-atrisk-pct" [class]="'risk-' + r.band">{{ r.riskPct }}%</span>
                        </div>
                      }
                      <div class="ps-atrisk-foot muted">{{ atRiskRows.length > 50 ? 'Showing top 50 of ' + atRiskRows.length : atRiskRows.length + ' members' }} · highest first</div>
                    </div>
                  } @else {
                    <div class="ps-atrisk-empty muted" data-testid="ps-atrisk-empty">No results yet — run this prediction from <strong>Models in Production</strong> to see who's at risk.</div>
                  }
                }
                <div class="ps-action-bar" [class.locked]="!selected.canOpen" data-testid="ps-action-bar">
                  @if (selected.canOpen) {
                    <button mjButton variant="primary" size="sm" data-testid="ps-act-review" (click)="scrollToList()"><i class="fa-solid fa-list-check"></i> Review the call list</button>
                    <button mjButton variant="secondary" size="sm" data-testid="ps-act-save" (click)="askAgentTo('Save these renewal-risk scores onto the member records so my team can use them.')"><i class="fa-solid fa-floppy-disk"></i> Save scores to records</button>
                    <button mjButton variant="secondary" size="sm" data-testid="ps-act-list" (click)="askAgentTo('Put these at-risk members into a list called &quot;At-Risk Renewals&quot; for outreach.')"><i class="fa-solid fa-paper-plane"></i> Send to a list</button>
                    <button mjButton variant="secondary" size="sm" data-testid="ps-act-export" [disabled]="atRiskRows.length === 0" (click)="exportList()"><i class="fa-solid fa-file-export"></i> Share / export</button>
                  } @else {
                    <div class="ps-action-locked"><i class="fa-solid fa-lock"></i> {{ selected.trust.gateReason }}</div>
                  }
                </div>
              </div>
            }
          </div>

          @if (chatOpen) {
            <aside class="ps-biz-copilot" data-testid="ps-predictions-copilot">
              <div class="ps-biz-copilot-head">
                <div class="ps-biz-copilot-title"><i class="fa-solid fa-robot"></i> New prediction</div>
                <button class="ps-biz-copilot-close" (click)="closeChat()" aria-label="Close"><i class="fa-solid fa-xmark"></i></button>
              </div>
              <div class="ps-biz-copilot-body">
                @if (currentUser) {
                  <mj-conversation-chat-area
                    [Provider]="Provider" [environmentId]="chatEnvironmentId" [currentUser]="currentUser"
                    [conversation]="chatConversation" [conversationId]="chatConversationId" [isNewConversation]="chatIsNewConversation"
                    [suppressNewConversationEmptyState]="true" [allowMentions]="false" [overlayMode]="true"
                    [showExportButton]="false" [showShareButton]="false" [showArtifactIndicator]="false"
                    [showAgentPicker]="false" [showAgentModePicker]="false"
                    [defaultAgentId]="modelDevAgentId" [pendingMessage]="pendingPrompt"
                    [applicationScope]="'Application'" [applicationId]="applicationId" [appContext]="chatAppContext"
                    (conversationCreated)="onChatConversationCreated($event)"
                    (pendingMessageConsumed)="onChatPendingMessageConsumed()"
                    emptyStateGreeting="What do you want to predict? Describe it in plain words.">
                  </mj-conversation-chat-area>
                } @else { <div class="ps-biz-copilot-empty"><mj-loading text="Connecting…" size="small"></mj-loading></div> }
              </div>
            </aside>
          }
        </div>
      }
    </mj-page-body-interior>
  `, changeDetection: ChangeDetectionStrategy.OnPush, styles: ["\n      :host { display: flex; flex-direction: column; width: 100%; height: 100%; min-height: 0; }\n      .ps-biz-host { display: flex; flex: 1; min-height: 0; overflow: hidden; }\n      .ps-biz-main { flex: 1; min-width: 0; overflow-y: auto; padding: 16px 18px 28px; }\n      .ps-biz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }\n      .ps-biz-card { background: var(--mj-bg-surface); border: 1px solid var(--mj-border-default); border-radius: var(--mj-radius-lg); padding: 18px; box-shadow: var(--mj-shadow-sm); display: flex; flex-direction: column; gap: 10px; transition: box-shadow .15s, transform .15s; }\n      .ps-biz-card:hover { box-shadow: var(--mj-shadow-md); transform: translateY(-2px); }\n      .ps-biz-card.blocked { opacity: .85; background: var(--mj-bg-surface-card); }\n      .ps-biz-card-title { font-size: var(--mj-text-lg); font-weight: 600; color: var(--mj-text-primary); margin: 0; }\n      .ps-biz-card-line { color: var(--mj-text-secondary); font-size: var(--mj-text-sm); margin: 0; flex: 1; }\n      .ps-biz-card-foot { display: flex; justify-content: flex-end; }\n      .ps-trust-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--mj-radius-full); font-size: var(--mj-text-xs); font-weight: 600; }\n      .trust-good, .trust-excellent { background: var(--mj-status-success-bg); color: var(--mj-status-success-text); }\n      .trust-fair { background: var(--mj-status-warning-bg); color: var(--mj-status-warning-text); }\n      .trust-poor { background: var(--mj-status-error-bg); color: var(--mj-status-error-text); }\n      .ps-biz-empty { text-align: center; padding: 64px 16px; color: var(--mj-text-secondary); }\n      .ps-biz-empty i { font-size: 40px; color: var(--mj-brand-primary); margin-bottom: 12px; }\n      .ps-biz-empty h3 { margin: 0 0 6px; color: var(--mj-text-primary); }\n      .ps-biz-empty p { margin: 0 0 16px; }\n      .ps-biz-crumb { display: flex; align-items: center; gap: 8px; font-size: var(--mj-text-sm); color: var(--mj-text-muted); margin-bottom: 14px; }\n      .ps-biz-crumb a { color: var(--mj-text-link); cursor: pointer; }\n      .ps-biz-crumb a:hover { text-decoration: underline; }\n      .ps-biz-crumb i { font-size: 10px; }\n      .ps-trust-banner { display: flex; gap: 16px; align-items: center; padding: 18px 20px; border-radius: var(--mj-radius-lg); border: 1px solid; margin-bottom: 18px; }\n      .ps-trust-banner.trust-good, .ps-trust-banner.trust-excellent { background: var(--mj-status-success-bg); border-color: var(--mj-status-success-border); }\n      .ps-trust-banner.trust-fair { background: var(--mj-status-warning-bg); border-color: var(--mj-status-warning-border); }\n      .ps-trust-banner.trust-poor { background: var(--mj-status-error-bg); border-color: var(--mj-status-error-border); }\n      .ps-trust-dots { display: flex; gap: 3px; font-size: 18px; }\n      .ps-trust-dots i { color: var(--mj-border-strong); } .ps-trust-dots i.on { color: var(--mj-status-warning); }\n      .ps-trust-banner.trust-good .ps-trust-dots i.on, .ps-trust-banner.trust-excellent .ps-trust-dots i.on { color: var(--mj-status-success); }\n      .ps-trust-grade { font-weight: 700; font-size: var(--mj-text-lg); color: var(--mj-text-primary); }\n      .ps-trust-line { font-weight: 600; color: var(--mj-text-primary); margin-top: 2px; }\n      .ps-trust-explain, .ps-trust-evidence { font-size: var(--mj-text-sm); margin-top: 4px; }\n      .ps-action-bar { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-radius: var(--mj-radius-lg); background: var(--mj-bg-surface-card); border: 1px solid var(--mj-border-default); }\n      .ps-action-bar.locked { background: var(--mj-status-error-bg); border-color: var(--mj-status-error-border); }\n      .ps-action-locked { display: flex; align-items: center; gap: 8px; color: var(--mj-status-error-text); font-weight: 600; font-size: var(--mj-text-sm); }\n      .ps-drivers { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 0 0 16px; color: var(--mj-text-secondary); font-size: var(--mj-text-sm); }\n      .ps-drivers i { color: var(--mj-status-warning); }\n      .ps-driver-chip { background: var(--mj-bg-surface-card); border: 1px solid var(--mj-border-default); border-radius: var(--mj-radius-full); padding: 2px 10px; font-weight: 600; color: var(--mj-text-primary); }\n      .ps-atrisk { border: 1px solid var(--mj-border-default); border-radius: var(--mj-radius-lg); overflow: hidden; margin-bottom: 16px; background: var(--mj-bg-surface); }\n      .ps-atrisk-head { display: grid; grid-template-columns: 1fr 140px 52px; gap: 12px; padding: 8px 14px; background: var(--mj-bg-surface-card); border-bottom: 1px solid var(--mj-border-default); font-size: var(--mj-text-xs); font-weight: 600; color: var(--mj-text-muted); text-transform: uppercase; letter-spacing: .03em; }\n      .ps-atrisk-rcol { grid-column: 2 / span 2; text-align: right; }\n      .ps-atrisk-row { display: grid; grid-template-columns: 1fr 140px 52px; gap: 12px; align-items: center; padding: 9px 14px; border-bottom: 1px solid var(--mj-border-subtle); }\n      .ps-atrisk-row:last-child { border-bottom: none; }\n      .ps-atrisk-row:hover { background: var(--mj-bg-surface-hover); }\n      .ps-atrisk-id { font-size: var(--mj-text-xs); color: var(--mj-text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n      .ps-atrisk-bar { height: 8px; border-radius: var(--mj-radius-full); background: var(--mj-bg-surface-sunken); overflow: hidden; }\n      .ps-atrisk-fill { display: block; height: 100%; border-radius: var(--mj-radius-full); }\n      .ps-atrisk-pct { text-align: right; font-weight: 700; font-size: var(--mj-text-sm); font-variant-numeric: tabular-nums; }\n      .ps-atrisk-fill.risk-high { background: var(--mj-status-error); }\n      .ps-atrisk-fill.risk-medium { background: var(--mj-status-warning); }\n      .ps-atrisk-fill.risk-low { background: var(--mj-status-success); }\n      .ps-atrisk-pct.risk-high { color: var(--mj-status-error-text); }\n      .ps-atrisk-pct.risk-medium { color: var(--mj-status-warning-text); }\n      .ps-atrisk-pct.risk-low { color: var(--mj-status-success-text); }\n      .ps-atrisk-foot { padding: 8px 14px; font-size: var(--mj-text-xs); }\n      .ps-atrisk-empty { padding: 24px; text-align: center; border: 1px dashed var(--mj-border-default); border-radius: var(--mj-radius-lg); margin-bottom: 16px; }\n      .mono { font-family: var(--mj-font-family-mono); }\n      .ps-biz-copilot { width: 420px; max-width: 42vw; flex: none; border-left: 1px solid var(--mj-border-default); background: var(--mj-bg-surface); display: flex; flex-direction: column; min-height: 0; }\n      .ps-biz-copilot-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--mj-border-default); }\n      .ps-biz-copilot-title { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--mj-text-primary); }\n      .ps-biz-copilot-title i { color: var(--mj-brand-primary); }\n      .ps-biz-copilot-close { background: transparent; border: none; cursor: pointer; padding: 6px 8px; border-radius: 6px; color: var(--mj-text-muted); }\n      .ps-biz-copilot-close:hover { background: var(--mj-bg-surface-hover); color: var(--mj-text-secondary); }\n      .ps-biz-copilot-body { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }\n      .ps-biz-copilot-body mj-conversation-chat-area { flex: 1; min-height: 0; display: block; }\n      .ps-biz-copilot-empty { display: flex; align-items: center; justify-content: center; flex: 1; }\n      @media (max-width: 1100px) { .ps-biz-host.chat-open .ps-biz-main { display: none; } .ps-biz-copilot { width: 100%; max-width: none; border-left: none; } }\n    "] }]
    }], null, null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(PSPredictionsResourceComponent, { className: "PSPredictionsResourceComponent", filePath: "src/PredictiveStudio/resources/ps-predictions-resource.component.ts", lineNumber: 237 }); })();
/** Tree-shaking prevention — called from the subpath module so the @RegisterClass survives bundling. */
export function LoadPSPredictionsResource() {
    // intentionally empty
}
//# sourceMappingURL=ps-predictions-resource.component.js.map