1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="07ef375e-5a9a-4672-9409-cd03a136e618",e._sentryDebugIdIdentifier="sentry-dbid-07ef375e-5a9a-4672-9409-cd03a136e618")}catch(e){}}(),(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3707],{13509:(e,t,a)=>{"use strict";a.d(t,{A:()=>c});var s=a(37876),r=a(14232),n=a(48230),l=a.n(n),i=a(18334),o=a(74503),d=a(13415);function c(e){var t,a;let{workspaceId:n}=e,[c,u]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=!1;if(u(null),n)return(async()=>{let{data:t,error:a}=await d.N.rpc("held_work_summary",{p_workspace_id:n});if(a)return i.Cp(Error("held_work_summary failed: ".concat(a.message)));e||u(null!=t?t:null)})(),()=>{e=!0}},[n]);let m=(null!=(t=null==c?void 0:c.assessments)?t:0)+(null!=(a=null==c?void 0:c.opportunities)?a:0);if(!c||0===m)return null;let x=[c.opportunities?"".concat(c.opportunities," ").concat(1===c.opportunities?"opportunity":"opportunities"):null,c.assessments?"".concat(c.assessments," ").concat(1===c.assessments?"assessment":"assessments"):null].filter(Boolean).join(" and ");return(0,s.jsx)("div",{className:"mb-6 rounded-md border-l-4 border-indigo-400 bg-indigo-50 p-4 dark:bg-indigo-900/30",children:(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)(o.A,{className:"mt-0.5 h-5 w-5 shrink-0 text-indigo-500 dark:text-indigo-300","aria-hidden":"true"}),(0,s.jsxs)("p",{className:"text-sm text-indigo-800 dark:text-indigo-200",children:[x," older than your plan's history window ",1===m?"is":"are"," being kept for you, not deleted."," ",(0,s.jsx)(l(),{href:"/subscription",className:"font-medium underline",children:"Upgrade"})," ","and ",1===m?"it comes":"they come"," back exactly as you left ",1===m?"it":"them","."]})]})})}},29119:(e,t,a)=>{"use strict";a.d(t,{J:()=>n});var s=a(37876);a(14232);var r=a(93784);function n(e){let{title:t,message:a,onConfirm:n,onCancel:l,confirmLabel:i="Delete",isLoading:o=!1}=e;return(0,s.jsx)("div",{className:"fixed inset-0 bg-gray-500/75 dark:bg-gray-900/80 flex items-center justify-center p-4 z-50",children:(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full",children:[(0,s.jsx)("div",{className:"p-6",children:(0,s.jsxs)("div",{className:"flex items-start",children:[(0,s.jsx)("div",{className:"flex-shrink-0",children:(0,s.jsx)("div",{className:"w-10 h-10 rounded-full bg-red-100 dark:bg-red-900/50 flex items-center justify-center",children:(0,s.jsx)(r.A,{className:"h-5 w-5 text-red-600 dark:text-red-400"})})}),(0,s.jsxs)("div",{className:"ml-4",children:[(0,s.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:t}),(0,s.jsx)("p",{className:"mt-2 text-sm text-gray-500 dark:text-gray-400",children:a})]})]})}),(0,s.jsxs)("div",{className:"bg-gray-50 dark:bg-gray-900/50 px-6 py-4 flex justify-end space-x-3 rounded-b-lg",children:[(0,s.jsx)("button",{type:"button",onClick:l,disabled:o,className:"px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-transparent hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50 transition-colors",children:"Cancel"}),(0,s.jsx)("button",{type:"button",onClick:n,disabled:o,className:"px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-red-600 hover:bg-red-700 dark:bg-red-500 dark:hover:bg-red-600 disabled:opacity-50 transition-colors",children:o?"Deleting...":i})]})]})})}},47782:(e,t,a)=>{"use strict";a.d(t,{MG:()=>c,cN:()=>d,dX:()=>m,h6:()=>u,ib:()=>i,zv:()=>o});var s=a(13415),r=a(17933),n=a(80163);async function l(){var e;let{data:t}=await s.N.auth.getSession(),a=null==(e=t.session)?void 0:e.access_token;if(!a)throw Error("You must be signed in to use AI features");return{"Content-Type":"application/json",Authorization:"Bearer ".concat(a)}}async function i(e){let t={title:e.title,category:e.category,description:e.description,opportunity_id:e.id};try{return(await (0,n.J)("/api/opportunities/analyze-jobs",t)).result}catch(e){if(!(e instanceof n.v))throw e}let a=await fetch("/api/opportunities/analyze",{method:"POST",headers:await l(),body:JSON.stringify(t)});if(!a.ok){let e=await a.text().catch(()=>""),t=null;try{t=e?JSON.parse(e):null}catch(e){t=null}if([502,503,504].includes(a.status))throw Error("The analysis is taking longer than the connection will wait. It may still finish on its own â reload in a moment, and if no anal
1ysis appears, run it again.");throw Error((null==t?void 0:t.error)||"Failed to analyze opportunity (".concat(a.status,")"))}return a.json()}async function o(e,t){let a=await fetch("/api/opportunities/chat",{method:"POST",headers:await l(),body:JSON.stringify({messages:e,context:t})});if(!a.ok)throw Error((await a.json()).error||"Failed to chat");return(await a.json()).message}async function d(e){let{data:t,error:a}=await s.N.from("opportunities").select("*").eq("workspace_id",e).order("created_at",{ascending:!1});if(a)throw a;return(null!=t?t:[]).map(r.Hu)}async function c(e,t,a){let{data:n,error:l}=await s.N.from("opportunities").insert({...a,workspace_id:e,created_by:t,status:"draft"}).select().single();if(l)throw l;return(0,r.Hu)(n)}async function u(e,t){let{data:a,error:n}=await s.N.from("opportunities").update({...(0,r.Kj)(t),updated_at:new Date().toISOString()}).eq("id",e).select().single();if(n)throw n;return(0,r.Hu)(a)}async function m(e){let{error:t}=await s.N.from("opportunities").delete().eq("id",e);if(t)throw t}},67674:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>sh});var s=a(37876),r=a(14232),n=a(18334),l=a(16317),i=a(13509),o=a(45403),d=a(35739),c=a(36414),u=a(6394),m=a(13415),x=a(55304),g=a(55892),h=a(28330);function p(e){var t;let{workspaceId:a,onReset:l}=e,{user:i}=(0,g.A)(),[p,y]=(0,r.useState)(!1),[b,f]=(0,r.useState)(!1),[v,w]=(0,r.useState)(null),[k,j]=(0,r.useState)(null);if((0,r.useEffect)(()=>{let e=!0;if(y(!1),a)return m.N.from("workspaces").select("is_demo").eq("id",a).maybeSingle().then(t=>{let{data:a}=t;e&&y(!!(null==a?void 0:a.is_demo))}),()=>{e=!1}},[a]),!a||!p)return null;let N=(0,h.j)(String(null!=(t=null==i?void 0:i.role)?t:"")),_=async e=>{w(e),j(null);try{let t=await fetch("/api/workspaces/".concat(encodeURIComponent(a),"/demo"),{method:"POST",headers:{...await (0,x.authHeaders)(),"Content-Type":"application/json"},body:JSON.stringify({action:e})}),s=await t.json().catch(()=>({}));if(!t.ok)throw Error(s.error||"Request failed");j("reset"===e?"Demo reset to its prepared state.":"Saved. Future resets return to this state."),f(!1),"reset"===e&&(null==l||l())}catch(e){n.Cp(e),j(e instanceof Error?e.message:"Request failed")}finally{w(null)}};return(0,s.jsxs)("div",{className:"mb-6 rounded-md border border-amber-300 bg-amber-50 p-3 dark:border-amber-700/60 dark:bg-amber-900/20",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)(o.A,{className:"h-5 w-5 shrink-0 text-amber-600 dark:text-amber-300","aria-hidden":"true"}),(0,s.jsx)("span",{className:"text-sm font-medium text-amber-900 dark:text-amber-100",children:"Demo workspace"}),(0,s.jsx)("span",{className:"text-sm text-amber-800 dark:text-amber-200",children:"Changes here can be undone with a reset."}),(0,s.jsxs)("div",{className:"ml-auto flex flex-wrap gap-2",children:[b?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("button",{type:"button",onClick:()=>_("reset"),disabled:null!==v,className:"inline-flex items-center rounded-md bg-amber-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-amber-700 disabled:opacity-50",children:["reset"===v?(0,s.jsx)(d.A,{className:"mr-1.5 h-4 w-4 animate-spin"}):(0,s.jsx)(c.A,{className:"mr-1.5 h-4 w-4"}),"Discard changes and reset"]}),(0,s.jsx)("button",{type:"button",onClick:()=>f(!1),className:"rounded-md border border-amber-300 px-3 py-1.5 text-sm text-amber-900 dark:border-amber-700 dark:text-amber-100",children:"Cancel"})]}):(0,s.jsxs)("button",{type:"button",onClick:()=>f(!0),className:"inline-flex items-center rounded-md border border-amber-300 bg-white px-3 py-1.5 text-sm font-medium text-amber-900 hover:bg-amber-100 dark:border-amber-700 dark:bg-transparent dark:text-amber-100",children:[(0,s.jsx)(c.A,{className:"mr-1.5 h-4 w-4"}),"Reset demo"]}),N&&(0,s.jsxs)("button",{type:"button",onClick:()=>_("capture"),disabled:null!==v,className:"inline-flex items-center rounded-md border border-amber-300 bg-white px-3 py-1.5 text-sm text-amber-900 hover:bg-amber-100 disabled:opacity-50 dark:border-amber-700 dark:bg-transparent dark:text-amber-100",children:["capture"===v?(0,s.jsx)(d.A,{className:"mr-1.5 h-4 w-4 animate-spin"}):(0,s.jsx)(u.A,{className:"mr-1.5 h-4 w-4"}),"Save as prepared state"]})]})]}
1),k&&(0,s.jsx)("p",{className:"mt-2 text-sm text-amber-900 dark:text-amber-100",children:k})]})}var y=a(93784),b=a(46443),f=a(29998),v=a(31992),w=a(74062),k=a(60383),j=a(61052),N=a(59917),_=a(31999),S=a(93536),A=a(79247),C=a(83981),T=a(28419),P=a(80310);let E=["marketing","hr","finance","operations","production","maintenance","quality","warehouse_logistics","field_service","sales","customer_service","it","legal","procurement","other"],F={marketing:"Marketing",hr:"Human Resources",finance:"Finance",operations:"Operations",production:"Production & Manufacturing",maintenance:"Maintenance",quality:"Quality",warehouse_logistics:"Warehouse & Logistics",field_service:"Field Service",sales:"Sales",customer_service:"Customer Service",it:"Information Technology",legal:"Legal",procurement:"Procurement",other:"Other"},q=E.map(e=>({value:e,label:F[e]}));function I(e){var t;return e?null!=(t=F[e])?t:e:F.other}function O(e){let{opportunities:t,onOpportunityClick:a}=e;return 0===t.length?(0,s.jsxs)("div",{className:"text-center py-12 bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700",children:[(0,s.jsx)(P.A,{className:"mx-auto h-12 w-12 text-gray-400 dark:text-gray-500"}),(0,s.jsx)("h3",{className:"mt-2 text-sm font-medium text-gray-900 dark:text-white",children:"No opportunities"}),(0,s.jsx)("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"Get started by creating a new automation opportunity."})]}):(0,s.jsx)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3",children:t.map(e=>(0,s.jsx)("div",{onClick:()=>null==a?void 0:a(e),className:"bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 hover:border-indigo-500 dark:hover:border-indigo-400 transition-colors cursor-pointer",children:(0,s.jsxs)("div",{className:"p-6",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,s.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-indigo-100 dark:bg-indigo-900/50 text-indigo-800 dark:text-indigo-200",children:I(e.category)}),(0,s.jsxs)("div",{className:"flex items-center",children:[(e=>{switch(e){case"analyzing":return(0,s.jsx)(A.A,{className:"h-5 w-5 text-yellow-500"});case"analyzed":return(0,s.jsx)(C.A,{className:"h-5 w-5 text-green-500"});case"signed_off":return(0,s.jsx)(C.A,{className:"h-5 w-5 text-green-600"});case"business_case":case"proposal":case"in_review":return(0,s.jsx)(A.A,{className:"h-5 w-5 text-indigo-500"});case"changes_requested":return(0,s.jsx)(y.A,{className:"h-5 w-5 text-amber-500"});case"ready_for_project":return(0,s.jsx)(C.A,{className:"h-5 w-5 text-indigo-500"});case"converted":return(0,s.jsx)(T.A,{className:"h-5 w-5 text-purple-500"});default:return(0,s.jsx)(y.A,{className:"h-5 w-5 text-gray-400 dark:text-gray-500"})}})(e.status),(0,s.jsx)("span",{className:"ml-2 text-sm text-gray-500 dark:text-gray-400",children:(e=>{switch(e){case"analyzing":return"AI Analysis in Progress";case"analyzed":return"Analysis Complete";case"business_case":return"Business Case";case"proposal":return"Proposal";case"in_review":return"In Review (sign-off)";case"changes_requested":return"Changes Requested";case"signed_off":return"Signed Off";case"ready_for_project":return"Ready for Project";case"converted":return"Converted to Project";default:return"Draft"}})(e.status)})]})]}),(0,s.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:e.title}),(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400 line-clamp-3 mb-4",children:e.description}),e.aiAnalysis&&(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,s.jsx)("span",{className:"text-gray-500 dark:text-gray-400",children:"Automation Potential"}),(0,s.jsxs)("span",{className:"font-medium text-indigo-600 dark:text-indigo-400",children:[e.aiAnalysis.automationPotential,"%"]})]}),(0,s.jsx)("div",{className:"mt-2 relative pt-1",children:(0,s.jsx)("div",{className:"overflow-hidden h-2 text-xs flex rounded bg-gray-200 dark:bg-gray-700",children:(0,s.jsx)("div",{style:{width:"".concat(e.aiAnalysis.automationPotential,"%")},className:"shadow-none flex flex-col text-center whitespace-nowrap text-white justify-center bg-indigo-500 dark:bg-indigo-400"})})})]}),(0,s.jsxs)("div",{className:"mt-4 flex items-center text-sm text-indigo-600 dark:text-indigo-400",children:["View Details",(0,s.jsx)(T.A,{className:"ml-1 h-4 w-4"})]})]})},e.id))})}var z=a(24757);let R={low:1,medium:2,high:3},D={low:1,medium:2,high:3},M=e=>Math.round(10*e)/10,L={quick_win:"Quick win",big_bet:"Big bet",fill_in:"Fill-in",deprioritize:"Deprioritize"},U={quick_win:"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-200",big_bet:"bg-indigo-100 text-indigo-800 dark:bg-indigo-900/30 dark:text-indigo-200",fill_in:"bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-200",deprioritize:"bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300"},H=["","Low","Medium","High"];function W(e){let{opportunities:t}=e,a=(0,r.useMemo)(()=>t.map(e=>{var t,a;return{id:e.id,title:e.title,automation:null!=(a=null==(t=e.aiAnalysis)?void 0:t.automationPotential)?a:null,grading:(0,z.ON)(e).grading}}
1).map(e=>({...e,portfolio:function(e){var t,a;let s=e.complexity?R[e.complexity]:2,r=null!=(a=null!=(t=e.business_value)?t:e.priority_level)?a:null,n=r?D[r]:2,l=null!=e.automation_potential?e.automation_potential/100*3:n,i=M((n+l)/2),o=s<=2,d=M(i-(s-1)*.5);return{effort:s,impact:i,quadrant:i>=2?o?"quick_win":"big_bet":o?"fill_in":"deprioritize",score:d}}(e.grading)})).sort((e,t)=>t.portfolio.score-e.portfolio.score||e.portfolio.effort-t.portfolio.effort),[t]);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"mb-4 flex items-center",children:[(0,s.jsx)(v.A,{className:"h-5 w-5 mr-2 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Opportunities ranked by effort \xd7 impact â compare and pick what to pursue."})]}),0===a.length?(0,s.jsx)("div",{className:"text-center py-12 text-gray-500 dark:text-gray-400",children:"No opportunities yet. Create and analyze one to see it ranked here."}):(0,s.jsx)("div",{className:"overflow-x-auto bg-white dark:bg-gray-800 rounded-lg shadow",children:(0,s.jsxs)("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[(0,s.jsx)("thead",{className:"bg-gray-50 dark:bg-gray-900/40",children:(0,s.jsx)("tr",{children:["#","Opportunity","Quadrant","Impact","Effort","Automation","Score"].map(e=>(0,s.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:e},e))})}),(0,s.jsx)("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:a.map((e,t)=>{var a;return(0,s.jsxs)("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-700/40",children:[(0,s.jsx)("td",{className:"px-4 py-3 text-sm text-gray-500 dark:text-gray-400",children:t+1}),(0,s.jsx)("td",{className:"px-4 py-3 text-sm font-medium text-gray-900 dark:text-white",children:e.title}),(0,s.jsx)("td",{className:"px-4 py-3",children:(0,s.jsx)("span",{className:"inline-flex px-2 py-0.5 rounded-full text-xs font-medium ".concat(U[e.portfolio.quadrant]),children:L[e.portfolio.quadrant]})}),(0,s.jsx)("td",{className:"px-4 py-3 text-sm text-gray-700 dark:text-gray-300",children:e.portfolio.impact}),(0,s.jsx)("td",{className:"px-4 py-3 text-sm text-gray-700 dark:text-gray-300",children:null!=(a=H[e.portfolio.effort])?a:e.portfolio.effort}),(0,s.jsx)("td",{className:"px-4 py-3 text-sm text-gray-700 dark:text-gray-300",children:null!=e.automation?"".concat(e.automation,"%"):"â"}),(0,s.jsx)("td",{className:"px-4 py-3 text-sm font-semibold text-gray-900 dark:text-white",children:e.portfolio.score})]},e.id)})})]})})]})}var B=a(41180),J=a(27011),G=a(95197),$=a(47782),V=a(78581),X=a(55885),Y=a(27069);let K=e=>"$".concat(Math.round(e).toLocaleString("en-US"));async function Q(e){let t=new Map;if(0===e.length)return new Map;let{data:a}=await m.N.from("opportunity_versions").select("opportunity_id, version, structured").in("opportunity_id",e);for(let e of null!=a?a:[]){let a=t.get(e.opportunity_id);(!a||e.version>a.version)&&t.set(e.opportunity_id,{version:e.version,payload:e.structured})}return new Map([...t].map(e=>{let[t,a]=e;return[t,a.payload]}))}async function Z(e){let t=await (0,$.cN)(e);if(0===t.length)return(0,V.P)([]);let a=await Q(t.map(e=>e.id)),s=t.map(e=>{var t,s,r,n,l,i;let o=a.get(e.id),d=null!=(n=null==o?void 0:o.grading)?n:(0,z.ON)(e).grading;return{status:e.status,annual_savings:null!=(l=null==o||null==(t=o.business_case)?void 0:t.annual_savings)?l:null,realized_annual_savings:null!=(i=null==o||null==(r=o.delivery)||null==(s=r.actuals)?void 0:s.realized_annual_savings)?i:null,automation_potential:d.automation_potential,quick_win:d.quick_win}});return(0,V.P)(s)}async function ee(e){let t=await (0,$.cN)(e),a=await Q(t.map(e=>e.id)),s=t.map(e=>{var t;let s=null==(t=a.get(e.id))?void 0:t.business_case;return{id:e.id,title:e.title,annual_loss:s?(0,X.Z5)(s).annual_loss:null}}),{data:r}=await m.N.from("lead_assessments").select("coi_value, type").eq("converted_workspace_id",e).order("created_at",{ascending:!1}).limit(1).maybeSingle(),n=(null==r?void 0:r.coi_value)==null?null:Number(r.coi_value),l=function(e){switch(e){case"business_risk_assessment":return"estimated_from_score";case"coi_calculator":return"estimated_from_profile";default:return null}}(null!=(i=null==r?void 0:r.type)?i:null);var i,o=null!=n&&Number.isFinite(n)&&n>0&&null!=l?{annual_loss:n,basis:l}:null;let d=s.filter(e=>null!=e.annual_loss),c=d.reduce((e,t)=>
1{var a;return e+(null!=(a=t.annual_loss)?a:0)},0);return{estimate:o,measured_annual_loss:Math.round(c),assessed_count:d.length,unassessed_count:s.length-d.length,delta:o?Math.round(c-o.annual_loss):null,coverage_ratio:o&&o.annual_loss>0?Math.round(c/o.annual_loss*100)/100:null}}async function et(e){let t=await (0,$.cN)(e),a=await Q(t.map(e=>e.id)),s=t.map(e=>{var t,s,r,n,l,i,o;let d=a.get(e.id);return{opportunity_id:e.id,title:e.title,status:e.status,run_stats:null==d||null==(t=d.delivery)?void 0:t.run_stats,loaded_hourly_rate:null!=(i=null==d||null==(r=d.business_case)||null==(s=r.assumptions)?void 0:s.loaded_hourly_rate)?i:null,realized_annual_savings:null!=(o=null==d||null==(l=d.delivery)||null==(n=l.actuals)?void 0:n.realized_annual_savings)?o:null}}),r=null;try{var n;let{data:t}=await m.N.auth.getSession(),a=null==(n=t.session)?void 0:n.access_token;if(a){let t=await fetch("/api/workspaces/".concat(e,"/billing-facts"),{headers:{Authorization:"Bearer ".concat(a)}});if(t.ok){let{fact:e}=await t.json();if(e&&"number"==typeof e.fees_paid)r={fees_paid:e.fees_paid,as_of:e.as_of};else if(e&&"string"==typeof e.fees_paid){let t=Number(e.fees_paid);Number.isFinite(t)&&(r={fees_paid:t,as_of:e.as_of})}}}}catch(e){}return function(e,t){var a,s;let r=e.map(e=>{let t=function(e,t){if(!e||0===e.workflows.length)return{value:null,runs:0,unmeasured:0,window:null};let a=e.workflows.filter(e=>null!=e.minutes_saved_per_run&&Number.isFinite(e.minutes_saved_per_run)&&e.minutes_saved_per_run>0),s=e.workflows.reduce((e,t)=>e+t.runs_completed,0),r=e.workflows.length-a.length;return 0===a.length||null==t||t<=0?{value:null,runs:s,unmeasured:r,window:e.window_days}:{value:Math.round(a.reduce((e,a)=>e+a.runs_completed*(a.minutes_saved_per_run/60)*t,0)),runs:s,unmeasured:r,window:e.window_days}}(e.run_stats,e.loaded_hourly_rate);return{opportunity_id:e.opportunity_id,title:e.title,status:e.status,measured_value:t.value,measured_window_days:t.window,measured_runs:t.runs,unmeasured_workflows:t.unmeasured,asserted_value:e.realized_annual_savings}}),n=r.filter(e=>null!=e.measured_value),l=r.filter(e=>null!=e.asserted_value);return{by_project:r,measured_total:n.length?n.reduce((e,t)=>e+t.measured_value,0):null,asserted_total:l.length?l.reduce((e,t)=>e+t.asserted_value,0):null,fees_paid:null!=(a=null==t?void 0:t.fees_paid)?a:null,fees_as_of:null!=(s=null==t?void 0:t.as_of)?s:null,projects_measured:n.length,projects_total:r.length}}(s,r)}let ea=e=>"$".concat(Math.round(e).toLocaleString("en-US")),es=["discovery","qualified","proposal","signed_off","delivery","closed"];function er(e){let{workspaceId:t}=e,[a,n]=(0,r.useState)(null),[l,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(null),[u,m]=(0,r.useState)(null),[g,h]=(0,r.useState)(!0);if((0,r.useEffect)(()=>{if(!t)return;let e=!0;return(async()=>{h(!0);try{let[a,s,r,l]=await Promise.all([Z(t),ee(t).catch(()=>null),et(t).catch(()=>null),(async()=>{var e;let a=await fetch("/api/workspaces/".concat(t,"/process-inventory"),{headers:await (0,x.authHeaders)()});return a.ok?(null!=(e=(await a.json()).items)?e:[]).filter(e=>"inventoried"===e.status).length:null})().catch(()=>null)]);e&&(n(a),i(s),c(r),m(l))}catch(e){console.error("Failed to load portfolio report:",e)}finally{e&&h(!1)}})(),()=>{e=!1}},[t]),g)return(0,s.jsx)("div",{className:"flex items-center justify-center py-6",children:(0,s.jsx)(d.A,{className:"h-6 w-6 animate-spin text-indigo-600"})});if(!a||0===a.total)return null;let p=[{label:"Opportunities",value:String(a.total)},{label:"Predicted annual savings",value:ea(a.predicted_annual_savings),highlight:!0},...a.realized_annual_savings>0?[{label:"Realized savings",value:ea(a.realized_annual_savings),highlight:!0}]:[],{label:"Quick wins",value:String(a.quick_wins)},{label:"Avg automation",value:null!=a.avg_automation_potential?"".concat(a.avg_automation_potential,"%"):"â"},...null!=u&&u>0?[{label:"Inventory backlog",value:String(u)}]:[]];return(0,s.jsxs)("div",{className:"mb-6",children:[(0,s.jsxs)("div",{className:"flex items-center mb-3",children:[(0,s.jsx)(B.A,{className:"h-5 w-5 mr-2 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h3",{className:"text-sm font-semibold text-gray-900 dark:text-white uppercase tracking-wide",children:"Portfolio"})]}),(0,s.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-4",children:p.map(e=>(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3 bg-white dark:bg-gray-800",children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:e.label}),(0,s.jsx)("div",{className:"text-xl font-semibold ".concat(e.highlight?"text-green-600 dark:text-green-400":"text-gray-900 dark:text-white"),children:e.value})]},e.label))}),l&&(null!=l.estimate||l.unassessed_count>0)&&(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3 mb-4 bg-white dark:bg-gray-800",children:[(0,s.jsxs)("div",{className:"flex items-center mb-2",children:[(0,s.jsx)(J.A,{className:"h-4 w-4 text-gray-500 dark:text-gray-400"}),(0,s.jsx)("span",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Estimated vs measured"}),null!=l.coverage_ratio&&(0,s.jsxs)("span",{className:"ml-auto text-xs text-gray-500 dark:text-gray-400",children:[Math.round(100*l.coverage_ratio),"% of the estimate accounted for"]})]}),(0,s.jsx)("p",{className:"text-xs text-gray-700 dark:text-gray-300 whitespace-pre-line",children:(function(e){var t;let a=[];return e.estimate?(a.push("We estimated **".concat(K(e.estimate.annual_loss),"/year** for your organization ")+"(".concat(Y.CP[e.estimate.basis].toLowerCase(),").")),0===e.assessed_count?(a.push(""),a.push("No individual processes have been assessed against it yet.")):(a.push(""),a.push("Since then we have measured **".concat(K(e.measured_annual_loss),"/year** across ")+"".concat(e.assessed_count," assessed ").concat(1===e.assessed_count?"process":"processes"," â ")+"".concat(null==(t=e).delta?"":t.delta>0?"**".concat(K(t.delta),"/year more** than the original estimate. Assessing a process ")+"usually finds costs an org-level estimate cannot see.":t.delta<0?"**".concat(K(Math.abs(t.delta)),"/year less** so far, which is what you would expect ")+"while part of the operation is still unassessed.":"matching the original estimate.")))):a.push(e.assessed_count>0?"Across ".concat(e.assessed_count," assessed ").concat(1===e.assessed_count?"process":"processes",", ")+"staying as-is costs an estimated **".concat(K(e.measured_annual_loss),"/year**."):"No processes have been assessed yet."),e.unassessed_count>0&&(a.push(""),a.push("**".concat(e.unassessed_count,"** identified ").concat(1===e.unassessed_count?"process":"processes"," ")+"".concat(1===e.unassessed_count?"has":"have"," not been assessed yet and ")+"".concat(1===e.unassessed_count?"is":"are"," not counted in the figure above."))),a.join("\n")})(l).replace(/\*\*/g,"")})]}),o&&(null!=o.measured_total||null!=o.asserted_total||null!=o.fees_paid)&&(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3 mb-4 bg-white dark:bg-gray-800",children:[(0,s.jsxs)("div",{className:"flex items-center mb-2",children:[(0,s.jsx)(G.A,{className:"h-4 w-4 text-gray-500 dark:text-gray-400"}),(0,s.jsx)("span",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Value delivered to date"}),o.projects_measured<o.projects_total&&(0,s.jsxs)("span",{className:"ml-auto text-xs text-gray-500 dark:text-gray-400",children:[o.projects_total-o.projects_measured," of"," ",o.projects_total," projects unmeasured â counted, not valued at zero"]})]}),(0,s.jsxs)("div",{className:"grid grid-cols-3 gap-3 mb-2",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Measured (in window)"}),(0,s.jsx)("div",{className:"text-lg font-semibold text-green-600 dark:text-green-400",children:null!=o.measured_total?ea(o.measured_total):"â"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Asserted (typed)"}),(0,s.jsx)("div",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:null!=o.asserted_total?ea(o.asserted_total):"â"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Fees paid"}),(0,s.jsx)("div",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:null!=o.fees_paid?ea(o.fees_paid):"not recorded"})]})]}),o.by_project.some(e=>null!=e.measured_value||null!=e.asserted_value)&&(0,s.jsx)("div",{className:"space-y-0.5",children:o.by_project.filter(e=>null!=e.measured_value||null!=e.asserted_value).map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between text-xs text-gray-700 dark:text-gray-300",children:[(0,s.jsx)("span",{className:"truncate",children:e.title}),(0,s.jsx)("span",{className:"shrink-0 ml-3",children:null!=e.measured_value?"".concat(ea(e.measured_value)," measured (").concat(e.measured_runs.toLocaleStr
1ing("en-US")," runs, ").concat(e.measured_window_days,"d)"):"".concat(ea(e.asserted_value)," asserted")})]},e.opportunity_id))})]}),(0,s.jsx)("div",{className:"flex flex-wrap gap-2",children:es.map(e=>(0,s.jsxs)("span",{className:"inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300",children:[V.B[e],(0,s.jsx)("span",{className:"ml-1.5 font-semibold text-gray-900 dark:text-white",children:a.by_stage[e]})]},e))})]})}var en=a(28249),el=a(88992),ei=a(13810),eo=a(22442);let ed=eo.Ik({title:eo.Yj().min(1,"Title is required").max(100,"Title is too long"),category:eo.k5(E),customCategory:eo.Yj().optional(),description:eo.Yj().min(50,"Please provide more details (minimum 50 characters)").max(2e3,"Description is too long")});function ec(e){let{onSubmit:t,isSubmitting:a=!1}=e,[n,l]=(0,r.useState)(!1),{register:i,handleSubmit:o,watch:d,formState:{errors:c}}=(0,el.mN)({resolver:(0,ei.u)(ed),defaultValues:{title:"",category:"other",customCategory:"",description:""}});d("category");let u=async e=>{let a={title:e.title,category:"other"===e.category&&e.customCategory?"other":e.category,description:e.description};await t(a)};return(0,s.jsxs)("form",{onSubmit:o(u),className:"space-y-6",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"title",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Opportunity Title"}),(0,s.jsx)("input",{type:"text",id:"title",...i("title"),className:"mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white",placeholder:"e.g., Automate Invoice Processing"}),c.title&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-600 dark:text-red-400",children:c.title.message})]}),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"category",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Category"}),(0,s.jsx)("select",{id:"category",...i("category"),onChange:e=>{i("category").onChange(e),l("other"===e.target.value)},className:"mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white",children:q.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))}),c.category&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-600 dark:text-red-400",children:c.category.message})]}),n&&(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"customCategory",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Custom Category"}),(0,s.jsx)("input",{type:"text",id:"customCategory",...i("customCategory"),className:"mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white",placeholder:"Enter custom category"}),c.customCategory&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-600 dark:text-red-400",children:c.customCategory.message})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"description",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Process Description"}),(0,s.jsxs)("div",{className:"mt-1 mb-2",children:[(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Please provide detailed information about the process, including:"}),(0,s.jsxs)("ul",{className:"mt-1 list-disc list-inside text-sm text-gray-500 dark:text-gray-400",children:[(0,s.jsx)("li",{children:"Current manual steps involved"}),(0,s.jsx)("li",{children:"Tools and systems used"}),(0,s.jsx)("li",{children:"Frequency of execution"}),(0,s.jsx)("li",{children:"Pain points and challenges"}),(0,s.jsx)("li",{children:"Desired outcomes"})]})]}),(0,s.jsx)("textarea",{id:"description",...i("description"),rows:6,className:"mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white",placeholder:"Describe the current process and its challenges..."}),c.description&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-600 dark:text-red-400",children:c.description.message})]}),(0,s.jsx)("div",{className:"flex justify-end",children:(0,s.jsx)("button",{type:"submit",disabled:a,className:"inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800 disabled:opacity-50",children:a?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(j.A,{className:"animate-spin h-4 w-4 mr-2"}),"Analyzing..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(P.A,{className:"h-4 w-4 mr-2"}),"Create Opportunity"]})})})]})}function eu(e){let{onClose:t,onSubmit:a,isSubmitting:r}=e;return(0,s.jsx)("div",{className:"fixed inset-0 bg-gray-500/75 dark:bg-gray-900/80 flex items-center justify-center p-4 z-50",children:(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-3xl w-full max-h-[90vh] overflow-hidden",children:[(0,s.jsxs)("div",{className:"px-6 py-4 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between",children:[(0,s.jsx)("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"Create Automation Opportunity"}),(0,s.jsx)("button",{onClick:t,className:"text-gray-400 hover:text-gray-500 dark:hover:text-gray-300",children:(0,s.jsx)(en.A,{className:"h-6 w-6"})})]}),(0,s.jsx)("div",{className:"px-6 py-4 max-h-[calc(90vh-129px)] overflow-y-auto",children:(0,s.jsx)(ec,{onSubmit:a,isSubmitting:r})})]})})}let em=eo.Ik({title:eo.Yj().min(1,"Title is required").max(100,"Title is too long"),category:eo.k5(E),description:eo.Yj().min(50,"Please provide more details (minimum 50 characters)").max(2e3,"Description is too long")});function ex(e){let{opportunity:t,onClose:a,onSubmit:r,isSubmitting:n=!1}=e,{register:l,handleSubmit:i,formState:{errors:o,isDirty:d}}=(0,el.mN)({resolver:(0,ei.u)(em),defaultValues:{title:t.title,category:t.category,description:t.description}}),c=async e=>
1{await r(t.id,e)};return(0,s.jsx)("div",{className:"fixed inset-0 bg-gray-500/75 dark:bg-gray-900/80 flex items-center justify-center p-4 z-50",children:(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-3xl w-full max-h-[90vh] overflow-hidden",children:[(0,s.jsxs)("div",{className:"px-6 py-4 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between",children:[(0,s.jsx)("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"Edit Opportunity"}),(0,s.jsx)("button",{onClick:a,className:"text-gray-400 hover:text-gray-500 dark:hover:text-gray-300",children:(0,s.jsx)(en.A,{className:"h-6 w-6"})})]}),(0,s.jsxs)("form",{onSubmit:i(c),className:"px-6 py-4 max-h-[calc(90vh-129px)] overflow-y-auto",children:[(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"title",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Opportunity Title"}),(0,s.jsx)("input",{type:"text",id:"title",...l("title"),className:"mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white sm:text-sm",placeholder:"e.g., Automate Invoice Processing"}),o.title&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-600 dark:text-red-400",children:o.title.message})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"category",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Category"}),(0,s.jsx)("select",{id:"category",...l("category"),className:"mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white sm:text-sm",children:q.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))}),o.category&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-600 dark:text-red-400",children:o.category.message})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"description",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Process Description"}),(0,s.jsx)("textarea",{id:"description",...l("description"),rows:8,className:"mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white sm:text-sm",placeholder:"Describe the current process and its challenges..."}),o.description&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-600 dark:text-red-400",children:o.description.message})]}),t.aiAnalysis&&(0,s.jsx)("div",{className:"bg-yellow-50 dark:bg-yellow-900/30 border border-yellow-200 dark:border-yellow-800 rounded-md p-4",children:(0,s.jsxs)("p",{className:"text-sm text-yellow-700 dark:text-yellow-300",children:[(0,s.jsx)("strong",{children:"Note:"})," This opportunity has been analyzed. Significant changes to the description may require re-analysis for accurate insights."]})})]}),(0,s.jsxs)("div",{className:"mt-6 flex justify-end space-x-3",children:[(0,s.jsx)("button",{type:"button",onClick:a,className:"px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600",children:"Cancel"}),(0,s.jsx)("button",{type:"submit",disabled:n||!d,className:"inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 disabled:cursor-not-allowed",children:n?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(j.A,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.A,{className:"h-4 w-4 mr-2"}),"Save Changes"]})})]})]})]})})}
1var eg=a(71742),eh=a(54893),ep=a(4525),ey=a(58725),eb=a(29053);function ef(e){let{precedents:t}=e,[a,n]=(0,r.useState)({});return(null==t?void 0:t.length)?(0,s.jsxs)("div",{className:"mt-3 rounded-lg border border-gray-200 dark:border-gray-700 p-3",children:[(0,s.jsxs)("h5",{className:"text-sm font-medium text-gray-900 dark:text-white flex items-center gap-1.5 mb-1",children:[(0,s.jsx)(ep.A,{className:"h-4 w-4 text-indigo-600 dark:text-indigo-400"}),"Grounded in ",t.length," executed project",1===t.length?"":"s"]}),(0,s.jsx)("p",{className:"text-[11px] text-gray-500 dark:text-gray-400 mb-2",children:"Retrieved from the outcome corpus (measured results only) when this was generated. Precedents inform the recommendation â the computed figures come from this client's own business case."}),(0,s.jsx)("div",{className:"space-y-1.5",children:t.map(e=>{let t=a[e.corpus_id+e.section],r=function(e){var t,a,s,r;let n=null==(t=e.measurement)?void 0:t.measured;if(!n)return null;let l=[];for(let e of((null==(a=n.run_stats)?void 0:a.runs_completed)!=null&&l.push("".concat(n.run_stats.runs_completed," measured runs over ").concat(n.run_stats.window_days," days")+(null!=n.run_stats.annual_savings?" (â$".concat(Math.round(n.run_stats.annual_savings).toLocaleString("en-US"),"/yr)"):" (not yet dollarized)")),null!=(s=n.metrics)?s:[]))(null==e?void 0:e.name)!=null&&null!=e.baseline_value&&null!=e.actual_value&&l.push("".concat(e.name,": ").concat(e.baseline_value," â ").concat(e.actual_value," ").concat(null!=(r=e.unit)?r:"").trim());return l.length?"Measured: ".concat(l.join("; ")):null}(e);return(0,s.jsxs)("div",{className:"rounded-md border border-gray-100 dark:border-gray-700/60",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>n(a=>({...a,[e.corpus_id+e.section]:!t})),className:"w-full flex items-center gap-2 px-2 py-1.5 text-left",children:[t?(0,s.jsx)(ey.A,{className:"h-3.5 w-3.5 shrink-0 text-gray-400"}):(0,s.jsx)(eb.A,{className:"h-3.5 w-3.5 shrink-0 text-gray-400"}),(0,s.jsx)("span",{className:"text-xs text-gray-900 dark:text-white min-w-0 flex-1 truncate",children:e.title}),(0,s.jsxs)("span",{className:"text-[10px] text-gray-500 dark:text-gray-400 shrink-0 capitalize",children:[e.section,e.industry?" \xb7 ".concat(e.industry):""," \xb7 ".concat(Math.round(100*e.similarity),"% match")]})]}),t&&(0,s.jsxs)("div",{className:"px-7 pb-2",children:[(0,s.jsx)("p",{className:"text-xs text-gray-700 dark:text-gray-300 whitespace-pre-wrap",children:e.content}),r&&(0,s.jsx)("p",{className:"mt-1 text-[11px] text-green-700 dark:text-green-400",children:r})]})]},e.corpus_id+e.section)})})]}):null}function ev(e){var t,a,r,n,l,i;let{analysis:o}=e,d=null!=(t=o.complexity)?t:"unknown",c=null!=(a=o.automationPotential)?a:0,u=null!=(r=o.timeEstimate)?r:"â",m=null!=(n=o.potentialBenefits)?n:[],x=null!=(l=o.risks)?l:[],g=null!=(i=o.recommendations)?i:[];return(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:"Automation Potential"}),(0,s.jsx)(N.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"})]}),(0,s.jsx)("div",{className:"flex items-end space-x-2",children:(0,s.jsxs)("span",{className:"text-3xl font-bold text-gray-900 dark:text-white",children:[c,"%"]})}),(0,s.jsx)("div",{className:"mt-2 w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2",children:(0,s.jsx)("div",{className:"h-2 rounded-full ".concat(c>=80?"bg-green-500 dark:bg-green-400":c>=60?"bg-yellow-500 dark:bg-yellow-400":c>=40?"bg-orange-500 dark:bg-orange-400":"bg-red-500 dark:bg-red-400"),style:{width:"".concat(c,"%")}})})]}),(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:"Complexity"}),(0,s.jsx)(eg.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"})]}),(0,s.jsx)("span",{className:"inline-flex items-center px-3 py-1 rounded-full text-sm font-medium ".concat((e=>{switch(e){case"low":return"bg-green-100 dark:bg-green-900/50 text-green-800 dark:text-green-200";case"medium":return"bg-yellow-100 dark:bg-yellow-900/50 text-yellow-800 dark:text-yellow-200";case"high":return"bg-red-100 dark:bg-red-900/50 text-red-800 dark:text-red-200";default:return"bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200"}})(d)),children:d.charAt(0).toUpperCase()+d.slice(1)})]}),(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:"Time Estimate"}),(0,s.jsx)(A.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"})]}),(0,s.jsx)("span",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:u})]})]}
1),o.suggestedApproach&&(0,s.jsx)("div",{className:"bg-indigo-50 dark:bg-indigo-900/30 rounded-lg p-4 border border-indigo-100 dark:border-indigo-800",children:(0,s.jsxs)("div",{className:"flex items-start",children:[(0,s.jsx)(P.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400 mt-0.5"}),(0,s.jsxs)("div",{className:"ml-3",children:[(0,s.jsx)("h4",{className:"text-sm font-medium text-indigo-800 dark:text-indigo-200",children:"Suggested Approach"}),(0,s.jsx)("p",{className:"mt-1 text-sm text-indigo-700 dark:text-indigo-300",children:o.suggestedApproach})]})]})}),(0,s.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsxs)("div",{className:"flex items-center mb-3",children:[(0,s.jsx)(B.A,{className:"h-5 w-5 text-green-600 dark:text-green-400"}),(0,s.jsx)("h4",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Potential Benefits"})]}),(0,s.jsx)("ul",{className:"space-y-2",children:m.map((e,t)=>(0,s.jsxs)("li",{className:"flex items-start text-sm",children:[(0,s.jsx)(C.A,{className:"h-4 w-4 text-green-500 dark:text-green-400 mr-2 mt-0.5 flex-shrink-0"}),(0,s.jsx)("span",{className:"text-gray-700 dark:text-gray-300",children:e})]},t))})]}),(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsxs)("div",{className:"flex items-center mb-3",children:[(0,s.jsx)(y.A,{className:"h-5 w-5 text-yellow-600 dark:text-yellow-400"}),(0,s.jsx)("h4",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Risks & Challenges"})]}),(0,s.jsx)("ul",{className:"space-y-2",children:x.map((e,t)=>(0,s.jsxs)("li",{className:"flex items-start text-sm",children:[(0,s.jsx)(y.A,{className:"h-4 w-4 text-yellow-500 dark:text-yellow-400 mr-2 mt-0.5 flex-shrink-0"}),(0,s.jsx)("span",{className:"text-gray-700 dark:text-gray-300",children:e})]},t))})]})]}),(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsxs)("div",{className:"flex items-center mb-3",children:[(0,s.jsx)(C.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Recommendations"})]}),(0,s.jsx)("ol",{className:"space-y-2 list-decimal list-inside",children:g.map((e,t)=>(0,s.jsx)("li",{className:"text-sm text-gray-700 dark:text-gray-300",children:e},t))})]}),(0,s.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[o.requiredResources&&o.requiredResources.length>0&&(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsxs)("div",{className:"flex items-center mb-3",children:[(0,s.jsx)(eg.A,{className:"h-5 w-5 text-gray-600 dark:text-gray-400"}),(0,s.jsx)("h4",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Required Resources"})]}),(0,s.jsx)("ul",{className:"space-y-1",children:o.requiredResources.map((e,t)=>(0,s.jsxs)("li",{className:"text-sm text-gray-700 dark:text-gray-300",children:["⢠",e]},t))})]}),o.estimatedROI&&(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsxs)("div",{className:"flex items-center mb-3",children:[(0,s.jsx)(eh.A,{className:"h-5 w-5 text-green-600 dark:text-green-400"}),(0,s.jsx)("h4",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Estimated ROI"})]}),(0,s.jsx)("p",{className:"text-sm text-gray-700 dark:text-gray-300",children:o.estimatedROI})]}),(0,s.jsx)(ef,{precedents:o.precedents})]})]})}var ew=a(71233),ek=a(4792),ej=a(28113);function eN(e){let{opportunity:t}=e,{user:a}=(0,g.A)(),[n,l]=(0,r.useState)([]),[i,o]=(0,r.useState)(null),[c,u]=(0,r.useState)(!0),[m,x]=(0,r.useState)(!1),[h,p]=(0,r.useState)(""),[y,b]=(0,r.useState)(null),f=async()=>{u(!0);try{let e=await (0,z.yO)(t.id);l(e),o(e.length?e[e.length-1]:null)}catch(e){console.error("Failed to load opportunity versions:",e),b("Failed to load versions.")}finally{u(!1)}};(0,r.useEffect)(()=>{f()},[t.id]);let v=async e=>{if(a){x(!0),b(null);try{await e(),await f()}catch(e){console.error("Version action failed:",e),b("Action failed. Please try again.")}finally{x(!1)}}},w=()=>{let e=h.trim();e&&v(async()=>{await (0,z.XM)(t.id,{role:"user",content:e},a.id),p("")})};return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)(ew.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-lg font-medium text-gray-900 dark:text-white",children:"Version history"}),n.length>0&&(0,s.jsxs)("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:["v",n[n.length-1].version]})]}),n.length>0&&(0,s.jsxs)("button",{onClick:()=>v(()=>(0,z.zb)(t,"Snapshot of current analysis",a.id)),disabled:m,className:"inline-flex items-center px-3 py-1.5 text-xs font-medium rounded-md border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50 transition-colors",children:[(0,s.jsx)(ek.A,{className:"h-3.5 w-3.5 mr-1.5"}),"Save snapshot"]})]}),y&&(0,s.jsx)("div",{className:"mb-3 text-sm text-red-600 dark:text-red-400",children:y}),c?(0,s.jsxs)("div",{className:"flex items-center py-6 text-gray-500 dark:text-gray-400",children:[(0,s.jsx)(d.A,{className:"h-5 w-5 mr-2 animate-spin"})," Loading versionsâ¦"]}):0===n.length?(0,s.jsxs)("div",{className:"text-center py-6 bg-gray-50 dark:bg-gray-900/50 rounded-lg",children:[(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400 mb-3",children:"No saved versions yet. Capture the current analysis as version 1 to start iterating with history."}),(0,s.jsxs)("button",{onClick:()=>v(()=>(0,z.OG)(t,a.id)),disabled:m,className:"inline-flex items-center px-4 py-2 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 transition-colors",children:[m?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):(0,s.jsx)(ek.A,{className:"h-4 w-4 mr-2"}),"Create initial version"]})]}):(0,s.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[(0,s.jsx)("div",{className:"md:col-span-1 space-y-2",children:[...n].reverse().map(e=>(0,s.jsxs)("button",{onClick:()=>o(e),className:"w-full text-left p-3 rounded-lg border transition-colors ".concat((null==i?void 0:i.id)===e.id?"border-indigo-500 dark:border-indigo-400 bg-indigo-50 dark:bg-indigo-900/20":"border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("span",{className:"text-sm font-medium text-gray-900 dark:text-white",children:["v",e.version]}),(0,s.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:new Date(e.created_at).toLocaleDateString()})]}),e.change_summary&&(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1 line-clamp-2",children:e.change_summary})]},e.id))}),(0,s.jsx)("div",{className:"md:col-span-2",children:(0,s.jsx)("pre",{className:"text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap font-sans bg-gray-50 dark:bg-gray-900/50 rounded-lg p-4 max-h-72 overflow-y-auto",children:(null==i?void 0:i.narrative)||"Select a ver
1sion to view its narrative."})})]}),n.length>0&&(0,s.jsxs)("div",{className:"mt-4 flex items-center gap-2",children:[(0,s.jsx)("input",{type:"text",value:h,onChange:e=>p(e.target.value),onKeyDown:e=>"Enter"===e.key&&w(),placeholder:"Add a note / context to iterate onâ¦",className:"flex-1 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-sm"}),(0,s.jsx)("button",{onClick:w,disabled:m||!h.trim(),className:"inline-flex items-center px-3 py-2 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 transition-colors",children:(0,s.jsx)(ej.A,{className:"h-4 w-4"})})]})]})}var e_=a(79503),eS=a(21355),eA=a(81197),eC=a(78165),eT=a(90004),eP=a(73884),eE=a(37045),eF=a(46575);let eq=new Map(eF.k.map(e=>[e.key,e])),eI=new Set(["collaborative_robot","industrial_robot_cell"]);var eO=a(90823),ez=a(63423),eR=a(70912);let eD=e=>"$".concat(Math.round(e).toLocaleString("en-US")),eM=e=>null!=e?eD(e):"â",eL=["hire","outsource","automate","other"];function eU(e){let{alternatives:t,onChange:a,totalAnnualLoss:r,proposedCapture:n,proposedCost:l}=e,i=(e,s)=>a(t.map((t,a)=>a===e?{...t,...s,source:"user_entered"}:t)),o=t.some(e=>"automate"===e.kind),d=(0,eR.yj)(t,r);return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3 mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)(J.A,{className:"h-4 w-4 text-gray-500 dark:text-gray-400"}),(0,s.jsx)("span",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"What they are comparing us against"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[!o&&(0,s.jsx)("button",{type:"button",onClick:()=>a([...t,(0,eR.AS)(n,l,null)]),className:"text-xs font-medium text-indigo-600 dark:text-indigo-400 hover:underline",children:"Add our proposal"}),(0,s.jsxs)("button",{type:"button",onClick:()=>a([...t,{kind:"hire",annual_cost:null,one_time_cost:null,value_capture:n,ramp_months:null,source:"user_entered"}]),className:"inline-flex items-center text-xs font-medium text-indigo-600 dark:text-indigo-400 hover:underline",children:[(0,s.jsx)(k.A,{className:"h-3.5 w-3.5 mr-1"})," Add alternative"]})]})]}),0===t.length?(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Buyers weigh automation against hiring, outsourcing, or a point tool far more often than against doing nothing. A proposal that never names the alternative loses to one it never addressed."}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"space-y-2 mb-3",children:t.map((e,r)=>{var n,l,o;return(0,s.jsxs)("div",{className:"grid grid-cols-12 gap-2 items-end",children:[(0,s.jsxs)("div",{className:"col-span-3",children:[(0,s.jsx)("label",{className:eW,children:"Option"}),(0,s.jsx)("select",{value:e.kind,onChange:e=>i(r,{kind:e.target.value}),className:eH,children:eL.map(e=>(0,s.jsx)("option",{value:e,children:eR.PT[e]},e))})]}),(0,s.jsxs)("div",{className:"col-span-2",children:[(0,s.jsx)("label",{className:eW,children:"Removes %"}),(0,s.jsx)("input",{type:"number",min:0,max:100,value:Math.round(100*e.value_capture),onChange:e=>i(r,{value_capture:Number(e.target.value)/100}),className:eH})]}),(0,s.jsxs)("div",{className:"col-span-3",children:[(0,s.jsx)("label",{className:eW,children:"Cost / year"}),(0,s.jsx)("input",{type:"number",min:0,value:null!=(n=e.annual_cost)?n:"",placeholder:"not priced",onChange:e=>i(r,{annual_cost:""===e.target.value?null:Number(e.target.value)}),className:eH})]}),(0,s.jsxs)("div",{className:"col-span-2",children:[(0,s.jsx)("label",{className:eW,children:"One-time"}),(0,s.jsx)("input",{type:"number",min:0,value:null!=(l=e.one_time_cost)?l:"",placeholder:"â",onChange:e=>i(r,{one_time_cost:""===e.target.value?null:Number(e.target.value)}),className:eH})]}),(0,s.jsxs)("div",{className:"col-span-1",children:[(0,s.jsx)("label",{className:eW,children:"Ramp"}),(0,s.jsx)("input",{type:"number",min:0,value:null!=(o=e.ramp_months)?o:"",placeholder:"mo",onChange:e=>i(r,{ramp_months:""===e.target.value?null:Number(e.target.value)}),className:eH})]}),(0,s.jsx)("div",{className:"col-span-1 pb-2",children:(0,s.jsx)("button",{type:"button","aria-label":"Remove alternative",onClick:()=>a(t.filter((e,t)=>
1t!==r)),className:"text-gray-400 hover:text-red-600 dark:hover:text-red-400",children:(0,s.jsx)(S.A,{className:"h-4 w-4"})})})]},r)})}),(0,s.jsx)("div",{className:"overflow-x-auto",children:(0,s.jsxs)("table",{className:"w-full text-xs",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"text-gray-500 dark:text-gray-400 text-left",children:[(0,s.jsx)("th",{className:"font-medium py-1 pr-2",children:"Option"}),(0,s.jsx)("th",{className:"font-medium py-1 px-2 text-right",children:"Removes / yr"}),(0,s.jsx)("th",{className:"font-medium py-1 px-2 text-right",children:"Net / yr"}),(0,s.jsx)("th",{className:"font-medium py-1 px-2 text-right",children:"Year 1"}),(0,s.jsx)("th",{className:"font-medium py-1 pl-2 text-right",children:"3-yr net"})]})}),(0,s.jsx)("tbody",{children:d.map((e,t)=>{var a;return(0,s.jsxs)("tr",{className:"border-t border-gray-100 dark:border-gray-800 ".concat(e.option.kind===eR.Wv?"text-amber-700 dark:text-amber-300":""),children:[(0,s.jsx)("td",{className:"py-1.5 pr-2",children:(null==(a=e.option.label)?void 0:a.trim())||eR.PT[e.option.kind]}),(0,s.jsx)("td",{className:"py-1.5 px-2 text-right",children:eD(e.annual_value)}),(0,s.jsx)("td",{className:"py-1.5 px-2 text-right",children:eM(e.net_annual_value)}),(0,s.jsx)("td",{className:"py-1.5 px-2 text-right",children:eM(e.first_year_net)}),(0,s.jsx)("td",{className:"py-1.5 pl-2 text-right font-medium",children:eM(e.three_year_net)})]},t)})})]})}),(0,s.jsx)("p",{className:"mt-2 text-[11px] text-gray-500 dark:text-gray-400",children:"Blank costs stay blank â an unpriced option shows a dash, never a flattering zero. Ramp is charged against both the first year and the horizon."})]})]})}let eH="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-sm",eW="block text-xs font-medium text-gray-600 dark:text-gray-400";var eB=a(60835),eJ=a(92619);let eG={loaded_hourly_rate:"loaded_hourly_rate",annual_hours:"annual_hours",efficiencyPct:"automation_efficiency",implementation_cost:"implementation_cost"},e$={unknown:"bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-300",default:"bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-300",derived:"bg-slate-100 text-slate-700 dark:bg-slate-700/60 dark:text-slate-300",extracted:"bg-green-100 text-green-800 dark:bg-green-900/40 dark:text-green-300",user_entered:"bg-green-100 text-green-800 dark:bg-green-900/40 dark:text-green-300",measured:"bg-green-100 text-green-800 dark:bg-green-900/40 dark:text-green-300"},eV=(e,t)=>({...e,...t,source:"user_entered"}),eX=e=>"$".concat(Math.round(e).toLocaleString("en-US"));function eY(e){var t,a,n,l,i,o,c,u,m,x,h,p;let{opportunity:y,refreshToken:b}=e,{user:f}=(0,g.A)(),[v,w]=(0,r.useState)(null),[j,N]=(0,r.useState)(null),[_,A]=(0,r.useState)(null),[C,T]=(0,r.useState)(new Set),[P,E]=(0,r.useState)([]),[F,q]=(0,r.useState)(null),[I,O]=(0,r.useState)(!1),[R,D]=(0,r.useState)(!1),M=(0,r.useRef)([]),L=e=>{O(!0),E(e)},[U,H]=(0,r.useState)(null),[W,B]=(0,r.useState)([]),[J,G]=(0,r.useState)(!0),[$,V]=(0,r.useState)(!1),[Y,K]=(0,r.useState)(!1),[Q,Z]=(0,r.useState)(null),[ee,et]=(0,r.useState)([]);(0,r.useEffect)(()=>{let e=!0;return(async()=>{try{var t,a;let s=await (0,eJ.I8)(y.workspaceId);if(!e||!(null==s?void 0:s.success))return;let r=(null!=(a=null==(t=s.data)?void 0:t.metrics)?a:{}).labor_rates;Array.isArray(r)&&et(r)}catch(e){}})(),()=>{e=!1}},[y.workspaceId]);let ea=async()=>{G(!0),Z(null);try{var e,t,a,s,r,n,l;let i,o=null;try{o=null!=(t=(i=(await (0,z.CA)(y.id)).structured).business_case)?t:null}catch(e){i=(0,z.ON)(y)}let d=null!=(a=null==o?void 0:o.assumptions)?a:(0,X.mL)(i);w(i),N(o),T(new Set);let c=null!=(r=null!=(s=null==(e=i.landscape)?void 0:e.cost_drivers)?s:null==o?void 0:o.cost_drivers)?r:[];E(c),M.current=c,q(null),H(null!=(n=i.scenarios)?n:null),B(null!=(l=i.alternatives)?l:[]),O(!1),D(!1),A({loaded_hourly_rate:d.loaded_hourly_rate,annual_hours:d.annual_hours,efficiencyPct:Math.round(100*d.automation_efficiency),implementation_cost:d.implementation_cost})}catch(e){console.error("Failed to load business case:",e),Z("Failed to load business case.")}finally{G(!1)}};(0,r.useEffect)(()=>{ea()},[y.id]),(0,r.useEffect)(()=>
1{if(b){if(!(I||C.size>0||null!==F))return void ea();(async()=>{try{var e,t;let a=null!=(t=null==(e=(await (0,z.CA)(y.id)).structured.landscape)?void 0:e.cost_drivers)?t:[],s=M.current;if(a.length>=s.length&&s.every((e,t)=>JSON.stringify(e)===JSON.stringify(a[t]))){let e=a.slice(s.length);M.current=a,e.length&&E(t=>[...t,...e]);return}}catch(e){}D(!0)})()}},[b]);let es=_?{loaded_hourly_rate:_.loaded_hourly_rate,annual_hours:_.annual_hours,automation_efficiency:_.efficiencyPct/100,implementation_cost:_.implementation_cost}:void 0,er=(0,r.useMemo)(()=>{let e=j?{...(0,eO.q)(j.provenance)}:{};for(let a of C){var t;e[a]=(0,eO._h)("user_entered",null,null!=(t=null==f?void 0:f.id)?t:null)}return e},[j,C,null==f?void 0:f.id]),en=(0,r.useMemo)(()=>v&&es?(0,X.Ub)(v,es,{provenance:er,costDrivers:P}):null,[v,_,er,P]),el=(0,r.useMemo)(()=>v?function(e){var t,a,s,r;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:eF.k,l=null!=(s=null==(a=e.landscape)||null==(t=a.process)?void 0:t.steps)?s:[];if(0===l.length)return null;let i=new Map;for(let e of l)for(let t of(0,eE._E)(e,n))"fits"===t.verdict&&i.set(t.modality,[...null!=(r=i.get(t.modality))?r:[],e.name]);let o=new Set((0,eE.g7)(l,n).map(e=>e.modality)),d=[],c=[],u=[],m=new Set;for(let[e,t]of i){let a=eq.get(e);if(a){if(!a.cost_band_usd){a.priced_by_quote&&c.push({name:a.name,note:a.priced_by_quote});continue}for(let s of(d.push({modality:e,name:a.name,low:a.cost_band_usd.low,high:a.cost_band_usd.high,step_names:t,shared:o.has(e)}),a.cost_band_usd.cites))m.has(s.label)||(m.add(s.label),u.push(s))}}if(0===d.length&&0===c.length)return null;d.sort((e,t)=>t.high-e.high||e.name.localeCompare(t.name));let x=d.reduce((e,t)=>e+t.low,0),g=d.reduce((e,t)=>e+t.high,0),h=d.find(e=>eI.has(e.modality))?{low:(0,eE.jg)(x).low,high:(0,eE.jg)(g).high}:void 0;return{low:x,high:g,lines:d,cites:u,quoted_separately:c,installed:h}}(v):null,[v]),ei=null!=(o=null==v||null==(t=v.landscape)?void 0:t.unpriced_losses)?o:[],eo=(e,t)=>{A(a=>a?{...a,[e]:t}:a),T(t=>new Set(t).add(eG[e]))},ed=(0,eO.q)(null==en?void 0:en.provenance),ec=null!=(u=null!=F?F:U)?u:(0,eB.XT)(null!=(c=null==_?void 0:_.implementation_cost)?c:null),eu=(e,t)=>q(ec.map(a=>a.key===e?{...a,...t,source:"user_entered"}:a)),em="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-sm",ex="block text-xs font-medium text-gray-600 dark:text-gray-400";return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[(0,s.jsxs)("div",{className:"flex items-center mb-4",children:[(0,s.jsx)(e_.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-lg font-medium text-gray-900 dark:text-white",children:"Business case"}),j&&(0,s.jsxs)("span",{className:"ml-2 inline-flex items-center text-xs text-green-700 dark:text-green-300",children:[(0,s.jsx)(eS.A,{className:"h-3.5 w-3.5 mr-1"})," generated"]})]}),Q&&(0,s.jsx)("div",{className:"mb-3 text-sm text-red-600 dark:text-red-400",children:Q}),J||!_?(0,s.jsxs)("div",{className:"flex items-center py-6 text-gray-500 dark:text-gray-400",children:[(0,s.jsx)(d.A,{className:"h-5 w-5 mr-2 animate-spin"})," Loadingâ¦"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)(eK,{text:"Loaded rate ($/hr)",akey:"loaded_hourly_rate",provenance:ed,className:ex}),(0,s.jsx)("input",{type:"number",value:_.loaded_hourly_rate,onChange:e=>eo("loaded_hourly_rate",Number(e.target.value)),className:em}),ee.length>0&&(0,s.jsx)("div",{className:"mt-1 flex flex-wrap gap-1",children:ee.map(e=>(0,s.jsxs)("button",{type:"button",onClick:()=>eo("loaded_hourly_rate",e.hourly_rate),title:e.quote?"â".concat(e.quote,"â").concat(e.source_label?" â ".concat(e.source_label):""):void 0,className:"text-[11px] px-1.5 py-0.5 rounded-full border border-indigo-200 dark:border-indigo-800 text-indigo-700 dark:text-indigo-300 hover:bg-indigo-50 dark:hover:bg-indigo-900/30",children:[e.role," $",e.hourly_rate]},e.role))})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)(eK,{text:"Annual hours",akey:"annual_hours",provenance:ed,className:ex}),(0,s.jsx)("input",{type:"number",value:_.annual_hours,onChange:e=>eo("annual_hours",Number(e.target.value)),className:em})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)(eK,{text:"Automation %",akey:"automation_efficie
1ncy",provenance:ed,className:ex}),(0,s.jsx)("input",{type:"number",min:0,max:100,value:_.efficiencyPct,onChange:e=>eo("efficiencyPct",Number(e.target.value)),className:em})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)(eK,{text:"Implementation $",akey:"implementation_cost",provenance:ed,className:ex}),(0,s.jsx)("input",{type:"number",value:null!=(m=_.implementation_cost)?m:"",placeholder:"optional",onChange:e=>eo("implementation_cost",""===e.target.value?null:Number(e.target.value)),className:em})]})]}),el&&el.lines.length>0&&(0,s.jsxs)("div",{className:"mb-4 rounded-lg border border-slate-200 dark:border-slate-700 p-3 text-xs",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-1",children:[(0,s.jsxs)("span",{className:"font-medium text-gray-900 dark:text-white",children:["Equipment that fits these steps: ",eX(el.low),"â",eX(el.high)]}),el.installed&&(0,s.jsxs)("span",{className:"text-gray-500 dark:text-gray-400",children:["installed ",eX(el.installed.low),"â",eX(el.installed.high)]}),(0,s.jsx)("button",{type:"button",onClick:()=>{var e,t;return eo("implementation_cost",null!=(t=null==(e=el.installed)?void 0:e.high)?t:el.high)},className:"ml-auto rounded-md border border-indigo-200 px-2 py-1 font-medium text-indigo-700 hover:bg-indigo-50 dark:border-indigo-800 dark:text-indigo-300 dark:hover:bg-indigo-900/30",children:"Use as implementation cost"})]}),(0,s.jsx)("ul",{className:"mt-1.5 space-y-0.5 text-gray-600 dark:text-gray-300",children:el.lines.map(e=>(0,s.jsxs)("li",{children:[e.name,": ",eX(e.low),"â",eX(e.high),e.shared?" (one unit across the places it serves)":""]},e.modality))}),(0,s.jsx)("p",{className:"mt-1.5 text-gray-500 dark:text-gray-400",children:function(e){let t=["".concat(e.lines.length," ").concat(1===e.lines.length?"option":"options"," that fit these steps, at published list prices, one unit each")];return e.installed&&t.push("installed, a robot cell runs ".concat(eE.Oq.value.low,"-").concat(eE.Oq.value.high," times the equipment")),e.quoted_separately.length&&t.push("".concat(e.quoted_separately.map(e=>e.name).join(" and ")," ").concat(1===e.quoted_separately.length?"is":"are"," quoted separately and not in this total")),t.push("installation, controls and integration are extra"),"".concat(t.join("; "),".")}(el)})]}),(null==en?void 0:en.confidence)&&(0,s.jsxs)("div",{className:"rounded-lg border p-3 mb-4 ".concat("high"===en.confidence.level?"border-green-200 dark:border-green-900/50 bg-green-50 dark:bg-green-900/10":"medium"===en.confidence.level?"border-slate-200 dark:border-slate-700 bg-slate-50 dark:bg-slate-800/40":"border-amber-200 dark:border-amber-900/50 bg-amber-50 dark:bg-amber-900/10"),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,s.jsxs)("div",{className:"flex items-center min-w-0",children:[(0,s.jsx)(eA.A,{className:"h-4 w-4 shrink-0 text-gray-500 dark:text-gray-400"}),(0,s.jsx)("span",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Grounding"}),(0,s.jsx)("span",{className:"ml-2 text-sm text-gray-600 dark:text-gray-400 truncate",children:en.confidence.no_input_is_grounded?"no input is grounded in this client's figures":"".concat(en.confidence.weakest.length," of 4 inputs not confirmed")})]}),(0,s.jsxs)("span",{className:"text-sm font-semibold text-gray-900 dark:text-white shrink-0",children:[en.confidence.score,"/100"]})]}),en.confidence.next_best_input&&(0,s.jsxs)("p",{className:"mt-2 text-xs text-gray-600 dark:text-gray-400",children:["Confirming"," ",(0,s.jsx)("strong",{className:"font-medium",children:eO.pX[en.confidence.next_best_input].toLowerCase()})," ","would improve this case more than any other input."]}),(null==(a=en.range)?void 0:a.dominant_input)&&(0,s.jsxs)("p",{className:"mt-1 text-xs text-gray-600 dark:text-gray-400",children:["Savings could plausibly land anywhere from"," ",(0,s.jsx)("strong",{className:"font-medium",children:eX(en.range.annual_savings.low)})," to"," ",(0,s.jsx)("strong",{className:"font-medium",children:eX(en.range.annual_savings.high)}),"; about ",Math.round(100*en.range.dominant_share),"% of that spread comes from"," ",eO.pX[en.range.dominant_input].toLowerCase(),"."]})]}),(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3 mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"text-sm font-medium text-gray-900 dark:text-white",children:"Other
1costs of doing nothing"}),(0,s.jsx)("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:"optional â only priced losses count"})]}),(0,s.jsxs)("button",{type:"button",onClick:()=>L(e=>[...e,{kind:"rework",quantity:0,unit_cost:0,source:"user_entered"}]),className:"inline-flex items-center text-xs font-medium text-indigo-600 dark:text-indigo-400 hover:underline",children:[(0,s.jsx)(k.A,{className:"h-3.5 w-3.5 mr-1"})," Add cost driver"]})]}),ei.length>0&&(0,s.jsxs)("div",{className:"mb-3 rounded-md border border-amber-200 bg-amber-50 p-2 dark:border-amber-900/50 dark:bg-amber-900/10",children:[(0,s.jsx)("p",{className:"text-xs font-medium text-amber-900 dark:text-amber-200",children:"Named by the client, not counted here"}),(0,s.jsx)("ul",{className:"mt-1 space-y-0.5",children:ei.map((e,t)=>(0,s.jsxs)("li",{className:"text-xs text-amber-800 dark:text-amber-300",children:[e.label," ",(0,s.jsxs)("span",{className:"text-amber-700/70 dark:text-amber-400/70",children:["â",e.quote,"â"]})]},t))}),(0,s.jsx)("p",{className:"mt-1 text-xs text-amber-800 dark:text-amber-300",children:"Each needs two numbers to count: how often it happens, and what one costs. Ask for those and add them above."})]}),0===P.length?(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Rework and scrap, throughput you can't reach, compliance findings, turnover â priced here, these usually dwarf the labor line."}):(0,s.jsx)("div",{className:"space-y-2",children:P.map((e,t)=>(0,s.jsxs)("div",{className:"grid grid-cols-12 gap-2 items-end",children:[(0,s.jsxs)("div",{className:"col-span-5",children:[(0,s.jsx)("label",{className:ex,children:"Driver"}),(0,s.jsx)("select",{value:e.kind,onChange:e=>L(a=>a.map((a,s)=>s===t?eV(a,{kind:e.target.value}):a)),className:em,children:ez.zi.filter(e=>"labor"!==e).map(e=>(0,s.jsx)("option",{value:e,children:ez.w_[e]},e))})]}),(0,s.jsxs)("div",{className:"col-span-3",children:[(0,s.jsx)("label",{className:ex,children:ez.Fr[e.kind].quantity}),(0,s.jsx)("input",{type:"number",min:0,value:e.quantity||"",onChange:e=>L(a=>a.map((a,s)=>s===t?eV(a,{quantity:Number(e.target.value)}):a)),className:em})]}),(0,s.jsxs)("div",{className:"col-span-3",children:[(0,s.jsx)("label",{className:ex,children:ez.Fr[e.kind].unit_cost}),(0,s.jsx)("input",{type:"number",min:0,value:e.unit_cost||"",onChange:e=>L(a=>a.map((a,s)=>s===t?eV(a,{unit_cost:Number(e.target.value)}):a)),className:em})]}),(0,s.jsx)("div",{className:"col-span-1 pb-2",children:(0,s.jsx)("button",{type:"button","aria-label":"Remove cost driver",onClick:()=>L(e=>e.filter((e,a)=>a!==t)),className:"text-gray-400 hover:text-red-600 dark:hover:text-red-400",children:(0,s.jsx)(S.A,{className:"h-4 w-4"})})})]},t))})]}),en&&(0,s.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-4",children:[(0,s.jsx)(eQ,{label:"Current annual cost",value:eX(en.current_annual_cost)}),(0,s.jsx)(eQ,{label:"Annual savings",value:eX(en.annual_savings),highlight:!0,sub:en.range?"".concat(eX(en.range.annual_savings.low)," â ").concat(eX(en.range.annual_savings.high)):void 0}),(0,s.jsx)(eQ,{label:"Residual cost",value:eX(en.residual_annual_cost)}),(0,s.jsx)(eQ,{label:"Payback",value:null!=en.payback_months?"".concat(en.payback_months," mo"):"â",sub:(null==(n=en.range)?void 0:n.payback_months)?"".concat(en.range.payback_months.low," â ").concat(null!=(x=en.range.payback_months.high)?x:"â"," mo"):void 0})]}),en&&(()=>{let e=(0,X.Z5)(en);return(0,s.jsxs)("div",{className:"rounded-lg border border-amber-200 dark:border-amber-900/50 bg-amber-50 dark:bg-amber-900/10 p-4 mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center mb-2",children:[(0,s.jsx)(eC.A,{className:"h-4 w-4 text-amber-600 dark:text-amber-400"}),(0,s.jsx)("h5",{className:"ml-2 text-sm font-semibold text-amber-800 dark:text-amber-300",children:"Cost of inaction"})]}),(0,s.jsxs)("p",{className:"text-sm text-gray-700 dark:text-gray-300",children:["Staying as-is costs an estimated ",(0,s.jsxs)("strong",{children:[eX(e.annual_loss),"/year"]})," â about ",(0,s.jsxs)("strong",{children:[eX(e.monthly_loss),"/month"]}),".",null!=e.break_even_delay_months&&null!=e.implementation_cost&&(0,s.jsxs)(s.Fragment,{children:[" ","Waiting longer than ",(0,s.jsxs)("strong",{children:["~",e.break_even_delay_months," months"]})," ","costs more than the entire ",eX(e.implementation_cost)," implementation."]})]}),e.components&&e.components.length>1&&(0,s.jsxs)("div",{className:"mt-3 space-y-1",children:[e.components.map((t,a)=>(0,s.jsxs)("div",{className:"flex items-baseline justify-between text-xs",children:[(0,s.jsxs)("span",{className:"text-gray-700 dark:text-gray-300 truncate mr-2",children:[t.label,(0,s.jsxs)("span",{className:"ml-1.5 text-gray-500 dark:text-gray-500",children:[t.quantity.toLocaleStr
1ing("en-US")," \xd7 ",eX(t.unit_cost)]})]}),(0,s.jsxs)("span",{className:"font-medium text-amber-700 dark:text-amber-300 shrink-0",children:[eX(t.annual_loss),(0,s.jsx)("span",{className:"ml-1 text-gray-500 dark:text-gray-500 font-normal",children:e.annual_loss>0?"".concat(Math.round(t.annual_loss/e.annual_loss*100),"%"):"â"})]})]},a)),(0,s.jsx)("p",{className:"pt-1 text-[11px] text-gray-500 dark:text-gray-400",children:"Only losses with a figure behind them are counted â this total is a floor, not a ceiling."})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3 mt-3 text-center",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Lost / month"}),(0,s.jsx)("div",{className:"text-base font-semibold text-amber-700 dark:text-amber-300",children:eX(e.monthly_loss)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"3-yr cumulative"}),(0,s.jsx)("div",{className:"text-base font-semibold text-amber-700 dark:text-amber-300",children:eX(e.three_year_loss)})]})]})]})})(),en&&(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3 mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center mb-2",children:[(0,s.jsx)(eT.A,{className:"h-4 w-4 text-gray-500 dark:text-gray-400"}),(0,s.jsx)("span",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Your options"}),(0,s.jsx)("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:"select the one being proposed"})]}),(0,s.jsx)("div",{className:"overflow-x-auto",children:(0,s.jsxs)("table",{className:"w-full text-xs",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"text-gray-500 dark:text-gray-400 text-left",children:[(0,s.jsx)("th",{className:"font-medium py-1 pr-2",children:"Option"}),(0,s.jsx)("th",{className:"font-medium py-1 px-2 w-20",children:"Captures"}),(0,s.jsx)("th",{className:"font-medium py-1 px-2 w-28",children:"Investment"}),(0,s.jsx)("th",{className:"font-medium py-1 px-2 text-right",children:"Annual value"}),(0,s.jsx)("th",{className:"font-medium py-1 px-2 text-right",children:"Still lost"}),(0,s.jsx)("th",{className:"font-medium py-1 pl-2 text-right",children:"Payback"})]})}),(0,s.jsx)("tbody",{children:(0,eB.v9)(ec,(0,X.Z5)(en)).map(e=>{var t;let a=e.scenario.key===eB.US;return(0,s.jsxs)("tr",{className:"border-t border-gray-100 dark:border-gray-800 ".concat(a?"text-amber-700 dark:text-amber-300":""),children:[(0,s.jsx)("td",{className:"py-1.5 pr-2",children:(0,s.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[!a&&(0,s.jsx)("input",{type:"radio",name:"scenario",checked:!!e.scenario.selected,onChange:()=>q((0,eB.Bh)(ec,e.scenario.key)),className:"h-3 w-3 text-indigo-600"}),(0,s.jsx)("span",{className:a?"font-medium":"",children:e.scenario.name})]})}),(0,s.jsx)("td",{className:"py-1.5 px-2",children:a?"â":(0,s.jsx)("input",{type:"number",min:0,max:100,value:Math.round(100*e.scenario.value_capture),onChange:t=>eu(e.scenario.key,{value_capture:Number(t.target.value)/100}),className:"w-14 rounded border-gray-300 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-xs py-0.5"})}),(0,s.jsx)("td",{className:"py-1.5 px-2",children:a?"â":(0,s.jsx)("input",{type:"number",min:0,value:null!=(t=e.scenario.implementation_cost)?t:"",placeholder:"â",onChange:t=>eu(e.scenario.key,{implementation_cost:""===t.target.value?null:Number(t.target.value)}),className:"w-24 rounded border-gray-300 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-xs py-0.5"})}),(0,s.jsx)("td",{className:"py-1.5 px-2 text-right font-medium",children:eX(e.annual_value)}),(0,s.jsx)("td",{className:"py-1.5 px-2 text-right",children:eX(e.residual_annual_loss)}),(0,s.jsx)("td",{className:"py-1.5 pl-2 text-right",children:null!=e.payback_months?"".concat(e.payback_months," mo"):"â"})]},e.scenario.key)})})]})})]}),en&&(0,s.jsx)(eU,{alternatives:W,onChange:e=>{O(!0),B(e)},totalAnnualLoss:(0,X.Z5)(en).annual_loss,proposedCapture:null!=(h=null==(l=ec.find(e=>e.selected))?void 0:l.value_capture)?h:1,proposedCost:null!=(p=null==(i=ec.find(e=>e.selected))?void 0:i.implementation_cost)?p:_.implementation_cost}),en&&(0,s.jsx)("pre",{className:"text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap font-sans bg-gray-50 dark:bg-gray-900/50 rounded-lg p-4 max-h-60 overflow-y-auto mb-4",children:en.narrative}),(0,s.jsxs)("div",{className:"flex justify-end gap-3",children:[R&&(0,s.jsxs)("div",{className:"w-full rounded-lg border border-amber-200 dark:border-amber-900/50 bg-amber-50 dark:bg-amber-900/10 p-3 mb-2 text-xs text-gray-700 dark:text-gray-300 flex items-center justify-between gap-3",children:[(0,s.jsx)("span",{children:"The case inputs changed elsewhere (an accepted extraction or saved measures). Generating from this panel's copy would lose them â reload first. Unsaved edits here will be discarded by the reload."}),(0,s.jsx)("button",{type:"button",onClick:ea,className:"shrink-0 text-xs font-medium text-indigo-600 dark:text-indigo-400 hover:underline",children:"Reload"})]}),j&&(0,s.jsxs)("button",{onClick:()=>(async()=>
1{if(f){K(!0),Z(null);try{await (0,z.KZ)(y,f.id),await ea()}catch(e){console.error("Failed to polish business case:",e),Z("Failed to polish business case.")}finally{K(!1)}}})(),disabled:Y||$,className:"inline-flex items-center px-4 py-2 text-sm font-medium rounded-md border border-indigo-300 dark:border-indigo-700 text-indigo-700 dark:text-indigo-300 hover:bg-indigo-50 dark:hover:bg-indigo-900/30 disabled:opacity-50 transition-colors",title:"Rewrite the wording with AI â figures stay unchanged",children:[Y?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):(0,s.jsx)(eP.A,{className:"h-4 w-4 mr-2"}),j.polished?"Re-polish with AI":"Polish with AI"]}),(0,s.jsxs)("button",{onClick:()=>(async()=>{if(f&&es){V(!0),Z(null);try{await (0,z.Y3)(y,es,f.id,{provenance:er,costDrivers:P,scenarios:ec,alternatives:W}),await ea()}catch(e){console.error("Failed to generate business case:",e),Z("Failed to generate business case.")}finally{V(!1)}}})(),disabled:$||Y||R,className:"inline-flex items-center px-4 py-2 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 transition-colors",children:[$?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):(0,s.jsx)(e_.A,{className:"h-4 w-4 mr-2"}),j?"Regenerate business case":"Generate business case"]})]})]})]})}function eK(e){let{text:t,akey:a,provenance:r,className:n}=e,l=r[a].source;return(0,s.jsxs)("label",{className:"".concat(n," flex items-center gap-1.5"),children:[(0,s.jsx)("span",{children:t}),(0,s.jsx)("span",{title:"".concat(eO.pX[a]," â ").concat(eO.Rc[l]),className:"px-1.5 py-0.5 rounded text-[10px] font-medium leading-none ".concat(e$[l]),children:eO.kv[l]})]})}function eQ(e){let{label:t,value:a,highlight:r,sub:n}=e;return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3",children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:t}),(0,s.jsx)("div",{className:"text-lg font-semibold ".concat(r?"text-green-600 dark:text-green-400":"text-gray-900 dark:text-white"),children:a}),n&&(0,s.jsx)("div",{className:"text-[11px] text-gray-500 dark:text-gray-400 mt-0.5",children:n})]})}var eZ=a(46906),e0=a(77051),e1=a(72502);let e5=["uipath","automation anywhere","blue prism","power automate","n8n","zapier","make.com","workato"],e4=["manually","by hand","manual entry","manual input"];var e2=a(40337);let e3=new Set(["rpa_workflow","ai_agent","integration_change"]);function e6(e){var t;let{opportunityId:a,opportunityTitle:n,components:l}=e,[i,o]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=!0;return(async()=>{try{let t=await fetch("/api/suite/entitlement?opportunityId=".concat(a),{headers:await (0,x.authHeaders)()}),s=await t.json();if(!e||!t.ok||!s.linked)return;o(s)}catch(e){}})(),()=>{e=!1}},[a]);let d=l.some(e=>e3.has(e.kind));return i&&d?(0,s.jsxs)("div",{className:"mt-4 rounded-lg border border-indigo-200 bg-indigo-50/60 p-4 dark:border-indigo-800/60 dark:bg-indigo-900/20",children:[(0,s.jsxs)("div",{className:"flex items-center text-sm font-medium text-indigo-900 dark:text-indigo-200",children:[(0,s.jsx)(eP.A,{className:"mr-2 h-4 w-4 shrink-0"}),"Ready to put this into action?"]}),(0,s.jsxs)("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[i.automation&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("span",{className:"inline-flex items-center text-sm text-emerald-700 dark:text-emerald-300",children:[(0,s.jsx)(e1.A,{className:"mr-1.5 h-4 w-4"}),"Automation & Integrations is on your plan"]}),i.workflows_url&&(0,s.jsxs)("a",{href:i.workflows_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center rounded-md border border-indigo-300 bg-white px-3 py-1.5 text-sm font-medium text-indigo-700 hover:bg-indigo-50 dark:border-indigo-700 dark:bg-transparent dark:text-indigo-300 dark:hover:bg-indigo-900/40",children:["Open your workflows",(0,s.jsx)(e2.A,{className:"ml-1.5 h-3.5 w-3.5"})]})]}),!i.automation&&(0,s.jsxs)("a",{href:null!=(t=i.billing_url)?t:"#",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 transition-colors",children:["Add Automation & Integrations â $99/mo",(0,s.jsx)(e2.A,{className:"ml-1.5 h-3.5 w-3.5"})]})]}),(0,s.jsx)("p",{className:"mt-2 text-xs text-indigo-700/70 dark:text-indigo-300/60",children:i.automation?"To have any part of this done for you, choose who does what below and request support.":"The add-on bills to your existing account, with no new checkout, and you can cancel anytime. To have any part of this done for you, choose who does what below."})]}):null}var e7=a(26473);async function e9(e){var t;let a=await fetch("/api/opportunities/service-request",{method:"POST",headers:{...await (0,x.authHeaders)(),"Content-Type":"application/json"},body:JSON.stringify(e)}),s=await a.json().catch(()=>({}));if(!a.ok)throw Error(s.error||"Request failed");return{viaAgency:null!=(t=s.viaAgency)?t:null}}function e8(e){switch(e){case"rpa_workflow":case"ai_agent":case"integration_change":return"Have this built and run";case"sop":case"policy":return"Have this drafted and rolled out";default:return null}}let te={sop:"SOP",policy:"Policy",rpa_workflow:"Workflow",ai_agent:"AI agent",integration_change:"Integration",note:"Note"},tt={sop:"bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-300",policy:"bg-purple-100 text-purple-800 dark:bg-purple-900/40 dark:text-purple-300",rpa_workflow:"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/40 dark:text-emerald-300",ai_agent:"bg-cyan-100 text-cyan-800 dark:bg-cyan-900/40 dark:text-cyan-300",integration_change:"bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-300",note:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300"};function ta(e){let{opportunity:t}=e,{user:a}=(0,g.A)(),[l,i]=(0,r.useState)([]),[o,c]=(0,r.useState)({}),[u,m]=(0,r.useState)({}),[x,h]=(0,r.useState)(null),[p,b]=(0,r.useState)(void 0),[f,v]=(0,r.useState)([]),[w,k]=(0,r.useState)(!0),[j,N]=(0,r.useState)(!1),[_,S]=(0,r.useState)(null),[A,C]=(0,r.useState)(null),T=(0,r.useMemo)(()=>(function(e){let t=[],a=e.some(e=>"rpa_workflow"===e.kind);for(let s of e){let e=function(e){var t,a;return"".concat(e.title,"\n").concat(null!=(t=e.content)?t:"","\n").concat(JSON.stringify(null!=(a=e.spec)?a:{})).toLowerCase()}(s);for(let a of e5)if(e.includes(a)){t.push({component:s.title,kind:"names_vendor",message:'Names the third-party automation product "'.concat(a,"\". Delivery runs on the customer's own automation platform â describe the capability, not a product.")});break}let r=function(e){var t;let a=null==(t=e.spec)?void 0:t.steps;return Array.isArray(a)?a.map(e=>"string"==typeof e?e:"string"==typeof(null==e?void 0:e.name)?e.name:""):[]}(s);if(("sop"===s.kind||"rpa_workflow"===s.kind)&&0===r.length&&t.push({component:s.title,kind:"empty_steps",message:"Has no steps, so it is not usable as a deliverable."}),"sop"===s.kind&&a){let e=r.filter(e=>{let t=e.toLowerCase();return e4.some(e=>t.includes(e))});e.length>0&&t.push({component:s.title,kind:"contradicts_workflow",message:"Describes the process as it runs today, not after automation: ".concat(e.length," step(s) instruct manual work that the workflow automates. The SOP should cover only what a person still owns â inputs, the review gate, and exceptions.")})}}return t})(l),[l]),P=async(e,a)=>{h(e),m(t=>({...t,[e]:""}));try{var s;let r=(s=a.kind,e7.o[s]),{viaAgency:n}=await e9({opportunityId:t.id,title:t.title,note:"".concat(e8(a.kind),": ").concat(a.title),capabilities:r?[r]:void 0});c(t=>({...t,[e]:n?"Asked. It is handled through ".concat(n,"."):"Asked. The delivery team will scope it with you."}))}catch(t){n.Cp(t),m(a=>({...a,[e]:t instanceof Error?t.message:"Request failed. Try again."}))}finally{h(null)}},E=async()=>{k(!0),S(null);try{var e,a,s,r,n;let l=(await (0,z.CA)(t.id)).structured;i(null!=(r=null==(e=l.solution)?void 0:e.components)?r:[]),b(null==(a=l.solution)?void 0:a.precedents),v(null!=(n=null==(s=l.solution)?void 0:s.critique)?n:[])}catch(e){i([]),b(void 0),v([])}finally{k(!1)}};return(0,r.useEffect)(()=>{E()},[t.id]),(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)(eZ.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-lg font-medium text-gray-900 dark:text-white",children:"Solution deliverables"}),l.length>0&&(0,s.jsxs)("span",{className:"ml-2 inline-flex items-center text-xs text-green-700 dark:text-green-300",children:[(0,s.jsx)(eS.A,{className:"h-3.5 w-3.5 mr-1"})," ",l.length," generated"]})]}),(0,s.jsxs)("button",{onClick:()=>(async()=>
1{if(a){N(!0),S(null);try{await (0,z.uf)(t,a.id),await E()}catch(e){S(e instanceof Error?e.message:"Failed to generate deliverables.")}finally{N(!1)}}})(),disabled:j||w,className:"inline-flex items-center px-4 py-2 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 transition-colors",title:"Draft SOPs, policies and workflow definitions from the analysis",children:[j?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):(0,s.jsx)(e0.A,{className:"h-4 w-4 mr-2"}),l.length?"Regenerate deliverables":"Generate deliverables"]})]}),_&&(0,s.jsx)("div",{className:"mb-3 text-sm text-red-600 dark:text-red-400",children:_}),f.length>0&&(0,s.jsxs)("div",{className:"mb-4 rounded-lg border border-rose-300 bg-rose-50 p-3 dark:border-rose-800/60 dark:bg-rose-900/20",children:[(0,s.jsxs)("div",{className:"flex items-center text-sm font-medium text-rose-900 dark:text-rose-200",children:[(0,s.jsx)(y.A,{className:"mr-2 h-4 w-4 shrink-0"}),"Red-team review: ",f.length," finding",1===f.length?"":"s"," to judge before sign-off"]}),(0,s.jsx)("ul",{className:"mt-2 space-y-2",children:f.map((e,t)=>(0,s.jsxs)("li",{className:"text-sm text-rose-800 dark:text-rose-300",children:[(0,s.jsx)("span",{className:"font-semibold uppercase text-[10px] tracking-wide mr-1.5",children:e.severity}),(0,s.jsx)("span",{className:"font-medium",children:e.title}
1),e.component?(0,s.jsxs)("span",{className:"text-rose-600 dark:text-rose-400",children:[" (",e.component,")"]}):null,(0,s.jsx)("div",{className:"mt-0.5",children:e.detail}),(0,s.jsxs)("div",{className:"mt-0.5 text-xs italic text-rose-700/80 dark:text-rose-400/80",children:["Based on: â",e.basis,"â"]})]},t))})]}),T.length>0&&(0,s.jsxs)("div",{className:"mb-4 rounded-lg border border-amber-300 bg-amber-50 p-3 dark:border-amber-800/60 dark:bg-amber-900/20",children:[(0,s.jsxs)("div",{className:"flex items-center text-sm font-medium text-amber-900 dark:text-amber-200",children:[(0,s.jsx)(y.A,{className:"mr-2 h-4 w-4 shrink-0"}),"Review before sending: ",T.length," issue",1===T.length?"":"s"," found"]}),(0,s.jsx)("ul",{className:"mt-2 space-y-1.5",children:T.map((e,t)=>(0,s.jsxs)("li",{className:"text-sm text-amber-800 dark:text-amber-300",children:[(0,s.jsx)("span",{className:"font-medium",children:e.component})," â ",e.message]},t))})]}),w?(0,s.jsxs)("div",{className:"flex items-center py-4 text-gray-500 dark:text-gray-400",children:[(0,s.jsx)(d.A,{className:"h-5 w-5 mr-2 animate-spin"})," Loadingâ¦"]}):0===l.length?(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No deliverables yet. Generation drafts the SOPs, policies and workflow definitions this solution needs â grounded in the analysis above, saved as a new version."}):(0,s.jsxs)("div",{className:"space-y-2",children:[l.map((e,t)=>(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700",children:[(0,s.jsxs)("button",{className:"w-full flex items-center gap-2 px-3 py-2 text-left",onClick:()=>C(A===t?null:t),children:[A===t?(0,s.jsx)(ey.A,{className:"h-4 w-4 text-gray-400 shrink-0"}):(0,s.jsx)(eb.A,{className:"h-4 w-4 text-gray-400 shrink-0"}),(0,s.jsx)("span",{className:"inline-flex px-2 py-0.5 rounded text-xs font-medium ".concat(tt[e.kind]),children:te[e.kind]}),(0,s.jsx)("span",{className:"text-sm font-medium text-gray-900 dark:text-white truncate",children:e.title})]}),A===t&&(0,s.jsxs)("div",{className:"px-4 pb-3 border-t border-gray-100 dark:border-gray-800",children:[e.content&&(0,s.jsx)("pre",{className:"mt-3 text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap font-sans max-h-72 overflow-y-auto",children:e.content}),e8(e.kind)&&(0,s.jsxs)("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[o[t]?(0,s.jsxs)("span",{className:"inline-flex items-center text-xs text-emerald-700 dark:text-emerald-300",children:[(0,s.jsx)(e1.A,{className:"mr-1.5 h-3.5 w-3.5"}),o[t]]}):(0,s.jsxs)("button",{type:"button",onClick:()=>P(t,e),disabled:x===t,className:"inline-flex items-center rounded-md border border-indigo-300 bg-white px-2.5 py-1 text-xs font-medium text-indigo-700 hover:bg-indigo-50 disabled:opacity-50 dark:border-indigo-700 dark:bg-transparent dark:text-indigo-300 dark:hover:bg-indigo-900/40",children:[x===t?(0,s.jsx)(d.A,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(eg.A,{className:"mr-1.5 h-3.5 w-3.5"}),e8(e.kind)]}),u[t]&&(0,s.jsx)("span",{className:"text-xs text-red-600 dark:text-red-400",children:u[t]})]}),e.spec&&(0,s.jsxs)("details",{className:"mt-2",children:[(0,s.jsx)("summary",{className:"text-xs text-gray-500 dark:text-gray-400 cursor-pointer",children:"Structured spec"}),(0,s.jsx)("pre",{className:"mt-1 text-xs text-gray-600 dark:text-gray-400 whitespace-pre-wrap bg-gray-50 dark:bg-gray-900/50 rounded p-2 max-h-56 overflow-y-auto",children:JSON.stringify(e.spec,null,2)})]})]})]},t)),(0,s.jsx)(ef,{precedents:p}),(0,s.jsx)(e6,{opportunityId:t.id,opportunityTitle:t.title,components:l})]})]})}var ts=a(32257);let tr=[{key:"discover",label:"Discover",description:"Surface and capture the opportunity"},{key:"diagnose",label:"Diagnose",description:"Analyze, grade, and quantify the business case"},{key:"design",label:"Design",description:"Deliverables, proposal, and client review"},{key:"deploy",label:"Deploy",description:"Sign-off through delivery to live"},{key:"drive",label:"Drive",description:"Monitor results against the success hypothesis"}
1],tn={draft:"discover",gathering_info:"discover",analyzing:"discover",analyzed:"diagnose",business_case:"diagnose",proposal:"design",in_review:"design",changes_requested:"design",signed_off:"deploy",ready_for_project:"deploy",converted:"deploy",in_delivery:"deploy",live:"deploy",monitoring:"drive"};function tl(e){var t;let{status:a}=e,r=null!=(t=tn[a])?t:null;if(!r)return null;let n=tr.findIndex(e=>e.key===r);return(0,s.jsxs)("div",{className:"mb-6",children:[(0,s.jsx)("div",{className:"text-[11px] uppercase tracking-wider text-gray-400 dark:text-gray-500 mb-2",children:"The Intellimate AI Method"}),(0,s.jsx)("ol",{className:"flex items-center",children:tr.map((e,t)=>{let a=t<n,r=t===n;return(0,s.jsxs)("li",{className:"flex items-center flex-1 last:flex-none",title:e.description,children:[(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsx)("div",{className:"flex h-6 w-6 items-center justify-center rounded-full text-[11px] font-semibold border ".concat(a?"bg-indigo-600 border-indigo-600 text-white":r?"border-indigo-600 text-indigo-600 dark:text-indigo-400 dark:border-indigo-400":"border-gray-300 dark:border-gray-600 text-gray-400 dark:text-gray-500"),children:a?(0,s.jsx)(ts.A,{className:"h-3.5 w-3.5"}):t+1}),(0,s.jsx)("span",{className:"mt-1 text-[11px] ".concat(r?"font-semibold text-indigo-700 dark:text-indigo-300":a?"text-gray-600 dark:text-gray-300":"text-gray-400 dark:text-gray-500"),children:e.label})]}),t<tr.length-1&&(0,s.jsx)("div",{className:"mx-2 h-px flex-1 -mt-4 ".concat(t<n?"bg-indigo-500":"bg-gray-200 dark:bg-gray-700")})]},e.key)})})]})}var ti=a(76730),to=a(37719);let td={systemizable:"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/40 dark:text-emerald-300",partially_systemizable:"bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-300",not_yet_systemizable:"bg-red-100 text-red-800 dark:bg-red-900/40 dark:text-red-300"};function tc(e){var t;let{opportunity:a,refreshToken:n}=e,[l,i]=(0,r.useState)([]);(0,r.useEffect)(()=>{let e=!0;return(async()=>{try{var t,s,r;let n=(await (0,z.CA)(a.id)).structured;e&&i(null!=(r=null==(s=n.landscape)||null==(t=s.process)?void 0:t.steps)?r:[])}catch(t){e&&i([])}})(),()=>{e=!1}},[a.id,n]);let o=(0,to.BF)(null==(t=a.details)?void 0:t.processSuitability,l);if(!o)return null;let d=o.signals.find(e=>"accessible"===e.key);return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3",children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)(ti.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-lg font-medium text-gray-900 dark:text-white",children:"Three-Signal Systemization Test"})]}),(0,s.jsxs)("span",{className:"inline-flex px-2.5 py-0.5 rounded-full text-xs font-medium ".concat(td[o.verdict]),children:[to.pl[o.verdict]," \xb7 ",o.score,"/100"]})]}),(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-3",children:"Repetitive \xd7 Accessible to automation \xd7 Documentable â scored from your process answers and the process map; the weakest signal decides."}),(0,s.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:o.signals.map(e=>(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex justify-between text-xs text-gray-600 dark:text-gray-300 mb-1",children:[(0,s.jsx)("span",{children:e.label}),(0,s.jsx)("span",{className:"font-medium",children:e.score})]}),(0,s.jsx)("div",{className:"h-2 w-full rounded-full bg-gray-100 dark:bg-gray-700 overflow-hidden",children:(0,s.jsx)("div",{className:"h-full ".concat(e.score>=70?"bg-emerald-500":e.score>=35?"bg-amber-500":"bg-red-500"),style:{width:"".concat(Math.max(e.score,4),"%")}})})]},e.key))}),(null==d?void 0:d.basis)&&(0,s.jsxs)("p",{className:"mt-2 text-[11px] text-gray-500 dark:text-gray-400",children:["Accessible to automation â ",d.basis,"."]})]})}var tu=a(60375),tm=a(49996),tx=a(74206),tg=a(31844),th=a(30860),tp=a(88258);async function ty(e,t){let{data:{session:a}}=await m.N.auth.getSession();if(!a)throw Error("You must be signed in");let s=await fetch("/api/proposals/create-review-link",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(a.access_token)},body:JSON.stringify({opportunityId:e,reviewers:t})});if(!s.ok){var r;throw Error(null!=(r=(await s.json().catch(()=>({}))).error)?r:"Failed to create review link")}return(await s.json()).links}async function tb(e){let{data:t,error:a}=await m.N.from("proposal_approvals").select("*").eq("opportunity_id",e).order("created_at",{ascending:!0});if(a)throw a;return null!=t?t:[]}async function tf(e,t){let{data:a,error:s}=await m.N.from("proposal_views").select("approval_id, version, device, viewed_at").eq("opportunity_id",e);if(s)throw s;return function(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"2026-08-21T00:00:00.000Z",s=new Map;for(let e of t){let t=s.get(e.approval_id);
1t?t.push(e):s.set(e.approval_id,[e])}let r=Date.parse(a),n=e.map(e=>{var t,a,n,l,i;let o,d=(null!=(n=s.get(e.id))?n:[]).slice().sort((e,t)=>e.viewed_at.localeCompare(t.viewed_at));return o=d.length>0?"opened":Number.isFinite(Date.parse(e.created_at))&&Date.parse(e.created_at)>=r?"not_opened":"unknown",{approval_id:e.id,reviewer_name:e.reviewer_name,reviewer_email:e.reviewer_email,status:e.status,state:o,views:d.length,first_viewed_at:null!=(l=null==(t=d[0])?void 0:t.viewed_at)?l:null,last_viewed_at:null!=(i=null==(a=d[d.length-1])?void 0:a.viewed_at)?i:null,devices:[...new Set(d.map(e=>e.device))].sort()}});return{total_views:t.length,reviewers:n,opened_count:n.filter(e=>"opened"===e.state).length,not_opened_count:n.filter(e=>"not_opened"===e.state).length,unknown_count:n.filter(e=>"unknown"===e.state).length}}(t.map(e=>{var t,a;return{id:e.id,reviewer_name:null!=(t=e.reviewer_name)?t:null,reviewer_email:null!=(a=e.reviewer_email)?a:null,status:e.status,created_at:e.created_at}}),null!=a?a:[])}var tv=a(80873);let tw={pending:{label:"Pending",cls:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-200",Icon:A.A},approved:{label:"Approved",cls:"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-200",Icon:C.A},changes_requested:{label:"Changes requested",cls:"bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-200",Icon:tu.A}};function tk(e){let{opportunity:t,refreshToken:n}=e,{user:l}=(0,g.A)(),[i,o]=(0,r.useState)(null),[c,u]=(0,r.useState)([]),[m,x]=(0,r.useState)(null),[h,p]=(0,r.useState)(!0),[y,b]=(0,r.useState)(!1),[f,v]=(0,r.useState)(""),[w,k]=(0,r.useState)(!1),[j,N]=(0,r.useState)([]),[_,S]=(0,r.useState)(!1),[A,C]=(0,r.useState)(null),[T,P]=(0,r.useState)(!0),E=async()=>{p(!0),C(null);try{var e,a;let s=(await (0,z.CA)(t.id)).structured;o(null!=(a=s.proposal)?a:null),P((0,tv.qO)(null==(e=s.success_hypothesis)?void 0:e.metrics))}catch(e){o(null),P(!1)}try{let e=await tb(t.id);u(e),x(await tf(t.id,e).catch(()=>null))}catch(e){}p(!1)};(0,r.useEffect)(()=>{E()},[t.id,n]);let F=()=>(async()=>{let e=f.trim();if(e){k(!0),C(null);try{let a=await ty(t.id,[{email:e}]);N(e=>[...e,...a]),v(""),u(await tb(t.id))}catch(e){console.error("Failed to request sign-off:",e),C(e instanceof Error?e.message:"Failed to request sign-off.")}finally{k(!1)}}})(),q=i?(0,tp.Mu)(i):"";return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)(tm.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-lg font-medium text-gray-900 dark:text-white",children:"Proposal"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[i&&(0,s.jsx)("button",{onClick:()=>{var e;return null==(e=navigator.clipboard)?void 0:e.writeText(q)},className:"p-2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",title:"Copy markdown",children:(0,s.jsx)(tx.A,{className:"h-4 w-4"})}),i&&(0,s.jsx)("button",{onClick:()=>(async()=>{if(i){S(!0),C(null);try{let{pdf:e}=await Promise.all([a.e(4155),a.e(2591),a.e(214),a.e(6341),a.e(1071),a.e(5230),a.e(3954)]).then(a.bind(a,90858)),{default:t}=await Promise.all([a.e(4155),a.e(2591),a.e(214),a.e(6341),a.e(1071),a.e(5230),a.e(5190)]).then(a.bind(a,92825)),s=await e(r.createElement(t,{proposal:i})).toBlob(),n="".concat(i.client_name.replace(/[^a-z0-9]/gi,"_"),"_Proposal.pdf"),l=window.URL.createObjectURL(s),o=document.createElement("a");o.href=l,o.download=n,document.body.appendChild(o),o.click(),document.body.removeChild(o),window.URL.revokeObjectURL(l)}catch(e){console.error("Failed to generate PDF:",e),C("Failed to generate PDF.")}finally{S(!1)}}})(),disabled:_,className:"p-2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 disabled:opacity-50",title:"Download PDF",children:_?(0,s.jsx)(d.A,{className:"h-4 w-4 animate-spin"}):(0,s.jsx)(tg.A,{className:"h-4 w-4"})}),(0,s.jsxs)("button",{onClick:()=>(async()=>{if(l){b(!0),C(null);try{await (0,z.Ux)(t,l.id),await E()}catch(e){console.error("Failed to generate proposal:",e),C("Failed to generate proposal.")}finally{b(!1)}}})(),disabled:y||h,className:"inline-flex items-center px-3 py-1.5 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 transition-colors",children:[y?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):(0,s.jsx)(tm.A,{className:"h-4 w-4 mr-2"}),i?"Regenerate":"Generate proposal"]})]})]}),A&&(0,s.jsx)("div",{className:"mb-3 text-sm text-red-600 dark:text-red-400",children:A}),h?(0,s.jsxs)("div",{className:"flex items-center py-6 text-gray-500 dark:text-gray-400",children:[(0,s.jsx)(d.A,{className:"h-5 w-5 mr-2 animate-spin"})," Loadingâ¦"]}):i?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("pre",{className:"text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap font-sans bg-gray-50 dark:bg-gray-900/50 rounded-lg p-4 max-h-80 overflow-y-auto mb-4",children:q}),(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsx)("h5",{className:"text-sm font-medium text-gray-900 dark:text-white mb-3",children:"Client sign-off"}),c.length>0&&(0,s.jsxs)("div",{className:"space-y-2 mb-3",children:[c.map(e=>{var t;let a=null!=(t=tw[e.status])?t:tw.pending,r=null==m?void 0:m.reviewers.find(t=>t.approval_id===e.id);return(0,s.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,s.jsxs)("span",{className:"text-gray-700 dark:text-gray-300",children:[e.reviewer_email,(0,s.jsxs)("span",{className:"text-gray-400 dark:text-gray-500",children:[" \xb7 v",e.version]}),(null==r?void 0:r.state)==="opened"&&(0,s.jsxs)("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:[(0,s.jsx)(th.A,{className:"h-3 w-3 inline mr-0.5"}),"opened ",r.views,"\xd7",r.last_viewed_at&&" \xb7 last ".concat(new Date(r.last_viewed_at).toLocaleDateString())]}),(null==r?void 0:r.state)==="not_opened"&&(0,s.jsx)("span",{className:"ml-2 text-xs text-amber-600 dar
1k:text-amber-400",children:"not opened yet"})]}),(0,s.jsxs)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ".concat(a.cls),children:[(0,s.jsx)(a.Icon,{className:"h-3.5 w-3.5 mr-1"}),a.label]})]},e.id)}),m&&(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 pt-1",children:function(e){if(0===e.reviewers.length)return"No review links have been sent yet.";if(0===e.total_views&&0===e.not_opened_count)return"No open data for these links â they were sent before opens were recorded.";let t=[],a=e.opened_count+e.not_opened_count;return t.push("".concat(e.opened_count," of ").concat(a," ")+"".concat(1===a?"reviewer has":"reviewers have"," opened it")+"".concat(e.total_views>0?", ".concat(e.total_views," ").concat(1===e.total_views?"time":"times"," in total"):"",".")),e.not_opened_count>0&&t.push("".concat(e.not_opened_count," ").concat(1===e.not_opened_count?"has":"have"," not opened it yet.")),e.unknown_count>0&&t.push("".concat(e.unknown_count," ").concat(1===e.unknown_count?"link predates":"links predate"," ")+"open tracking, so ".concat(1===e.unknown_count?"it is":"they are"," unknown.")),t.join(" ")}(m)})]}),!T&&(0,s.jsxs)("div",{className:"rounded-lg border border-amber-200 dark:border-amber-900/50 bg-amber-50 dark:bg-amber-900/10 p-3 mb-2 text-xs text-gray-700 dark:text-gray-300",children:["Sign-off needs at least one success measure with a before-reading. Once delivery changes the process, a baseline can never be captured â record it under ",(0,s.jsx)("strong",{children:"Success measures"})," while it still exists."]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("input",{type:"email",value:f,onChange:e=>v(e.target.value),onKeyDown:e=>"Enter"===e.key&&F(),placeholder:"[email protected]",className:"flex-1 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-sm"}),(0,s.jsxs)("button",{onClick:F,disabled:w||!f.trim()||!T,className:"inline-flex items-center px-3 py-2 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 transition-colors",children:[w?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):(0,s.jsx)(ej.A,{className:"h-4 w-4 mr-2"}),"Request sign-off"]})]}),j.length>0&&(0,s.jsxs)("div",{className:"mt-3 space-y-2",children:[j.map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"flex-1 text-xs bg-gray-50 dark:bg-gray-900 px-2 py-1.5 rounded border border-gray-200 dark:border-gray-700 overflow-x-auto",children:e.url}),(0,s.jsx)("button",{onClick:()=>{var t;return null==(t=navigator.clipboard)?void 0:t.writeText(e.url)},className:"p-1.5 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",title:"Copy link",children:(0,s.jsx)(tx.A,{className:"h-4 w-4"})})]},e.token)),(0,s.jsx)("p",{className:"text-xs text-gray-400 dark:text-gray-500",children:j.every(e=>e.emailed)?"Each reviewer has been emailed their link. Copy above to share manually too.":"Copy each link to its reviewer. They can review and sign off without an account."})]})]})]}):(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400 py-2",children:"Generate a branded, client-facing proposal from this opportunity's analysis and business case."})]})}var tj=a(38041);function tN(e){let t=[e.estimated_duration_minutes?"".concat(e.estimated_duration_minutes," min"):null,e.difficulty_level].filter(Boolean);return t.length?"".concat(e.title," (").concat(t.join(", "),")"):e.title}function t_(e){return 1===e.length?e[0]:2===e.length?"".concat(e[0]," and ").concat(e[1]):"".concat(e.slice(0,-1).join(", ")," and ").concat(e[e.length-1])}var tS=a(93365),tA=a(36640),tC=a(15595),tT=a(51240);let tP={exec_brief:"Executive brief",roi_handout:"ROI model",process_map:"How it runs today, and after",pilot_scope:"Pilot scope",assumptions_risk:"What has to be true",scorecard:"Outcome scorecard",case_study:"Case study (measured outcomes)"},tE=e=>
1"$".concat(Math.round(e).toLocaleString("en-US")),tF=(e,t)=>"".concat(e," ").concat(t).concat(1===e?"":"s");function tq(e,t){var a,s;let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{training:n,provider:l,agency:i}=r,o=(()=>{switch(e){case"exec_brief":return function(e){var t,a,s,r,n,l,i;let o=e.business_case;if(!o)return null;let d=(0,X.Z5)(o),c=(0,eB.Kn)(null!=(n=e.scenarios)?n:[]),u=null!=(l=null==c?void 0:c.implementation_cost)?l:o.assumptions.implementation_cost,m=[],x=(0,tA.Jv)(e)||(null==(a=e.landscape)||null==(t=a.current_state_notes)?void 0:t.join(" "))||"".concat(e.title," runs as it always has.");return m.push({heading:"The situation",body:x.length>400?"".concat(x.slice(0,397).trimEnd(),"â¦"):x}),m.push({heading:"What it costs to leave it",body:"**".concat(tE(d.annual_loss)," a year** â about ").concat(tE(d.monthly_loss)," a month.")+(null!=d.break_even_delay_months&&null!=d.implementation_cost?" Waiting more than ~".concat(d.break_even_delay_months," months costs more than fixing it."):"")}),m.push({heading:"What we recommend",body:c?"**".concat(c.name,"** â ").concat(null!=(i=c.description)?i:"the scoped option we recommend."):(null==(r=e.solution)||null==(s=r.approach)?void 0:s.trim())||"Automate the process as scoped in the business case."}),m.push({heading:"The ask",body:null!=u?"".concat(tE(u)," one-time.")+(null!=o.payback_months?" Pays back in about ".concat(o.payback_months," months."):""):"Approve the scope so we can price it."}),{kind:"exec_brief",title:e.title,subtitle:"One-page summary",sections:m}}(t);case"roi_handout":return function(e){var t,a;let s=e.business_case;if(!s)return null;let r=(0,eO.q)(s.provenance),n=null!=(t=s.confidence)?t:(0,eO.pE)(r,s.assumptions),l=(0,X.Z5)(s),i=[];i.push({heading:"The figures",body:s.narrative});let o=l.components?(0,ez.F6)(l.components):"";return o&&i.push({heading:"What the loss is made of",body:o}),i.push({heading:"How firmly they are held",body:(0,tS.SU)(null!=(a=s.range)?a:(0,tS.p_)(s))}),i.push({heading:"Every input, and where it came from",body:Object.keys(eO.pX).map(e=>"- ".concat(eO.pX[e],": ").concat(eO.Rc[r[e].source])).join("\n")}),{kind:"roi_handout",title:"".concat(e.title," â the numbers"),subtitle:"Grounding ".concat(n.score,"/100"),sections:i}}(t);case"process_map":return function(e,t,a){var s;let r=null==(s=e.landscape)?void 0:s.process;if(!r||0===r.steps.length)return null;let n=(0,tC.Lz)(r),l=[];l.push({heading:"How it runs today",body:(0,tC.U3)(r)});let i=r.steps.filter(e=>!0===e.automatable),o=r.steps.filter(e=>!0!==e.automatable),d=[];i.length?(d.push("**".concat(i.length," of ").concat(r.steps.length," steps** stop being done by a person:")),d.push(...i.map(e=>"- ".concat(e.name||"â")))):d.push("No step has yet been judged automatable, so nothing is shown as removed."),o.length&&(d.push(""),d.push("**What still needs a person:**"),d.push(...o.map(e=>"- ".concat(e.name||"â")+(e.constraint?" â ".concat(e.constraint):null==e.automatable?" â not yet assessed":"")))),null!=n.blocked_hours&&n.blocked_hours>0&&(d.push(""),d.push("About ".concat(Math.round(n.blocked_hours).toLocaleString("en-US")," hours a year sit in steps ")+"that cannot be automated, whatever the software. That is the ceiling on this process.")),l.push({heading:"What changes",body:d.join("\n")});let c=(null==t?void 0:t.length)?function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(0,tj.IA)(e,t).map(e=>({competencyName:e.competencyName,excerpt:e.excerpt,attribution:(0,tj.kx)(e,(0,tj.pX)(t.provider))}))}(e,{...t,provider:t.provider});if(0===a.length)return null;let s=new Map;for(let e of a){var r,n;let t=null!=(r=e.competencyName)?r:"General";s.set(t,[...null!=(n=s.get(t))?n:[],e])}let l=new Map;for(let t of(0,tj.QG)(e))t.competencyName&&l.set(t.competencyName,t);let i=["The steps that still need a person need specific, checkable skills. What each one covers, quoted from the training that covers it:"];for(let[e,a]of s){for(let t of(i.push(""),i.push("**".concat(e,"**")),a))i.push(""),i.push("> ".concat(t.excerpt)),i.push("> â ".concat(t.attribution));let s=function(e,t){if(!e)return null;let a=(0,tj.pX)(t);if(e.held.length){let s,r,n=e.held[0],l=1===e.held.length,i=l&&n.slug&&(null==t?void 0:t.learner_url_base)?" â open it at ".concat((s=t.learner_url_base,r=n.slug,"".concat(s.replace(/\/+$/,""),"/").concat(r))):"";return"Already in ".concat(a?"your ".concat(a," subscription"):"your training subscription",": ").concat(t_(e.held.map(tN)),". ")+"Assign ".concat(l?"it":"them"," to the people working this step").concat(i,".")}if(e.offers.length){let a=1===e.offers.length,s=(null==t?void 0:t.catalog_url)?" â see ".concat(t.catalog_url):"";return"Not in your subscription yet: ".concat(t_(e.offers.map(tN)),". ")+"Adding ".concat(a?"it":"them"," trains the people who will run this step").concat(s,".")}return null}(l.get(e),t.provider);s&&(i.push(""),i.push(s))}return{heading:"What the people at these steps need to know",body:i.join("\n")}}(t,{provider:a}):null;c&&l.push(c);let u=function(e,t){let a=new Map;for(let t of e)for(let e of(0,eE._E)(t,eF.k)){var s,r;if("fits"!==e.verdict)continue;let t=eF.k.find(t=>t.key===e.modality);for(let e of null!=(s=null==t?void 0:t.safety_basis)?s:[]){let s=null!=(r=a.get(e.label))?r:{cite:e,modalities:new Set};s.modalities.add(t.name),a.set(e.label,s)}}if(0===a.size)return null;let n=["The options above are judged against published rules, not our opinion. What applies here, and to which option:",""];for(let{cite:e,modalities:t}of a.values()){let a=e.organization?" (".concat(e.organization,")"):"",s=e.url?" â ".concat(e.url):"";n.push("- **".concat(e.label,"**").concat(a," â ").concat([...t].join(", ")).concat(s))}return n.push(""),n.push((null==t?void 0:t.catalog_url)?"Training that covers working to these rules is listed above. The full catalog is at ".concat(t.catalog_url,"."):"Training that covers working to these rules is listed above."),{heading:"The rules these steps answer to",body:n.join("\n")}}(r.steps,a);return u&&l.push(u),{kind:"process_map",title:"".concat(e.title," â how the work runs"),subtitle:"".concat(tF(n.step_count,"step")," \xb7 ").concat(tF(n.handoff_count,"handoff")," \xb7 ").concat(tF(n.system_count,"system")),sections:l}}(t,n,l);case"pilot_scope":return function(e){var t,a,s,r,n,l,i,o,d;let c=e.business_case,u=(0,eB.Kn)(null!=(i=e.scenarios)?i:[]);if(!c||!u)return null;let m=(0,eB.v9)(null!=(o=e.scenarios)?o:[],(0,X.Z5)(c)).find(e=>e.scenario.key===u.key),x=[];x.push({heading:"Scope",body:(null==(t=u.description)?void 0:t.trim())||"".concat(u.name," of ").concat(e.title,".")}),(null==(s=e.solution)||null==(a=s.components)?void 0:a.length)&&x.push({heading:"What we deliver",body:e.solution.components.map(e=>"- (".concat(e.kind,") ").concat(e.title)).join("\n")}),x.push({heading:"What it costs and returns",body:"- Investment: ".concat(null!=u.implementation_cost?tE(u.implementation_cost):"to be priced","\n")+"- Value captured: ".concat(m?tE(m.annual_value):"â","/year\n")+"- Still lost after: ".concat(m?tE(m.residual_annual_loss):"â","/year\n")+"- Payback: ".concat((null==m?void 0:m.payback_months)!=null?"~".concat(m.payback_months," months"):"â")});let g=null!=(d=null==(r=e.success_hypothesis)?void 0:r.metrics)?d:[];return x.push({heading:"How we will know it worked",body:g.length?g.map(e=>"- ".concat(e.name,": ").concat(null!=e.baseline_value?"".concat(e.baseline_value," ").concat(e.unit," today"):"**no before-reading yet**")+"".concat(null!=e.target_value?" â target ".concat(e.target_value," ").concat(e.unit):"")).join("\n"):"**No measures agreed yet.** Nothing recorded before the work starts can be proven afterwards â this needs settling before delivery begins."}),(null==(l=e.solution)||null==(n=l.required_resources)?void 0:n.length)&&x.push({heading:"What we need from you",body:e.solution.required_resources.map(e=>"- ".concat(e)).join("\n")}),{kind:"pilot_scope",title:"".concat(e.title," â ").concat(u.name),subtitle:"Scope and success measures",sections:x}}(t);case"assumptions_risk":return function(e){var t,a,s,r;let n=e.business_case;if(!n)return null;let l=(0,eO.q)(n.provenance),i=null!=(s=n.confidence)?s:(0,eO.pE)(l,n.assumptions),o=null!=(r=n.range)?r:(0,tS.p_)(n),d=[],c=i.weakest;return d.push({heading:"What this case rests on",body:c.length?c.map(e=>"- **".concat(eO.pX[e],"** â ").concat(eO.Rc[l[e].source].toLowerCase(),". ")+"If this is wrong, the answer moves.").join("\n"):"Every input came from your business rather than our defaults."}),d.push({heading:"How wrong it could be",body:(0,tS.SU)(o)+(i.implementation_cost_missing?"\n\nPayback cannot be stated at all until the implementation cost is set.":"")}),(null==(a=e.solution)||null==(t=a.risks)?void 0:t.length)&&d.push({heading:"What could go wrong in delivery",body:e.solution.risks.map(e=>"- ".concat(e)).join("\n")}),d.push({heading:"What would settle it",body:i.next_best_input?"Confirming **".concat(eO.pX[i.next_best_input].toLowerCase(),"** narrows this ")+"more than anything else you could give us.":"Nothing outstanding â the inputs are confirmed."}),{kind:"assumptions_risk",title:"".concat(e.title," â what has to be true"),subtitle:"Stated before you have to ask",
1sections:d}}(t);case"scorecard":var a,s,r=t;let i=null!=(s=null==(a=r.success_hypothesis)?void 0:a.metrics)?s:[];return 0===i.length?null:{kind:"scorecard",title:"".concat(r.title," â outcome"),subtitle:"What we predicted, and what happened",sections:[{heading:"Results",body:(0,tv.l9)(i)}]};case"case_study":return function(e){var t,a,s,r,n,l,i,o,d,c,u,m,x,g,h,p,y;let b=null!=(g=null==(t=e.success_hypothesis)?void 0:t.metrics)?g:[],f=b.filter(tv.V2),v=(0,tT.K)(null==(a=e.delivery)?void 0:a.run_stats,null!=(h=null==(r=e.business_case)||null==(s=r.assumptions)?void 0:s.loaded_hourly_rate)?h:null),w=null!=v&&v.runs_completed>0;if(0===f.length&&!w)return null;let k=[],j=(0,tA.Jv)(e,{tense:"past"})||(null==(l=e.landscape)||null==(n=l.current_state_notes)?void 0:n.join(" "))||"".concat(e.title," ran as a manual process.");k.push({heading:"The situation",body:j.length>400?"".concat(j.slice(0,397).trimEnd(),"â¦"):j}),(null==(o=e.solution)||null==(i=o.components)?void 0:i.length)?k.push({heading:"What was delivered",body:e.solution.components.map(e=>"- (".concat(e.kind,") ").concat(e.title)).join("\n")}):(null==(c=e.solution)||null==(d=c.approach)?void 0:d.trim())&&k.push({heading:"What was delivered",body:e.solution.approach.trim()});let N=[];if(w&&v){let e="Over a **".concat(v.window_days,"-day** window the delivered automations completed ")+"**".concat(v.runs_completed.toLocaleString("en-US")," runs** across ").concat(v.workflows_total," ")+"workflow".concat(1===v.workflows_total?"":"s",".");null!=v.annual_savings&&(e+=" The ".concat(v.workflows_measured," with a supplied minutes-per-run annualize to ")+"**".concat(tE(v.annual_savings),"/year** in recovered time."));let t=v.workflows_total-v.workflows_measured;t>0&&(e+=0===v.workflows_measured?" None has a supplied minutes-per-run yet, so the runs are counted, not valued â unmeasured is not zero.":" The other ".concat(t," ").concat(1===t?"is":"are"," counted, not valued â unmeasured is not zero.")),N.push(e)}b.length>0&&N.push((0,tv.l9)(b)),k.push({heading:"What was measured",body:N.join("\n\n")});let _=null!=(p=null==(u=e.business_case)?void 0:u.annual_savings)?p:null;null!=_&&(null==v?void 0:v.annual_savings)!=null&&k.push({heading:"Predicted, then delivered",body:"- Predicted (modeled, at proposal): ".concat(tE(_),"/year\n")+"- Measured (annualized from run counts over ".concat(v.window_days," days): ").concat(tE(v.annual_savings),"/year")});let S=[];for(let e of f){let t=(0,tv.Qi)(e);S.push("- ".concat(e.name,": ").concat(e.baseline_value," â ").concat(e.actual_value," ").concat(null!=(y=e.unit)?y:"").trimEnd()+(null!=t.improvement_pct?" (".concat(Math.round(Math.abs(t.improvement_pct)),"% ").concat(null!=t.improvement&&t.improvement>=0?"better":"worse",")"):""))}w&&v&&S.push("- ".concat(v.runs_completed.toLocaleString("en-US")," automated runs completed in ").concat(v.window_days," days")+(null!=v.annual_savings?", annualizing to ~".concat(tE(v.annual_savings),"/year"):""));
1let A=null==(x=e.delivery)||null==(m=x.actuals)?void 0:m.realized_annual_savings;return k.push({heading:"Publishable claims",body:S.join("\n")+"\n\nEvery claim above traces to a measured reading."+(null!=A?" A separately ASSERTED realized-savings figure (".concat(tE(A),"/year, typed rather than measured) exists on this engagement and is deliberately excluded."):" Asserted figures are deliberately excluded.")}),{kind:"case_study",title:"".concat(e.title," â case study"),subtitle:"Anonymized \xb7 measured outcomes only",sections:k}}(t)}})();return o?{...o,...!(a=i)?{preparedBy:null,providerCredit:null}:{preparedBy:(null==(s=a.name)?void 0:s.trim())||null,providerCredit:a.showProviderAttribution?"Powered by Intellimate AI":null}}:null}function tI(e){let t=["# ".concat(e.title)];for(let a of(e.subtitle&&t.push("_".concat(e.subtitle,"_")),e.preparedBy&&t.push("Prepared by ".concat(e.preparedBy)),e.sections))t.push(""),t.push("## ".concat(a.heading)),t.push(""),t.push(a.body);return e.providerCredit&&(t.push(""),t.push("---"),t.push(e.providerCredit)),t.join("\n")}let tO={exec_brief:"Generate the business case first.",roi_handout:"Generate the business case first.",assumptions_risk:"Generate the business case first.",process_map:"Map the process steps first.",pilot_scope:"Select one of the options in the business case.",scorecard:"Agree the success measures first.",case_study:"Deliver and measure first â a case study needs at least one measured outcome."};function tz(e){var t,a,n;let{opportunity:l}=e,[i,o]=(0,r.useState)(null),[c,u]=(0,r.useState)(!0),[m,g]=(0,r.useState)(null),[h,p]=(0,r.useState)(null),[y,b]=(0,r.useState)(null),[f,v]=(0,r.useState)(void 0),[w,k]=(0,r.useState)(void 0),j=r.useRef(null),N=r.useRef(null);(0,r.useEffect)(()=>{if(!m||N.current===l.id)return;N.current=l.id;let e=!0;return(async()=>{try{let t=await (0,x.authHeaders)(),a=await fetch("/api/agency/brand?opportunityId=".concat(encodeURIComponent(l.id)),{headers:t});if(!e||!a.ok)return;let s=await a.json();e&&s.agency&&k(s.agency)}catch(e){}})(),()=>{e=!1}},[m,l.id]),(0,r.useEffect)(()=>{let e=!0;return(async()=>{u(!0);try{let t=await (0,z.CA)(l.id);e&&o(t.structured)}catch(t){e&&o(null)}finally{e&&u(!1)}})(),()=>{e=!1}},[l.id]);let _=null!=(n=null==i||null==(a=i.landscape)||null==(t=a.process)?void 0:t.steps)?n:[],S=r.useMemo(()=>(0,tj.H2)(_,eF.k).join(","),[JSON.stringify(_.map(e=>{var t;return null!=(t=e.operation)?t:null}))]);if((0,r.useEffect)(()=>{if(!m||!S)return;let e="".concat(l.id,":").concat(S);if(j.current===e)return;j.current=e;let t=!0;return(async()=>{try{let e=await (0,x.authHeaders)(),a=await fetch("/api/opportunities/capability-training?opportunityId=".concat(encodeURIComponent(l.id),"&capabilities=").concat(encodeURIComponent(S)),{headers:e});if(!t)return;let s=a.ok?await a.json():null;t&&(b((null==s?void 0:s.linked)&&s.data?s.data:null),v((null==s?void 0:s.linked)?s.provider:void 0))}catch(e){t&&b(null)}})(),()=>{t=!1}},[m,S,l.id]),c)return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6 flex items-center text-gray-500 dark:text-gray-400",children:[(0,s.jsx)(d.A,{className:"h-5 w-5 mr-2 animate-spin"})," Loadingâ¦"]});if(!i)return null;let A=new Set(Object.keys(tP).filter(e=>null!=tq(e,i))),C=Object.keys(tP),T=m?tq(m,i,{training:null!=y?y:void 0,provider:f,agency:w}):null,P=T?tI(T):"",E=async(e,t)=>{var a;await (null==(a=navigator.clipboard)?void 0:a.writeText(t)),p(e),setTimeout(()=>p(null),1500)};return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[(0,s.jsxs)("div",{className:"flex items-center mb-4",children:[(0,s.jsx)(eS.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-lg font-medium text-gray-900 dark:text-white",children:"Documents"}),(0,s.jsx)("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:"built from this opportunity â no new figures"})]}),(0,s.jsx)("div",{className:"space-y-2",children:C.map(e=>{let t=A.has(e);return(0,s.jsxs)("div",{className:"flex items-center justify-between rounded-lg border border-gray-200 dark:border-gray-700 px-3 py-2",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("span",{className:"text-sm ".concat(t?"text-gray-900 dark:text-white font-medium":"text-gray-400 dark:text-gray-500"),children:tP[e]}),!t&&(0,s.jsx)("span",{className:"ml-2 text-xs text-gray-400 dark:text-gray-500",children:tO[e]})]}),t&&(0,s.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,s.jsx)("button",{onClick:()=>E(e,tI(tq(e,i,{training:null!=y?y:void 0,provider:f,agency:w}))),className:"p-1.5 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",title:"Copy markdown",children:h===e?(0,s.jsx)(ts.A,{className:"h-4 w-4 text-green-600"}):(0,s.jsx)(tx.A,{className:"h-4 w-4"})}),(0,s.jsx)("button",{onClick:()=>g(m===e?null:e),className:"text-xs font-medium text-indigo-600 dark:text-indigo-400 hover:underline",children:m===e?"Hide":"Preview"})]})]},e)})}),T&&(0,s.jsx)("pre",{className:"mt-3 text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap font-sans bg-gray-50 dark:bg-gray-900/50 rounded-lg p-4 max-h-80 overflow-y-auto",children:P})]})}var tR=a(9498);let tD="block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-sm",tM="block text-xs font-medium text-gray-600 dark:text-gray-400",tL=e=>""===e?null:Number(e);function tU(e){let{opportunity:t,onSaved:a}=e,{user:n}=(0,g.A)(),[l,i]=(0,r.useState)([]),[o,c]=(0,r.useState)(!0),[u,m]=(0,r.useState)(!1),[x,h]=(0,r.useState)(null),p=async()=>{c(!0);try{var e,a;let s=(await (0,z.CA)(t.id)).structured;i(null!=(a=null==(e=s.success_hypothesis)?void 0:e.metrics)?a:[])}catch(e){i([])}finally{c(!1)}};(0,r.useEffect)(()=>{p()},[t.id]);let b=(e,t)=>i(a=>a.map((a,s)=>s===e?{...a,...t,source:"user_entered",captured_at:null!=t.baseline_value&&null==a.baseline_value?new Date().toISOString():a.captured_at,actual_captured_at:null!=t.actual_value&&null==a.actual_value?new Date().toISOString():a.actual_captured_at}:a)),f=async()=>
1{if(n){m(!0),h(null);try{await (0,z.Ub)(t.id,l,n.id),await p(),null==a||a()}catch(e){console.error("Failed to save success measures:",e),h("Failed to save success measures.")}finally{m(!1)}}};if(o)return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6 flex items-center text-gray-500 dark:text-gray-400",children:[(0,s.jsx)(d.A,{className:"h-5 w-5 mr-2 animate-spin"})," Loadingâ¦"]});let v=(0,tv.vq)(l),w=(0,tv.qO)(l);return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[(0,s.jsxs)("div",{className:"flex items-center mb-3",children:[(0,s.jsx)(tR.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-lg font-medium text-gray-900 dark:text-white",children:"Success measures"}),(0,s.jsxs)("button",{onClick:()=>i(e=>[...e,(0,tv.X9)()]),className:"ml-auto inline-flex items-center text-xs font-medium text-indigo-600 dark:text-indigo-400 hover:underline",children:[(0,s.jsx)(k.A,{className:"h-3.5 w-3.5 mr-1"})," Add measure"]})]}),x&&(0,s.jsx)("div",{className:"mb-3 text-sm text-red-600 dark:text-red-400",children:x}),!w&&(0,s.jsxs)("div",{className:"rounded-lg border border-amber-200 dark:border-amber-900/50 bg-amber-50 dark:bg-amber-900/10 p-3 mb-3 flex items-start",children:[(0,s.jsx)(y.A,{className:"h-4 w-4 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0"}),(0,s.jsx)("p",{className:"ml-2 text-xs text-gray-700 dark:text-gray-300",children:"Nothing here has a before-reading yet. Once the process changes, a baseline can never be taken retroactively â this project would be unprovable for good."})]}),0===l.length?(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"What will be different, and how will you know? Record it now â the reading only exists while the process is still unchanged."}):(0,s.jsx)("div",{className:"space-y-2",children:l.map((e,t)=>{var a,r,n,l,o;let d=(0,tv.Qi)(e);return(0,s.jsxs)("div",{className:"grid grid-cols-12 gap-2 items-end",children:[(0,s.jsxs)("div",{className:"col-span-3",children:[(0,s.jsx)("label",{className:tM,children:"Measure"}),(0,s.jsx)("input",{value:e.name,placeholder:"Orders per week",onChange:e=>b(t,{name:e.target.value,key:e.target.value}),className:tD})]}),(0,s.jsxs)("div",{className:"col-span-2",children:[(0,s.jsx)("label",{className:tM,children:"Unit"}),(0,s.jsx)("input",{value:e.unit,placeholder:"orders/week",onChange:e=>b(t,{unit:e.target.value}),className:tD})]}),(0,s.jsxs)("div",{className:"col-span-2",children:[(0,s.jsx)("label",{className:tM,children:"Better is"}),(0,s.jsxs)("select",{value:e.direction,onChange:e=>b(t,{direction:e.target.value}),className:tD,children:[(0,s.jsx)("option",{value:"increase",children:"Higher"}),(0,s.jsx)("option",{value:"decrease",children:"Lower"})]})]}),(0,s.jsxs)("div",{className:"col-span-2",children:[(0,s.jsx)("label",{className:tM,children:"Before"}),(0,s.jsx)("input",{type:"number",value:null!=(a=e.baseline_value)?a:"",placeholder:"not read",onChange:e=>b(t,{baseline_value:tL(e.target.value)}),className:tD})]}),(0,s.jsxs)("div",{className:"col-span-1",children:[(0,s.jsx)("label",{className:tM,children:"Target"}),(0,s.jsx)("input",{type:"number",value:null!=(r=e.target_value)?r:"",placeholder:"â",onChange:e=>b(t,{target_value:tL(e.target.value)}),className:tD})]}),(0,s.jsxs)("div",{className:"col-span-1",children:[(0,s.jsx)("label",{className:tM,children:"Now"}),(0,s.jsx)("input",{type:"number",value:null!=(n=e.actual_value)?n:"",placeholder:"â",onChange:e=>b(t,{actual_value:tL(e.target.value)}),className:tD})]}),(0,s.jsxs)("div",{className:"col-span-1 flex items-center justify-end pb-2",children:[d.measured&&(0,s.jsx)("span",{className:"text-xs font-medium mr-2 ".concat((null!=(l=d.improvement)?l:0)>0?"text-green-600 dark:text-green-400":(null!=(o=d.improvement)?o:0)<0?"text-red-600 dark:text-red-400":"text-gray-500"),title:null!=d.target_attainment?"".concat(Math.round(100*d.target_attainment),"% of target"):void 0,children:null!=d.improvement_pct?"".concat(d.improvement_pct>0?"+":"").concat(d.improvement_pct,"%"):"â"}),(0,s.jsx)("button",{"aria-label":"Remove measure",onClick:()=>i(e=>e.filter((e,a)=>a!==t)),className:"text-gray-400 hover:text-red-600 dark:hover:text-red-400",children:(0,s.jsx)(S.A,{className:"h-4 w-4"})})]})]},t)})}),(0,s.jsxs)("div",{className:"flex items-center justify-between mt-3",children:[(0,s.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:v.measured_count>0?"".concat(v.improved_count," of ").concat(v.measured_count," improved")+(v.regressed_count>0?", ".concat(v.regressed_count," went the wrong way"):""):v.measurable_count>0?"Baselines recorded. Read them again after delivery.":""}),(0,s.jsxs)("button",{onClick:f,disabled:u||0===l.length,className:"inline-flex items-center px-3 py-1.5 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 disabled:opacity-50",children:[u?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Save measures"]})]})]})}var tH=a(48995),tW=a(6048),tB=a(76158),tJ=a(64681);let tG=[".txt",".md",".vtt",".srt",".csv",".tsv",".log"];function t$(e){let t=e.toLowerCase();return tG.some(e=>t.endsWith(e))}let tV=/^\s*(\d{1,2}:)?\d{1,2}:\d{2}[.,]\d{1,3}\s*-->\s*(\d{1,2}:)?\d{1,2}:\d{2}[.,]\d{1,3}.*$/,tX=/^\s*\d+\s*$/,tY=/^\s*WEBVTT.*$/i,tK=/<[^>]*>/g;function tQ(e,t){let a=function(e,t){let a=t.toLowerCase();return(a.endsWith(".vtt")||a.endsWith(".srt")?function(e){let t=[];for(let a of e.split(/\r?\n/)){if(tV.test(a)||tX.test(a)||tY.test(a))continue;let e=a.replace(tK,"").trimEnd();e.trim()&&(t.length&&t[t.length-1]===e||t.push(e))}return t.join("\n")}(e):e).trim()}(e,t);return{text:a.slice(0,24e3),truncated:a.length>24e3,original_length:a.length}}let tZ=[".pdf",".docx",".xlsx"],t0=[".eml"];function t1(e){return e.toLowerCase().endsWith(".eml")}let t5=[".png",".jpg",".jpeg",".webp"];function t4(e){let t=e.toLowerCase();return tZ.some(e=>t.endsWith(e))}function t2(e){let t=e.toLowerCase();return t5.some(e=>t.endsWith(e))}
1class t3 extends Error{constructor(e,t){super(t),this.name="UnreadableDocumentError",this.reason=e}}async function t6(e,t){let{authHeaders:s}=await Promise.resolve().then(a.bind(a,55304)),r=await fetch("/api/opportunities/ocr",{method:"POST",headers:await s({"Content-Type":"application/json"}),body:JSON.stringify({image:e,page:t})}),n=await r.json().catch(()=>({}));if(!r.ok){var l;throw new t3("corrupt",null!=(l=n.error)?l:"Could not read that image.")}return"string"==typeof n.text?n.text:""}async function t7(){let e=await a.e(8233).then(a.bind(a,53553));return e.GlobalWorkerOptions.workerSrc="/pdf.worker.min.mjs",e}function t9(e,t){let a=[],s=0;for(let r of e)a.push(s),s+=r.length+t.length;return{text:e.join(t),pageOffsets:a}}async function t8(e,t){let a,s=await t7(),r=new Uint8Array(await e.arrayBuffer()),n=s.getDocument({data:r});try{a=await n.promise}catch(t){let e=t instanceof Error?t.message:String(t);if(/password/i.test(e))throw new t3("encrypted","That PDF is password-protected. Unlock it and try again, or paste the text.");throw new t3("corrupt","That PDF could not be opened.")}let l=[];for(let e=1;e<=a.numPages;e+=1){let t=await a.getPage(e),s=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").join(" ").replace(/[ \t]+/g," ").trim();s&&l.push(s)}if(l.length>0){let{text:e,pageOffsets:t}=t9(l,"\n\n");return await n.destroy(),{text:e,pageOffsets:t}}if(!t.allowOcr)throw await n.destroy(),new t3("ocr_not_allowed","That PDF has no selectable text â it looks like a scan. We can read it with AI, but that sends the page images to our AI provider instead of keeping them in your browser.");let i=[],o=Math.min(a.numPages,20);for(let e=1;e<=o;e+=1){var d;null==(d=t.onProgress)||d.call(t,"Reading page ".concat(e," of ").concat(o,"â¦"));let s=await a.getPage(e),r=s.getViewport({scale:2}),n=document.createElement("canvas");n.width=Math.ceil(r.width),n.height=Math.ceil(r.height);let l=n.getContext("2d");if(!l)break;await s.render({canvas:n,canvasContext:l,viewport:r}).promise;let c=await t6(n.toDataURL("image/png"),e);c.trim()&&i.push(c.trim())}let c=a.numPages;if(await n.destroy(),0===i.length)throw new t3("no_text_layer","We could not read any text from that scan.");let{text:u,pageOffsets:m}=t9(i,"\n\n");return{text:u,pageOffsets:m,ocr:!0,notice:c>o?"Read the first ".concat(o," of ").concat(c," pages by AI. The rest were not read. ")+"Check the figures against the original before relying on them.":"Read by AI from the page images, because this PDF has no selectable text. Check the figures against the original before relying on them."}}async function ae(e){let t,s=await a.e(2616).then(a.t.bind(a,9921,23)),r=await e.arrayBuffer();try{t=await s.extractRawText({arrayBuffer:r})}catch(e){throw new t3("corrupt","That Word file could not be read. If it is an older .doc, save it as .docx and try again.")}if(!t.value.trim())throw new t3("no_text_layer","That Word file had no text in it â only images or drawings, which we do not read yet.");return{text:t.value}}function at(e){if(null==e)return"";let t=e instanceof Date?e.toISOString().slice(0,10):String(e);return/[",\n\r]/.test(t)?'"'.concat(t.replace(/"/g,'""'),'"'):t}async function aa(e){let t,s=(await Promise.all([a.e(1071),a.e(4453)]).then(a.bind(a,90482))).default;try{t=await s(e)}catch(e){throw new t3("corrupt","That spreadsheet could not be read. If it is an older .xls, save it as .xlsx and try again.")}let r=t.find(e=>e.data.some(e=>e.some(e=>""!==at(e).trim())));if(!r)throw new t3("no_text_layer","That spreadsheet had no data in it.");let n=r.data.map(e=>e.map(at).join(",")).join("\n"),l=t.filter(e=>e.sheet!==r.sheet).map(e=>e.sheet);return{text:n,notice:l.length?'Read the "'.concat(r.sheet,'" sheet. ').concat(l.length," other sheet").concat(1===l.length?"":"s"," ")+"(".concat(l.join(", "),") ").concat(1===l.length?"was":"were"," not read â ")+"load them separately if they matter.":void 0}}async function as(e){let{emailToSourceText:t,UnreadableEmailError:s}=await a.e(559).then(a.bind(a,10559));try{let a=await t(await e.arrayBuffer());return{text:a.text,notice:a.notice}}catch(e){if(e instanceof s)throw new t3("empty"===e.reason?"no_text_layer":"corrupt",e.message);throw e}}async function ar(e,t){var a;if(!t.allowOcr)throw new t3("ocr_not_allowed","That is a picture, so reading it means
1sending the image to our AI provider instead of keeping it in your browser.");let s=await new Promise((t,a)=>{let s=new FileReader;s.onload=()=>{var e;return t(String(null!=(e=s.result)?e:""))},s.onerror=()=>a(new t3("corrupt","That image could not be read.")),s.readAsDataURL(e)});null==(a=t.onProgress)||a.call(t,"Reading the imageâ¦");let r=await t6(s,null);if(!r.trim())throw new t3("no_text_layer","We could not read any text in that image.");return{text:r,ocr:!0,notice:"Read by AI from the image. Check the figures against the original before relying on them."}}async function an(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=e.name.toLowerCase();if(a.endsWith(".pdf"))return t8(e,t);if(a.endsWith(".docx"))return ae(e);if(a.endsWith(".xlsx"))return aa(e);if(t1(a))return as(e);if(t2(a))return ar(e,t);throw new t3("corrupt","".concat(e.name," is not a document we parse."))}var al=a(80163);function ai(e,t){let a=null!=t?t:function(e){var t,a,s,r;let n=null!=(t=e.split(/\r?\n/).find(e=>e.trim()))?t:"",l=(null!=(a=n.match(/\t/g))?a:[]).length,i=(null!=(s=n.match(/,/g))?s:[]).length,o=(null!=(r=n.match(/;/g))?r:[]).length;return l>=i&&l>=o&&l>0?" ":o>i?";":","}(e),s=[],r=[],n="",l=!1;for(let t=0;t<e.length;t+=1){let i=e[t];if(l){'"'===i?'"'===e[t+1]?(n+='"',t+=1):l=!1:n+=i;continue}'"'===i?l=!0:i===a?(r.push(n),n=""):"\n"===i?(r.push(n),s.push(r),r=[],n=""):"\r"!==i&&(n+=i)}(""!==n||r.length)&&(r.push(n),s.push(r));let[i=[],...o]=s.filter(e=>e.some(e=>""!==e.trim()));return{headers:i.map(e=>e.trim()),rows:o}}function ao(e){let t=e.replace(/[$,\s]/g,"");if(""===t||!/^-?\d*\.?\d+$/.test(t))return null;let a=Number(t);return Number.isFinite(a)?a:null}function ad(e){let t=e.trim();if(!/^\d{4}-\d{2}-\d{2}|^\d{1,2}[/-]\d{1,2}[/-]\d{2,4}/.test(t))return null;let a=Date.parse(t);return Number.isFinite(a)?a:null}var ac=a(2502),au=a(95159);let am="block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-sm",ax="block text-[11px] font-medium text-gray-600 dark:text-gray-400";function ag(e){var t,a,n,l,i,o,d;let{text:c,sourceLabel:u,startingId:m,onAccept:x}=e,g=(0,r.useMemo)(()=>ai(c),[c]),h=(0,r.useMemo)(()=>g.headers.map((e,t)=>(function(e,t){let a=t.filter(e=>null!=e&&""!==e.trim()),s={name:e,non_empty:a.length,distinct:new Set(a.map(e=>e.trim())).size};if(0===a.length)return{...s,kind:"empty"};let r=a.map(ao).filter(e=>null!=e),n=a.map(ad).filter(e=>null!=e),l=.8*a.length;if(n.length>=l){let e=Math.min(...n),t=Math.max(...n);return{...s,kind:"date",span:{earliest:new Date(e).toISOString(),latest:new Date(t).toISOString(),days:Math.round((t-e)/864e5)}}}return r.length>=l?{...s,kind:"number",numeric:{min:Math.min(...r),max:Math.max(...r),mean:Math.round(r.reduce((e,t)=>e+t,0)/r.length*100)/100}}:{...s,kind:"text"}})(e,g.rows.map(e=>{var a;return null!=(a=e[t])?a:""}))),[g]),p=h.filter(e=>"date"===e.kind),[y,b]=(0,r.useState)(null!=(l=null==(t=p[0])?void 0:t.name)?l:""),[f,v]=(0,r.useState)(null!=(i=null==(a=p[0])?void 0:a.name)?i:""),[w,k]=(0,r.useState)(null!=(o=null==(n=p[1])?void 0:n.name)?o:""),[j,N]=(0,r.useState)(u||"Process from export"),_=(0,r.useMemo)(()=>(function(e,t){if(0===e)return{occurrences_per_year:null,reason:"The export has no rows.",observed_rows:0,undated_rows:0,span_days:null};if(!(null==t?void 0:t.span))return{occurrences_per_year:null,reason:"No date column was identified, so the rows cannot be placed in time.",observed_rows:0,undated_rows:e,span_days:null};let a=t.non_empty,s=Math.max(0,e-a),r=t.span.days;return 0===a?{occurrences_per_year:null,reason:"No row has a date in that column.",observed_rows:0,undated_rows:e,span_days:r}:r<28?{occurrences_per_year:null,reason:"The dated rows cover ".concat(r," day").concat(1===r?"":"s",", which is too short a window to ")+"scale to a year without guessing. Export at least ".concat(28," days."),observed_rows:a,undated_rows:s,span_days:r}:{occurrences_per_year:Math.round(a/r*365),reason:s>0?"".concat(s.toLocaleString("en-US")," of ").concat(e.toLocaleStr
1ing("en-US")," rows have no ")+"date and are not counted â the rate comes from the ".concat(a.toLocaleString("en-US")," that do."):null,observed_rows:a,undated_rows:s,span_days:r}})(g.rows.length,h.find(e=>e.name===y)),[g.rows.length,h,y]),S=(0,r.useMemo)(()=>f&&w&&f!==w?function(e,t,a){let s=e.headers.indexOf(t),r=e.headers.indexOf(a);if(s<0||r<0)return{median_minutes:null,usable_rows:0,excluded_rows:e.rows.length};let n=[],l=0;for(let t of e.rows){var i,o;let e=ad(null!=(i=t[s])?i:""),a=ad(null!=(o=t[r])?o:"");if(null==e||null==a||a<e){l+=1;continue}n.push((a-e)/6e4)}if(0===n.length)return{median_minutes:null,usable_rows:0,excluded_rows:l};n.sort((e,t)=>e-t);let d=Math.floor(n.length/2);return{median_minutes:Math.round(10*(n.length%2==0?(n[d-1]+n[d])/2:n[d]))/10,usable_rows:n.length,excluded_rows:l}}(g,f,w):null,[g,f,w]),A=null!=_.occurrences_per_year||(null==S?void 0:S.median_minutes)!=null;return(0,s.jsxs)("div",{className:"rounded-lg border border-indigo-200 dark:border-indigo-900/50 bg-indigo-50/40 dark:bg-indigo-900/10 p-3 mb-3",children:[(0,s.jsxs)("div",{className:"flex items-center mb-2",children:[(0,s.jsx)(ac.A,{className:"h-4 w-4 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("span",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"This looks like an export"}),(0,s.jsxs)("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:[g.rows.length.toLocaleString("en-US")," rows \xb7 ",g.headers.length," columns"]})]}),(0,s.jsx)("p",{className:"text-xs text-gray-600 dark:text-gray-400 mb-3",children:"Counts and durations are calculated from the file, not read out of it by AI. Tell us which columns mean what."}),0===p.length?(0,s.jsx)("p",{className:"text-xs text-amber-700 dark:text-amber-400",children:"No date column was recognized, so these rows cannot be placed in time. Volume and cycle time both need one."}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:ax,children:"Date of each occurrence"}),(0,s.jsxs)("select",{value:y,onChange:e=>b(e.target.value),className:am,children:[(0,s.jsx)("option",{value:"",children:"â"}),p.map(e=>(0,s.jsx)("option",{value:e.name,children:e.name},e.name))]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:ax,children:"Started"}),(0,s.jsxs)("select",{value:f,onChange:e=>v(e.target.value),className:am,children:[(0,s.jsx)("option",{value:"",children:"â"}),p.map(e=>(0,s.jsx)("option",{value:e.name,children:e.name},e.name))]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:ax,children:"Finished"}),(0,s.jsxs)("select",{value:w,onChange:e=>k(e.target.value),className:am,children:[(0,s.jsx)("option",{value:"",children:"â"}),p.map(e=>(0,s.jsx)("option",{value:e.name,children:e.name},e.name))]})]})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3 mb-3",children:[(0,s.jsx)(ah,{label:"Times per year",value:null!=_.occurrences_per_year?_.occurrences_per_year.toLocaleString("en-US"):"â",detail:null!=_.occurrences_per_year?"".concat(_.observed_rows.toLocaleString("en-US")," dated rows over ").concat(_.span_days," days")+(_.reason?" \xb7 ".concat(_.reason):""):null!=(d=_.reason)?d:""}),(0,s.jsx)(ah,{label:"Median duration",value:(null==S?void 0:S.median_minutes)!=null?"".concat(S.median_minutes," min"):"â",detail:null==S?"Pick a started and finished column.":null==S.median_minutes?"No row had both a start and a finish.":"".concat(S.usable_rows," usable rows")+(S.excluded_rows>0?", ".concat(S.excluded_rows," excluded as unmeasurable"):"")})]}),(0,s.jsxs)("div",{className:"flex items-end gap-2",children:[(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("label",{className:ax,children:"Add as a step called"}),(0,s.jsx)("input",{value:j,onChange:e=>N(e.target.value),className:am})]}),(0,s.jsx)("button",{onClick:()=>{var e;return x([(0,tC.zu)({id:"s".concat(m),name:j.trim()||"Process from export",occurrences_per_year:_.occurrences_per_year,minutes:null!=(e=null==S?void 0:S.median_minutes)?e:null,source:"measured",note:"From ".concat(u||"an export",": ").concat(g.rows.length.toLocaleStr
1ing("en-US")," rows")+(null!=_.span_days?" over ".concat(_.span_days," days"):"")+((null==S?void 0:S.median_minutes)!=null?", median ".concat(S.median_minutes," min across ").concat(S.usable_rows," usable rows"):"")})])},disabled:!A,className:"px-3 py-1.5 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 disabled:opacity-50",children:"Add step"})]}),!A&&(0,s.jsxs)("p",{className:"mt-2 text-[11px] text-gray-500 dark:text-gray-400 flex items-start",children:[(0,s.jsx)(au.A,{className:"h-3 w-3 mr-1 mt-0.5 shrink-0"}),"Nothing measurable yet â a step with no volume and no duration would add nothing the business case can use."]})]})]})}function ah(e){let{label:t,value:a,detail:r}=e;return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-3",children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:t}),(0,s.jsx)("div",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:a}),(0,s.jsx)("div",{className:"text-[11px] text-gray-500 dark:text-gray-400 mt-0.5",children:r})]})}var ap=a(76928),ay=a(15682);let ab=[".m4a",".mp3",".mp4",".wav",".webm",".ogg",".mpga",".mpeg"];function af(e){let{onTranscript:t,disabled:a}=e,[n,l]=(0,r.useState)(!1),[i,o]=(0,r.useState)(!1),[c,u]=(0,r.useState)(0),[m,g]=(0,r.useState)(null),h=(0,r.useRef)(null),p=(0,r.useRef)([]),y=(0,r.useRef)(null);(0,r.useEffect)(()=>()=>{y.current&&clearInterval(y.current);let e=h.current;e&&"inactive"!==e.state&&e.stop(),null==e||e.stream.getTracks().forEach(e=>e.stop())},[]);let b=async(e,a,s)=>{o(!0),g(null);try{var r,n,l;let i=await fetch("/api/opportunities/transcribe",{method:"POST",headers:await (0,x.authHeaders)({"Content-Type":e.type||"application/octet-stream","x-filename":a}),body:e}),o=await i.json();if(!i.ok)return void g(null!=(n=o.error)?n:"Could not transcribe that recording.");if(!(null==(r=o.text)?void 0:r.trim()))return void g(null!=(l=o.warning)?l:"No speech was found in that recording.");t(o.text,s)}catch(e){g("Could not transcribe that recording.")}finally{o(!1)}},f=async()=>{g(null);try{let e=await navigator.mediaDevices.getUserMedia({audio:!0}),t=new MediaRecorder(e);p.current=[],t.ondataavailable=e=>{e.data.size>0&&p.current.push(e.data)},t.onstop=async()=>{e.getTracks().forEach(e=>e.stop());let a=new Blob(p.current,{type:t.mimeType||"audio/webm"}),s=new Date().toLocaleString();a.size>0&&await b(a,"recording.webm","Recording, ".concat(s))},t.start(),h.current=t,l(!0),u(0),y.current=setInterval(()=>u(e=>e+1),1e3)}catch(e){g("No microphone available, or permission was declined.")}},v=async e=>{if(e){if(g(null),!function(e){let t=e.toLowerCase();return ab.some(e=>t.endsWith(e))}(e.name))return void g("".concat(e.name," is not an audio file we can transcribe."));await b(e,e.name,e.name)}},w="".concat(Math.floor(c/60),":").concat(String(c%60).padStart(2,"0"));return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 flex-wrap",children:[n?(0,s.jsxs)("button",{onClick:()=>{var e;y.current&&clearInterval(y.current),y.current=null,null==(e=h.current)||e.stop(),h.current=null,l(!1)},className:"inline-flex items-center px-3 py-1.5 text-sm font-medium rounded-md text-white bg-red-600 hover:bg-red-700",children:[(0,s.jsx)(ap.A,{className:"h-4 w-4 mr-2"})," Stop \xb7 ",w]}):(0,s.jsxs)("button",{onClick:f,disabled:a||i,className:"inline-flex items-center px-3 py-1.5 text-sm font-medium rounded-md border border-indigo-300 dark:border-indigo-700 text-indigo-700 dark:text-indigo-300 hover:bg-indigo-50 dark:hover:bg-indigo-900/30 disabled:opacity-50",children:[i?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):(0,s.jsx)(ay.A,{className:"h-4 w-4 mr-2"}),i?"Transcribingâ¦":"Record a walkthrough"]}),(0,s.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-xs text-gray-600 dark:text-gray-400 cursor-pointer hover:text-gray-900 dark:hover:text-gray-200",children:[(0,s.jsx)(tB.A,{className:"h-3.5 w-3.5"}),(0,s.jsx)("span",{children:"or load a recording"}),(0,s.jsx)("input",{type:"file",accept:ab.join(","),className:"hidden",disabled:a||i||n,onChange:e=>{var t;return v(null==(t=e.target.files)?void 0:t[0])}})]}),n&&(0,s.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Recording â we don't keep the audio; it goes to our transcription provider and only the text comes back."})]}),m&&(0,s.jsx)("div",{className:"mt-2 text-sm text-red-600 dark:text-red-400",children:m})]})}var av=a(8728),aw=a(79261);function ak(e){let{opportunityId:t,disabled:a,onUse:n}=e,[l,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(!0),[u,m]=(0,r.useState)([]),[g,h]=(0,r.useState)(!0),[p,y]=(0,r.useState)(null),[b,f]=(0,r.useState)(!1),[v,w]=(0,r.useState)(!1),[k,j]=(0,r.useState)(null),N=async()=>{h(!0);try{var e,a;let s=await (0,x.authHeaders)(),[r,n]=await Promise.all([fetch("/api/opportunities/".concat(t,"/inbound-alias"),{headers:s}),fetch("/api/opportunities/".concat(t,"/inbound-emails"),{headers:s})]);if(503===r.status)return void c(!1);let l=await r.json(),o=await n.json();r.ok&&i(null!=(e=l.address)?e:null),n.ok&&m(null!=(a=o.emails)?a:[])}catch(e){}finally{h(!1)}};(0,r.useEffect)(()=>{N()},[t]);let _=async()=>{f(!0),j(null);try{let a=await fetch("/api/opportunities/".concat(t,"/inbound-alias"),{method:"POST",headers:await (0,x.authHeaders)()}),s=await a.json();if(!a.ok){var e;j(null!=(e=s.error)?e:"Could not create the address.");return}i(s.address)}catch(e){j("Could not create the address.")}finally{f(!1)}},A=async(e,a)=>{y(e),j(null);try{var s,r;let l=await fetch("/api/opportunities/".concat(t,"/inbound-emails"),{method:"POST",headers:await (0,x.authHeaders)({"Content-Type":"application/json"}),body:JSON.stringify({email_id:e,action:a})}),i=await l.json();if(!l.ok)return void j(null!=(s=i.error)?s:"Could not update that email.");"accept"===a&&n(i.body_text,i.subject?"Email: ".concat(i.subject):"Forwarded email",null!=(r=i.notice)?r:null),m(t=>t.filter(t=>t.id!==e))}catch(e){j("Could not update that email.")}finally{y(null)}},C=async()=>
1{if(l)try{await navigator.clipboard.writeText(l),w(!0),setTimeout(()=>w(!1),1500)}catch(e){}};return o?g?(0,s.jsxs)("div",{className:"mb-2 flex items-center text-xs text-gray-400 dark:text-gray-500",children:[(0,s.jsx)(d.A,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"})," Checking the mailboxâ¦"]}):(0,s.jsxs)("div",{className:"mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400",children:[(0,s.jsx)(av.A,{className:"h-3.5 w-3.5"}),l?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("span",{children:["Forward documents to"," ",(0,s.jsx)("code",{className:"text-indigo-700 dark:text-indigo-300",children:l})]}),(0,s.jsx)("button",{type:"button",onClick:C,className:"inline-flex items-center hover:text-gray-900 dark:hover:text-gray-200","aria-label":"Copy forwarding address",children:v?(0,s.jsx)(ts.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(tx.A,{className:"h-3.5 w-3.5"})})]}):(0,s.jsx)("button",{type:"button",onClick:_,disabled:b||a,className:"font-medium text-indigo-600 dark:text-indigo-400 hover:underline disabled:opacity-50",children:b?"Creatingâ¦":"Get a forwarding address for this opportunity"})]}),k&&(0,s.jsx)("div",{className:"mt-1 text-xs text-red-600 dark:text-red-400",children:k}),u.length>0&&(0,s.jsx)("div",{className:"mt-2 space-y-1.5",children:u.map(e=>{var t;return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-2 flex items-center gap-2",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("div",{className:"text-xs text-gray-900 dark:text-white truncate",children:null!=(t=e.subject)?t:"(no subject)"}),(0,s.jsxs)("div",{className:"text-[11px] text-gray-500 dark:text-gray-400 truncate",children:[e.from_email," \xb7 ",new Date(e.received_at).toLocaleString()]}),"quarantined"===e.status&&(0,s.jsxs)("div",{className:"text-[11px] text-amber-700 dark:text-amber-400 flex items-center gap-1",children:[(0,s.jsx)(aw.A,{className:"h-3 w-3 shrink-0"}),"Sender is not a member of this workspace â read it only if you know them."]}),e.notice&&(0,s.jsx)("div",{className:"text-[11px] text-amber-700 dark:text-amber-400",children:e.notice})]}),(0,s.jsx)("button",{type:"button",onClick:()=>A(e.id,"accept"),disabled:p===e.id||a,className:"shrink-0 text-xs font-medium text-indigo-600 dark:text-indigo-400 hover:underline disabled:opacity-50",children:p===e.id?"â¦":"Read it"}),(0,s.jsx)("button",{type:"button",onClick:()=>A(e.id,"discard"),disabled:p===e.id||a,"aria-label":"Discard email",className:"shrink-0 text-gray-400 hover:text-red-600 dark:hover:text-red-400 disabled:opacity-50",children:(0,s.jsx)(S.A,{className:"h-3.5 w-3.5"})})]},e.id)})})]}):null}var aj=a(90146);function aN(e){let{opportunityId:t,disabled:a,onUse:n}=e,[l,i]=(0,r.useState)([]),[o,d]=(0,r.useState)([]),[c,u]=(0,r.useState)(!1),[m,g]=(0,r.useState)(!0),[h,p]=(0,r.useState)(!1),[y,b]=(0,r.useState)(null),[f,v]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=!0;return(async()=>{try{let r=await fetch("/api/suite/documents?opportunityId=".concat(t),{headers:await (0,x.authHeaders)()}),n=await r.json();if(!e)return;if(r.ok&&n.linked){var a,s;u(!0),i(null!=(a=n.documents)?a:[]),d(null!=(s=n.knowledge)?s:[])}}catch(e){}finally{e&&g(!1)}})(),()=>{e=!1}},[t]);let w=async(e,a)=>{b(a),v(null);try{var s,r;let l=await fetch("/api/suite/documents?opportunityId=".concat(t,"&").concat("doc"===e?"doc":"knowledge","=").concat(a),{headers:await (0,x.authHeaders)()}),i=await l.json();if(!l.ok)return void v(null!=(s=i.error)?s:"Could not read that document.");if("doc"===e){let e=i.document;if(!(null==e?void 0:e.content))return void v(null!=(r=null==e?void 0:e.note)?r:"That document has no readable content yet.");let t="".concat(e.title).concat(e.version?" rev ".concat(e.version.number," (").concat(e.version.status,")"):""," â suite document library");n(e.content,t)}else{let e=i.knowledge;if(!(null==e?void 0:e.content))return void v("That knowledge entry has no content.");n(e.content,"".concat(e.title," â suite knowledge"))}}catch(e){v("Could not read that document.")}finally{b(null)}};
1return m||!c||0===l.length&&0===o.length?null:(0,s.jsxs)("div",{className:"mb-2",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>p(e=>!e),className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200",children:[(0,s.jsx)(aj.A,{className:"h-3.5 w-3.5"}),(0,s.jsxs)("span",{children:["Suite document library â ",l.length," document",1===l.length?"":"s",o.length>0&&", ".concat(o.length," knowledge entr").concat(1===o.length?"y":"ies")]}),(0,s.jsx)("span",{className:"text-gray-400 dark:text-gray-500",children:h?"hide":"show"})]}),f&&(0,s.jsx)("div",{className:"mt-1 text-xs text-red-600 dark:text-red-400",children:f}),h&&(0,s.jsxs)("div",{className:"mt-2 space-y-1.5 max-h-56 overflow-y-auto pr-1",children:[l.map(e=>(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-2 flex items-center gap-2",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("div",{className:"text-xs text-gray-900 dark:text-white truncate",children:e.title}),(0,s.jsx)("div",{className:"text-[11px] text-gray-500 dark:text-gray-400",children:[e.type,e.version?"rev ".concat(e.version.number," (").concat(e.version.status,")"):"no version yet"].filter(Boolean).join(" \xb7 ")})]}),(0,s.jsx)("button",{type:"button",onClick:()=>w("doc",e.id),disabled:y===e.id||a||!e.version,className:"shrink-0 text-xs font-medium text-indigo-600 dark:text-indigo-400 hover:underline disabled:opacity-50",children:y===e.id?"â¦":"Read it"})]},e.id)),o.map(e=>(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-2 flex items-center gap-2",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("div",{className:"text-xs text-gray-900 dark:text-white truncate",children:e.title}),(0,s.jsxs)("div",{className:"text-[11px] text-gray-500 dark:text-gray-400",children:["knowledge",e.category?" \xb7 ".concat(e.category):""]})]}),(0,s.jsx)("button",{type:"button",onClick:()=>w("knowledge",e.id),disabled:y===e.id||a,className:"shrink-0 text-xs font-medium text-indigo-600 dark:text-indigo-400 hover:underline disabled:opacity-50",children:y===e.id?"â¦":"Read it"})]},e.id))]})]})}var a_=a(84919);let aS="block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-sm";function aA(e){var t,a,n,l;let{onAccept:i,onFindings:o,opportunityId:c,startingId:u}=e,[m,g]=(0,r.useState)(""),[h,p]=(0,r.useState)(""),[b,f]=(0,r.useState)(null),[v,w]=(0,r.useState)(new Set),[k,j]=(0,r.useState)(new Set),[N,_]=(0,r.useState)(new Set),[S,A]=(0,r.useState)(!1),[C,T]=(0,r.useState)(!1),[P,E]=(0,r.useState)(null),[F,q]=(0,r.useState)(null),[I,O]=(0,r.useState)(!1),[z,R]=(0,r.useState)(void 0),[D,M]=(0,r.useState)(null),[L,U]=(0,r.useState)(null),H=async function(e){let t,a,s,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e)return;E(null),q(null),M(null);let n=t$(e.name),l=t4(e.name)||t1(e.name)||t2(e.name);if(!n&&!l)return void E("".concat(e.name," needs a parser we do not have yet. Text, Markdown, CSV, ")+"meeting transcripts (.vtt, .srt), PDF and Word (.docx) work today. For anything else, paste the text.");l&&O(!0);try{if(l){let n=await an(e,{allowOcr:r,onProgress:U});t=n.text,a=n.notice,s=n.pageOffsets}else t=await e.text()}catch(t){if(t instanceof t3&&"ocr_not_allowed"===t.reason){M(e),q(t.message);return}E(t instanceof t3?t.message:"".concat(e.name," could not be read."));return}finally{O(!1),U(null)}let i=tQ(t,e.name);if(!i.text.trim())return void E("".concat(e.name," had no readable text in it."));g(i.text),R(i.truncated?void 0:s),h.trim()||p(e.name),a&&i.truncated?q("".concat(a," It is also longer than we read in one pass â the first ")+"".concat(24e3.toLocaleString("en-US")," characters were loaded.")):a?q(a):i.truncated&&q("".concat(e.name," is longer than we read in one pass â the first ")+"".concat(24e3.toLocaleString("en-US")," characters were loaded. ")+"Anything after that was not read.")},W=async()=>{T(!0),E(null),f(null);try{let t;try{t=(await (0,al.J)("/api/opportunities/extract-process-jobs",{text:m,s
1ource_label:h,opportunity_id:c})).result}catch(s){if(!(s instanceof al.v))return void E(s instanceof Error?s.message:"Failed to read that source.");let a=await fetch("/api/opportunities/extract-process",{method:"POST",headers:await (0,x.authHeaders)({"Content-Type":"application/json"}),body:JSON.stringify({text:m,source_label:h})});if(t=await a.json(),!a.ok){var e;E(null!=(e=t.error)?e:"Failed to read that source.");return}}f((0,tJ.WY)(m,t,z)),w(new Set),j(new Set),_(new Set),A(!1)}catch(e){E("Failed to read that source.")}finally{T(!1)}},B=e=>t=>e(e=>{let a=new Set(e);return a.has(t)?a.delete(t):a.add(t),a}),J=B(w),G=B(j),$=B(_),V=async()=>{var e,t,a;if(!b)return;let s=(0,tJ.A4)(b,b.steps.map((e,t)=>({index:t,accepted:v.has(t)})),u),r=(0,tJ.CL)(b,(null!=(e=b.cost_drivers)?e:[]).map((e,t)=>({index:t,accepted:k.has(t)}))),n=(0,tJ.Mn)(b,(null!=(t=b.metrics)?t:[]).map((e,t)=>({index:t,accepted:N.has(t)})));s.length&&(i(s),w(new Set),A(!0));let l=(null!=(a=b.unpriced_losses)?a:[]).filter(e=>e.verified).map(e=>({label:e.value,quote:e.quote}));if((r.length||n.length||l.length)&&o){T(!0),E(null);try{await o({drivers:r,metrics:n,unpricedLosses:l},b.source_label)}catch(e){E((s.length?"The ".concat(s.length," accepted step").concat(1===s.length?" was":"s were"," added below, but the "):"The ")+"accepted cost drivers and measures could not be saved. Nothing was discarded â try again.");return}finally{T(!1)}}f(null),g(""),w(new Set),j(new Set),_(new Set),A(!1)},X=b?(0,tJ.qS)(b):null,Y=m.trim().length>40&&function(e){let t=e.split(/\r?\n/).filter(e=>e.trim()).slice(0,12);if(t.length<3)return!1;let a=ai(t.join("\n"));if(a.headers.length<2||a.rows.length<2)return!1;let s=new Set(a.rows.map(e=>e.length));return 1===s.size&&[...s][0]===a.headers.length}(m),K=o?(null!=(t=null==b?void 0:b.unpriced_losses)?t:[]).filter(e=>e.verified):[],Q=o&&null!=(a=null==b?void 0:b.cost_drivers)?a:[],Z=o&&null!=(n=null==b?void 0:b.metrics)?n:[],ee=v.size+k.size+N.size,et=(null!=(l=null==b?void 0:b.steps.length)?l:0)+Q.length+Z.length;return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3 mb-3",children:[(0,s.jsxs)("div",{className:"flex items-center mb-2",children:[(0,s.jsx)(tW.A,{className:"h-4 w-4 text-gray-500 dark:text-gray-400"}),(0,s.jsx)("span",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Read a document or transcript"}),(0,s.jsx)("span",{className:"ml-auto",children:(0,s.jsx)(a_.A,{title:"Dictate into the box",disabled:C,onText:e=>g(t=>(0,a_.O)(t,e))})})]}),(0,s.jsx)("div",{className:"grid grid-cols-4 gap-2 mb-2",children:(0,s.jsx)("input",{value:h,onChange:e=>p(e.target.value),placeholder:"What is this? e.g. AP walkthrough, 21 Aug",className:"col-span-4 ".concat(aS)})}),c&&(0,s.jsx)(aN,{opportunityId:c,disabled:C,onUse:(e,t)=>{let a=tQ(e,t);g(a.text),R(void 0),h.trim()||p(t),q(a.truncated?"Longer than we read in one pass â the first ".concat(24e3.toLocaleString("en-US")," characters were loaded."):null)}}),c&&(0,s.jsx)(ak,{opportunityId:c,disabled:C,onUse:(e,t,a)=>{let s=tQ(e,t);g(s.text),R(void 0),h.trim()||p(t),q([a,s.truncated?"Longer than we read in one pass â the first ".concat(24e3.toLocaleString("en-US")," characters were loaded."):null].filter(Boolean).join(" ")||null)}}),(0,s.jsx)("div",{className:"mb-2",children:(0,s.jsx)(af,{disabled:C,onTranscript:(e,t)=>{g(e),h.trim()||p(t),q("Transcribed. Check it reads right, then read it for steps.")}})}),(0,s.jsxs)("label",{className:"flex items-center gap-2 mb-2 text-xs text-gray-600 dark:text-gray-400 cursor-pointer hover:text-gray-900 dark:hover:text-gray-200",children:[(0,s.jsx)(tB.A,{className:"h-3.5 w-3.5"}),(0,s.jsx)("span",{children:"Load a file"}),(0,s.jsx)("input",{type:"file",accept:[...tG,...tZ,...t0,...t5].join(","),className:"hidden",disabled:I,onChange:e=>{var t;return H(null==(t=e.target.files)?void 0:t[0])}}),(0,s.jsx)("span",{className:"text-gray-400 dark:text-gray-500",children:I?null!=L?L:"Reading the documentâ¦":"".concat([...tG,...tZ,...t0].join(" ")," â read in your browser, never uploaded. ")+"".concat(t5.join(" ")," and scanned PDFs need AI to read them, which sends the images to our AI provider.")})]}),(0,s.jsx)("textarea",{value:m,onChange:e=>{g(e.target.value),R(void 0)},rows:5,placeholder:"Paste an SOP, a policy, or a meeting transcript. Nothing is saved until you accept it.",className:aS}),Y&&(0,s.jsx)("div",{className:"mt-3",children:(0,s.jsx)(ag,{text:m,s
1ourceLabel:h,startingId:u,onAccept:e=>{i(e),g(""),f(null)}})}),P&&(0,s.jsx)("div",{className:"mt-2 text-sm text-red-600 dark:text-red-400",children:P}),D&&(0,s.jsxs)("div",{className:"mt-2 flex items-center gap-3",children:[(0,s.jsx)("button",{type:"button",onClick:()=>H(D,!0),disabled:I,className:"inline-flex items-center rounded-md bg-indigo-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-indigo-500 disabled:opacity-50",children:I?null!=L?L:"Readingâ¦":"Read it with AI"}),(0,s.jsx)("button",{type:"button",onClick:()=>{M(null),q(null)},className:"text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",children:"No, I will paste the text"})]}),F&&(0,s.jsx)("div",{className:"mt-2 text-xs text-amber-700 dark:text-amber-400",children:F}),(0,s.jsx)("div",{className:"flex justify-end mt-2",children:(0,s.jsxs)("button",{onClick:W,disabled:C||m.trim().length<40,className:"inline-flex items-center px-3 py-1.5 text-sm font-medium rounded-md border border-indigo-300 dark:border-indigo-700 text-indigo-700 dark:text-indigo-300 hover:bg-indigo-50 dark:hover:bg-indigo-900/30 disabled:opacity-50",children:[C?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Read it"]})}),b&&(0,s.jsxs)("div",{className:"mt-3 border-t border-gray-100 dark:border-gray-800 pt-3",children:[b.warnings.length>0&&(0,s.jsxs)("div",{className:"rounded-lg border border-amber-200 dark:border-amber-900/50 bg-amber-50 dark:bg-amber-900/10 p-2 mb-3 flex items-start",children:[(0,s.jsx)(y.A,{className:"h-4 w-4 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0"}),(0,s.jsx)("div",{className:"ml-2 text-xs text-gray-700 dark:text-gray-300",children:b.warnings.map((e,t)=>(0,s.jsx)("p",{children:e},t))})]}),0===et?(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Nothing in that source could be tied to a process step, a priced loss, or a measure. Try a walkthrough or an SOP that describes who does what."}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-2",children:[X.step_count," step",1===X.step_count?"":"s"," found,"," ",X.timed_step_count," with timings",Q.length>0&&", ".concat(Q.length," priced loss").concat(1===Q.length?"":"es"),Z.length>0&&", ".concat(Z.length," measure").concat(1===Z.length?"":"s"),". Every value below is quoted from your source â accept the ones that are right."]}),(0,s.jsx)("div",{className:"space-y-2",children:b.steps.map((e,t)=>(0,s.jsx)(aC,{step:e,accepted:v.has(t),frozen:S,onToggle:()=>J(t)},t))}),S&&b.steps.length>0&&(0,s.jsx)("p",{className:"mt-1 text-[11px] text-gray-500 dark:text-gray-400",children:"Steps from this reading were already added to the editor below â only the cost drivers and measures are still waiting."}),Q.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-xs font-medium text-gray-700 dark:text-gray-300 mt-3 mb-1.5",children:"Costs of doing nothing the source priced â accepted ones join the business-case inputs."}),(0,s.jsx)("div",{className:"space-y-2",children:Q.map((e,t)=>(0,s.jsx)(aE,{driver:e,accepted:k.has(t),onToggle:()=>G(t)},t))})]}),Z.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-xs font-medium text-gray-700 dark:text-gray-300 mt-3 mb-1.5",children:"Measures the source names â accepted ones join the success measures."}),(0,s.jsx)("div",{className:"space-y-2",children:Z.map((e,t)=>(0,s.jsx)(aF,{metric:e,accepted:N.has(t),onToggle:()=>$(t)},t))})]}),K.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-xs font-medium text-gray-700 dark:text-gray-300 mt-3 mb-1.5",children:"Named but never priced â carried as context, never counted."}),(0,s.jsx)("ul",{className:"space-y-1",children:K.map((e,t)=>(0,s.jsxs)("li",{className:"text-xs text-gray-600 dark:text-gray-400",children:[e.value," ",(0,s.jsxs)("span",{className:"text-gray-400 dark:text-gray-500",children:["â",e.quote,"â"]})]},t))})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between mt-3",children:[(0,s.jsxs)("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:[ee," of ",et," selected"]}),(0,s.jsxs)("button",{onClick:V,disabled:0===ee||C,className:"inline-flex items-center px-3 py-1.5 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 disabled:opacity-50",children:[C?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Add ",ee," selected"]})]})]})]})]})}function aC(e){var t;let{step:a,accepted:r,frozen:n,onToggle:l}=e,i=[];if(a.operation&&i.push(["Kind",(0,tC.kF)(a.operation),""]),a.actor&&i.push(["Who",a.actor.value,a.actor.quote]),a.system&&i.push(["System",a.system.value,a.system.quote]),a.minutes&&i.push(["Minutes",String(a.minutes.value),a.minutes.quote]),a.occurrences_per_year&&i.push(["Per year",String(a.occurrences_per_year.value),a.occurrences_per_year.quote]),a.handoff_to&&i.push(["Hands to",a.handoff_to.value,a.handoff_to.quote]),a.constraint&&i.push(["Constraint",a.constraint.value,a.constraint.quote]),(null==(t=a.operation)?void 0:t.kind)==="physical"){let e=a.operation;for(let[t,a]of[["Item",e.item],["Size",e.size],["Min weight (lb)",e.weight_min_lb],["Max weight (lb)",e.weight_max_lb],["Material",e.material],["Variants",e.variant_count],["Tolerance",e.tolerance],["Space",e.space],["Utilities",e.utilities]])a&&i.push([t,String(a.value),a.quote]);for(let[t,a]of[["Rigidity",e.rigidity],["Arrives",e.presentation],["Variability",e.variability],["People nearby",e.people_nearby],...e.environment.map(e=>["Environment",e])]){if(!a)continue;let e="boolean"==typeof a.value?a.value?"yes":"no":a.value.replace(/_/g," ");i.push(["Environment"===t?"Environment (".concat(e,")"):t,e,a.quote])}}return(0,s.jsxs)("div",{className:"rounded-lg border p-2 ".concat(r?"border-green-300 dark:border-green-800 bg-green-50 dark:bg-green-900/10":"border-gray-200 dark:border-gray-700"),children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("div",{className:"text-sm text-gray-900 dark:text-white",children:a.name.value}),(0,s.jsxs)("div",{className:"text-[11px] text-gray-500 dark:text-gray-400 italic truncate",children:["â",a.name.quote,"â"]})]}),n?(0,s.jsx)("span",{className:"shrink-0 text-[11px] font-medium text-green-700 dark:text-green-400 pt-1",children:"Added"}):(0,s.jsx)("button",{onClick:l,className:"shrink-0 p-1 rounded ".concat(r?"text-green-700 dark:text-green-400":"text-gray-400 hover:text-gray-700 dark:hover:text-gray-300"),"aria-label":r?"Reject step":"Accept step",children:r?(0,s.jsx)(ts.A,{className:"h-4 w-4"}):(0,s.jsx)(en.A,{className:"h-4 w-4"})})]}),i.length>0&&(0,s.jsx)("div",{className:"mt-1.5 grid grid-cols-2 gap-x-3 gap-y-1",children:i.map(e=>{let[t,a,r]=e;return(0,s.jsxs)("div",{className:"text-[11px] min-w-0",children:[(0,s.jsxs)("span",{className:"text-gray-500 dark:text-gray-400",children:[t,": "]}
1),(0,s.jsx)("span",{className:"text-gray-900 dark:text-white font-medium",children:a}),r&&(0,s.jsxs)("span",{className:"text-gray-400 dark:text-gray-500 italic truncate block",children:["â",r,"â"]})]},t)})})]})}function aT(e){let{accepted:t,onToggle:a,title:r,quote:n,children:l,toggleLabel:i}=e;return(0,s.jsx)("div",{className:"rounded-lg border p-2 ".concat(t?"border-green-300 dark:border-green-800 bg-green-50 dark:bg-green-900/10":"border-gray-200 dark:border-gray-700"),children:(0,s.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("div",{className:"text-sm text-gray-900 dark:text-white",children:r}),(0,s.jsxs)("div",{className:"text-[11px] text-gray-500 dark:text-gray-400 italic truncate",children:["â",n,"â"]}),l]}),(0,s.jsx)("button",{onClick:a,className:"shrink-0 p-1 rounded ".concat(t?"text-green-700 dark:text-green-400":"text-gray-400 hover:text-gray-700 dark:hover:text-gray-300"),"aria-label":t?"Reject ".concat(i):"Accept ".concat(i),children:t?(0,s.jsx)(ts.A,{className:"h-4 w-4"}):(0,s.jsx)(en.A,{className:"h-4 w-4"})})]})})}let aP=e=>"$".concat(Math.round(e).toLocaleString("en-US"));function aE(e){var t,a;let{driver:r,accepted:n,onToggle:l}=e,i=r.quantity.value*r.unit_cost.value;return(0,s.jsx)(aT,{accepted:n,onToggle:l,toggleLabel:"cost driver",title:(0,s.jsxs)(s.Fragment,{children:[null!=(a=null==(t=r.label)?void 0:t.value)?a:ez.w_[r.kind],(0,s.jsxs)("span",{className:"text-gray-500 dark:text-gray-400",children:[" ","â ",r.quantity.value.toLocaleString("en-US")," \xd7 ",aP(r.unit_cost.value)," ="," ",aP(i),"/yr"]})]}),quote:r.quantity.quote,children:r.unit_cost.quote!==r.quantity.quote&&(0,s.jsxs)("div",{className:"text-[11px] text-gray-400 dark:text-gray-500 italic truncate",children:["â",r.unit_cost.quote,"â"]})})}function aF(e){var t,a,r,n;let{metric:l,accepted:i,onToggle:o}=e,d=(e,t)=>t?"".concat(e," ").concat(t.value.toLocaleString("en-US")).concat(l.unit?" ".concat(l.unit):""):null,c=[d("today",l.baseline_value),d("target",l.target_value)].filter(Boolean).join(", ");return(0,s.jsx)(aT,{accepted:i,onToggle:o,toggleLabel:"measure",title:(0,s.jsxs)(s.Fragment,{children:[l.name.value,(0,s.jsxs)("span",{className:"text-gray-500 dark:text-gray-400",children:[" ","â better is ","decrease"===l.direction?"lower":"higher",c?"; ".concat(c):"; no reading stated"]})]}),quote:null!=(n=null!=(r=null==(t=l.baseline_value)?void 0:t.quote)?r:null==(a=l.target_value)?void 0:a.quote)?n:l.name.quote})}var aq=a(10338);let aI=e=>e.replace(/_/g," ");function aO(e){var t;let{step:a,onChange:r,inputClass:n,labelClass:l}=e,i=null!=(t=a.operation)?t:null;return(0,s.jsxs)("div",{className:"col-span-12 sm:col-span-4",children:[(0,s.jsx)("label",{className:l,children:"Kind of work"}),(0,s.jsxs)("select",{value:(0,tC.dQ)(i),onChange:e=>r({operation:(0,tC.R8)(e.target.value,i)}),className:n,children:[(0,s.jsx)("option",{value:"",children:"Not typed"}),(0,s.jsxs)("optgroup",{label:"Information work",children:[(0,s.jsx)("option",{value:"information:",children:"Information (unspecified)"}),aq.a_.map(e=>(0,s.jsx)("option",{value:"information:".concat(e),children:tC.Hw[e]},e))]}),(0,s.jsxs)("optgroup",{label:"Physical work",children:[(0,s.jsx)("option",{value:"physical:",children:"Physical (unspecified)"}),aq.R0.map(e=>(0,s.jsx)("option",{value:"physical:".concat(e),children:tC.Hw[e]},e))]})]})]})}function az(e){let{step:t,onChange:a,inputClass:r,labelClass:n}=e,l=t.operation;if((null==l?void 0:l.kind)!=="physical")return null;let i=l.attributes,o=e=>a({operation:{...l,attributes:{...i,...e}}}),d=(e,t,a,l)=>{var d;return(0,s.jsxs)("div",{className:l,children:[(0,s.jsx)("label",{className:n,children:t}),(0,s.jsx)("input",{value:null!=(d=i[e])?d:"",placeholder:a,onChange:t=>{let a;return o({[e]:""===(a=t.target.value).trim()?null:a})},className:r})]})},c=(e,t)=>{var a;return(0,s.jsxs)("div",{className:"col-span-4 sm:col-span-2 flex flex-col justify-end",children:[(0,s.jsx)("label",{className:n,children:t}),(0,s.jsx)("input",{type:"number",min:0,value:null!=(a=i[e])?a:"",placeholder:"â",onChange:t=>{let a;return o({[e]:""===(a=t.target.value)?null:Number(a)})},className:r})]})},u=(e,t,a)=>{var l;return(0,s.jsxs)("div",{className:"col-span-4 sm:col-span-2 flex flex-col justify-end",children:[(0,s.jsx)("label",{className:n,children:t}),(0,s.jsxs)("select",{value:null!=(l=i[e])?l:"",onChange:t=>o({[e]:""===t.target.value?null:t.target.value}),className:r,children:[(0,s.jsx)("option",{value:"",children:"Unknown"}),a.map(e=>(0,s.jsx)("option",{value:e,children:aI(e)},e))]})]})};return(0,s.jsxs)("details",{className:"col-span-12 rounded-md border border-gray-200 dark:border-gray-700 p-2",children:[(0,s.jsx)("summary",{className:"text-[11px] font-medium text-gray-600 dark:text-gray-400 cursor-pointer",children:"Physical details: what is handled, and under what conditions"}),(0,s.jsxs)("div",{className:"mt-2 grid grid-cols-12 gap-2",children:[d("item","Item handled","area rug","col-span-12 sm:col-span-4"),d("size","Size","5x8 to 10x14 ft","col-span-12 sm:col-span-4"),d("material","Material","wool","col-span-12 sm:col-span-4"),c("weight_min_lb","Min weight (lb)"),c("weight_max_lb","Max weight (lb)"),c("variant_count","Variants"),u("rigidity","Rigidity",aq.mc),u("presentation","Arrives",aq.p6),u("variability","Variability",aq.Zi),d("tolerance","Tolerance","\xb10.1 mm","col-span-12 sm:col-span-4"),d("space","Space","38 in between machines","col-span-12 sm:col-span-4"),d("utilities","Utilities","shop air, 220V","col-span-12 sm:col-span-4"),(0,s.jsxs)("div",{className:"col-span-12 sm:col-span-3",children:[(0,s.jsx)("label",{className:n,children:"People nearby"}),(0,s.jsxs)("select",{value:null==i.people_nearby?"":i.people_nearby?"yes":"no",onChange:e=>o({people_nearby:""===e.target.value?null:"yes"===e.target.value}),className:r,children:[(0,s.jsx)("option",{value:"",children:"Unknown"}),(0,s.jsx)("option",{value:"yes",children:"Yes"}),(0,s.jsx)("option",{value:"no",children:"No"})]})]}),(0,s.jsxs)("fieldset",{className:"col-span-12 sm:col-span-9",children:[(0,s.jsx)("legend",{className:n,children:"Environment"}),(0,s.jsx)("div",{className:"flex flex-wrap gap-x-3 gap-y-1 pt-1",children:aq.h6.map(e=>(0,s.jsxs)("label",{className:"inline-flex items-center text-xs text-gray-700 dark:text-gray-300",children:[(0,s.jsx)("input",{type:"checkbox",className:"mr-1",checked:i.environment.includes(e),onChange:t=>o({environment:t.target.checked?[...i.environment,e]:i.environment.filter(t=>t!==e)})}),aI(e)]},e))})]})]})]})}var aR=a(30726),aD=a(83198);function aM(e){var t;let{step:a,opportunityId:n}=e,[l,i]=(0,r.useState)(!1),{fits:o,marginal:d,excluded:c}=(0,r.useMemo)(()=>{let e=(0,eE._E)(a,eF.k);return{fits:e.filter(e=>"fits"===e.verdict),marginal:e.filter(e=>"marginal"===e.verdict),excluded:e.filter(e=>"excluded"===e.verdict)}},[a]),[u,m]=(0,r.useState)(null),[g,h]=(0,r.useState)(!1),[p,y]=(0,r.useState)(void 0),b=(0,r.useRef)(null),f=(0,r.useMemo)(()=>[...new Set(o.flatMap(e=>{var t,a;return null!=(a=null==(t=aL.get(e.modality))?void 0:t.capabilities)?a:[]}))].sort().join(","),[o]);return((0,r.useEffect)(()=>
1{if(!l||!n||!f)return;let e="".concat(n,":").concat(f);if(b.current===e)return;b.current=e;let t=!1;return(async()=>{try{let e=await (0,x.authHeaders)(),a=await fetch("/api/opportunities/capability-training?opportunityId=".concat(encodeURIComponent(n),"&capabilities=").concat(encodeURIComponent(f)),{headers:e});if(t)return;if(!a.ok)return void h(!0);let s=await a.json();if(t)return;m(s.linked&&s.data?(0,tj.QG)(s.data):[]),y(s.linked?s.provider:void 0)}catch(e){t||h(!0)}})(),()=>{t=!0}},[l,n,f]),(null==(t=a.operation)?void 0:t.kind)==null)?(0,s.jsx)("p",{className:"col-span-12 text-[11px] text-gray-500 dark:text-gray-400",children:"Say whether this is information work or physical work, and the options for it appear here."}):(0,s.jsxs)("div",{className:"col-span-12 mt-1",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>i(e=>!e),"aria-expanded":l,className:"flex w-full items-center gap-1 text-left text-[11px] font-medium text-gray-600 dark:text-gray-300 hover:text-indigo-600 dark:hover:text-indigo-400",children:[l?(0,s.jsx)(ey.A,{className:"h-3 w-3 shrink-0"}):(0,s.jsx)(eb.A,{className:"h-3 w-3 shrink-0"}),(0,s.jsxs)("span",{children:["Options for this step",o.length>0&&(0,s.jsxs)("span",{className:"ml-1 text-green-700 dark:text-green-400",children:[o.length," fit"]}),d.length>0&&(0,s.jsxs)("span",{className:"ml-1 text-amber-700 dark:text-amber-500",children:[d.length," need more detail"]})]})]}),l&&(0,s.jsxs)("div",{className:"mt-2 space-y-2",children:[0===o.length&&0===d.length&&(0,s.jsx)("p",{className:"text-[11px] text-gray-500 dark:text-gray-400",children:"Nothing in the library addresses this step as described."}),o.map(e=>(0,s.jsx)(aW,{evaluation:e,tone:"fits",training:u,provider:p},e.modality)),d.map(e=>(0,s.jsx)(aW,{evaluation:e,tone:"marginal",training:null,provider:p},e.modality)),g&&(0,s.jsx)("p",{className:"text-[11px] text-amber-700 dark:text-amber-500",children:"Training coverage could not be checked just now."}),o.some(e=>{var t;return null==(t=aL.get(e.modality))?void 0:t.cost_band_usd})&&(0,s.jsx)("p",{className:"text-[11px] text-gray-500 dark:text-gray-400",children:eE.rx.band_note}),c.length>0&&(0,s.jsxs)("p",{className:"text-[11px] text-gray-400 dark:text-gray-500",children:[c.length," other ",1===c.length?"option does":"options do"," not apply to this kind of work."]})]})]})}let aL=new Map(eF.k.map(e=>[e.key,e])),aU=e=>"$".concat(e.toLocaleString("en-US")),aH={friendly:"You can do this in-house",with_care:"In-house with care",not_recommended:"Bring in help"};function aW(e){var t;let{evaluation:a,tone:r,training:n,provider:l}=e,i=aL.get(a.modality);if(!i)return null;let o=(null!=n?n:[]).filter(e=>i.capabilities.includes(e.capability)).map(e=>(0,tj.it)(e,l)).filter(e=>!!e);return(0,s.jsxs)("div",{className:"rounded-md border ".concat("fits"===r?"border-green-200 dark:border-green-900":"border-amber-200 dark:border-amber-900"," bg-white dark:bg-gray-900 p-2"),children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-gray-900 dark:text-gray-100",children:i.name}),i.safety_critical&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-red-50 dark:bg-red-950 px-1 py-0.5 text-[10px] font-medium text-red-700 dark:text-red-300",title:(null!=(t=i.safety_basis)?t:[]).map(e=>e.label).join(" \xb7 "),children:[(0,s.jsx)(aR.A,{className:"h-2.5 w-2.5"}),"Safety-critical"]}),(0,s.jsx)("span",{className:"text-[10px] text-gray-500 dark:text-gray-400",children:aH[i.diy]})]}),(0,s.jsx)("p",{className:"mt-0.5 text-[11px] text-gray-600 dark:text-gray-300",children:i.summary}),!i.cost_band_usd&&i.priced_by_quote&&(0,s.jsxs)("p",{className:"mt-1 text-[11px] text-gray-500 dark:text-gray-400",children:[(0,s.jsx)("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:"Priced by quote:"})," ",i.priced_by_quote]}),i.cost_band_usd&&(0,s.jsxs)("p",{className:"mt-1 text-[11px] text-gray-700 dark:text-gray-300",children:[(0,s.jsxs)("span",{className:"font-medium",children:["Equipment, at list: ",aU(i.cost_band_usd.low),"â",aU(i.cost_band_usd.high)]})," ",(0,s.jsxs)("span",{className:"text-gray-500 dark:text-gray-400",children:[i.cost_band_usd.basis," Source: ",i.cost_band_usd.cites.map(e=>e.label).join("; "),"."]})]}),"marginal"===r&&(0,s.jsx)("ul",{className:"mt-1 space-y-0.5",children:a.reasons.map((e,t)=>(0,s.jsxs)("li",{className:"flex items-start gap-1 text-[11px] text-amber-800 dark:text-amber-400",children:[(0,s.jsx)(y.A,{className:"mt-0.5 h-2.5 w-2.5 shrink-0"}),(0,s.jsx)("span",{children:e})]},t))}),o.map((e,t)=>(0,s.jsxs)("p",{className:"mt-1 flex items-start gap-1 text-[11px] text-indigo-700 dark:text-indigo-300",children:[(0,s.jsx)(aD.A,{className:"mt-0.5 h-2.5 w-2.5 shrink-0"}),(0,s.jsx)("span",{children:e})]},t)),i.safety_basis&&i.safety_basis.length>0&&(0,s.jsxs)("p",{className:"mt-1 text-[10px] text-gray-500 dark:text-gray-400",children:["Safety basis: ",i.safety_basis.map(e=>
1e.label).join(", ")]})]})}let aB="block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-sm",aJ="block text-[11px] font-medium text-gray-600 dark:text-gray-400",aG=e=>""===e?null:Number(e),a$=new Map(eF.k.map(e=>[e.key,e.name]));function aV(e){let{opportunity:t,onFindingsSaved:a}=e,{user:n}=(0,g.A)(),[l,i]=(0,r.useState)((0,tC.Ey)()),[o,c]=(0,r.useState)(!0),[u,m]=(0,r.useState)(!1),[x,h]=(0,r.useState)(null),[p,y]=(0,r.useState)(null),b=async()=>{c(!0);try{var e,a;let s=(await (0,z.CA)(t.id)).structured;i(null!=(a=null==(e=s.landscape)?void 0:e.process)?a:(0,tC.Ey)())}catch(e){i((0,tC.Ey)())}finally{c(!1)}};(0,r.useEffect)(()=>{b()},[t.id]);let f=(e,t)=>i(a=>({...a,steps:a.steps.map((a,s)=>s===e?{...a,...t,source:"user_entered",note:"extracted"===a.source&&a.note?"".concat(a.note.split(" â")[0]," Edited since."):a.note}:a)})),v=async()=>{if(n){m(!0),h(null);try{await (0,z.wv)(t.id,{...l,captured_by:n.id,captured_at:new Date().toISOString()},n.id),await b(),null==a||a()}catch(e){console.error("Failed to save process map:",e),h("Failed to save the process map.")}finally{m(!1)}}};if(o)return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6 flex items-center text-gray-500 dark:text-gray-400",children:[(0,s.jsx)(d.A,{className:"h-5 w-5 mr-2 animate-spin"})," Loadingâ¦"]});let w=(0,tC.Lz)(l),j=(0,eE.g7)(l.steps,eF.k);return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[(0,s.jsxs)("div",{className:"flex items-center mb-3",children:[(0,s.jsx)(eZ.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-lg font-medium text-gray-900 dark:text-white",children:"How it runs today"}),(0,s.jsxs)("button",{onClick:()=>i(e=>({...e,steps:[...e.steps,(0,tC.zu)({id:"s".concat(e.steps.length+1)})]})),className:"ml-auto inline-flex items-center text-xs font-medium text-indigo-600 dark:text-indigo-400 hover:underline",children:[(0,s.jsx)(k.A,{className:"h-3.5 w-3.5 mr-1"})," Add step"]})]}),x&&(0,s.jsx)("div",{className:"mb-3 text-sm text-red-600 dark:text-red-400",children:x}),(0,s.jsx)(aA,{startingId:l.steps.length+1,opportunityId:t.id,onAccept:e=>i(t=>({...t,steps:[...t.steps,...e]})),onFindings:async(e,s)=>{var r;if(!n)throw Error("Not signed in");await (0,z.Vc)(t.id,e,n.id,s);let l=[e.drivers.length&&"".concat(e.drivers.length," cost driver").concat(1===e.drivers.length?"":"s"," added to the business-case inputs"),e.metrics.length&&"".concat(e.metrics.length," measure").concat(1===e.metrics.length?"":"s"," added to the success measures"),(null==(r=e.unpricedLosses)?void 0:r.length)&&"".concat(e.unpricedLosses.length," named loss").concat(1===e.unpricedLosses.length?"":"es"," kept as context, not counted")].filter(Boolean);y("".concat(l.join("; "),".")),null==a||a()}}),p&&(0,s.jsx)("div",{className:"mb-3 text-xs text-green-700 dark:text-green-400",children:p}),w.step_count>0&&(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3 mb-3 text-xs text-gray-700 dark:text-gray-300",children:[null!=w.annual_hours?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("strong",{children:[w.annual_hours.toLocaleString("en-US")," hrs/yr"]})," across"," ",w.costed_step_count," timed step",1===w.costed_step_count?"":"s"," \xb7 ",w.handoff_count," ","handoff",1===w.handoff_count?"":"s"," \xb7 ",w.system_count," system",1===w.system_count?"":"s",null!=w.automatable_share&&(0,s.jsxs)(s.Fragment,{children:[" \xb7 ",Math.round(100*w.automatable_share),"% of those hours judged automatable"]}),". These now drive the business case instead of our defaults."]}):(0,s.jsx)(s.Fragment,{children:"No step has a duration and frequency yet, so the business case is still using defaults."}),w.uncosted_step_count>0&&(0,s.jsxs)("div",{className:"mt-1 text-amber-700 dark:text-amber-400",children:[w.uncosted_step_count," step",1===w.uncosted_step_count?" is":"s are"," untimed and left out of the total rather than assumed free."]})]}),j.length>0&&(0,s.jsxs)("div",{className:"mb-3 rounded-md border border-indigo-200 bg-indigo-50 p-3 text-xs text-indigo-900 dark:border-indigo-800 dark:bg-indigo-900/20 dark:text-indigo-100",children:[(0,s.jsx)("p",{className:"font-medium",children:"One unit may cover the work in more than one place"}),(0,s.jsx)("ul",{className:"mt-1 space-y-1",children:j.map(e=>{var t;return(0,s.jsxs)("li",{children:[(0,s.jsx)("span",{className:"font-medium",children:null!=(t=a$.get(e.modality))?t:e.modality})," ",e.step_names.length>1?(0,s.jsxs)(s.Fragment,{children:["fits ",e.step_names.length," steps: ",e.step_names.join(", "),"."]}):(0,s.jsxs)(s.Fragment,{children:["covers â",e.step_names[0],"â, which runs in ",e.places," places at once."]})]},"".concat(e.modality,"-").concat(e.step_ids.join("-")))})}),(0,s.jsx)("p",{className:"mt-1.5",children:"Worth pricing as one before pricing as several â if it reaches every place the work happens, their combined demand fits one cycle, and one stoppage affecting all of them is acceptable."})]}),0===l.steps.length?(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Walk the process once and write down each step, who does it, and roughly how long it takes. Timings here replace the product defaults the business case falls back on."}):(0,s.jsx)("div",{className:"space-y-3",children:l.steps.map((e,a)=>{var r,n,o,d,c,u,m;let x=(0,tC.JX)(e);return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3 relative",children:[(0,s.jsxs)("div",{className:"grid grid-cols-12 gap-2",children:[(0,s.jsxs)("div",{className:"col-span-12 sm:col-span-5",children:[(0,s.jsxs)("label",{className:"".concat(aJ," flex items-center justify-between"),children:[(0,s.jsxs)("span",{children:["Step ",a+1]}),(0,s.jsx)(a_.A,{title:"Describe this step out loud",onText:t=>f(a,{name:(0,a_.O)(e.name,t)})})]}),(0,s.jsx)("input",{value:e.name,placeholder:"Key the invoice into the ERP",onChange:e=>f(a,{name:e.target.value}),className:aB})]}),(0,s.jsxs)("div",{className:"col-span-6 sm:col-span-3",children:[(0,s.jsx)("label",{className:aJ,children:"Who (role)"}),(0,s.jsx)("input",{value:null!=(r=e.actor)?r:"",placeholder:"AP clerk",onChange:e=>f(a,{actor:e.target.value||null}),className:aB})]}),(0,s.jsxs)("div",{className:"col-span-5 sm:col-span-3",children:[(0,s.jsx)("label",{className:aJ,children:"System"}),(0,s.jsx)("input",{value:null!=(n=e.system)?n:"",placeholder:"ERP",onChange:e=>f(a,{system:e.target.value||null}),className:aB})]}),(0,s.jsx)("div",{className:"col-span-1 flex items-end justify-end",children:(0,s.jsx)("button",{"aria-label":"Remove step",onClick:()=>i(e=>({...e,steps:e.steps.filter((e,t)=>
1t!==a)})),className:"text-gray-400 hover:text-red-600 dark:hover:text-red-400 pb-2",children:(0,s.jsx)(S.A,{className:"h-4 w-4"})})}),(0,s.jsxs)("div",{className:"col-span-4 sm:col-span-2",children:[(0,s.jsx)("label",{className:aJ,children:"Minutes each"}),(0,s.jsx)("input",{type:"number",min:0,value:null!=(o=e.minutes)?o:"",placeholder:"â",onChange:e=>f(a,{minutes:aG(e.target.value)}),className:aB})]}),(0,s.jsxs)("div",{className:"col-span-4 sm:col-span-2",children:[(0,s.jsx)("label",{className:aJ,children:"Times / year"}),(0,s.jsx)("input",{type:"number",min:0,value:null!=(d=e.occurrences_per_year)?d:"",placeholder:"â",onChange:e=>f(a,{occurrences_per_year:aG(e.target.value)}),className:aB})]}),(0,s.jsxs)("div",{className:"col-span-4 sm:col-span-2",children:[(0,s.jsx)("label",{className:aJ,title:"How many places this same step runs at once",children:"Places at once"}),(0,s.jsx)("input",{type:"number",min:1,value:null!=(c=e.parallel_instances)?c:"",placeholder:"1",onChange:e=>{let t=aG(e.target.value);f(a,{parallel_instances:null!=t&&t>=2?t:null})},className:aB})]}),(0,s.jsxs)("div",{className:"col-span-4 sm:col-span-2",children:[(0,s.jsx)("label",{className:aJ,children:"Redone %"}),(0,s.jsx)("input",{type:"number",min:0,max:100,value:null!=e.rework_rate?Math.round(100*e.rework_rate):"",placeholder:"â",onChange:e=>{let t=aG(e.target.value);f(a,{rework_rate:null==t?null:t/100})},className:aB})]}),(0,s.jsxs)("div",{className:"col-span-6 sm:col-span-3",children:[(0,s.jsx)("label",{className:aJ,children:"Hands off to"}),(0,s.jsx)("input",{value:null!=(u=e.handoff_to)?u:"",placeholder:"another team",onChange:e=>f(a,{handoff_to:e.target.value||null}),className:aB})]}),(0,s.jsxs)("div",{className:"col-span-6 sm:col-span-3",children:[(0,s.jsx)("label",{className:aJ,children:"Automatable?"}),(0,s.jsxs)("select",{value:null==e.automatable?"":e.automatable?"yes":"no",onChange:e=>f(a,{automatable:""===e.target.value?null:"yes"===e.target.value}),className:aB,children:[(0,s.jsx)("option",{value:"",children:"Not judged"}),(0,s.jsx)("option",{value:"yes",children:"Yes"}),(0,s.jsx)("option",{value:"no",children:"No"})]})]}),(0,s.jsx)(aO,{step:e,onChange:e=>f(a,e),inputClass:aB,labelClass:aJ}),(0,s.jsxs)("div",{className:"col-span-12 sm:col-span-8",children:[(0,s.jsxs)("label",{className:"".concat(aJ," flex items-center justify-between"),children:[(0,s.jsx)("span",{children:"Constraint (a limit to engineer around)"}),(0,s.jsx)(a_.A,{title:"Describe the limit out loud",onText:t=>f(a,{constraint:(0,a_.O)(e.constraint,t)})})]}),(0,s.jsx)("input",{value:null!=(m=e.constraint)?m:"",placeholder:"Needs a wet signature / parts arrive jumbled in a bin / takes two people to lift",onChange:e=>f(a,{constraint:e.target.value||null}),className:aB})]}),(0,s.jsx)(az,{step:e,onChange:e=>f(a,e),inputClass:aB,labelClass:aJ}),(0,s.jsx)(aM,{step:e,opportunityId:t.id})]}),(0,s.jsxs)("div",{className:"mt-1 text-[11px] text-gray-500 dark:text-gray-400",children:[null!=x?"".concat(Math.round(x).toLocaleString("en-US")," hrs/yr"):"not timed",e.handoff_to?" \xb7 hands off to ".concat(e.handoff_to):""]}),a<l.steps.length-1&&(0,s.jsx)(tH.A,{className:"h-3 w-3 text-gray-300 dark:text-gray-600 absolute -bottom-2.5 left-6"})]},a)})}),(0,s.jsx)("div",{className:"flex justify-end mt-3",children:(0,s.jsxs)("button",{onClick:v,disabled:u||0===l.steps.length,className:"inline-flex items-center px-3 py-1.5 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 disabled:opacity-50",children:[u?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Save process map"]})})]})}var aX=a(46293),aY=a(69786),aK=a(71760);let aQ=[{value:"customer",label:"We do it"},{value:"intellimate",label:"Intellimate AI"},{value:"not_needed",label:"Not needed"}];function aZ(e){let{opportunity:t,refreshToken:a,onSaved:l}=e,{user:i}=(0,g.A)(),[o,c]=(0,r.useState)(null),[u,m]=(0,r.useState)(null),[x,h]=(0,r.useState)([]),[p,y]=(0,r.useState)(!0),[b,f]=(0,r.useState)(!1),[v,w]=(0,r.useState)(!1),[k,j]=(0,r.useState)(null),[N,_]=(0,r.useState)(null),[S,A]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=!0;return(async()=>{y(!0);try{var a;let[s,r]=await Promise.all([(0,z.CA)(t.id),(0,aK.o)(t.workspaceId).catch(e=>(n.Cp(e),null))]);if(!e)return;let l=s.structured;c(l),m(r),h((0,aY.H$)((0,aY.If)(l),null!=(a=null==r?void 0:r.capabilities)?a:{},l.responsibility)),A(!1)}catch(t){e&&c(null)}finally{e&&y(!1)}})(),()=>{e=!1}},[t.id,t.workspaceId,a]);let C=(0,r.useMemo)(()=>[...new Set(x.map(e=>e.capability))],[x]),T=(0,r.useMemo)(()=>(0,aY.iT)(x),[x]),P=(0,r.useMemo)(()=>(0,aY.DN)(x),[x]);if(p)return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6 flex items-center text-gray-500 dark:text-gray-400",children:[(0,s.jsx)(d.A,{className:"h-5 w-5 mr-2 animate-spin"})," Loadingâ¦"]});if(!o)return null;let E=async()=>
1{if(i){f(!0),_(null);try{await (0,z.GF)(t.id,x,i.id),A(!1),null==l||l()}catch(e){n.Cp(e),_("Could not save who does what.")}finally{f(!1)}}},F=async()=>{w(!0),_(null);try{let{viaAgency:e}=await e9({opportunityId:t.id,title:t.title,gap:T,customerShare:P});j(e?"Request sent. It is handled through ".concat(e,"."):"Request sent. The delivery team will scope it with you.")}catch(e){n.Cp(e),_(e instanceof Error?e.message:"Request failed. Try again.")}finally{w(!1)}};return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)(aX.A,{className:"h-5 w-5 mr-2 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:"Who does what"})]}),(0,s.jsxs)("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:["For each kind of work this needs, choose who covers each phase.",u&&Object.keys(u.capabilities).length>0?" Starting points come from ".concat("agency"===u.owner&&u.ownerName?"".concat(u.ownerName,"'s"):"your"," profile."):" Set what you do in house on your profile and new opportunities start from it."]}),0===C.length?(0,s.jsx)("p",{className:"mt-4 text-sm text-gray-500 dark:text-gray-400",children:"Nothing to assign yet. Generate the solution deliverables or map the process steps, and the work they need appears here."}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"mt-4 space-y-3",children:C.map(e=>{var t;return(0,s.jsxs)("fieldset",{className:"rounded-md border border-gray-200 p-3 dark:border-gray-700",children:[(0,s.jsx)("legend",{className:"px-1 text-sm font-medium text-gray-900 dark:text-white",children:null!=(t=eE.$C[e])?t:e}),(0,s.jsx)("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 lg:grid-cols-4",children:aY.ZG.map(t=>{var a,r,n;return(0,s.jsxs)("label",{className:"block text-xs text-gray-600 dark:text-gray-400",children:[t.name,(0,s.jsx)("select",{className:"mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white",value:(a=t.key,null!=(n=null==(r=x.find(t=>t.capability===e&&t.phase===a))?void 0:r.owner)?n:"intellimate"),onChange:a=>{var s,r;return s=t.key,r=a.target.value,void(h(t=>t.map(t=>t.capability===e&&t.phase===s?{...t,owner:r}:t)),A(!0),j(null))},children:aQ.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))})]},t.key)})})]},e)})}),(0,s.jsx)("div",{className:"mt-4 rounded-md bg-gray-50 p-3 text-sm dark:bg-gray-900/50",children:T.length?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"font-medium text-gray-900 dark:text-white",children:"Intellimate AI covers"}),(0,s.jsx)("ul",{className:"mt-1 list-disc pl-5 text-gray-700 dark:text-gray-300",children:T.map(e=>(0,s.jsxs)("li",{children:[eE.$C[e.capability],": ",(0,aY.gp)(e.phases)]},e.capability))})]}):(0,s.jsx)("div",{className:"text-gray-700 dark:text-gray-300",children:"You cover everything this needs yourselves."})}),(0,s.jsxs)("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[(0,s.jsxs)("button",{type:"button",onClick:E,disabled:b||!S,className:"inline-flex items-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-indigo-700 disabled:opacity-50 dark:bg-indigo-500 dark:hover:bg-indigo-600",children:[b&&(0,s.jsx)(d.A,{className:"mr-1.5 h-4 w-4 animate-spin"}),"Save who does what"]}),k?(0,s.jsxs)("span",{className:"inline-flex items-center text-sm text-emerald-700 dark:text-emerald-300",children:[(0,s.jsx)(e1.A,{className:"mr-1.5 h-4 w-4"}),k]}):(0,s.jsxs)("button",{type:"button",onClick:F,disabled:v||S||0===T.length,title:S?"Save your changes first, so the request matches what is saved":void 0,className:"inline-flex items-center rounded-md border border-indigo-300 bg-white px-3 py-1.5 text-sm font-medium text-indigo-700 hover:bg-indigo-50 disabled:opacity-50 dark:border-indigo-700 dark:bg-transparent dark:text-indigo-300 dark:hover:bg-indigo-900/40",children:[v?(0,s.jsx)(d.A,{className:"mr-1.5 h-4 w-4 animate-spin"}):(0,s.jsx)(eg.A,{className:"mr-1.5 h-4 w-4"}),"Request support for this"]})]}),N&&(0,s.jsx)("div",{className:"mt-2 text-sm text-red-600 dark:text-red-400",children:N})]})]})}function a0(e){let{opportunityId:t}=e,[a,n]=(0,r.useState)(null),[l,i]=(0,r.useState)(null),[o,d]=(0,r.useState)([]),[c,u]=(0,r.useState)([]),[m,g]=(0,r.useState)(null),[h,p]=(0,r.useState)(!1);return((0,r.useEffect)(()=>{let e=!0;return(async()=>{try{var a,s,r,l,o,c;let m=await fetch("/api/suite/readiness?opportunityId=".concat(t),{headers:await (0,x.authHeaders)()}),h=await m.json();if(!e||!m.ok||!h.linked)return;n(null!=(s=h.gap_summary)?s:null),i(null!=(r=h.risk_summary)?r:null),d(null!=(l=h.teams)?l:[]),u(null!=(o=h.framework_coverage)?o:[]),g(null!=(c=null==(a=h.org)?void 0:a.name)?c:null),p(!!(h.gap_summary||h.risk_summary))}catch(e){}})(),()=>{e=!1}},[t]),h)?(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[(0,s.jsxs)("div",{className:"flex items-center mb-3",children:[(0,s.jsx)(aD.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-lg font-medium text-gray-900 dark:text-white",children:"Change readiness"}),(0,s.jsxs)("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:["from the training suite",m?" \xb7 ".concat(m):""," â risk figures are weighted scores, not dollars"]})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-3",children:[(0,s.jsx)(a1,{label:"Open competency gaps",value:a?String(a.open_gaps):"â"}),(0,s.jsx)(a1,{label:"People with gaps",value:a?String(a.people_with_gaps):"â"}
1),(0,s.jsx)(a1,{label:"Avg gap risk (score)",value:l?String(l.avg_risk):"â"}),(0,s.jsx)(a1,{label:"High-risk gaps",value:l?String(l.high_risk_gaps):"â"})]}),o.length>0&&(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3 mb-3",children:[(0,s.jsx)("div",{className:"text-xs font-medium text-gray-700 dark:text-gray-300 mb-1.5",children:"Teams, riskiest first"}),(0,s.jsx)("div",{className:"space-y-0.5",children:o.map((e,t)=>{var a;return(0,s.jsxs)("div",{className:"flex items-center justify-between text-xs text-gray-700 dark:text-gray-300",children:[(0,s.jsx)("span",{className:"truncate",children:null!=(a=e.department)?a:"Unassigned"}),(0,s.jsxs)("span",{className:"shrink-0 ml-3 text-gray-500 dark:text-gray-400",children:[e.open_gaps," gap",1===e.open_gaps?"":"s"," across ",e.members," member",1===e.members?"":"s"," \xb7 risk score ",e.total_risk]})]},t)})})]}),c.length>0&&(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3",children:[(0,s.jsx)("div",{className:"text-xs font-medium text-gray-700 dark:text-gray-300 mb-1.5",children:"Thinnest framework coverage"}),(0,s.jsx)("div",{className:"space-y-0.5",children:c.map((e,t)=>(0,s.jsxs)("div",{className:"flex items-center justify-between text-xs text-gray-700 dark:text-gray-300",children:[(0,s.jsxs)("span",{className:"truncate",children:[e.framework," \xb7 ",e.name]}),(0,s.jsxs)("span",{className:"shrink-0 ml-3 text-gray-500 dark:text-gray-400",children:[e.holders,"/",e.members," hold it (",Math.round(e.coverage_pct),"%)"]})]},t))})]})]}):null}function a1(e){let{label:t,value:a}=e;return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3",children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:t}),(0,s.jsx)("div",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:a})]})}var a5=a(80535);let a4=["problem","prescription","result"];function a2(e){let{opportunityId:t}=e,[a,n]=(0,r.useState)(null),[l,i]=(0,r.useState)(!0),[o,c]=(0,r.useState)(null),[u,m]=(0,r.useState)(""),[g,h]=(0,r.useState)(!1),[p,y]=(0,r.useState)(null),[b,f]=(0,r.useState)(null);if((0,r.useEffect)(()=>{let e=!1;return(async()=>{try{let a=await fetch("/api/opportunities/".concat(t,"/corpus"),{headers:await (0,x.authHeaders)()});if(!a.ok)return;let s=await a.json();if(e)return;n(s),c(s.draft),i(!1)}catch(e){}})(),()=>{e=!0}},[t]),l||!a||!o)return null;let v=async()=>{if(!u)return void f("Pick the consent basis first â it is recorded on every corpus row.");h(!0),f(null),y(null);try{let s=await fetch("/api/opportunities/".concat(t,"/corpus"),{method:"POST",headers:await (0,x.authHeaders)({"Content-Type":"application/json"}),body:JSON.stringify({sections:o,consent_basis:u})}),r=await s.json();if(!s.ok){var e;f(null!=(e=r.error)?e:"Publish failed");return}y("Published to the outcome corpus â future prescriptions can now cite this engagement."),n({...a,published_sections:3})}catch(e){f("Publish failed â check the connection and try again.")}finally{h(!1)}};return(0,s.jsxs)("div",{className:"mt-4 rounded-lg border border-indigo-200 dark:border-indigo-900/50 p-3",children:[(0,s.jsx)("div",{className:"flex items-center justify-between mb-1",children:(0,s.jsxs)("h5",{className:"text-sm font-medium text-gray-900 dark:text-white flex items-center gap-1.5",children:[(0,s.jsx)(ep.A,{className:"h-4 w-4 text-indigo-600 dark:text-indigo-400"}),"Outcome corpus",a.published_sections>0&&(0,s.jsx)("span",{className:"font-normal text-xs text-green-700 dark:text-green-400",children:"published â republishing updates it"})]})}),a.qualified?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("p",{className:"text-[11px] text-gray-500 dark:text-gray-400 mb-2",children:[a.reasons.join(" ")," Review before publishing: strip anything that could identify the client â this text becomes cross-client evidence future prescriptions cite."]}),a4.map(e=>(0,s.jsxs)("div",{className:"mb-2",children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-gray-700 dark:text-gray-300 capitalize",children:e}),(0,s.jsx)("input",{value:o[e].title,onChange:t=>c({...o,[e]:{...o[e],title:t.target.value}}),disabled:g,className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-xs"}),(0,s.jsx)("textarea",{rows:3,value:o[e].content,onChange:t=>c({...o,[e]:{...o[e],content:t.target.value}}),disabled:g,className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-xs"})]},e)),(0,s.jsxs)("div",{className:"flex items-end gap-2",children:[(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("label",{className:"block text-xs text-gray-500 dark:text-gray-400",children:"Consent basis for sharing this outcome"}),(0,s.jsxs)("select",{value:u,onChange:e=>m(e.target.value),disabled:g,className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-xs",children:[(0,s.jsx)("option",{value:"",children:"Selectâ¦"}),(0,s.jsx)("option",{value:"contract_clause",children:"Contract clause (engagement terms allow it)"}),(0,s.jsx)("option",{value:"explicit_optin",children:"Explicit opt-in from the client"}),(0,s.jsx)("option",{value:"internal",children:"Internal engagement (our own)"})]})]}),(0,s.jsx)("button",{onClick:v,disabled:g||!u,className:"px-3 py-2 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 transition-colors",children:g?(0,s.jsx)(d.A,{className:"h-4 w-4 animate-spin"}):a.published_sections>0?"Republish":"Publish"})]}),p&&(0,s.jsx)("p",{className:"mt-2 text-xs text-green-700 dark:text-green-400",children:p}),b&&(0,s.jsx)("p",{className:"mt-2 text-xs text-red-600 dark:text-red-400",children:b})]}):(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:a.reasons.join(" ")})]})}let a3={customer:"Your team",intellimate:"Intellimate AI"};function a6(e){let{opportunity:t}=e,{user:a}=(0,g.A)(),[n,l]=(0,r.useState)(null),[i,o]=(0,r.useState)(!0),[c,u]=(0,r.useState)(!1),[m,x]=(0,r.useState)({}),[h,p]=(0,r.useState)(null),[y,b]=(0,r.useState)(""),[f,v]=(0,r.useState)(""),[w,j]=(0,r.useState)(null),[N,_]=(0,r.useState)([]),[S,A]=(0,r.useState)(null),C=async()=>{o(!0);try{var e,a,s,r,n,i,d,c;let o=(await (0,z.CA)(t.id)).structured;l(null!=(n=o.delivery)?n:null),_(o.responsibility?(0,aY.H$)((0,aY.If)(o),{},o.responsibility):[]),p(null!=(i=null==(e=o.business_case)?void 0:e.annual_savings)?i:null),j(null!=(d=null==(s=o.business_case)||null==(a=s.assumptions)?void 0:a.loaded_hourly_rate)?d:null);let u=null==(r=o.delivery)?void 0:r.actuals;b((null==u?void 0:u.realized_annual_savings)!=null?String(u.realized_annual_savings):""),v(null!=(c=null==u?void 0:u.go_live_date)?c:"")}catch(e){l(null),p(null)}finally{o(!1)}};(0,r.useEffect)(()=>{C()},[t.id]);let T=async e=>{if(a){u(!0),A(null);try{await e(),await C()}catch(e){console.error("Delivery action failed:",e),A(e instanceof Error&&e.message?e.message:"Action failed. Please try again.")}finally{u(!1)}}},P=(e,s)=>T(()=>(0,z.Uw)(t.id,t=>t.delivery?{...t,delivery:(0,tT.E0)(e(t.delivery))}:t,s,a.id)),E=e=>{var t;let a=(null!=(t=m[e])?t:"").trim();a&&(x(t=>({...t,[e]:""})),P(t=>
1({...t,phases:t.phases.map(t=>t.key===e?{...t,tasks:[...t.tasks,{id:crypto.randomUUID(),title:a,status:"todo",owner:(0,aY.oM)(N,e)}]}:t)}),"Added delivery task (".concat(e,")")))},F=e=>"$".concat(Math.round(e).toLocaleString("en-US")),q=n?(0,tT.cT)(h,n):null,I=(0,tT.K)(null==n?void 0:n.run_stats,w);return(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[(0,s.jsxs)("div",{className:"flex items-center mb-4",children:[(0,s.jsx)(a5.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-lg font-medium text-gray-900 dark:text-white",children:"Delivery"}),n&&(0,s.jsxs)("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:[n.progress,"%"]})]}),S&&(0,s.jsx)("div",{className:"mb-3 text-sm text-red-600 dark:text-red-400",children:S}),i?(0,s.jsxs)("div",{className:"flex items-center py-6 text-gray-500 dark:text-gray-400",children:[(0,s.jsx)(d.A,{className:"h-5 w-5 mr-2 animate-spin"})," Loadingâ¦"]}):n?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"mb-4",children:(0,s.jsx)("div",{className:"h-2 w-full rounded-full bg-gray-200 dark:bg-gray-700 overflow-hidden",children:(0,s.jsx)("div",{className:"h-full bg-indigo-600 dark:bg-indigo-500 transition-all",style:{width:"".concat(n.progress,"%")}})})}),(0,s.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:n.phases.map(e=>{var t,a;return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 p-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-gray-900 dark:text-white",children:e.name}),(0,s.jsxs)("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:[e.tasks.filter(e=>"done"===e.status).length,"/",e.tasks.length]})]}),(0,s.jsx)("div",{className:"space-y-1.5 mb-2",children:e.tasks.map(t=>(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-sm",children:[(0,s.jsxs)("label",{className:"flex min-w-0 flex-1 items-center cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:"done"===t.status,onChange:()=>{let a,s;return a=e.key,s=t.id,P(e=>({...e,phases:e.phases.map(e=>e.key===a?{...e,tasks:e.tasks.map(e=>e.id===s?{...e,status:"done"===e.status?"todo":"done"}:e)}:e)}),"Updated delivery task")},disabled:c,className:"h-4 w-4 text-indigo-600 rounded mr-2"}),(0,s.jsx)("span",{className:"done"===t.status?"line-through text-gray-400 dark:text-gray-500":"text-gray-700 dark:text-gray-300",children:t.title})]}),(0,s.jsxs)("select",{"aria-label":'Who does "'.concat(t.title,'"'),value:"customer"===t.owner||"intellimate"===t.owner?t.owner:"",onChange:a=>{let s,r,n;return s=e.key,r=t.id,n=""===a.target.value?null:a.target.value,P(e=>({...e,phases:e.phases.map(e=>e.key===s?{...e,tasks:e.tasks.map(e=>e.id===r?{...e,owner:n}:e)}:e)}),"Set delivery task owner")},disabled:c,className:"rounded-md border-gray-300 bg-white py-0.5 text-xs text-gray-700 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200",children:[(0,s.jsx)("option",{value:"",children:"Unassigned"}),(0,s.jsx)("option",{value:"customer",children:a3.customer}),(0,s.jsx)("option",{value:"intellimate",children:a3.intellimate})]})]},t.id))}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("input",{type:"text",value:null!=(t=m[e.key])?t:"",onChange:t=>x(a=>({...a,[e.key]:t.target.value})),onKeyDown:t=>"Enter"===t.key&&E(e.key),placeholder:"Add taskâ¦",className:"flex-1 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-xs"}),(0,s.jsx)("button",{onClick:()=>E(e.key),disabled:c||!(null!=(a=m[e.key])?a:"").trim(),className:"p-1.5 text-indigo-600 dark:text-indigo-400 hover:bg-indigo-50 dark:hover:bg-indigo-900/30 rounded-md disabled:opacity-40",title:"Add task",children:(0,s.jsx)(k.A,{className:"h-4 w-4"})})]})]},e.key)})}),n.run_stats&&n.run_stats.workflows.length>0&&(0,s.jsxs)("div",{className:"mt-4 rounded-lg border border-green-200 dark:border-green-900/50 p-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,s.jsxs)("h5",{className:"text-sm font-medium text-gray-900 dark:text-white",children:["Measured runs"," ",(0,s.jsxs)("span",{className:"font-normal text-xs text-gray-500 dark:text-gray-400",children:["from ",n.run_stats.source,", last ",n.run_stats.window_days," days"]})]}),(null==I?void 0:I.annual_savings)!=null&&(0,s.jsxs)("span",{className:"text-sm font-semibold text-green-700 dark:text-green-400",title:"Annualized run-RATE from the window's measured runs. The portfolio's value-delivered figure is the same runs NOT annualized â dollars delivered within the window â so the two legitimately differ.",children:["â ",F(I.annual_savings),"/yr measured run-rate"]})]}),(0,s.jsx)("div",{className:"space-y-1.5 mt-2",children:n.run_stats.workflows.map(e=>{var t,a;return(0,s.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"text-gray-900 dark:text-white",children:e.name}),(0,s.jsxs)("span",{className:"text-gray-500 dark:text-gray-400",children:[" ","â ",e.runs_completed.toLocaleStr
1ing("en-US")," run",1===e.runs_completed?"":"s",e.runs_failed>0?", ".concat(e.runs_failed," failed"):""]})]}),(0,s.jsx)("label",{className:"text-gray-500 dark:text-gray-400 shrink-0",children:"min saved / run"}),(0,s.jsx)("input",{type:"number",min:0,defaultValue:null!=(t=e.minutes_saved_per_run)?t:"",placeholder:"â",onBlur:t=>((e,t)=>{var a;let s=""===t.trim()?null:Number(t);if(null!=s&&!Number.isFinite(s))return;let r=null==n||null==(a=n.run_stats)?void 0:a.workflows.find(t=>t.workflow_id===e);r&&r.minutes_saved_per_run!==s&&P(t=>({...t,run_stats:t.run_stats?{...t.run_stats,workflows:t.run_stats.workflows.map(t=>t.workflow_id===e?{...t,minutes_saved_per_run:s,minutes_saved_source:"user_entered"}:t)}:t.run_stats}),"Minutes-saved-per-run set on measured workflow")})(e.workflow_id,t.target.value),disabled:c,className:"w-20 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-xs"},"".concat(e.workflow_id,":").concat(null!=(a=e.minutes_saved_per_run)?a:""))]},e.workflow_id)})}),(0,s.jsxs)("p",{className:"mt-2 text-[11px] text-gray-500 dark:text-gray-400",children:[I&&I.workflows_measured<I.workflows_total?"".concat(I.workflows_total-I.workflows_measured," workflow").concat(I.workflows_total-I.workflows_measured==1?"":"s"," ha").concat(I.workflows_total-I.workflows_measured==1?"s":"ve"," no minutes-per-run yet and ").concat(I.workflows_total-I.workflows_measured==1?"is":"are"," left out of the measured figure rather than guessed. "):"",(null==I?void 0:I.annual_savings)!=null&&null!=w?"Dollarized at the business case's $".concat(w,"/hr loaded rate, annualized from the window."):null==w?"Generate the business case to dollarize these runs â the loaded hourly rate comes from there.":""]})]}),(0,s.jsxs)("div",{className:"mt-4 rounded-lg border border-gray-200 dark:border-gray-700 p-3",children:[(0,s.jsxs)("h5",{className:"text-sm font-medium text-gray-900 dark:text-white mb-3",children:["Impact (realized vs predicted)",n.run_stats&&(0,s.jsx)("span",{className:"ml-2 font-normal text-xs text-gray-500 dark:text-gray-400",children:"the realized figure below is typed, not measured â the measured one is above"})]}),(0,s.jsxs)("div",{className:"grid grid-cols-3 gap-3 mb-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Predicted"}),(0,s.jsx)("div",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:null!=h?F(h):"â"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Realized"}),(0,s.jsx)("div",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:(null==q?void 0:q.realized)!=null?F(q.realized):"â"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Variance"}),(0,s.jsx)("div",{className:"text-sm font-semibold ".concat((null==q?void 0:q.variance)!=null?q.variance>=0?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400":"text-gray-900 dark:text-white"),children:(null==q?void 0:q.variance)!=null?"".concat(q.variance>=0?"+":"").concat(F(q.variance)).concat(null!=q.variance_pct?" (".concat(q.variance_pct>=0?"+":"").concat(q.variance_pct,"%)"):""):"â"})]})]}),(0,s.jsxs)("div",{className:"flex items-end gap-2",children:[(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("label",{className:"block text-xs text-gray-500 dark:text-gray-400",children:"Realized annual savings ($)"}),(0,s.jsx)("input",{type:"number",value:y,onChange:e=>b(e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-sm"})]}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("label",{className:"block text-xs text-gray-500 dark:text-gray-400",children:"Go-live date"}),(0,s.jsx)("input",{type:"date",value:f,onChange:e=>v(e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-sm"})]}),(0,s.jsx)("button",{onClick:()=>P(e=>({...e,actuals:{realized_annual_savings:""===y.trim()?null:Number(y),go_live_date:f||null}}
1),"Updated impact actuals"),disabled:c,className:"px-3 py-2 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 transition-colors",children:"Save"})]})]}),(0,s.jsx)(a2,{opportunityId:t.id})]}):(0,s.jsxs)("div",{className:"text-center py-6 bg-gray-50 dark:bg-gray-900/50 rounded-lg",children:[(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400 mb-3",children:"This proposal is signed off. Start delivery to plan and track the build."}),(0,s.jsxs)("button",{onClick:()=>T(()=>(0,z.ny)(t,a.id)),disabled:c,className:"inline-flex items-center px-4 py-2 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 transition-colors",children:[c?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-2 animate-spin"}):(0,s.jsx)(a5.A,{className:"h-4 w-4 mr-2"}),"Start delivery"]})]})]})}let a7=["signed_off","in_delivery","live","monitoring"],a9={draft:{label:"Draft",icon:y.A,color:"text-gray-500 dark:text-gray-400",bg:"bg-gray-100 dark:bg-gray-700"},analyzing:{label:"Analyzing...",icon:A.A,color:"text-yellow-600 dark:text-yellow-400",bg:"bg-yellow-100 dark:bg-yellow-900/30"},analyzed:{label:"Analyzed",icon:C.A,color:"text-green-600 dark:text-green-400",bg:"bg-green-100 dark:bg-green-900/30"},gathering_info:{label:"Gathering Info",icon:A.A,color:"text-blue-600 dark:text-blue-400",bg:"bg-blue-100 dark:bg-blue-900/30"},business_case:{label:"Business Case",icon:A.A,color:"text-blue-600 dark:text-blue-400",bg:"bg-blue-100 dark:bg-blue-900/30"},proposal:{label:"Proposal",icon:A.A,color:"text-indigo-600 dark:text-indigo-400",bg:"bg-indigo-100 dark:bg-indigo-900/30"},in_review:{label:"In Review",icon:A.A,color:"text-yellow-600 dark:text-yellow-400",bg:"bg-yellow-100 dark:bg-yellow-900/30"},changes_requested:{label:"Changes Requested",icon:y.A,color:"text-amber-600 dark:text-amber-400",bg:"bg-amber-100 dark:bg-amber-900/30"},signed_off:{label:"Signed Off",icon:C.A,color:"text-green-600 dark:text-green-400",bg:"bg-green-100 dark:bg-green-900/30"},ready_for_project:{label:"Ready for Project",icon:C.A,color:"text-indigo-600 dark:text-indigo-400",bg:"bg-indigo-100 dark:bg-indigo-900/30"},converted:{label:"Converted to Project",icon:C.A,color:"text-purple-600 dark:text-purple-400",bg:"bg-purple-100 dark:bg-purple-900/30"}};function a8(e){let{opportunity:t,onClose:a,onAnalyze:n,onEdit:l,onDelete:i,onConvert:o,isAnalyzing:d,isConverting:c}=e,u=a9[t.status]||a9.draft,m=u.icon,[x,g]=r.useState(0);return(0,s.jsx)("div",{className:"fixed inset-0 bg-gray-500/75 dark:bg-gray-900/80 flex items-center justify-center p-4 z-50",children:(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-4xl w-full max-h-[90vh] overflow-hidden",children:[(0,s.jsxs)("div",{className:"px-6 py-4 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)(P.A,{className:"h-6 w-6 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h2",{className:"ml-3 text-xl font-semibold text-gray-900 dark:text-white",children:"Opportunity Details"})]}),(0,s.jsx)("button",{onClick:a,className:"text-gray-400 hover:text-gray-500 dark:hover:text-gray-300",children:(0,s.jsx)(en.A,{className:"h-6 w-6"})})]}),(0,s.jsxs)("div",{className:"px-6 py-4 max-h-[calc(90vh-180px)] overflow-y-auto",children:[(0,s.jsx)(tl,{status:t.status}),(0,s.jsxs)("div",{className:"mb-6",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,s.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-indigo-100 dark:bg-indigo-900/50 text-indigo-800 dark:text-indigo-200",children:I(t.category)}),(0,s.jsxs)("div",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ".concat(u.bg," ").concat(u.color),children:[(0,s.jsx)(m,{className:"h-3.5 w-3.5 mr-1"}),u.label]})]}),(0,s.jsx)("h3",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2",children:t.title}),(0,s.jsx)("p",{className:"text-gray-600 dark:text-gray-300 whitespace-pre-wrap",children:t.description}),(0,s.jsxs)("div",{className:"mt-4 text-xs text-gray-400 dark:text-gray-500",children:["Created: ",new Date(t.createdAt).toLocaleDateString(),t.updatedAt!==t.createdAt&&(0,s.jsxs)(s.Fragment,{children:[" ⢠Updated: ",new Date(t.updatedAt).toLocaleDateString()]})]})]}),t.aiAnalysis?(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6",children:[(0,s.jsxs)("div",{className:"flex items-center mb-4",children:[(0,s.jsx)(N.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h4",{className:"ml-2 text-lg font-medium text-gray-900 dark:text-white",children:"AI Analysis"})]}),(0,s.jsx)(ev,{analysis:t.aiAnalysis})]}):(0,s.jsx)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6",children:(0,s.jsxs)("div",{className:"text-center py-8 bg-gray-50 dark:bg-gray-900/50 rounded-lg",children:[(0,s.jsx)(N.A,{className:"mx-auto h-12 w-12 text-gray-400 dark:text-gray-500"}),(0,s.jsx)("h4",{className:"mt-2 text-sm font-medium text-gray-900 dark:text-white",children:"No Analysis Yet"}),(0,s.jsx)("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:'Click "Analyze with AI" to get intelligent insights about this automation opportunity.'})]})}),(0,s.jsx)(tc,{opportunity:t,refreshToken:x}),t.aiAnalysis&&(0,s.jsx)(ta,{opportunity:t}),t.aiAnalysis&&(0,s.jsx)(eY,{opportunity:t,refreshToken:x}),t.aiAnalysis&&(0,s.jsx)(tk,{opportunity:t,refreshToken:x}),t.aiAnalysis&&(0,s.jsx)(aV,{opportunity:t,onFindingsSaved:()=>g(Date.now())}),t.aiAnalysis&&(0,s.jsx)(aZ,{opportunity:t,refreshToken:x,onSaved:()=>g(Date.now())}),t.aiAnalysis&&(0,s.jsx)(tU,{opportunity:t,onSaved:()=>g(Date.now())}),(0,s.jsx)(tz,{opportunity:t}),(0,s.jsx)(a0,{opportunityId:t.id}),a7.includes(t.status)&&(0,s.jsx)(a6,{opportunity:t}),(0,s.jsx)(eN,{opportunity:t})]}),(0,s.jsxs)("div",{className:"px-6 py-4 border-t border-gray-200 dark:border-gray-700 flex flex-wrap items-center justify-between gap-3 bg-gray-50 dark:bg-gray-900/50",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)("button",{onClick:i,className:"inline-flex items-center px-3 py-2 border border-red-300 dark:border-red-700 text-sm font-medium rounded-md text-red-700 dark:text-red-400 bg-white dark:bg-transparent hover:bg-red-50 dark:hover:bg-red-900/30 transition-colors",children:[(0,s.jsx)(S.A,{className:"h-4 w-4 mr-2"}),"Delete"]}),"converted"!==t.status&&(0,s.jsxs)("button",{onClick:l,className:"inline-flex items-center px-3 py-2 border border-gray-300 dark:border-gray-600 text-sm font-medium rounded-md text-gray-700 dark:text-gray-300 bg-white dark:bg-transparent hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors",children:[(0,s.jsx)(_.A,{className:"h-4 w-4 mr-2"}),"Edit"]})]}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,s.jsx)("button",{onClick:a,className:"px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-transparent hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors",children:"Close"}),!t.aiAnalysis&&"converted"!==t.status&&(0,s.jsx)("button",{onClick:n,disabled:d,className:"inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 transition-colors",children:d?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(j.A,{className:"h-4 w-4 mr-2 animate-spin"}),"Analyzing..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(N.A,{className:"h-4 w-4 mr-2"}),"Analyze with AI"]})}),t.aiAnalysis&&!a7.includes(t.status)&&"converted"!==t.status&&(0,s.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 self-center",children:"Get client sign-off to start delivery"})]})]})]})})}var se=a(12572),st=a(1328);let sa={role:"assistant",content:"Hi! I'm here to help you identify and document automation opportunities. Let's start by understanding your process.\n\n**Tell me about a manual process that's taking up your team's time.** What repetitive tasks do you wish could be automated?",timestamp:new Date};function ss(e){let{onOpportunityCreated:t,initialContext:a}=e,[n,l]=(0,r.useState)([sa]),[i,o]=(0,r.useState)(""),[d,c]=(0,r.useState)(!1),[u,m]=(0,r.useState)(a||{}),x=(0,r.useRef)(null);(0,r.useEffect)(()=>{var e;null==(e=x.current)||e.scrollIntoView({behavior:"smooth"})},[n]);let g=async()=>
1{if(!i.trim()||d)return;let e={role:"user",content:i.trim(),timestamp:new Date};l(t=>[...t,e]),o(""),c(!0);try{let t=[...n,e].map(e=>({role:e.role,content:e.content})),a=await $.zv(t,u),s={role:"assistant",content:a,timestamp:new Date};l(e=>[...e,s]),!u.description&&e.content.length>100&&m(t=>({...t,description:(t.description||"")+"\n"+e.content}))}catch(e){console.error("Chat error:",e),l(e=>[...e,{role:"assistant",content:"I apologize, I encountered an error. Please try again.",timestamp:new Date}])}finally{c(!1)}};return(0,s.jsxs)("div",{className:"flex flex-col h-[500px] bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700",children:[(0,s.jsxs)("div",{className:"px-4 py-3 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)(eP.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("span",{className:"ml-2 font-medium text-gray-900 dark:text-white",children:"AI Discovery Assistant"})]}),n.length>3&&(0,s.jsx)("button",{onClick:()=>{let e=n.filter(e=>"user"===e.role).map(e=>e.content).join("\n\n");t&&t({title:u.title||"New Automation Opportunity",category:u.category||"other",description:u.description||e})},className:"inline-flex items-center px-3 py-1.5 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 transition-colors",children:"Create Opportunity"})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:[n.map((e,t)=>(0,s.jsx)("div",{className:"flex ".concat("user"===e.role?"justify-end":"justify-start"),children:(0,s.jsxs)("div",{className:"flex max-w-[80%] ".concat("user"===e.role?"flex-row-reverse":"flex-row"),children:[(0,s.jsx)("div",{className:"flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center ".concat("user"===e.role?"bg-indigo-100 dark:bg-indigo-900/50 ml-2":"bg-gray-100 dark:bg-gray-700 mr-2"),children:"user"===e.role?(0,s.jsx)(se.A,{className:"h-4 w-4 text-indigo-600 dark:text-indigo-400"}):(0,s.jsx)(st.A,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"})}),(0,s.jsxs)("div",{className:"rounded-lg px-4 py-2 ".concat("user"===e.role?"bg-indigo-600 dark:bg-indigo-500 text-white":"bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-gray-100"),children:[(0,s.jsx)("p",{className:"text-sm whitespace-pre-wrap",children:e.content}),(0,s.jsx)("p",{className:"text-xs mt-1 ".concat("user"===e.role?"text-indigo-200 dark:text-indigo-300":"text-gray-400 dark:text-gray-500"),children:e.timestamp.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})]})},t)),d&&(0,s.jsx)("div",{className:"flex justify-start",children:(0,s.jsxs)("div",{className:"flex items-center bg-gray-100 dark:bg-gray-700 rounded-lg px-4 py-2",children:[(0,s.jsx)(j.A,{className:"h-4 w-4 text-gray-600 dark:text-gray-400 animate-spin"}),(0,s.jsx)("span",{className:"ml-2 text-sm text-gray-600 dark:text-gray-400",children:"Thinking..."})]})}),(0,s.jsx)("div",{ref:x})]}),(0,s.jsx)("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-gray-700",children:(0,s.jsxs)("div",{className:"flex items-end space-x-2",children:[(0,s.jsx)("textarea",{value:i,onChange:e=>o(e.target.value),onKeyPress:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),g())},placeholder:"Describe your process or answer the question...",rows:2,className:"flex-1 resize-none rounded-lg border border-gray-300 dark:border-gray-600 px-3 py-2 text-sm text-gray-900 dark:text-white bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent placeholder-gray-400 dark:placeholder-gray-500"}),(0,s.jsx)("button",{onClick:g,disabled:!i.trim()||d,className:"inline-flex items-center justify-center w-10 h-10 rounded-lg bg-indigo-600 dark:bg-indigo-500 text-white hover:bg-indigo-700 dark:hover:bg-indigo-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:(0,s.jsx)(ej.A,{className:"h-4 w-4"})})]})})]})}function sr(e){let{workspaceId:t,onAccepted:a}=e,[n,l]=(0,r.useState)([]),[i,o]=(0,r.useState)(null),[c,u]=(0,r.useState)(null),[m,g]=(0,r.useState)(!1),[h,p]=(0,r.useState)(null),[b,f]=(0,r.useState)(null),[v,w]=(0,r.useState)(null),[k,j]=(0,r.useState)(0),[N,_]=(0,r.useState)(new Set),[S,A]=(0,r.useState)([]),C=async()=>{try{var e,a;
1let s=await fetch("/api/workspaces/".concat(t,"/discovery"),{headers:await (0,x.authHeaders)()}),r=await s.json();if(!s.ok)throw Error(null!=(e=r.error)?e:"Failed to load surveys");l(null!=(a=r.surveys)?a:[])}catch(e){o(e instanceof Error?e.message:"Failed to load surveys")}};(0,r.useEffect)(()=>{C()},[t]);let T=async()=>{g(!0),o(null);try{var e;let a=await fetch("/api/workspaces/".concat(t,"/discovery"),{method:"POST",headers:await (0,x.authHeaders)({"Content-Type":"application/json"}),body:JSON.stringify({})}),s=await a.json();if(!a.ok)throw Error(null!=(e=s.error)?e:"Failed to create the link");await C(),u("Link created â copy it and send it to the team.")}catch(e){o(e instanceof Error?e.message:"Failed to create the link")}finally{g(!1)}},P=e=>"".concat(window.location.origin,"/discover/").concat(e.token),E=async e=>{try{await navigator.clipboard.writeText(P(e)),p(e.id),setTimeout(()=>p(null),1500)}catch(t){u(P(e))}},F=async(e,a)=>{g(!0);try{var s;let r=await fetch("/api/workspaces/".concat(t,"/discovery"),{method:"PATCH",headers:await (0,x.authHeaders)({"Content-Type":"application/json"}),body:JSON.stringify({survey_id:e.id,is_active:a})});if(!r.ok)throw Error(null!=(s=(await r.json()).error)?s:"Failed");await C()}catch(e){o(e instanceof Error?e.message:"Failed")}finally{g(!1)}},q=async e=>{g(!0),o(null),w(null),_(new Set),A([]);try{var a,s,r,n,l;let i=await fetch("/api/workspaces/".concat(t,"/discovery?survey=").concat(e.id),{headers:await (0,x.authHeaders)()}),o=await i.json();if(!i.ok)throw Error(null!=(a=o.error)?a:"Failed to load responses");let d=null!=(s=o.responses)?s:[];if(0===d.length)return void u("No responses yet.");let c=d.slice(0,50),m=[];d.length>c.length&&m.push("".concat(d.length-c.length," of ").concat(d.length," responses were not read ")+"in this pass (".concat(50," per run). Run the review again to cover them."));let g=[],h=0,p=0;for(let e=0;e<c.length;e++){f("Reading response ".concat(e+1," of ").concat(c.length,"â¦"));try{let t=await fetch("/api/opportunities/extract-inventory",{method:"POST",headers:await (0,x.authHeaders)({"Content-Type":"application/json"}),body:JSON.stringify({text:c[e].body,source_label:"Team discovery"})}),a=await t.json();if(402===t.status){m.push("The AI budget ran out after ".concat(p," of ").concat(c.length," responses â ")+"the rest were not read. ".concat(null!=(r=a.error)?r:"").trim());break}if(!t.ok)throw Error(null!=(n=a.error)?n:"read failed");g.push(a),p+=1}catch(e){h+=1}}h>0&&m.push("".concat(h," ").concat(1===h?"response":"responses"," could not be read and ").concat(1===h?"is":"are"," not counted."));let y=function(e){let t=new Map;for(let b of e){let e=new Set;for(let f of b.items){var a,s,r,n,l,i,o,d,c,u,m,x,g,h,p,y;let b=f.name.value.trim().toLowerCase();if(!b||e.has(b))continue;e.add(b);let v=t.get(b);if(!v){t.set(b,{name:f.name.value.trim(),mentions:1,quotes:f.name.quote?[f.name.quote]:[],department:(null==(d=f.department)||null==(o=d.value)?void 0:o.trim())||null,owner_role:(null==(u=f.owner_role)||null==(c=u.value)?void 0:c.trim())||null,occurrences_per_year:null!=(g=null==(m=f.occurrences_per_year)?void 0:m.value)?g:null,minutes_per_occurrence:null!=(h=null==(x=f.minutes_per_occurrence)?void 0:x.value)?h:null,systems:[...f.systems]});continue}v.mentions+=1,f.name.quote&&v.quotes.length<3&&v.quotes.push(f.name.quote),null!=v.department||(v.department=(null==(s=f.department)||null==(a=s.value)?void 0:a.trim())||null),null!=v.owner_role||(v.owner_role=(null==(n=f.owner_role)||null==(r=n.value)?void 0:r.trim())||null),null!=v.occurrences_per_year||(v.occurrences_per_year=null!=(p=null==(l=f.occurrences_per_year)?void 0:l.value)?p:null),null!=v.minutes_per_occurrence||(v.minutes_per_occurrence=null!=(y=null==(i=f.minutes_per_occurrence)?void 0:i.value)?y:null),v.systems=[...new Set([...v.systems,...f.systems])].sort()}}return[...t.values()].sort((e,t)=>t.mentions-e.mentions||e.name.localeCompare(t.name))}(g);try{let e=await fetch("/api/workspaces/".concat(t,"/process-inventory"),{headers:await (0,x.authHeaders)()});if(e.ok){let t=await e.json(),a=new Set((null!=(l=t.items)?l:[]).filter(e=>"dismissed"!==e.status).map(e=>e.name.trim().toLowerCase())),s=y.filter(e=>a.has(e.name.trim().toLowerCase()));s.length>0&&(y=y.filter(e=>!a.has(e.name.trim().toLowerCase())),m.push("".concat(s.length," ").concat(1===s.length?"candidate is":"candidates are"," already ")+"in the inventory and ".concat(1===s.length?"was":"were"," left out: ")+"".concat(s.map(e=>e.name).join(", "),".")))}}catch(e){}w(y),j(g.length),A(m)}catch(e){o(e instanceof Error?e.message:"Failed to review responses")}finally{f(null),g(!1)}},I=async()=>
1{if(!v)return;let e=v.filter((e,t)=>N.has(t));if(0!==e.length){g(!0),o(null);try{var s;let r=await fetch("/api/workspaces/".concat(t,"/process-inventory"),{method:"POST",headers:await (0,x.authHeaders)({"Content-Type":"application/json"}),body:JSON.stringify({items:e.map(e=>{var t;return{name:e.name,department:e.department,owner_role:e.owner_role,occurrences_per_year:e.occurrences_per_year,minutes_per_occurrence:e.minutes_per_occurrence,systems:e.systems,source_label:"Team discovery",source_quote:null!=(t=e.quotes[0])?t:null,notes:"Named independently in ".concat(e.mentions," of ").concat(k," responses.")}})})}),n=await r.json();if(!r.ok)throw Error(null!=(s=n.error)?s:"Failed to add to the inventory");u("".concat(e.length," ").concat(1===e.length?"process":"processes"," added to the inventory.")),w(null),_(new Set),null==a||a()}catch(e){o(e instanceof Error?e.message:"Failed to add to the inventory")}finally{g(!1)}}};return(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)(aX.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h3",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Ask the team"}),(0,s.jsx)("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:"an anonymous link for the people doing the work â convergence ranks the answers"})]}),(0,s.jsx)("button",{onClick:T,disabled:m,className:"text-sm text-indigo-600 dark:text-indigo-400 hover:underline disabled:opacity-50",children:"New link"})]}),(i||c)&&(0,s.jsx)("div",{className:"mt-3 border-l-4 p-2.5 rounded-r-md text-sm ".concat(i?"bg-red-50 dark:bg-red-900/30 border-red-400 text-red-700 dark:text-red-300":"bg-green-50 dark:bg-green-900/30 border-green-400 text-green-700 dark:text-green-300"),children:null!=i?i:c}),n.length>0&&(0,s.jsx)("div",{className:"mt-3 space-y-2",children:n.map(e=>(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-sm rounded-md border border-gray-100 dark:border-gray-700 p-2 ".concat(e.is_active?"":"opacity-60"),children:[(0,s.jsxs)("span",{className:"text-gray-900 dark:text-white",children:[new Date(e.created_at).toLocaleDateString("en-US")," \xb7 ",e.response_count," ",1===e.response_count?"response":"responses",!e.is_active&&" \xb7 closed"]}),(0,s.jsxs)("span",{className:"ml-auto flex items-center gap-2",children:[(0,s.jsxs)("button",{onClick:()=>E(e),className:"inline-flex items-center text-xs text-indigo-600 dark:text-indigo-400 hover:underline",children:[(0,s.jsx)(tx.A,{className:"h-3.5 w-3.5 mr-1"}),h===e.id?"Copied":"Copy link"]}),e.response_count>0&&(0,s.jsxs)("button",{onClick:()=>q(e),disabled:m,className:"text-xs px-2 py-1 rounded-md text-white bg-indigo-600 hover:bg-indigo-700 disabled:opacity-50",children:["Review ",e.response_count]}),(0,s.jsx)("button",{onClick:()=>F(e,!e.is_active),disabled:m,className:"text-xs text-gray-500 dark:text-gray-400 hover:underline",children:e.is_active?"Close":"Reopen"})]})]},e.id))}),b&&(0,s.jsxs)("p",{className:"mt-3 flex items-center text-sm text-gray-600 dark:text-gray-300",children:[(0,s.jsx)(d.A,{className:"h-4 w-4 mr-1.5 animate-spin"})," ",b]}),v&&(0,s.jsxs)("div",{className:"mt-3 border-t border-gray-100 dark:border-gray-700 pt-3",children:[S.map((e,t)=>(0,s.jsxs)("p",{className:"flex items-start text-xs text-amber-700 dark:text-amber-300 mb-1",children:[(0,s.jsx)(y.A,{className:"h-3.5 w-3.5 mr-1 mt-0.5 shrink-0"}),e]},t)),0===v.length?(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No processes could be tied back to these responses."}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-2",children:[v.length," candidate ",1===v.length?"process":"processes"," ","from ",k," responses, most-named first. Accept what belongs in the census."]}),(0,s.jsx)("div",{className:"space-y-1.5",children:v.map((e,t)=>(0,s.jsxs)("label",{className:"flex items-start gap-2 p-2 rounded border border-gray-100 dark:border-gray-700 cursor-pointer hover:border-indigo-300 dark:hover:border-indigo-600",children:[(0,s.jsx)("input",{type:"checkbox",className:"mt-0.5",checked:N.has(t),onChange:e=>_(a=>
1{let s=new Set(a);return e.target.checked?s.add(t):s.delete(t),s})}),(0,s.jsxs)("span",{className:"min-w-0",children:[(0,s.jsxs)("span",{className:"block text-sm text-gray-900 dark:text-white",children:[e.name,(0,s.jsxs)("span",{className:"ml-2 inline-flex items-center px-1.5 py-0.5 rounded-full text-[11px] font-medium ".concat(e.mentions>1?"bg-indigo-100 text-indigo-800 dark:bg-indigo-900/40 dark:text-indigo-300":"bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300"),children:["named by ",e.mentions]})]}),(0,s.jsx)("span",{className:"block text-xs text-gray-500 dark:text-gray-400",children:[e.department,e.owner_role,null!=e.occurrences_per_year?"".concat(e.occurrences_per_year,"/yr"):null,null!=e.minutes_per_occurrence?"".concat(e.minutes_per_occurrence," min"):null,e.systems.length?e.systems.join(", "):null].filter(Boolean).join(" \xb7 ")||"No figures stated"}),e.quotes[0]&&(0,s.jsxs)("span",{className:"block text-xs italic text-gray-400 dark:text-gray-500 truncate",children:["â",e.quotes[0],"â"]})]})]},t))}),(0,s.jsxs)("button",{onClick:I,disabled:m||0===N.size,className:"mt-3 inline-flex items-center px-4 py-2 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 disabled:opacity-50",children:[m?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-1.5 animate-spin"}):(0,s.jsx)(ts.A,{className:"h-4 w-4 mr-1.5"}),"Add ",N.size||""," to the inventory"]})]})]})]})}let sn="block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white text-sm";function sl(e){return(0,to.BF)(e.process_suitability)}let si=[{value:"",label:"Not rated"},{value:"highly_effective",label:"Strong"},{value:"effective",label:"Adequate"},{value:"ineffective",label:"Weak"},{value:"not_implemented",label:"Absent"}],so=[{key:"repetitiveNature",label:"Repetitive"},{key:"digitalAccessibility",label:"Digitally accessible"},{key:"documentationStatus",label:"Documentable"}];function sd(e){let{workspaceId:t,onPromoted:a}=e,[n,l]=(0,r.useState)([]),[i,o]=(0,r.useState)(!0),[c,u]=(0,r.useState)(null),[m,g]=(0,r.useState)(null),[h,p]=(0,r.useState)(!1),[b,f]=(0,r.useState)(""),[v,k]=(0,r.useState)(""),[j,N]=(0,r.useState)(!1),[_,S]=(0,r.useState)(!1),[A,C]=(0,r.useState)(null),[T,P]=(0,r.useState)(new Set),[E,F]=(0,r.useState)(!1),[q,I]=(0,r.useState)(null),[O,z]=(0,r.useState)({}),[R,D]=(0,r.useState)(null),M=async()=>{try{var e,a;let s=await fetch("/api/workspaces/".concat(t,"/process-inventory"),{headers:await (0,x.authHeaders)()}),r=await s.json();if(!s.ok)throw Error(null!=(e=r.error)?e:"Failed to load the inventory");l(null!=(a=r.items)?a:[])}catch(e){u(e instanceof Error?e.message:"Failed to load the inventory")}finally{o(!1)}};(0,r.useEffect)(()=>{o(!0),M()},[t]);let L=(0,r.useMemo)(()=>{let e=n.map(e=>({item:e,signal:sl(e)})),t=e=>"dismissed"===e.item.status?2:+(null===e.signal);return e.sort((e,a)=>{var s,r,n,l;let i=t(e)-t(a);return 0!==i?i:(null!=(n=null==(s=a.signal)?void 0:s.score)?n:-1)-(null!=(l=null==(r=e.signal)?void 0:r.score)?l:-1)})},[n]),U=(0,r.useMemo)(()=>{let e=n.filter(e=>"dismissed"!==e.status);return{total:e.length,screened:e.filter(e=>null!==sl(e)).length,promoted:e.filter(e=>"promoted"===e.status).length}},[n]),H=async e=>{let t,a;if(!e)return;u(null),g(null);let s=t$(e.name),r=t4(e.name)||t1(e.name);if(!s&&!r)return void u("".concat(e.name," needs a parser we do not have yet. Text, Markdown, CSV, ")+"meeting transcripts (.vtt, .srt), PDF and Word (.docx) work today. For anything else, paste the text.");r&&N(!0);try{if(r){let s=await an(e,{allowOcr:!1});t=s.text,a=s.notice}else t=await e.text()}catch(t){u(t instanceof t3?t.message:"".concat(e.name," could not be read."));return}finally{N(!1)}let n=tQ(t,e.name);if(!n.text.trim())return void u("".concat(e.name," had no readable text in it."));f(n.text),v.trim()||k(e.name),a?g(a):n.truncated&&g("".concat(e.name," is longer than we read in one pass â the first ")+"".concat(24e3.toLocaleString("en-US")," characters were loaded."))},W=async()=>{S(!0),u(null),C(null);try{var e;let t=await fetch("/api/opportunities/extract-inventory",{method:"POST",headers:await (0,x.authHeaders)({"Content-Type":"application/json"}),body:JSON.stringify({text:b,source_label:v})}),a=await t.json();if(!t.ok)throw Error(null!=(e=a.error)?e:"Failed to read that source");C(a),P(new Set)}catch(e){u(e instanceof Error?e.message:"Failed to read that source")}finally{S(!1)}},B=async()=>
1{if(!A)return;let e=function(e,t){let a=new Set(t.filter(e=>e.accepted).map(e=>e.index));return e.items.filter((e,t)=>a.has(t)).map(t=>{var a,s,r,n,l,i,o,d;return{name:t.name.value.trim(),department:(null==(s=t.department)||null==(a=s.value)?void 0:a.trim())||null,owner_role:(null==(n=t.owner_role)||null==(r=n.value)?void 0:r.trim())||null,occurrences_per_year:null!=(o=null==(l=t.occurrences_per_year)?void 0:l.value)?o:null,minutes_per_occurrence:null!=(d=null==(i=t.minutes_per_occurrence)?void 0:i.value)?d:null,systems:t.systems,source_label:e.source_label||null,source_quote:t.name.quote||null}})}(A,A.items.map((e,t)=>({index:t,accepted:T.has(t)})));if(0!==e.length){F(!0),u(null);try{var a;let s=await fetch("/api/workspaces/".concat(t,"/process-inventory"),{method:"POST",headers:await (0,x.authHeaders)({"Content-Type":"application/json"}),body:JSON.stringify({items:e})}),r=await s.json();if(!s.ok)throw Error(null!=(a=r.error)?a:"Failed to save the inventory items");g("".concat(e.length," ").concat(1===e.length?"process":"processes"," added to the inventory.")),C(null),P(new Set),f(""),k(""),await M()}catch(e){u(e instanceof Error?e.message:"Failed to save the inventory items")}finally{F(!1)}}},J=async e=>{D(e.id),u(null);try{var t,a,s,r;let n={};for(let r of so){let l=O[r.key];l&&(n[r.key]={rating:l,notes:null!=(s=null==(a=e.process_suitability)||null==(t=a[r.key])?void 0:t.notes)?s:""})}let i=await fetch("/api/process-inventory/".concat(e.id),{method:"PATCH",headers:await (0,x.authHeaders)({"Content-Type":"application/json"}),body:JSON.stringify({process_suitability:Object.keys(n).length?n:null})}),o=await i.json();if(!i.ok)throw Error(null!=(r=o.error)?r:"Failed to update the item");l(t=>t.map(t=>t.id===e.id?o.item:t)),I(null)}catch(e){u(e instanceof Error?e.message:"Failed to update the item")}finally{D(null)}},G=async(e,t)=>{D(e.id),u(null);try{var a;let s=await fetch("/api/process-inventory/".concat(e.id),{method:"PATCH",headers:await (0,x.authHeaders)({"Content-Type":"application/json"}),body:JSON.stringify({status:t})}),r=await s.json();if(!s.ok)throw Error(null!=(a=r.error)?a:"Failed to update the item");l(t=>t.map(t=>t.id===e.id?r.item:t))}catch(e){u(e instanceof Error?e.message:"Failed to update the item")}finally{D(null)}},$=async e=>{D(e.id),u(null);try{var t;let s=await fetch("/api/process-inventory/".concat(e.id,"/promote"),{method:"POST",headers:await (0,x.authHeaders)()}),r=await s.json();if(!s.ok)throw Error(null!=(t=r.error)?t:"Failed to promote the item");g('"'.concat(e.name,'" is now a draft opportunity â deep-dive it from the List view.')),await M(),null==a||a()}catch(e){u(e instanceof Error?e.message:"Failed to promote the item")}finally{D(null)}},V=[...tG,...tZ,...t0].join(",");return(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[(0,s.jsx)(sc,{label:"Processes inventoried",value:String(U.total)}),(0,s.jsx)(sc,{label:"Screened (Three-Signal)",value:String(U.screened)}),(0,s.jsx)(sc,{label:"Promoted to pipeline",value:String(U.promoted)}),(0,s.jsx)(sc,{label:"Standing backlog",value:String(U.total-U.promoted),hint:"Inventoried, not yet promoted â the expansion pipeline."})]}),(c||m)&&(0,s.jsx)("div",{className:"border-l-4 p-3 rounded-r-md text-sm ".concat(c?"bg-red-50 dark:bg-red-900/30 border-red-400 text-red-700 dark:text-red-300":"bg-green-50 dark:bg-green-900/30 border-green-400 text-green-700 dark:text-green-300"),children:null!=c?c:m}),(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)(w.A,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),(0,s.jsx)("h3",{className:"ml-2 text-sm font-medium text-gray-900 dark:text-white",children:"Take an inventory"}),(0,s.jsx)("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:"dictate a walkthrough, or load a document â every process it names, shallowly"})]}),(0,s.jsx)("button",{onClick:()=>p(e=>!e),className:"text-sm text-indigo-600 dark:text-indigo-400 hover:underline",children:h?"Hide":"Start"})]}),h&&(0,s.jsxs)("div",{className:"mt-4 space-y-3",children:[(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-2",children:[(0,s.jsx)("input",{className:"".concat(sn," sm:max-w-xs"),placeholder:"Source label (e.g. Plant walk 26 Aug)",value:v,onCh
1ange:e=>k(e.target.value)}),(0,s.jsxs)("label",{className:"inline-flex items-center px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md text-sm text-gray-700 dark:text-gray-200 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700",children:[j?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-1.5 animate-spin"}):(0,s.jsx)(tB.A,{className:"h-4 w-4 mr-1.5"}),"Load a file",(0,s.jsx)("input",{type:"file",accept:V,className:"hidden",onChange:e=>{var t;return H(null==(t=e.target.files)?void 0:t[0])}})]}),(0,s.jsx)(a_.A,{onText:e=>f(t=>(0,a_.O)(t,e)),title:"Dictate the walkthrough"})]}),(0,s.jsx)("textarea",{className:sn,rows:6,placeholder:"Talk or paste: who does what, how often, in which systems. Every process named lands as one inventory line.",value:b,onChange:e=>f(e.target.value)}),(0,s.jsx)("button",{onClick:W,disabled:_||b.trim().length<40,className:"inline-flex items-center px-4 py-2 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 disabled:opacity-50",children:_?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(d.A,{className:"h-4 w-4 mr-1.5 animate-spin"})," Readingâ¦"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tW.A,{className:"h-4 w-4 mr-1.5"})," List the processes"]})}),A&&(0,s.jsxs)("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-3",children:[A.warnings.map((e,t)=>(0,s.jsxs)("p",{className:"flex items-start text-xs text-amber-700 dark:text-amber-300 mb-1",children:[(0,s.jsx)(y.A,{className:"h-3.5 w-3.5 mr-1 mt-0.5 shrink-0"}),e]},t)),0===A.items.length?(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No processes could be tied back to this source."}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[A.items.length," proposed â accept what is right. Every line carries the sentence that named it."]}),(0,s.jsx)("button",{onClick:()=>P(e=>e.size===A.items.length?new Set:new Set(A.items.map((e,t)=>t))),className:"text-xs text-indigo-600 dark:text-indigo-400 hover:underline",children:T.size===A.items.length?"Clear all":"Select all"})]}),(0,s.jsx)("div",{className:"space-y-1.5",children:A.items.map((e,t)=>{var a,r;return(0,s.jsxs)("label",{className:"flex items-start gap-2 p-2 rounded border border-gray-100 dark:border-gray-700 cursor-pointer hover:border-indigo-300 dark:hover:border-indigo-600",children:[(0,s.jsx)("input",{type:"checkbox",className:"mt-0.5",checked:T.has(t),onChange:e=>P(a=>{let s=new Set(a);return e.target.checked?s.add(t):s.delete(t),s})}),(0,s.jsxs)("span",{className:"min-w-0",children:[(0,s.jsxs)("span",{className:"block text-sm text-gray-900 dark:text-white",children:[e.name.value,(null==(a=e.department)?void 0:a.value)?(0,s.jsxs)("span",{className:"text-gray-500 dark:text-gray-400",children:[" ","\xb7 ",e.department.value]}):null,(null==(r=e.owner_role)?void 0:r.value)?(0,s.jsxs)("span",{className:"text-gray-500 dark:text-gray-400",children:[" ","\xb7 ",e.owner_role.value]}):null]}),(0,s.jsx)("span",{className:"block text-xs text-gray-500 dark:text-gray-400",children:[e.occurrences_per_year?"".concat(e.occurrences_per_year.value,"/yr"):null,e.minutes_per_occurrence?"".concat(e.minutes_per_occurrence.value," min"):null,e.systems.length?e.systems.join(", "):null].filter(Boolean).join(" \xb7 ")||"No figures stated â that is fine for a census."}),(0,s.jsxs)("span",{className:"block text-xs italic text-gray-400 dark:text-gray-500 truncate",children:["â",e.name.quote,"â"]})]})]},t)})}),(0,s.jsxs)("button",{onClick:B,disabled:E||0===T.size,className:"mt-3 inline-flex items-center px-4 py-2 text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 disabled:opacity-50",children:[E?(0,s.jsx)(d.A,{className:"h-4 w-4 mr-1.5 animate-spin"}):(0,s.jsx)(ts.A,{className:"h-4 w-4 mr-1.5"}),"Add ",T.size||""," to the inventory"]})]})]})]})]}),(0,s.jsx)(sr,{workspaceId:t,onAccepted:M}),i?(0,s.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,s.jsx)(d.A,{className:"h-6 w-6 text-indigo-600 dark:text-indigo-400 animate-spin"})}):0===n.length?(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Nothing inventoried yet. Twenty minutes of talking on a plant walk is enough to start."}):(0,s.jsx)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 divide-y divide-gray-100 dark:divide-gray-700",children:L.map(e=>{let{item:t,signal:a}=e;return(0,s.jsxs)("div",{className:"dismissed"===t.status?"opacity-50":"",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 p-3",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("p",{className:"text-sm font-medium text-gray-900 dark:text-white truncate",children:[t.name,t.department?(0,s.jsxs)("span",{className:"font-normal text-gray-500 dark:text-gray-400",children:[" ","\xb7 ",t.department]}):null]}),(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:[t.owner_role,null!=t.occurrences_per_year?"".concat(t.occurrences_per_year,"/yr"):null,null!=t.minutes_per_occurrence?"".concat(t.minutes_per_occurrence," min"):null,t.systems.length?t.systems.join(", "):null].filter(
1Boolean).join(" \xb7 ")||"No figures stated"})]}),a?(0,s.jsx)("span",{className:"shrink-0 inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ".concat("systemizable"===a.verdict?"bg-green-100 text-green-800 dark:bg-green-900/40 dark:text-green-300":"partially_systemizable"===a.verdict?"bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-300":"bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300"),title:to.pl[a.verdict],children:a.score}):"dismissed"!==t.status?(0,s.jsx)("span",{className:"shrink-0 text-xs text-gray-400 dark:text-gray-500",children:"Not screened"}):null,"promoted"===t.status?(0,s.jsx)("span",{className:"shrink-0 inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-indigo-100 text-indigo-800 dark:bg-indigo-900/40 dark:text-indigo-300",children:"Promoted"}):"dismissed"===t.status?(0,s.jsx)("button",{onClick:()=>G(t,"inventoried"),disabled:R===t.id,className:"shrink-0 text-xs text-indigo-600 dark:text-indigo-400 hover:underline",children:"Restore"}):(0,s.jsxs)("div",{className:"shrink-0 flex items-center gap-2",children:[(0,s.jsx)("button",{onClick:()=>q===t.id?I(null):(e=>{var t,a,s,r,n,l,i;I(e.id);let o=null!=(r=e.process_suitability)?r:{};z({repetitiveNature:null!=(n=null==(t=o.repetitiveNature)?void 0:t.rating)?n:"",digitalAccessibility:null!=(l=null==(a=o.digitalAccessibility)?void 0:a.rating)?l:"",documentationStatus:null!=(i=null==(s=o.documentationStatus)?void 0:s.rating)?i:""})})(t),className:"text-xs text-indigo-600 dark:text-indigo-400 hover:underline",children:a?"Re-screen":"Screen"}),(0,s.jsx)("button",{onClick:()=>$(t),disabled:R===t.id,className:"text-xs px-2 py-1 rounded-md text-white bg-indigo-600 hover:bg-indigo-700 disabled:opacity-50",children:R===t.id?"â¦":"Deep-dive"}),(0,s.jsx)("button",{onClick:()=>G(t,"dismissed"),disabled:R===t.id,title:"Dismiss",className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:(0,s.jsx)(en.A,{className:"h-4 w-4"})})]})]}),q===t.id&&(0,s.jsx)("div",{className:"px-3 pb-3",children:(0,s.jsxs)("div",{className:"rounded-md bg-gray-50 dark:bg-gray-700/50 p-3",children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-2",children:"Three-Signal screen â the score is the weakest leg. Leave a leg unrated and it counts as unassessed, which blocks the test on purpose."}),(0,s.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:so.map(e=>{var t;return(0,s.jsxs)("label",{className:"text-xs text-gray-700 dark:text-gray-300",children:[e.label,(0,s.jsx)("select",{className:"".concat(sn," mt-1"),value:null!=(t=O[e.key])?t:"",onChange:t=>z(a=>({...a,[e.key]:t.target.value})),children:si.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))})]},e.key)})}),(0,s.jsxs)("button",{onClick:()=>J(t),disabled:R===t.id,className:"mt-3 inline-flex items-center px-3 py-1.5 text-xs font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 disabled:opacity-50",children:[R===t.id?(0,s.jsx)(d.A,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,s.jsx)(ts.A,{className:"h-3.5 w-3.5 mr-1"}),"Save screen"]})]})})]},t.id)})})]})}function sc(e){let{label:t,value:a,hint:r}=e;return(0,s.jsxs)("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-3",title:r,children:[(0,s.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:t}),(0,s.jsx)("div",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:a})]})}var su=a(29119),sm=a(17471),sx=a(89099);function sg(){let e=(0,sx.useRouter)(),{activeWorkspace:t}=(0,l.h)(),{user:a}=(0,g.A)(),[o,d]=(0,r.useState)([]),[c,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(null),[h,A]=(0,r.useState)(!1),[C,T]=(0,r.useState)(null),[P,E]=(0,r.useState)(!1),[F,q]=(0,r.useState)(null),[I,z]=(0,r.useState)("list"),[R,D]=(0,r.useState)(null),[M,L]=(0,r.useState)(null),[U,H]=(0,r.useState)(!0);(0,r.useEffect)(()=>{t&&B()},[t]);let B=async()=>{if(t){H(!0);try{let e=await $.cN(t.id);d(e)}catch(e){q(e instanceof Error?e.message:"Failed to load opportunities")}finally{H(!1)}}},J=async e=>{if(t&&a){E(!0),q(null);try{let s=await $.MG(t.id,a.id,e);d(e=>[s,...e]),A(!1),z("list")}catch(e){q(e instanceof Error?e.message:"Failed to create opportunity")}finally{E(!1)}}},G=async(e,t)=>{E(!0),q(null);try{let a=await $.h6(e,t);d(t=>t.map(t=>
1t.id===e?{...t,...a}:t)),x(null),(null==c?void 0:c.id)===e&&u({...c,...a})}catch(e){q(e instanceof Error?e.message:"Failed to update opportunity")}finally{E(!1)}},V=async e=>{D(e.id),q(null);try{await $.h6(e.id,{status:"analyzing"}),d(t=>t.map(t=>t.id===e.id?{...t,status:"analyzing"}:t));let t=await $.ib(e),a=await $.h6(e.id,{status:"analyzed",aiAnalysis:t});d(t=>t.map(t=>t.id===e.id?{...t,...a}:t)),u({...e,...a})}catch(t){q(t instanceof Error?t.message:"Failed to analyze opportunity");try{await $.h6(e.id,{status:"draft"}),d(t=>t.map(t=>t.id===e.id?{...t,status:"draft"}:t))}catch(t){n.Cp(t,{tags:{component:"OpportunitiesPage",operation:"revert_status_after_failed_analysis"},extra:{opportunityId:e.id}})}}finally{D(null)}},X=async e=>{try{await $.dX(e),d(t=>t.filter(t=>t.id!==e)),(null==c?void 0:c.id)===e&&u(null),T(null)}catch(e){q(e instanceof Error?e.message:"Failed to delete opportunity")}},Y=async s=>{if(t&&a){L(s.id),q(null);try{await sm.$I(t.id,a.id,{id:s.id}),d(e=>e.map(e=>e.id===s.id?{...e,status:"converted"}:e)),u(null),e.push("/projects")}catch(e){q(e instanceof Error?e.message:"Failed to convert to project")}finally{L(null)}}},K=o.find(e=>e.id===C);return t?(0,s.jsxs)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between mb-6 gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Automation Opportunities"}),(0,s.jsx)("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"Identify and analyze potential processes for automation"})]}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,s.jsxs)("div",{className:"flex flex-wrap bg-gray-100 dark:bg-gray-800 rounded-lg p-1",children:[(0,s.jsxs)("button",{onClick:()=>z("list"),className:"flex items-center px-3 py-1.5 text-sm font-medium rounded-md transition-colors ".concat("list"===I?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white"),children:[(0,s.jsx)(b.A,{className:"h-4 w-4 mr-1.5"}),"List"]}),(0,s.jsxs)("button",{onClick:()=>z("chat"),className:"flex items-center px-3 py-1.5 text-sm font-medium rounded-md transition-colors ".concat("chat"===I?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white"),children:[(0,s.jsx)(f.A,{className:"h-4 w-4 mr-1.5"}),"AI Discovery"]}),(0,s.jsxs)("button",{onClick:()=>z("portfolio"),className:"flex items-center px-3 py-1.5 text-sm font-medium rounded-md transition-colors ".concat("portfolio"===I?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white"),children:[(0,s.jsx)(v.A,{className:"h-4 w-4 mr-1.5"}),"Portfolio"]}),(0,s.jsxs)("button",{onClick:()=>z("inventory"),className:"flex items-center px-3 py-1.5 text-sm font-medium rounded-md transition-colors ".concat("inventory"===I?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white"),children:[(0,s.jsx)(w.A,{className:"h-4 w-4 mr-1.5"}),"Inventory"]})]}),(0,s.jsxs)("button",{onClick:()=>A(!0),className:"inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 transition-colors",children:[(0,s.jsx)(k.A,{className:"h-5 w-5 mr-2"}),"New Opportunity"]})]})]}),(0,s.jsx)(p,{workspaceId:t.id,onReset:B}),(0,s.jsx)(i.A,{workspaceId:t.id}),F&&(0,s.jsx)("div",{className:"mb-6 bg-red-50 dark:bg-red-900/30 border-l-4 border-red-400 p-4 rounded-r-md",children:(0,s.jsxs)("div",{className:"flex",children:[(0,s.jsx)(y.A,{className:"h-5 w-5 text-red-400"}),(0,s.jsx)("p",{className:"ml-3 text-sm text-red-700 dark:text-red-300",children:F}),(0,s.jsx)("button",{onClick:()=>q(null),className:"ml-auto text-red-400 hover:text-red-500 dark:hover:text-red-300",children:"\xd7"})]})}),U&&(0,s.jsxs)("div",{className:"flex items-center justify-center py-12",children:[(0,s.jsx)(j.A,{className:"h-8 w-8 text-indigo-600 dark:text-indigo-400 animate-spin"}),(0,s.jsx)("span",{className:"ml-3 text-gray-600 dark:text-gray-400",children:"Loading opportunities..."})]}),!U&&"chat"===I&&(0,s.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[(0,s.jsx)(ss,{onOpportunityCreated:e=>{J({title:e.title,category:e.category,description:e.description})}}),(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-gray-900 dark:text-white mb-4",children:"Recent Opportunities"}),0===o.length?(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No opportunities yet. Use the chat to discover one!"}):(0,s.jsx)("div",{className:"space-y-3",children:o.slice(0,5).map(e=>(0,s.jsxs)("div",{onClick:()=>u(e),className:"p-3 border border-gray-200 dark:border-gray-700 rounded-lg hover:border-indigo-500 dark:hover:border-indigo-400 cursor-pointer transition-colors",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-gray-900 dark:text-white truncate",children:e.title}),e.aiAnalysis&&(0,s.jsxs)("span",{className:"text-xs text-indigo-600 dark:text-indigo-400",children:[e.aiAnalysis.automationPotential,"%"]})]}),(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1 line-clamp-2",children:e.description})]},e.id))})]})]}),!U&&"portfolio"===I&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(er,{workspaceId:t.id}),(0,s.jsx)(W,{opportunities:o})]}),!U&&"inventory"===I&&(0,s.jsx)(sd,{workspaceId:t.id,onPromoted:B}),!U&&"list"===I&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(O,{opportunities:o,onOpportunityClick:u}),o.filter(e=>"draft"===e.status&&!e.aiAnalysis).length>0&&(0,s.jsxs)("div",{className:"mt-6",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-gray-900 dark:text-white mb-3",children:"Qu
1ick Actions - Ready for Analysis"}),(0,s.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:o.filter(e=>"draft"===e.status&&!e.aiAnalysis).slice(0,3).map(e=>(0,s.jsxs)("div",{className:"bg-indigo-50 dark:bg-indigo-900/30 rounded-lg p-4 border border-indigo-100 dark:border-indigo-800",children:[(0,s.jsx)("div",{className:"flex items-center justify-between mb-2",children:(0,s.jsx)("span",{className:"text-sm font-medium text-indigo-900 dark:text-indigo-100 truncate",children:e.title})}),(0,s.jsx)("p",{className:"text-xs text-indigo-700 dark:text-indigo-300 mb-3 line-clamp-2",children:e.description}),(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)("button",{onClick:()=>V(e),disabled:R===e.id,className:"flex-1 inline-flex items-center justify-center px-3 py-1.5 text-xs font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600 disabled:opacity-50 transition-colors",children:R===e.id?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(j.A,{className:"h-3 w-3 mr-1.5 animate-spin"}),"Analyzing..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(N.A,{className:"h-3 w-3 mr-1.5"}),"Analyze with AI"]})}),(0,s.jsx)("button",{onClick:()=>x(e),className:"p-1.5 text-indigo-600 dark:text-indigo-400 hover:bg-indigo-100 dark:hover:bg-indigo-800 rounded-md transition-colors",title:"Edit",children:(0,s.jsx)(_.A,{className:"h-4 w-4"})}),(0,s.jsx)("button",{onClick:()=>T(e.id),className:"p-1.5 text-red-600 dark:text-red-400 hover:bg-red-100 dark:hover:bg-red-900/30 rounded-md transition-colors",title:"Delete",children:(0,s.jsx)(S.A,{className:"h-4 w-4"})})]})]},e.id))})]})]}),h&&(0,s.jsx)(eu,{onClose:()=>A(!1),onSubmit:J,isSubmitting:P}),m&&(0,s.jsx)(ex,{opportunity:m,onClose:()=>x(null),onSubmit:G,isSubmitting:P}),c&&(0,s.jsx)(a8,{opportunity:c,onClose:()=>u(null),onAnalyze:()=>V(c),onEdit:()=>{x(c),u(null)},onDelete:()=>{T(c.id),u(null)},onConvert:()=>Y(c),isAnalyzing:R===c.id,isConverting:M===c.id}),C&&K&&(0,s.jsx)(su.J,{title:"Delete Opportunity",message:'Are you sure you want to delete "'.concat(K.title,'"? This action cannot be undone.'),onConfirm:()=>X(C),onCancel:()=>T(null)})]}):(0,s.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:(0,s.jsx)("div",{className:"bg-yellow-50 dark:bg-yellow-900/30 border-l-4 border-yellow-400 p-4 rounded-r-md",children:(0,s.jsxs)("div",{className:"flex",children:[(0,s.jsx)(y.A,{className:"h-5 w-5 text-yellow-400"}),(0,s.jsx)("p",{className:"ml-3 text-sm text-yellow-700 dark:text-yellow-300",children:"Please select a workspace to view opportunities"})]})})})}function sh(){return(0,s.jsx)(sg,{})}},78581:(e,t,a)=>{"use strict";a.d(t,{B:()=>r,P:()=>n});let s={draft:"discovery",analyzing:"discovery",gathering_info:"discovery",analyzed:"qualified",business_case:"qualified",proposal:"proposal",in_review:"proposal",changes_requested:"proposal",signed_off:"signed_off",in_delivery:"delivery",live:"delivery",monitoring:"delivery",converted:"closed",ready_for_project:"closed",archived:"closed"},r={discovery:"Discovery",qualified:"Qualified",proposal:"Proposal",signed_off:"Signed off",delivery:"Delivery",closed:"Closed"};function n(e){let t={discovery:0,qualified:0,proposal:0,signed_off:0,delivery:0,closed:0},a=0,r=0,n=0,l=0,i=0;for(let d of e){var o;t[null!=(o=s[d.status])?o:"discovery"]+=1,null!=d.annual_savings&&(a+=d.annual_savings),null!=d.realized_annual_savings&&(r+=d.realized_annual_savings),d.quick_win&&(n+=1),null!=d.automation_potential&&(l+=d.automation_potential,i+=1)}return{total:e.length,predicted_annual_savings:a,realized_annual_savings:r,quick_wins:n,avg_automation_potential:i?Math.round(l/i):null,by_stage:t}}},89116:(e,t,a)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/opportunities",function(){return a(67674)}])}},e=>{e.O(0,[1895,6366,9353,5885,7471,2740,636,6593,8792],()=>e(e.s=89116)),_N_E=e.O()}]);
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.