PageSourceSearch

https://karigor.ai/assets/customer-profiles-BsuI3pX2.js

js karigor.ai collected 2026-10-05 13:42:53 UTC 29,580 bytes, 1 lines download raw bytes

1import{a8 as V,j as e,c as y,r as g,J as T,K as b,M as C,N as _,aU as w,X as W,U as J,c2 as G,L as K}from"./index-BiPJBT4h.js";import{u as E}from"./useQuery-Bbt3x1At.js";import{c as k}from"./convexError-jU0BH14M.js";import{P as q}from"./plus-ZBSXBlQa.js";import{A as de}from"./archive-tVt3l7A0.js";import{T as Y}from"./trash-2-_DLnI96l.js";import{S as Z}from"./save-DDJtrEea.js";import{B as le}from"./building-2-7rLUErD0.js";import{E as ce}from"./eye-DOSUpA3a.js";import{P as me}from"./power-Dm9VKy_k.js";import{I as ue}from"./id-card-BChyD_cT.js";import{U as xe}from"./users-CpYw87YO.js";const he=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]],pe=V("archive-restore",he);const ge=[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"9",height:"7",x:"3",y:"14",rx:"1",key:"jqznyg"}],["rect",{width:"5",height:"7",x:"16",y:"14",rx:"1",key:"q5h2i8"}]],be=V("layout-template",ge),f=y("w-full rounded-md border border-border bg-background px-2.5 py-1.5","text-sm text-foreground placeholder:text-muted-foreground","outline-none focus:border-primary/60 disabled:opacity-60");function v({label:t,hint:c,compact:d=!1,children:n}){return e.jsxs("label",{className:"block",children:[e.jsxs("span",{className:y("mb-1 block font-medium text-foreground",d?"text-[11px]":"text-xs"),children:[t,c?e.jsx("span",{className:"ml-1.5 font-normal text-muted-foreground",children:c}):null]}),n]})}function A({title:t,message:c}){return e.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/40 bg-destructive/10 p-4",children:[e.jsx("p",{className:"text-sm font-medium text-destructive",children:t}),e.jsx("p",{className:"mt-1 text-xs text-destructive/90",children:c})]})}function ee(){return e.jsx("div",{className:"space-y-2","aria-hidden":!0,children:[0,1,2].map(t=>e.jsx("div",{className:"h-20 animate-pulse rounded-lg border border-border bg-secondary"},t))})}const Q=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,z=24,R=400,$=4e3,fe=4e3,ve=200;function ye(){return{slug:"",name:"",description:"",briefing:"",fields:[]}}function je(){return{key:"",label:"",hint:"",required:!1,maxLength:ve}}function Ne(t,c){if(c.requireSlug&&!Q.test(t.slug))return'Slug must be lowercase kebab-case, e.g. "enterprise-b2b".';if(t.name.trim().length===0)return"Template name is required.";if(t.fields.length>z)return`A template may declare at most ${z} fields.`;const d=new Set;for(const n of t.fields){if(!Q.test(n.key))return`Field key "${n.key||"(empty)"}" must be lowercase kebab-case.`;if(d.has(n.key))return`Duplicate field key "${n.key}".`;if(d.add(n.key),n.label.trim().length===0)return`Field "${n.key}" needs a label — the label is what the agent reads.`;if(!Number.isInteger(n.maxLength)||n.maxLength<1||n.maxLength>R)return`Field "${n.key}" max length must be a whole number between 1 and ${R}.`}return t.briefing.length>$?`Briefing must be ${$.toLocaleString()} characters or fewer.`:null}function F(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function D(t){return t?new Date(t).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"}):"—"}function we(){const[t,c]=g.useState(!1),[d,n]=g.useState({mode:"closed"}),m=T(b.customerProfiles.listTemplates,{includeArchived:t}),{data:i,isPending:u,isError:j,error:N}=E(m),x=i??[],o=C(b.customerProfiles.setTemplateStatus),p=_({mutationFn:r=>o(r),onSuccess:(r,l)=>{const h=r?.affectedOrgCount;l.status==="archived"?w.success(h&&h>0?`Template archived. ${h} organization${h===1?"":"s"} stop receiving a profile block on their next turn.`:"Template archived. No organization was using it."):w.success("Template restored. Orgs on it resume receiving a profile block.")},onError:r=>w.error(k(r))});if(j)return e.jsx(A,{title:"Could not load templates",message:k(N)});const a=d.mode==="edit"?x.find(r=>r._id===d.templateId):void 0;return e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[minmax(0,22rem)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:t,onChange:r=>c(r.target.checked),className:"h-3.5 w-3.5 rounded border-border accent-[var(--primary)]"}),"Show archived"]}),e.jsxs("button",{type:"button",onClick:()=>n({mode:"create"}),className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90",children:[e.jsx(q,{className:"h-3.5 w-3.5","aria-hidden":!0}),"New template"]})]}),u?e.jsx(ee,{}):x.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-6 text-center",children:[e.jsxs("p",{className:"text-sm font-medium text-foreground",children:["No ",t?"":"active ","templates yet"]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Until one exists, no organization can be given a profile, and every signed-in customer is treated exactly like an anonymous visitor."})]}):e.jsx("ul",{className:"space-y-2",children:x.map(r=>{const l=d.mode==="edit"&&d.templateId===r._id;
1return e.jsx("li",{children:e.jsxs("div",{className:y("rounded-lg border bg-card p-3 transition-colors",l?"border-primary/60 ring-1 ring-primary/30":"border-border hover:border-muted-foreground/30"),children:[e.jsxs("button",{type:"button",onClick:()=>n({mode:"edit",templateId:r._id}),className:"w-full text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:r.name}),r.status==="archived"?e.jsx("span",{className:"shrink-0 rounded border border-border bg-secondary px-1.5 py-px text-[10px] uppercase tracking-wide text-muted-foreground",children:"Archived"}):null]}),e.jsx("div",{className:"mt-0.5 font-mono text-[11px] text-muted-foreground",children:r.slug}),e.jsxs("div",{className:"mt-1.5 text-[11px] text-muted-foreground",children:[r.fields.length," field",r.fields.length===1?"":"s"," · ",r.briefing?"has briefing":"no briefing"," · ",D(r.updatedAt)]})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsx("button",{type:"button",disabled:p.isPending,onClick:()=>p.mutate({templateId:r._id,status:r.status==="active"?"archived":"active"}),className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-[11px] text-muted-foreground hover:bg-secondary hover:text-foreground disabled:opacity-50",children:r.status==="active"?e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-3 w-3","aria-hidden":!0}),"Archive"]}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"h-3 w-3","aria-hidden":!0}),"Restore"]})})})]})},r._id)})})]}),e.jsx("div",{children:d.mode==="closed"?e.jsx("div",{className:"flex h-full min-h-[16rem] items-center justify-center rounded-lg border border-dashed border-border p-8 text-center",children:e.jsx("p",{className:"max-w-sm text-sm text-muted-foreground",children:"Pick a template to edit, or create one. A template's fields and briefing are rendered verbatim into the system-role block the agent receives for every org assigned to it."})}):d.mode==="edit"&&!a?e.jsx(A,{title:"Template not found",message:"It may have been archived out of this list, or deleted in another tab."}):e.jsx(ke,{existing:a??null,onDone:()=>n({mode:"closed"}),onCancel:()=>n({mode:"closed"})},d.mode==="edit"?d.templateId:"create")})]})}function ke({existing:t,onDone:c,onCancel:d}){const[n,m]=g.useState(()=>t?{slug:t.slug,name:t.name,description:t.description??"",briefing:t.briefing??"",fields:t.fields.map(a=>({key:a.key,label:a.label,hint:a.hint??"",required:a.required,maxLength:a.maxLength}))}:ye()),[i,u]=g.useState(null),j=C(b.customerProfiles.createTemplate),N=C(b.customerProfiles.updateTemplate),x=_({mutationFn:async()=>{const a=n.fields.map(l=>({key:l.key,label:l.label.trim(),...l.hint.trim()?{hint:l.hint.trim()}:{},required:l.required,maxLength:l.maxLength})),r={name:n.name.trim(),...n.description.trim()?{description:n.description.trim()}:{},fields:a,...n.briefing.trim()?{briefing:n.briefing.trim()}:{}};return t?N({templateId:t._id,...r}):j({slug:n.slug,...r})},onSuccess:()=>{w.success(t?"Template updated.":"Template created."),c()},onError:a=>u(k(a))});function o(){const a=Ne(n,{requireSlug:!t});if(a){u(a);return}u(null),x.mutate()}function p(a,r){m(l=>({...l,fields:l.fields.map((h,S)=>S===a?{...h,...r}:h)}))}return e.jsxs("form",{className:"space-y-5 rounded-lg border border-border bg-card p-4",onSubmit:a=>{a.preventDefault(),o()},children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:t?`Edit "${t.name}"`:"New template"}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:t?"The slug is immutable — it is the key the audit trail refers to.":"The slug cannot be changed later. Pick it deliberately."})]}),e.jsx("button",{type:"button",onClick:d,"aria-label":"Close editor",className:"rounded-md p-1 text-muted-foreground hover:bg-secondary hover:text-foreground",children:e.jsx(W,{className:"h-4 w-4","aria-hidden":!0})})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(v,{label:"Slug",hint:"lowercase-kebab-case",children:e.jsx("input",{value:n.slug,disabled:!!t,onChange:a=>m(r=>({...r,slug:a.target.value})),onBlur:a=>m(r=>({...r,slug:F(a.target.value)})),placeholder:"enterprise-b2b",className:f})}),e.jsx(v,{label:"Name",hint:"shown to the agent",children:e.jsx("input",{value:n.name,onChange:a=>m(r=>({...r,name:a.target.value})),placeholder:"Enterprise B2B",className:f})})]}),e.jsx(v,{label:"Description",hint:"staff-facing only — never sent to the agent",children:e.jsx("input",{value:n.description,onChange:a=>m(r=>({...r,description:a.target.value})),placeholder:"For multi-site manufacturers with a procurement process",className:f})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:"Fields"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Order here is the order the agent reads. A field left empty on an org is omitted entirely, not sent as blank."})]}),e.jsxs("button",{type:"button",disabled:n.fields.length>=z,onClick:()=>m(a=>({...a,fields:[...a.fields,je()]})),className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-[11px] text-foreground hover:bg-secondary disabled:opacity-50",children:[e.jsx(q,{className:"h-3 w-3","aria-hidden":!0}
1),"Add field"]})]}),n.fields.length===0?e.jsx("p",{className:"rounded-md border border-dashed border-border px-3 py-4 text-center text-xs text-muted-foreground",children:"No fields. A template with no fields still delivers its briefing — that is a valid choice, not an unfinished one."}):e.jsx("ul",{className:"space-y-2",children:n.fields.map((a,r)=>e.jsxs("li",{className:"rounded-md border border-border bg-background p-2.5",children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]",children:[e.jsx(v,{label:"Label",compact:!0,children:e.jsx("input",{value:a.label,onChange:l=>{const h=l.target.value;p(r,{label:h,...a.key===""||a.key===F(a.label)?{key:F(h)}:{}})},placeholder:"Industry",className:f})}),e.jsx(v,{label:"Key",compact:!0,hint:"stable id",children:e.jsx("input",{value:a.key,onChange:l=>p(r,{key:l.target.value}),onBlur:l=>p(r,{key:F(l.target.value)}),placeholder:"industry",className:y(f,"font-mono")})})]}),e.jsxs("div",{className:"mt-2 grid gap-2 sm:grid-cols-[minmax(0,1fr)_7rem_auto]",children:[e.jsx(v,{label:"Hint",compact:!0,hint:"staff form help only",children:e.jsx("input",{value:a.hint,onChange:l=>p(r,{hint:l.target.value}),placeholder:"e.g. Manufacturing, Retail",className:f})}),e.jsx(v,{label:"Max length",compact:!0,children:e.jsx("input",{type:"number",min:1,max:R,value:a.maxLength,onChange:l=>p(r,{maxLength:Number(l.target.value)}),className:f})}),e.jsxs("div",{className:"flex items-end gap-2 pb-1",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:a.required,onChange:l=>p(r,{required:l.target.checked}),className:"h-3.5 w-3.5 rounded border-border accent-[var(--primary)]"}),"Required"]}),e.jsx("button",{type:"button","aria-label":`Remove field ${a.label||a.key||r+1}`,onClick:()=>m(l=>({...l,fields:l.fields.filter((h,S)=>S!==r)})),className:"rounded-md p-1 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",children:e.jsx(Y,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})]})]},r))})]}),e.jsx(v,{label:"Briefing",hint:"rendered VERBATIM to the agent for every org on this template",children:e.jsx("textarea",{value:n.briefing,rows:5,onChange:a=>m(r=>({...r,briefing:a.target.value})),placeholder:"Lead with procurement timelines. Never quote a price without a scoping call first.",className:y(f,"resize-y leading-relaxed")})}),e.jsxs("div",{className:"-mt-3 text-right text-[10px] tabular-nums text-muted-foreground",children:[n.briefing.length.toLocaleString()," /"," ",$.toLocaleString()]}),i?e.jsx("p",{role:"alert",className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:i}):null,e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:d,className:"rounded-md border border-border px-3 py-1.5 text-xs text-foreground hover:bg-secondary",children:"Cancel"}),e.jsxs("button",{type:"submit",disabled:x.isPending,className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50",children:[x.isPending?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}):e.jsx(Z,{className:"h-3.5 w-3.5","aria-hidden":!0}),t?"Save changes":"Create template"]})]})]})}function Pe(){const[t,c]=g.useState(null),d=E(T(b.customerProfiles.listProfiles,{})),n=E(T(b.admin.listOrgsForGrantAccess,{})),m=E(T(b.customerProfiles.listTemplates,{})),i=d.data??[],u=n.data??[],j=m.data??[];if(d.isError)return e.jsx(A,{title:"Could not load profiles",message:k(d.error)});const N=new Set(i.map(o=>o.orgId)),x=u.filter(o=>!N.has(o._id));return e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[minmax(0,24rem)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"space-y-5",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-xs font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:["Assigned (",i.length,")"]}),d.isPending?e.jsx(ee,{}):i.length===0?e.jsx("p",{className:"rounded-lg border border-dashed border-border px-3 py-5 text-center text-xs text-muted-foreground",children:"No organization has a profile. Every signed-in customer currently gets the same Front Desk an anonymous visitor gets."}):e.jsx("ul",{className:"space-y-2",children:i.map(o=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>c(o.orgId),className:y("w-full rounded-lg border bg-card p-3 text-left transition-colors",t===o.orgId?"border-primary/60 ring-1 ring-primary/30":"border-border hover:border-muted-foreground
1/30"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:o.orgName??e.jsx("span",{className:"text-muted-foreground italic",children:"organization no longer exists"})}),e.jsx(Se,{enabled:o.enabled,templateStatus:o.templateStatus})]}),e.jsxs("div",{className:"mt-1 text-[11px] text-muted-foreground",children:[o.templateName??"template missing"," ·"," ",o.values.length," field",o.values.length===1?"":"s"," filled",o.notes?" · has notes":""]}),e.jsxs("div",{className:"mt-0.5 text-[10px] text-muted-foreground/80",children:["Updated ",D(o.updatedAt)]})]})},o._id))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-xs font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:["No profile (",x.length,")"]}),n.isPending?e.jsx("div",{className:"h-16 animate-pulse rounded-lg bg-secondary","aria-hidden":!0}):x.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Every active organization has a profile."}):e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:x.map(o=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>c(o._id),className:y("inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] transition-colors",t===o._id?"border-primary/60 bg-primary/10 text-foreground":"border-border bg-card text-muted-foreground hover:text-foreground"),children:[e.jsx(q,{className:"h-3 w-3","aria-hidden":!0}),o.name]})},o._id))})]})]}),e.jsx("div",{children:t===null?e.jsx("div",{className:"flex h-full min-h-[16rem] items-center justify-center rounded-lg border border-dashed border-border p-8 text-center",children:e.jsx("p",{className:"max-w-sm text-sm text-muted-foreground",children:"Select an organization to give it a customer profile, or edit the one it already has."})}):e.jsx(Te,{orgId:t,orgName:u.find(o=>o._id===t)?.name??i.find(o=>o.orgId===t)?.orgName??null,templates:j,onClose:()=>c(null)},t)}
1)]})}function Se({enabled:t,templateStatus:c}){return c!=="active"?e.jsx("span",{className:"shrink-0 rounded border border-destructive/40 bg-destructive/10 px-1.5 py-px text-[10px] uppercase tracking-wide text-destructive",children:"Not sent"}):e.jsx("span",{className:y("shrink-0 rounded border px-1.5 py-px text-[10px] uppercase tracking-wide",t?"border-border bg-secondary text-foreground":"border-border bg-secondary text-muted-foreground"),children:t?"Live":"Paused"})}function Te({orgId:t,orgName:c,templates:d,onClose:n}){const m=E(T(b.customerProfiles.getProfileForOrg,{orgId:t})),i=m.data,[u,j]=g.useState(null),[N,x]=g.useState({}),[o,p]=g.useState(""),[a,r]=g.useState(!0),[l,h]=g.useState(null),[S,te]=g.useState(!1),[M,re]=g.useState(null);g.useEffect(()=>{if(m.isPending)return;const s=i?`${i._id}:${i.updatedAt}`:"none";M!==s&&(re(s),i?(j(i.templateId),x(Object.fromEntries(i.values.map(P=>[P.key,P.value]))),p(i.notes??""),r(i.enabled)):(j(null),x({}),p(""),r(!0)))},[i,m.isPending,M]);const B=d.filter(s=>s.status==="active"),L=(d.find(s=>s._id===u)??null)?.fields??(i&&i.templateId===u?i.templateFields:[]),se=C(b.customerProfiles.upsertProfile),I=_({mutationFn:()=>{if(!u)throw new Error("No template selected");return se({orgId:t,templateId:u,values:L.map(s=>({key:s.key,value:(N[s.key]??"").trim()})).filter(s=>s.value.length>0),...o.trim()?{notes:o.trim()}:{},enabled:i?i.enabled:a})},onSuccess:()=>{h(null),w.success("Profile saved. It applies from the customer’s next message.")},onError:s=>h(k(s))}),ae=C(b.customerProfiles.setProfileEnabled),O=_({mutationFn:s=>{if(!i)throw new Error("No saved profile to toggle");return ae({profileId:i._id,enabled:s})},onSuccess:(s,P)=>{w.success(P?"Profile resumed. The agent receives it again from the next message.":"Profile paused. The agent receives nothing staff wrote about this organization — it still sees who is asking.")},onError:s=>w.error(k(s))}),ne=C(b.customerProfiles.deleteProfile),U=_({mutationFn:()=>{if(!i)throw new Error("No saved profile to delete");return ne({profileId:i._id})},onSuccess:()=>{w.success("Profile deleted. The filled values are gone."),n()},onError:s=>w.error(k(s))});if(m.isError)return e.jsx(A,{title:"Could not load this organization's profile",message:k(m.error)});const H=L.filter(s=>s.required&&(N[s.key]??"").trim().length===0).map(s=>s.label);return e.jsxs("div",{className:"space-y-4 rounded-lg border border-border bg-card p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("span",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10",children:e.jsx(le,{className:"h-4 w-4 text-primary","aria-hidden":!0})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-sm font-semibold text-foreground",children:c??"Unnamed organization"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:m.isPending?"Loading…":i?`Profile saved ${D(i.updatedAt)}`:"No profile yet — nothing is sent to the agent for this org"})]})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":"Close editor",className:"rounded-md p-1 text-muted-foreground hover:bg-secondary hover:text-foreground",children:e.jsx(W,{className:"h-4 w-4","aria-hidden":!0})})]}),m.isPending?e.jsx("div",{className:"h-40 animate-pulse rounded-md bg-secondary","aria-hidden":!0}):e.jsxs(e.Fragment,{children:[e.jsx(v,{label:"Template",hint:"its fields and briefing shape what the agent is told",children:e.jsxs("select",{value:u??"",onChange:s=>j(s.target.value?s.target.value:null),className:f,children:[e.jsx("option",{value:"",children:"Select a template…"}),B.map(s=>e.jsx("option",{value:s._id,children:s.name},s._id)),i&&i.templateStatus!=="active"&&i.templateId===u?e.jsxs("option",{value:i.templateId,disabled:!0,children:[i.templateName??"Unknown"," (archived — nothing is sent)"]}):null]})}),B.length===0?e.jsx("p",{className:"rounded-md border border-border bg-secondary/60 px-3 py-2 text-xs text-muted-foreground",children:"There are no active templates. Create one on the Templates tab before assigning a profile."}):null,u?L.length===0?e.jsx("p",{className:"rounded-md border border-dashed border-border px-3 py-3 text-center text-xs text-muted-foreground",children:"This template declares no fields. Only its briefing and your notes will reach the agent."}):e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:L.map(s=>{const P=N[s.key]??"",X=P.length>s.maxLength;return e.jsxs(v,{label:`${s.label}${s.required?" *":""}`,hint:s.hint,children:[e.jsx("input",{value:P,onChange:ie=>x(oe=>({...oe,[s.key]:ie.target.value})),placeholder:"Leave empty to omit this line entirely",className:y(f,X&&"border-destructive/60")}),X?e.jsxs("span",{className:"mt-0.5 block text-[10px] text-destructive",children:[P.length," / ",s.maxLength," characters"]}):null]},s.key)})}):null,e.jsx(v,{label:"Staff notes",hint:"appended after the template briefing, rendered verbatim",children:e.jsx("textarea",{value:o,rows:4,onChange:s=>p(s.target.value),placeholder:"Anything the desk should know about this customer specifically.",className:y(f,"resize-y leading-relaxed")})}),e.jsxs("div",{className:"-mt-2 text-right text-[10px] tabular-nums text-muted-foreground",children:[o.length.toLocaleStr
1ing()," / ",fe.toLocaleString()]}),i?e.jsxs("p",{className:"rounded-md border border-border bg-secondary/50 px-3 py-2 text-[11px] text-muted-foreground",children:[i.enabled?"This profile is live. Use Pause below to stop sending it without losing what is filled in.":"This profile is paused — the agent receives nothing staff wrote about this organization, though it still sees who is asking. Use Resume below."," ","The customer's name and organization are identity, not profile, and are unaffected either way."]}):e.jsxs("label",{className:"flex items-start gap-2.5 rounded-md border border-border bg-background px-3 py-2.5",children:[e.jsx("input",{type:"checkbox",checked:a,onChange:s=>r(s.target.checked),className:"mt-0.5 h-3.5 w-3.5 rounded border-border accent-[var(--primary)]"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-xs font-medium text-foreground",children:"Send this profile to the agent once created"}),e.jsx("span",{className:"mt-0.5 block text-[11px] text-muted-foreground",children:"Off keeps everything you have filled in but sends nothing. You can change this any time with Pause/Resume."})]})]}),H.length>0?e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Required and still empty: ",H.join(", "),"."]}):null,l?e.jsx("p",{role:"alert",className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:l}):null,e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-t border-border pt-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>te(s=>!s),className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-foreground hover:bg-secondary",children:[e.jsx(ce,{className:"h-3.5 w-3.5","aria-hidden":!0}),S?"Hide":"Preview"," what the agent gets"]}),i?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:O.isPending,onClick:()=>O.mutate(!i.enabled),className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-muted-foreground hover:bg-secondary hover:text-foreground disabled:opacity-50",children:[e.jsx(me,{className:"h-3.5 w-3.5","aria-hidden":!0}),i.enabled?"Pause":"Resume"]}),e.jsxs("button",{type:"button",disabled:U.isPending,onClick:()=>{window.confirm(`Delete the profile for ${c??"this organization"}? The filled values are not recoverable.`)&&U.mutate()},className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-muted-foreground hover:bg-destructive/10 hover:text-destructive disabled:opacity-50",children:[e.jsx(Y,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Delete"]})]}):null]}),e.jsxs("button",{type:"button",disabled:I.isPending||!u,onClick:()=>{h(null),I.mutate()},className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50",children:[I.isPending?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}):e.jsx(Z,{className:"h-3.5 w-3.5","aria-hidden":!0}),i?"Save profile":"Create profile"]})]}),S?e.jsx(Ce,{orgId:t}):null]})]})}function Ce({orgId:t}){const{data:c,isPending:d,isError:n,error:m}=E(T(b.customerProfiles.previewBlockForOrg,{orgId:t}));return e.jsxs("section",{className:"space-y-2 rounded-md border border-border bg-background p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-foreground",children:"Profile block sent to the agent"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"reflects the SAVED profile, not unsaved edits"})]}),d?e.jsx("div",{className:"h-24 animate-pulse rounded bg-secondary","aria-hidden":!0}):n?e.jsx("p",{className:"text-xs text-destructive",children:k(m)}):c==null?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Nothing is sent. The agent treats a member of this organization exactly as it treats an anonymous visitor."}):e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words rounded bg-secondary/60 p-3 font-mono text-[11px] leading-relaxed text-foreground",children:c}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[c.length.toLocaleStr
1ing()," characters. The live block also names the signed-in customer; this preview has no conversation, so it cannot."]})]})]})}const Ee=[{id:"profiles",label:"Organizations",icon:xe},{id:"templates",label:"Templates",icon:be}];function Ue(){const{tab:t}=G.useSearch(),{isSuperAdmin:c}=G.useLoaderData();return c?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("header",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10",children:e.jsx(ue,{className:"h-5 w-5 text-primary","aria-hidden":!0})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-lg font-semibold text-foreground",children:"Customer Profiles"}),e.jsx("p",{className:"mt-0.5 max-w-3xl text-sm text-muted-foreground",children:"What the Front Desk knows about a signed-in customer before they type a word. A profile is delivered on a separate system-role channel at model-call time — it never travels as a message, and nothing said in a conversation can change it."})]})]}),e.jsx("nav",{className:"flex gap-1 border-b border-border","aria-label":"Customer profile tabs",children:Ee.map(d=>{const n=t===d.id;return e.jsxs(K,{to:"/dashboard/admin/customer-profiles",search:{tab:d.id},className:y("flex items-center gap-2 border-b-2 -mb-px px-4 py-2.5 text-sm font-medium transition-colors",n?"border-primary text-primary":"border-transparent text-muted-foreground hover:border-border hover:text-foreground"),children:[e.jsx(d.icon,{className:"h-4 w-4","aria-hidden":!0}),d.label]},d.id)})}),t==="templates"?e.jsx(we,{}):e.jsx(Pe,{})]}):e.jsxs("div",{className:"mx-auto max-w-lg rounded-lg border border-border bg-card p-6 text-center",children:[e.jsx("h1",{className:"text-base font-semibold text-foreground",children:"Super-admin only"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"A customer profile decides what the Front Desk agent is told about an organization before its members type a word, and a template is a platform-level row with no tenant. Both are restricted to Karigor super-admins."}),e.jsx(K,{to:"/dashboard/admin",className:"mt-4 inline-block rounded-md border border-border px-3 py-1.5 text-xs text-foreground hover:bg-secondary",children:"Back to admin overview"})]})}export{Ue as component};

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.