1import{r as p,j as e}from"./client-BL7zgfj8.js";import{a as R}from"./useQuery-BCcgmdio.js";import{u as B}from"./useMutation-BYfJlSRH.js";import{l as P,p as F,P as C,o as M,M as w,d as L,C as T,q as D,e as E,F as h,s as U,i as q,T as z,t as G,B as H,v as K,w as Q}from"./CockpitPage-Bj3ijec7.js";import{s as V,u as W}from"./App-Lc7KrvjH.js";import{u as Y}from"./clientContext-w-Ltx6Cd.js";import{U as I}from"./user-plus-BHKG5rlT.js";import{M as J}from"./mail-B1-BV9-Q.js";import{S as X}from"./shield-alert-BbHbScPS.js";import{C as Z}from"./circle-check-CtexJiLe.js";import{L as v}from"./loader-circle-D9h3qPuU.js";import{T as ee}from"./target-ofCyXkjW.js";import{U as te}from"./users-z2m0wAFL.js";import{C as se}from"./crown-CvLZASsW.js";import{X as ne}from"./x-DhP5J42q.js";import{P as S}from"./plus-DzVjti4N.js";import{l as ae}from"./capture-Rrof9wHQ.js";import{C as re}from"./check-Bpjum-V5.js";import{B as le}from"./building-2-RjlEg1Fz.js";import{C as ie}from"./chevron-right-CNOJzQz1.js";import"./mutation-Ck9dgto-.js";import"./queryClient-xNVL8ma7.js";import"./main-DBNnQIP9.js";import"./public-brand-C3WeamsF.js";import"./landingCapture-Bi4VhJiO.js";import"./chevron-down-CfaJy2Ic.js";import"./crmQueries-C8xSgfqS.js";import"./gauge-D2XUvXVZ.js";import"./compass-0-xkuIxp.js";import"./network-CQ1p0chb.js";import"./workflow-qvIJABfh.js";import"./sparkles-CcY0lTxK.js";import"./arrow-right-left-BT2keeYp.js";import"./index-Dh9noGnp.js";import"./queries-tSSSCb7B.js";const oe=3e4;async function ce(t){var m;const a=t.email.trim().toLowerCase();if(!a||!a.includes("@"))throw new Error("Enter a valid client email address.");if(!t.clientId)throw new Error("No tenant selected to invite the client into.");const i=new AbortController,s=setTimeout(()=>i.abort(),oe);try{const{data:o,error:r}=await V.functions.invoke("client-invite",{body:{action:"invite",email:a,client_id:t.clientId,full_name:((m=t.fullName)==null?void 0:m.trim())||void 0}});if(r)throw new Error(r.message);const l=o??{};if(l.success===!1||l.error)throw new Error(l.error??"Could not invite the client.");return{userId:l.user_id??null,assignmentId:l.assignment_id??null,invited:l.invited!==!1}}finally{clearTimeout(s)}}const de=["owner","team_lead","team_leader"];function me(){const{isClientUser:t,isAdmin:a}=W(),{activeClient:i}=Y(),[s,m]=p.useState(""),[o,r]=p.useState(""),[l,c]=p.useState(!1),[d,x]=p.useState(null),[n,j]=p.useState(null);if(t||!i||i.is_internal||!(a||i.role!=null&&de.includes(i.role)))return null;const b=async N=>{if(N.preventDefault(),!l){x(null),j(null),c(!0);try{await ce({email:s,clientId:i.id,fullName:o||void 0}),j(`Invite sent to ${s.trim().toLowerCase()}.`),m(""),r("")}catch(y){x(y instanceof Error?y.message:"Could not invite the client.")}finally{c(!1)}}};return e.jsxs("section",{className:"rounded-2xl border border-[#e8e2d5] bg-[#fffdf9] p-5",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx("span",{className:"flex h-7 w-7 items-center justify-center rounded-lg bg-[#f0e9dd] text-[#cc5500]",children:e.jsx(I,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium text-[#141413]",children:"Invite a client"}),e.jsxs("p",{className:"truncate text-[11px] text-[#8a8071]",children:["Give a client login to ",e.jsx("span",{className:"font-medium text-[#52483c]",children:i.name})]})]})]}),e.jsxs("form",{onSubmit:b,className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block font-mono text-[10px] uppercase tracking-wider text-[#8a8071]",children:"Client email"}),e.jsxs("div",{className:"relative",children:[e.jsx(J,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-[#b5ac9d]"}),e.jsx("input",{type:"email",required:!0,value:s,onChange:N=>m(N.target.value),placeholder:"[email protected]",disabled:l,className:"w-full rounded-lg border border-[#e8e2d5] bg-white py-2 pl-8 pr-3 text-[13px] text-[#141413] outline-none transition-colors focus:border-[#cc5500] disabled:opacity-50"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"mb-1 block font-mono text-[10px] uppercase tracking-wider text-[#8a8071]",children:["Full name ",e.jsx("span",{className:"text-[#b5ac9d]",children:"(optional)"})]}),e.jsx("input",{type:"text",value:o,onChange:N=>r(N.target.value),placeholder:"Jane Doe",disabled:l,className:"w-full rounded-lg border border-[#e8e2d5] bg-white px-3 py-2 text-[13px] text-[#141413] outline-none transition-colors focus:border-[#cc5500] disabled:opacity-50"})]}),d&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-rose-50 px-3 py-2 text-[12px] text-rose-700",children:[e.jsx(X,{className:"mt-0.5 h-3.5 w-3.5 flex-shrink-0"}),e.jsx("span",{children:d})]}),n&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-emerald-50 px-3 py-2 text-[12px] text-emerald-700",children:[e.jsx(Z,{className:"mt-0.5 h-3.5 w-3.5 flex-shrink-0"}),e.jsx("span",{children:n})]}),e.jsx("button",{type:"submit",disabled:l||!s.trim(),className:"inline-flex w-full items-center justify-center gap-2 rounded-lg bg-[#cc5500] px-3 py-2 text-[13px] font-medium text-white transition-colors hover:bg-[#b34a00] disabled:cursor-not-allowed disabled:opacity-50",children:l?e.jsxs(e.Fragment,{children:[e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"})," Sending inviteâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(I,{className:"h-3.5 w-3.5"})," Send set-password invite"]})}),e.jsx("p",{className:"text-[10px] leading-relaxed text-[#b5ac9d]",children:"The client sets their own password and sees only this tenant's cockpit â contacts, pipeline, relationships and AI spend. They never see other tenants or internal StepUp.One surfaces."})]})]})}const g=t=>t.full_name||t.email||"Unnamed operator",_=t=>z[t]||t.replace(/_/g," "),A=t=>
1t==null?"â":t.toLocaleString();function Xe(){const{drill:t,setIcp:a,setSubIcp:i}=P(),{data:s,isLoading:m,isError:o,error:r}=F(t.clientId,t.playId);if(m)return e.jsxs("div",{className:"flex items-center gap-2 px-1 py-16 text-sm text-stone-500",children:[e.jsx(v,{className:"h-4 w-4 animate-spin"}),"Loading structureâ¦"]});if(o||!s)return e.jsx("div",{className:`${C} px-5 py-6`,children:e.jsxs("p",{className:"text-sm text-rose-700",children:["Couldnât load this playâs structure",r instanceof Error?`: ${r.message}`:"."]})});const{play:l,owner:c,team:d,icps:x}=s,n=M[l.play_key],j=(f,b)=>{a(f),i(b)};return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("header",{className:"flex items-start gap-3",children:[e.jsx("span",{"aria-hidden":"true",className:"mt-1 h-9 w-1.5 rounded-full",style:{background:n==null?void 0:n.accent}}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:w,style:{color:n==null?void 0:n.accent},children:(n==null?void 0:n.title)??"Play"}),e.jsx("h2",{className:"text-xl font-serif text-stone-900",children:l.title}),(l.subtitle||(n==null?void 0:n.subtitle))&&e.jsx("p",{className:"text-sm text-stone-500",children:l.subtitle||(n==null?void 0:n.subtitle)})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-5 lg:grid-cols-[minmax(0,18rem)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"space-y-5",children:[e.jsx(xe,{clientId:l.client_id,playId:l.id,accent:n==null?void 0:n.accent,owner:c,team:d}),e.jsx(me,{})]}),e.jsxs("section",{className:`${C} p-5`,children:[e.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4",style:{color:n==null?void 0:n.accent}}),e.jsx("h3",{className:"text-sm font-medium text-stone-900",children:"Targeting"}),e.jsxs("span",{className:"text-xs text-stone-400",children:[x.length," ICP",x.length===1?"":"s"]})]}),x.length===0?e.jsx("p",{className:"rounded-lg border border-dashed border-stone-200 px-4 py-8 text-center text-sm text-stone-400",children:"No ICPs defined for this tenant yet."}):e.jsx("div",{className:"space-y-3",children:x.map(f=>e.jsx(pe,{icp:f,accent:n==null?void 0:n.accent,onOpenSubIcp:j},f.id))})]})]})]})}function xe({clientId:t,playId:a,accent:i,owner:s,team:m}){const o=m.filter(r=>!r.is_owner);return e.jsxs("section",{className:`${C} p-5`,children:[e.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[e.jsx(te,{className:"h-4 w-4",style:{color:i}}),e.jsx("h3",{className:"text-sm font-medium text-stone-900",children:"Who runs
1it"})]}),e.jsxs("div",{className:`${L} relative p-4`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-mono uppercase tracking-widest text-amber-700",children:[e.jsx(se,{className:"h-3 w-3"})," Owner"]}),e.jsx(ue,{clientId:t,playId:a,accent:i,candidates:m,currentOwnerId:(s==null?void 0:s.user_id)??null})]}),s?e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsx(k,{name:g(s),accent:i}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium text-stone-900",children:g(s)}),e.jsx("p",{className:"truncate text-xs text-stone-500",children:_(s.role_in_client)})]})]}):e.jsx("p",{className:"mt-3 text-sm text-stone-400",children:"No owner assigned."})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:`${w} mb-2 text-stone-400`,children:"Team"}),o.length===0?e.jsx("p",{className:"text-xs text-stone-400",children:"No other members on this tenant."}):e.jsx("ul",{className:"space-y-1.5",children:o.map(r=>e.jsxs("li",{className:"flex items-center gap-2.5",children:[e.jsx(k,{name:g(r),small:!0}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("p",{className:"truncate text-sm text-stone-800",children:g(r)})}),e.jsx("span",{className:T,children:_(r.role_in_client)})]},r.user_id))})]})]})}function ue({clientId:t,playId:a,accent:i,candidates:s,currentOwnerId:m}){const[o,r]=p.useState(!1),l=R(),c=B({mutationFn:d=>U(a,d),onSuccess:(d,x)=>{l.invalidateQueries({queryKey:["cockpit","structure",t,a]}),ae({clientId:t,entityId:null,eventType:"play_owner_set",surface:"structure",payload:{playId:a,ownerUserId:x}}),r(!1)}});return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>r(d=>!d),className:`${E} ${h} inline-flex items-center gap-1 px-2 py-1 text-xs`,children:[e.jsx(I,{className:"h-3.5 w-3.5"}),"Assign"]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-hidden":"true",tabIndex:-1,className:"fixed inset-0 z-10 cursor-default",onClick:()=>r(!1)}),e.jsxs("div",{className:"absolute right-0 top-full z-20 mt-1.5 w-60 overflow-hidden rounded-xl border border-stone-200 bg-white shadow-lg",children:[e.jsx("p",{className:`${w} border-b border-stone-100 px-3 py-2 text-stone-400`,children:"Reassign owner"}),e.jsxs("ul",{className:"max-h-64 overflow-y-auto py-1",children:[s.length===0&&e.jsx("li",{className:"px-3 py-2 text-xs text-stone-400",children:"No assignable members."}),s.map(d=>{const x=d.user_id===m;return e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:c.isPending,onClick:()=>
1c.mutate(d.user_id),className:`flex w-full items-center gap-2.5 px-3 py-2 text-left text-sm transition hover:bg-stone-50 disabled:opacity-50 ${x?"bg-stone-50":""}`,children:[e.jsx(k,{name:g(d),small:!0,accent:i}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-stone-800",children:g(d)}),e.jsx("span",{className:"block truncate text-[11px] text-stone-400",children:_(d.role_in_client)})]}),x&&e.jsx(re,{className:"h-4 w-4 text-emerald-600"})]})},d.user_id)})]}),c.isError&&e.jsx("p",{className:"border-t border-stone-100 px-3 py-2 text-[11px] text-rose-600",children:c.error instanceof Error?c.error.message:"Could not reassign."})]})]})]})}function pe({icp:t,accent:a,onOpenSubIcp:i}){const{data:s,isLoading:m}=D(t.id),[o,r]=p.useState(!1),l=!!s&&s.length>0;return e.jsxs("div",{className:`${L} p-4`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"truncate text-sm font-medium text-stone-900",children:t.name}),t.definition&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-xs leading-relaxed text-stone-500",children:t.definition})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("p",{className:"text-sm font-medium tabular-nums text-stone-900",children:A(t.estimated_number)}),e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-stone-400",children:"market"})]})]}),t.estimation_basis&&e.jsx("p",{className:"mt-1 text-[11px] italic text-stone-400",children:t.estimation_basis}),e.jsxs("div",{className:"mt-3 border-t border-stone-100 pt-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:`${w} text-stone-400`,children:["Sub-ICPs",l&&e.jsx("span",{className:"ml-1.5 text-stone-300",children:s.length})]}),e.jsxs("button",{type:"button",onClick:()=>r(c=>!c),"aria-expanded":o,className:`${E} ${h} px-2 py-1 text-[11px]`,children:[o?e.jsx(ne,{className:"h-3.5 w-3.5"}):e.jsx(S,{className:"h-3.5 w-3.5"}),o?"Cancel":"Add sub-ICP"]})]}),o&&e.jsx(he,{icpId:t.id,accent:a,onDone:()=>r(!1)}),m?e.jsxs("div",{className:"flex items-center gap-2 py-2 text-xs text-stone-400",children:[e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"})," Loading segmentsâ¦"]}):l?e.jsx("ul",{className:"space-y-1.5",children:s.map(c=>e.jsx(je,{subIcp:c,accent:a,onOpen:()=>i(t.id,c.id)},c.id))}):!o&&e.jsxs("button",{type:"button",onClick:()=>r(!0),className:`${h} flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-stone-200 px-4 py-4 text-xs text-stone-400 transition hover:border-stone-300 hover:bg-stone-50 hover:text-stone-600`,children:[e.jsx(S,{className:"h-3.5 w-3.5"}),"No sub-segments yet â define one"]})]})]})}function he({icpId:t,accent:a,onDone:i}){const s=G(),[m,o]=p.useState(""),[r,l]=p.useState(""),[c,d]=p.useState(""),[x,n]=p.useState(""),[j,f]=p.useState(""),b=m.trim(),N=b.length>0&&!s.isPending,y=()=>{if(!N)return;const u=j.trim()===""?null:Number(j.trim()),O=u!=null&&Number.isFinite(u)?Math.max(0,Math.round(u)):null;s.mutate({icpId:t,name:b,region:r.trim()||null,industry:c.trim()||null,definition:x.trim()||null,estimatedNumber:O},{onSuccess:()=>i()})};return e.jsxs("form",{onSubmit:u=>{u.preventDefault(),y()},className:"mb-3 space-y-2 rounded-lg border border-stone-200 bg-white p-3",children:[e.jsx("input",{value:m,onChange:u=>o(u.target.value),placeholder:"Sub-ICP name (required)",autoFocus:!0,className:`w-full rounded-md border border-stone-200 px-2.5 py-1.5 text-sm text-stone-900 placeholder:text-stone-400 ${h}`}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("input",{value:r,onChange:u=>l(u.target.value),placeholder:"Region",className:`w-full rounded-md border border-stone-200 px-2.5 py-1.5 text-sm text-stone-900 placeholder:text-stone-400 ${h}`}),e.jsx("input",{value:c,onChange:u=>d(u.target.value),placeholder:"Industry",className:`w-full rounded-md border border-stone-200 px-2.5 py-1.5 text-sm text-stone-900 placeholder:text-stone-400 ${h}`})]}),e.jsx("input",{value:x,onChange:u=>n(u.target.value),placeholder:"Definition (optional)",className:`w-full rounded-md border border-stone-200 px-2.5 py-1.5 text-sm text-stone-900 placeholder:text-stone-400 ${h}`}),e.jsx("input",{value:j,onChange:u=>f(u.target.value),type:"number",inputMode:"numeric",min:0,step:1,placeholder:"Estimated market size (optional)",className:`w-full rounded-md border border-stone-200 px-2.5 py-1.5 text-sm tabular-nums text-stone-900 placeholder:text-stone-400 ${h}`}),e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-0.5",children:[s.isError?e.jsx("p",{className:"min-w-0 flex-1 truncate text-[11px] text-rose-600",children:s.error instanceof Error?s.error.message:"Could not create sub-ICP."}):e.jsx("span",{}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:i,className:`${E} ${h} text-[12px]`,children:"Cancel"}),e.jsxs("button",{type:"submit",disabled:!N,className:`${H} ${h} text-[12px]`,style:a?{backgroundColor:a}:void 0,children:[s.isPending?e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(S,{className:"h-3.5 w-3.5"}),"Create sub-ICP"]})]})]})]})}function je({subIcp:t,accent:a,onOpen:i}){var d,x;const{drill:s}=P(),m=K(s.clientId,t.id),o=Q(s.clientId,t.id),r=((d=m.data)==null?void 0:d.length)??null,l=((x=o.data)==null?void 0:x.length)??null,c=[t.region,t.industry].filter(
1Boolean);return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:i,className:`${h} group flex w-full items-center gap-3 rounded-lg border border-transparent px-2 py-2 text-left transition hover:border-stone-200 hover:bg-stone-50`,children:[e.jsx(le,{className:"h-4 w-4 shrink-0 text-stone-300 group-hover:text-stone-400"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm text-stone-800",children:t.name}),e.jsx("div",{className:"mt-0.5 flex flex-wrap items-center gap-1",children:c.length>0?c.map(n=>e.jsx("span",{className:T,children:n},n)):e.jsx("span",{className:"text-[11px] text-stone-400",children:"No segment label"})})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-3 text-right",children:[e.jsx($,{label:"contacts",value:r,loading:m.isLoading}),e.jsx($,{label:"in pipeline",value:l,loading:o.isLoading,accent:a}),e.jsx(ie,{className:"h-4 w-4 text-stone-300 transition group-hover:translate-x-0.5 group-hover:text-stone-500"})]})]})})}function $({label:t,value:a,loading:i,accent:s}){return e.jsxs("div",{className:"min-w-[3.25rem]",children:[e.jsx("p",{className:"text-sm font-medium tabular-nums text-stone-900",style:s&&a?{color:s}:void 0,children:i?e.jsx(v,{className:"ml-auto h-3.5 w-3.5 animate-spin text-stone-300"}):A(a)}),e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-stone-400",children:t})]})}function k({name:t,accent:a,small:i}){const s=i?"h-7 w-7 text-[10px]":"h-10 w-10 text-xs";return e.jsx("span",{"aria-hidden":"true",className:`inline-flex shrink-0 items-center justify-center rounded-full font-medium ${s}`,style:{background:a?`${a}1a`:"#f5f5f4",color:a||"#57534e"},children:q(t)})}export{Xe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.