1import{r as n,j as t,H as T}from"./index-DnpRIAmU.js";import{ap as Q,aq as X,ar as Z,as as $,at as v,au as ee,av as te,aw as se,ax as M,ay as N,az as oe,aA as ie,aB as B,aC as ne,aD as le,aE as re}from"./P360_Landed_Cost_VSG-lXQHSAq-.js";import{f as ae,r as de,c as pe,p as ce,k as ue,u as he,e as ge}from"./autopilot-core-BO1s-Ux1.js";import{a as xe}from"./agent-analysis-BgoTJgll.js";import"./BrandIcon-CSLf_0Lr.js";import"./ProximaMark-9gSbc8v0.js";import"./brand-tokens-aDiy2ad6.js";import"./index-BDbnnScJ.js";import"./roxi-intents-BTNpDfdc.js";import"./demo-ops-BkVJXOcK.js";import"./vendor-portal-Ds_-CKYX.js";import"./geo-map-D8WqbLL9.js";import"./demo-client-CSMuKk86.js";import"./agents.config-BoLKqfL-.js";import"./agent-core-BqSH9yK-.js";import"./levers-DVcj3wYQ.js";import"./planstore-C21JoRUA.js";import"./retail-profile-DmxzHrEm.js";const k=a=>"$"+Math.round(Math.abs(a||0)).toLocaleString(),p=a=>({display:"inline-block",fontSize:10,fontWeight:800,letterSpacing:"0.06em",padding:"2px 8px",borderRadius:99,border:"1px solid",marginRight:6,cursor:"default",...a==="ok"?{background:"#ECFDF5",color:"#065F46",borderColor:"rgba(6,95,70,0.25)"}:a==="warn"?{background:"#FFFBEB",color:"#92400E",borderColor:"rgba(146,64,14,0.25)"}:a==="err"?{background:"#FEF2F2",color:"#B91C1C",borderColor:"rgba(185,28,28,0.25)"}:a==="blue"?{background:"#EFF6FF",color:"#1D4ED8",borderColor:"rgba(37,99,235,0.2)"}:{background:"var(--surface-sunken, #F8FAFC)",color:"var(--text-2)",borderColor:"var(--border)"}});function Ne({actions:a,refresh:S,setActive:W,user:w}){const u=w?.displayName?`${w.displayName.split(" ")[0]} · Autopilot`:"Autopilot",[i,I]=n.useState(()=>Q()),c=e=>{I(e),oe(e)},d=X(i),o=n.useMemo(()=>ae(de(a||[],{log:i.log})),[a,i.log]),A=n.useMemo(()=>[...new Set(o.map(e=>e.kind))],[o]),{suggestions:L}=n.useMemo(()=>Z(i,o),[i,o]),x=n.useMemo(()=>pe(o.filter(e=>!$(i,e)),{...i,mode:"guarded"}),[o,i]),O=n.useMemo(()=>o.filter(e=>e.guard.inside),[o]),[r,E]=n.useState(null),[D,C]=n.useState(!1),[y,q]=n.useState(!1),[F,m]=n.useState(null),[P,U]=n.useState({});n.useEffect(()=>{let e=!0;return ce(o,"cost360").then(s=>{e&&U(s)}),()=>{e=!1}},[o]),n.useEffect(()=>{E(null)},[o.map(e=>e.id).join("|")]);const h=n.useMemo(()=>{if(!r)return o;const e=new Map(o.map(s=>[s.id,s]));return r.order.map(s=>e.get(s)).filter(Boolean)},[o,r]).filter(e=>!$(i,e)),G=y?h:h.slice(0,5),K=e=>{const s=ie(e,u);m(s.toast),s.ok&&(T({product:"cost360",kind:"autopilot",text:`Autopilot: ${s.toast}`,page:e.tab||null}),c(B(i,{who:u,mode:d,kind:e.kind,title:e.title,value:e.value,expected:e.value})),S?.())},H=e=>{c(ne(i,e,u)),m(`Not today: ${e.title}. The autopilot learns from that.`)},R=()=>{const e=le(o,u,v(),null,i);let s={...i,lastRun:v()};for(const l of e.applied)s=B(s,{who:u,mode:"guarded",kind:l.kind,title:l.title,value:l.value,expected:l.value});c(s),m(`Autopilot applied ${e.applied.length} action${e.applied.length===1?"":"s"}; ${e.skipped.length} left for you.`),e.applied.length&&(S?.(),T({product:"cost360",kind:"autopilot",text:`The sourcing autopilot applied ${e.applied.length} action${e.applied.length===1?"":"s"} unattended: ${e.applied.slice(0,3).map(l=>l.title).join("; ")}.`}))};n.useEffect(()=>{d==="guarded"&&i.lastRun!==v()&&x.length&&R()},[d]);const _=async()=>{C(!0);try{const e=await ge(xe,{product:"Cost360",actions:o});E(e||{brief:N(o),order:o.map(s=>s.id),groups:[],decideFirst:[],defer:[],fallback:!0})}finally{C(!1)}},J=e=>r?.defer.find(s=>s.id===e),V=e=>r?.decideFirst.find(s=>s.id===e),z=(i.log||[]).slice(0,8),Y=e=>e.kind==="insure"?"Request cover":e.kind==="claim"?"Open the claim":e.kind==="book"?"Request booking":"Review",g=e=>({padding:"6px 12px",borderRadius:8,border:e?0:"1px solid var(--border-strong, #CBD5E1)",background:e?"var(--brand)":"#fff",color:e?"#fff":"var(--text-1)",fontWeight:700,fontSize:12,cursor:"pointer",fontFamily:"inherit"});return t.jsxs("div",{className:"card",style:{padding:20},"aria-label":"Autopilot",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap",marginBottom:6},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:14,fontWeight:700,letterSpacing:"-0.01em"},children:"Autopilot · today's plan"}),t.jsxs("div",{style:{fontSize:12,color:"var(--text-3)",marginTop:2},children:[O.length," of ",o.length," inside the guardrails · ",x.length," would apply unattended · limit ",k(re)," per action · spend, approvals and awards always a person's"]})]}),t.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:6},role:"radiogroup","aria-label":"Autopilot mode",children:Object.entries(ee).map(([e,s])=>t.jsx("button",{type:"button",role:"radio","aria-checked":d===e,style:g(
1d===e),onClick:()=>c(te(i,e)),children:s},e))})]}),d==="guarded"&&A.length>0&&t.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",flexWrap:"wrap",marginBottom:6},"aria-label":"Kinds applied unattended",children:[t.jsx("span",{style:{fontSize:12,color:"var(--text-3)"},children:"Apply unattended:"}),A.map(e=>{const s=se(i,e)==="guarded";return t.jsxs("button",{type:"button",style:{...p(s?"ok":""),cursor:"pointer",fontFamily:"inherit"},"aria-pressed":s,onClick:()=>c(M(i,e,s?"draft":"guarded")),children:[s?"â ":"â ",ue(e)]},e)})]}),L.map(e=>t.jsxs("div",{style:{fontSize:12,color:"var(--text-2)",background:"var(--brand-light, #EEF8F6)",padding:"6px 10px",borderRadius:8,margin:"6px 0"},children:[e.text,e.action==="enable"&&d==="guarded"&&t.jsx("button",{type:"button",className:"btn-ghost",style:{marginLeft:8},onClick:()=>c(M(i,e.kind,"guarded")),children:"Switch on"})]},e.kind+e.action)),t.jsxs("p",{style:{fontSize:12.5,color:"var(--text-2)",margin:"6px 0 10px",lineHeight:1.5},children:[r?.brief||N(o)," ",t.jsx("button",{type:"button",className:"btn-ghost",disabled:D||!o.length,onClick:_,children:D?"Reasoningâ¦":r?"Reason again":"Reason about today"}),r?.fallback&&t.jsx("span",{children:" · the model was not reachable; this is the ranked order."})]}),r?.groups?.length>0&&t.jsx("div",{style:{fontSize:12,color:"var(--text-2)",marginBottom:8},children:r.groups.map((e,s)=>t.jsxs("div",{children:[t.jsx("b",{children:e.title}),": ",e.ids.map(l=>o.find(f=>f.id===l)?.title).filter(Boolean).join("; "),e.why?` · ${e.why}`:""]},s))}),F&&t.jsx("div",{style:{fontSize:12,color:"var(--brand)",marginBottom:8},role:"status",children:F}),o.length>0&&t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap",marginBottom:10},children:[t.jsxs("button",{type:"button",style:g(!0),disabled:!x.length,onClick:R,title:"Applies every action a guarded run may apply, in rank order, and logs each one",children:["Apply ",x.length||""," unattended"]}),t.jsx("span",{style:{fontSize:12,color:"var(--text-3)"},children:d==="guarded"?`Guarded mode runs this once a day when the summary opens${i.lastRun?` · last run ${i.lastRun}`:""}.`:"Draft mode proposes only; switch to guarded to let it apply within the limit."})]}),t.jsxs("div",{style:{display:"grid",gap:8},children:[G.map(e=>{const s=J(e.id),l=V(e.id),f=[...e.notes||[],...P[e.id]||[]];return t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:14,alignItems:"flex-start",padding:"12px 14px",border:`1px solid ${e.guard.inside&&!s?"rgba(31,143,132,0.35)":"var(--border)"}`,borderRadius:10,background:e.guard.inside&&!s?"var(--brand-light, #EEF8F6)":"#fff"},children:[t.jsxs("div",{style:{minWidth:0,flex:1},children:[t.jsxs("span",{style:p(),children:["#",e.rank]}),t.jsx("span",{style:p(e.guard.inside?"ok":"warn"),children:e.guard.inside?"INSIDE GUARDRAILS":"NEEDS A PERSON"}),t.jsx("span",{style:p(),children:e.kind.toUpperCase()}),t.jsx("span",{style:p(e.urgencyDays!=null&&e.urgencyDays<=1?"err":e.urgencyDays!=null&&e.urgencyDays<=7?"warn":""),children:he(e.urgencyDays).toUpperCase()}),s&&t.jsx("span",{style:p("blue"),children:"DEFERRED"}),e.distrusted&&t.jsx("span",{style:p("blue"),children:"RANKED LAST"}),t.jsx("b",{style:{display:"block",marginTop:4,fontSize:13},children:e.title}),t.jsxs("small",{style:{color:"var(--text-3)",fontSize:12},children:[e.detail,e.value?` · ${k(e.value)}`:""]}),t.jsxs("small",{style:{display:"block",color:"var(--text-3)",fontSize:12},children:["Why now: ",e.because]}),!e.guard.inside&&t.jsx("small",{style:{display:"block",color:"#B45309",fontSize:12},children:e.guard.reasons.join(" · ")}),l&&t.jsxs("small",{style:{display:"block",color:"var(--brand)",fontSize:12},children:["Decide first: ",l.question]}),s&&t.jsxs("small",{style:{display:"block",color:"#1D4ED8",fontSize:12},children:["Deferred: ",s.why]}),f.map((b,j)=>t.jsx("small",{style:{display:"block",color:"#1D4ED8",fontSize:12},children:b},j)),e.why?.length>0&&t.jsxs("details",{style:{marginTop:6,fontSize:12,color:"var(--text-2)"},children:[t.jsx("summary",{style:{cursor:"pointer"},children:"Why"}),t.jsx("ul",{style:{margin:"4px 0 0 18px",padding:0},children:e.why.slice(0,4).map((b,j)=>t.jsx("li",{children:b},j))})]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.guard.inside&&t.jsx("button",{type:"button",style:g(!1),onClick:()=>K(e),children:Y(e)}),t.jsx("button",{type:"button",style:g(!1),onClick:()=>W(e.tab),children:"Review"}),t.jsx("button",{type:"button",style:g(!1),title:"Dismiss for today; the autopilot learns from it",onClick:()=>H(e),children:"Not now"})]})]},e.id)}),!h.length&&t.jsx("p",{style:{fontSize:12.5,color:"var(--text-3)"},children:o.length?"Everything on today's plan is dismissed for today.":"The autopilot has nothing to propose right now."})]}),h.length>5&&t.jsx("button",{type:"button",className:"btn-ghost",style:{marginTop:8},onClick:()=>q(!y),children:y?"Show the first five":`Show ${h.length-5} more`}),z.length>0&&t.jsxs("details",{style:{marginTop:10,fontSize:12},children:[t.jsxs("summary",{style:{cursor:"pointer",color:"var(--text-2)"},children:["What the autopilot did (",(i.log||[]).length,")"]}),t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",marginTop:6,fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{color:"var(--text-3)",textAlign:"left"},children:[t.jsx("th",{style:{padding:"4px 6px"},children:"When"}),t.jsx("th",{style:{padding:"4px 6px"},children:"Action"}),t.jsx("th",{style:{padding:"4px 6px"},children:"What"}),t.jsx("th",{style:{padding:"4px 6px"},children:"Mode"}),t.jsx("th",{style:{padding:"4px 6px",textAlign:"right"},children:"Value"})]})}),t.jsx("tbody",{children:z.map((e,s)=>t.jsxs("tr",{style:{borderTop:"1px solid var(--border)"},children:[t.jsx("td",{style:{padding:"4px 6px",whiteSpace:"nowrap"}
1,children:new Date(e.at).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}),t.jsxs("td",{style:{padding:"4px 6px"},children:[e.title,t.jsxs("span",{style:{color:"var(--text-3)"},children:[" · ",e.who]})]}),t.jsx("td",{style:{padding:"4px 6px"},children:e.event||"applied"}),t.jsx("td",{style:{padding:"4px 6px"},children:e.mode}),t.jsx("td",{style:{padding:"4px 6px",textAlign:"right"},children:e.value?k(e.value):""})]},s))})]}),t.jsx("p",{style:{color:"var(--text-3)",marginTop:6},children:"Insurance and booking requests are written to the shipment and the PO audit; claims open in Recovery. Each is reversed from its own screen. Dismissals teach the autopilot which kinds to rank first and which never to apply unattended."})]})]})}export{Ne as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.