1import{r as a,j as e}from"./entry-BCe1jibU.js";import{e as L,g4 as re,g5 as ae,g6 as ne,g7 as le,g8 as oe,g9 as ie,ga as de,gb as ce,gc as me,gd as ue,ge as pe,gf as ge,gg as xe}from"./graphql-4Y3Cu4kt.js";import{a as he}from"./pathPrefix-DU8I2oCO.js";import{u as Ce}from"./files-O0AlKPtA.js";import{w as H,P as B,t as ye,N as fe,x as je,T as K,v as W,X as be}from"./icons-B6i7AQrN.js";import{s as D}from"./toast-Blm9fZ-n.js";import{A as O}from"./adminLayout-OU-AekOj.js";import{A as V}from"./adminTable-LC-gvNan.js";import{e as _,a as X,i as ve,v as Ne,b as ke,c as we}from"./helpers-Dec8kFOQ.js";import{u as J,g as z,T as w,E as q,P as Ae,F as A,b as Se,d as U,S as De}from"./shared-iYkel3Mz.js";import{A as Z,a as F,c as y,d as R}from"./adminView-DkbsldBq.js";import"./types-CjJu7saM.js";import"./NativeButton-DgYgvC9L.js";import"./buttonStyles-DgzPUjES.js";import"./bundle-mjs-CSqCgoPn.js";import"./index-pNUg2pyP.js";import"./Scrollable-BvCr7Sb1.js";import"./XMarkIcon-CqPeZFAz.js";import"./InformationCircleIcon-DCmSqGbl.js";import"./auth-CgkXDIO7.js";import"./EvalCloneMarker-DeoTUGFR.js";import"./operations-Dn0xY-u2.js";import"./session-C75oaowB.js";import"./identity-X0DTFeA9.js";import"./Identity-QN8NXWkM.js";import"./billing-XWNTP5pu.js";import"./speechToText-BOPKEWM6.js";import"./types-CLw4uLQj.js";import"./shellCache-Br8NUPQk.js";function M(s){if(s.data)return s.data;throw new Error(Se(s)??"The mutation failed")}function Y(s){return s&&"message"in s&&typeof s.message=="string"?s.message:void 0}function ee(s){return s==null?null:String(s)}function Pe(s){return s==null?"":String(s)}function te(s,g){const c=URL.createObjectURL(new Blob([s],{type:"text/csv"})),u=document.createElement("a");u.href=c,u.download=g,u.click(),URL.revokeObjectURL(c)}function Ee(s){return{...s,createdAt:ee(s.createdAt),expiresAt:ee(s.expiresAt),redemptionLink:Pe(s.redemptionLink)}}const Le=re,Ie=ce,Me=ae,Te=me,ze=ne;function Ue({expiresAt:s}){const g=X(s),c={active:"Active",expired:"Expired","expiring-soon":"Expiring soon","no-expiry":"No expiry"},u={active:"bg-success-3 text-success-11",expired:"bg-danger-3 text-danger-11","expiring-soon":"bg-warning-3 text-warning-11","no-expiry":"bg-slate-3 text-slate-11"};return e.jsx("span",{className:`rounded-full px-2 py-0.5 text-xs font-medium ${u[g]}`,children:c[g]})}function At(){const[s,g]=a.useState("promo"),[c,u]=a.useState(""),[l,o]=a.useState(null),[j,p]=a.useState(!1),N=a.useCallback(()=>L(Le),[]),{data:r,error:h,loading:x,reload:k,setData:S}=J(N),n=r?.allPromoCodes.__typename==="QueryAllPromoCodesSuccess"?r.allPromoCodes.data:null,i=r?.legacySignupCodes.__typename==="QueryLegacySignupCodesSuccess"?r.legacySignupCodes.data:null,P=r?.allPromoCodes.__typename==="QueryAllPromoCodesSuccess"?void 0:Y(r?.allPromoCodes),b=r?.legacySignupCodes.__typename==="QueryLegacySignupCodesSuccess"?void 0:Y(r?.legacySignupCodes),v=a.useMemo(()=>(n?.promoCodes??[]).map(Ee).filter(t=>t.code.toLowerCase().includes(c.toLowerCase())),[n?.promoCodes,c]),E=a.useMemo(()=>(i?.codes??[]).filter(t=>t.code.toLowerCase().includes(c.toLowerCase())),[i?.codes,c]),f=a.useMemo(()=>new Map((i?.redemptionCounts??[]).map(t=>[t.code,t.count])),[i?.redemptionCounts]),C=a.useCallback(async()=>{if(!(!l||l.kind!=="expire"&&l.kind!=="remove")){p(!0);try{if(l.kind==="expire"){const t=await L(Me,{input:{id:l.id}}),m=M(t.expirePromoCode).promoCode;S(d=>!d||d.allPromoCodes.__typename!=="QueryAllPromoCodesSuccess"?d:{...d,allPromoCodes:{...d.allPromoCodes,data:{promoCodes:d.allPromoCodes.data.promoCodes.map(Q=>Q.id===m.id?{...Q,expiresAt:m.expiresAt}:Q)}}}),D({label:`Expired "${l.code}"`,level:"success"})}else{const t=await L(ze,{input:{code:l.code}}),m=M(t.removeLegacySignupCode);S(d=>d&&{...d,legacySignupCodes:{__typename:"QueryLegacySignupCodesSuccess",data:m}}),D({label:`Removed "${l.code}"`,level:"success"})}o(null)}catch(t){D({label:z(t),level:"danger"})}finally{p(!1)}}},[l,S]),I=a.useCallback(()=>{const t=["Code","Discount","Duration","Status","Created","Expires","Owner","Redemption Link"],m=v.map(d=>[_(d.code),d.discountPercentage!=null?`${Math.round(d.discountPercentage*100)}%`:"",d.durationInMonths!=null?`${d.durationInMonths} months`:"",X(d.expiresAt),d.createdAt?new Date(d.createdAt).toLocaleDateString():"",d.expiresAt?new Date(d.expiresAt).toLocaleDateString():"",_(d.owner?.name??d.owner?.email??""),d.redemptionLink]);te([t,...m].map(d=>d.join(",")).join(` 2`),`promo-codes-${new Date().toISOString().slice(0,10)}.csv`)},[v]),T=a.useCallback(()=>{const t=["Code","Credits/cycle","$/cycle","Expiry Days","Redemptions","Created By","Created At","Signup Link"],m=E.map(d=>[_(d.code),String(d.creditsPerBillingCycle),d.dollarAmountPerBillingCycle,d.expiryInDays!=null?String(d.expiryInDays):"",String(f.get(d.code)??0),_(d.createdBy??""),d.createdAt?new Date(d.createdAt).toLocaleDateString():"",`${window.location.origin}/signup?lindy_signup_code=${d.code}`]);te([t,...m].map(d=>d.join(",")).join(` 3`),`legacy-codes-${new Date().toISOString().slice(0,10)}.csv`)},[E,f]);if(x)return e.jsx(Z,{});if(h)return e.jsx(F,{message:h});if(P||b)return e.jsx(F,{message:P??b??"Unable to load promo codes"});const $=[{header:"Code",key:"code",render:t=>t.code,sorter:(t,m)=>t.code.localeCompare(m.code)},{header:"Discount",key:"discount",render:t=>t.discountPercentage==null?"â":`${Math.round(t.discountPercentage*100)}%`,sorter:(t,m)=>(t.discountPercentage??0)-(m.discountPercentage??0)},{header:"Duration",key:"duration",render:t=>t.durationInMonths==null?"â":`${t.durationInMonths}mo`,sorter:(t,m)=>(t.durationInMonths??0)-(m.durationInMonths??0)},{header:"Created",key:"created",render:t=>t.createdAt?new Date(t.createdAt).toLocaleDateString():"â",sorter:(t,m)=>(t.createdAt??"").localeCompare(m.createdAt??"")},{header:"Status",key:"status",render:t=>e.jsx(Ue,{expiresAt:t.expiresAt})},{header:"Expires",key:"expires",render:t=>t.expiresAt?new Date(t.expiresAt).toLocaleDateString():"â",sorter:(t,m)=>(t.expiresAt??"z").localeCompare(m.expiresAt??"z")},{header:"Owner",key:"owner",render:t=>t.owner?.name??t.owner?.email??"â",sorter:(t,m)=>(t.owner?.name??t.owner?.email??"").localeCompare(m.owner?.name??m.owner?.email??"")},{header:"Link",key:"redemption-link",render:t=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("code",{className:"max-w-[180px] truncate text-xs text-slate-11",children:t.redemptionLink.replace(/^https?:\/\//,"")}),e.jsx("button",{"aria-label":`Copy ${t.code} redemption link`,onClick:()=>
3{navigator.clipboard.writeText(t.redemptionLink),D({id:"copy-link",label:"Link copied",level:"success"})},type:"button",children:e.jsx(W,{className:"size-3.5"})})]})},{header:"",key:"expire",render:t=>X(t.expiresAt)==="expired"?null:e.jsx(y,{"aria-label":`Expire ${t.code}`,className:"border border-red-8 bg-transparent px-2 text-red-11 hover:bg-red-3",level:"outline",onClick:()=>o({code:t.code,id:t.databaseId,kind:"expire"}),size:"sm",children:e.jsx(K,{className:"size-4"})})}],G=[{header:"Code",key:"code",render:t=>t.code,sorter:(t,m)=>t.code.localeCompare(m.code)},{header:"Credits/cycle",key:"credits-per-cycle",render:t=>t.creditsPerBillingCycle.toLocaleString(),sorter:(t,m)=>t.creditsPerBillingCycle-m.creditsPerBillingCycle},{header:"$/cycle",key:"dollars-per-cycle",render:t=>`$${t.dollarAmountPerBillingCycle}`,sorter:(t,m)=>Number(t.dollarAmountPerBillingCycle)-Number(m.dollarAmountPerBillingCycle)},{header:"Expiry",key:"expiry-days",render:t=>t.expiryInDays!=null?`${t.expiryInDays} days`:e.jsx("span",{className:"rounded-full bg-slate-3 px-2 py-0.5 text-xs font-medium text-slate-11",children:"Permanent"}),sorter:(t,m)=>(t.expiryInDays??Number.MAX_SAFE_INTEGER)-(m.expiryInDays??Number.MAX_SAFE_INTEGER)},{header:"Redemptions",key:"redemptions",render:t=>f.get(t.code)??0,sorter:(t,m)=>(f.get(t.code)??0)-(f.get(m.code)??0)},{header:"Created",key:"created",render:t=>e.jsxs("span",{className:"text-slate-11",children:[t.createdBy?e.jsx("span",{title:t.createdBy,children:t.createdBy.split("@")[0]}):null,t.createdAt?e.jsx("span",{className:"ml-1 text-xs",children:new Date(t.createdAt).toLocaleDateString()}):null,!t.createdBy&&!t.createdAt?"â":null]}),sorter:(t,m)=>(t.createdAt??"").localeCompare(m.createdAt??"")},{header:"Link",key:"link",render:t=>{const m=`${window.location.origin}/signup?lindy_signup_code=${t.code}`;return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("code",{className:"max-w-[160px] truncate text-xs text-slate-11",children:m.replace(/^https?:\/\//,"")}),e.jsx("button",{"aria-label":`Copy ${t.code} signup link`,onClick:()=>{navigator.clipboard.writeText(m),D({id:"copy-link",label:"Link copied",level:"success"})},type:"button",children:e.jsx(W,{className:"size-3.5"})})]})}},{header:"",key:"remove",render:t=>e.jsx(y,{"aria-label":`Remove ${t.code}`,className:"border border-red-8 bg-transparent px-2 text-red-11 hover:bg-red-3",level:"outline",onClick:()=>o({code:t.code,kind:"remove"}),size:"sm",children:e.jsx(K,{className:"size-4"})})}];return e.jsxs(O,{title:"Promo Codes",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(w,{className:"max-w-xs",onChange:t=>u(t.target.value),placeholder:"Search codes...",value:c}),e.jsxs("div",{className:"flex w-fit rounded-md border border-slate-6 p-1",children:[e.jsxs("button",{className:`rounded px-3 py-1.5 text-sm ${s==="promo"?"bg-slate-4 font-medium":""}`,onClick:()=>g("promo"),children:["Promo Codes (",v.length,")"]}),e.jsxs("button",{className:`rounded px-3 py-1.5 text-sm ${s==="legacy"?"bg-slate-4 font-medium":""}`,onClick:()=>g("legacy"),children:["Legacy Codes (",E.length,")"]})]}),s==="promo"?e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(y,{level:"outline",size:"sm",onClick:I,children:[e.jsx(H,{className:"size-4"}),"Export CSV"]}),e.jsxs(y,{onClick:()=>o({kind:"create"}),children:[e.jsx(B,{className:"size-4"}),"Create promo code"]})]}),v.length?e.jsx("div",{className:"overflow-x-auto rounded-lg border border-edge",children:e.jsx(V,{columns:$,data:v,rowKey:t=>t.id})}):e.jsx(q,{children:"No promo codes found"})]}):e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(y,{level:"outline",size:"sm",onClick:T,children:[e.jsx(H,{className:"size-4"}),"Export CSV"]}),e.jsxs(y,{onClick:()=>o({kind:"legacy"}),children:[e.jsx(B,{className:"size-4"}),"Add legacy code"]})]}),E.length?e.jsx("div",{className:"overflow-x-auto rounded-lg border border-edge",children:e.jsx(V,{columns:G,data:E,rowKey:t=>t.code})}):e.jsx(q,{children:"No legacy codes found"}),i?.updatedBy?e.jsxs("p",{className:"text-sm text-slate-11",children:["Last modified by ",i.updatedBy,i.updatedAt?` on ${new Date(i.updatedAt).toLocaleDateString()}`:""]}):null]})]}),e.jsx(R,{onClose:()=>o(null),open:l?.kind==="create",title:"Create promo code",children:e.jsx($e,{identityId:r?.me?.id??"",onCancel:()=>o(null),onCreated:()=>{o(null),k()}})}),e.jsx(R,{onClose:()=>o(null),open:l?.kind==="legacy",title:"Add legacy signup code",children:e.jsx(Re,{onCancel:()=>o(null),onCreated:()=>{o(null),k()}})}),e.jsxs(R,{onClose:()=>o(null),open:l?.kind==="expire"||l?.kind==="remove",title:l?.kind==="expire"?"Expire promo code":"Remove legacy code",children:[e.jsx("p",{className:"text-sm text-slate-11",children:l?.kind==="expire"?`Expire "${l.code}"? Users will no longer be able to redeem it.`:l?.kind==="remove"?`Remove "${l.code}"? This cannot be undone.`:null}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx(y,{level:"gray",onClick:()=>o(null),children:"Cancel"}),e.jsx(y,{disabled:j,level:"danger",onClick:C,children:"Confirm"})]})]})]})}
3function $e({identityId:s,onCancel:g,onCreated:c}){const[u,l]=a.useState(""),[o,j]=a.useState(""),[p,N]=a.useState(""),[r,h]=a.useState(""),[x,k]=a.useState(null),[S,n]=a.useState(!1),[i,P]=a.useState(!1),b=a.useCallback(async()=>{P(!0);try{const v=await L(Ie,{input:{code:u.toUpperCase(),discountPercentage:Number(o)/100,durationInMonths:Number(p),expiresAt:r?`${r}T23:59:59.999Z`:null,identityId:s}}),E=M(v.createPromoCode).promoCode;D({label:`Created promo code "${E.code}"`,level:"success"}),c()}catch(v){n(!1),k(z(v))}finally{P(!1)}},[u,o,p,r,s,c]);return S?e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-slate-6 bg-slate-2 p-4 text-sm",children:["Creating code ",e.jsx("strong",{children:u.toUpperCase()}),": ",o,"% off for"," ",p," month",Number(p)!==1?"s":"",".",r?` Expires ${new Date(`${r}T00:00:00`).toLocaleDateString()}.`:" No expiration."]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(y,{level:"gray",onClick:()=>n(!1),children:"Go back"}),e.jsx(y,{disabled:i,onClick:b,children:i?"Creating...":"Confirm and create"})]})]}):e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(A,{label:"Code",children:e.jsx(w,{id:"promo-code",onChange:v=>l(v.target.value.toUpperCase()),placeholder:"ACME_PARTNER",value:u})}),e.jsx(A,{label:"Discount %",children:e.jsx(w,{id:"promo-discount",max:100,min:1,onChange:v=>j(v.target.value),placeholder:"20",type:"number",value:o})}),e.jsx(A,{label:"Duration (months)",children:e.jsx(w,{id:"promo-duration",max:12,min:1,onChange:v=>N(v.target.value),placeholder:"3",type:"number",value:p})}),e.jsx(A,{label:"Expires at (optional)",children:e.jsx(w,{id:"promo-expires",onChange:v=>h(v.target.value),type:"date",value:r})}),x?e.jsx(U,{children:x}):null,e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(y,{level:"gray",onClick:g,children:"Cancel"}),e.jsx(y,{onClick:()=>{const v=Ne({code:u,discount:o,duration:p});k(v),v||n(!0)},children:"Review"})]})]})}function Re({onCancel:s,onCreated:g}){const[c,u]=a.useState(""),[l,o]=a.useState(""),[j,p]=a.useState(""),[N,r]=a.useState(""),[h,x]=a.useState(null),[k,S]=a.useState(!1),[n,i]=a.useState(!1),P=a.useCallback(async()=>{i(!0);try{const b=await L(Te,{input:{code:c.trim(),creditsPerBillingCycle:Number(l),dollarAmountPerBillingCycle:Number(j).toFixed(2),expiryInDays:N?Number(N):null}});M(b.addLegacySignupCode),D({label:`Added legacy code "${c}"`,level:"success"}),g()}catch(b){S(!1),x(z(b))}finally{i(!1)}},[c,l,j,N,g]);return k?e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-slate-6 bg-slate-2 p-4 text-sm",children:["Creating code ",e.jsx("strong",{children:c.trim()}),": ",Number(l).toLocaleString()," ","credits/cycle at $",Number(j).toFixed(2),"/cycle.",N?` Expires after ${N} days.`:" No expiration (permanent)."]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(y,{level:"gray",onClick:()=>S(!1),children:"Go back"}),e.jsx(y,{disabled:n,onClick:P,children:n?"Adding...":"Confirm and add"})]})]}):e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(A,{label:"Code",children:e.jsx(w,{id:"legacy-code",onChange:b=>u(b.target.value),placeholder:"ENTERPRISE_DEMO",value:c})}),e.jsx(A,{label:"Credits per billing cycle",children:e.jsx(w,{id:"legacy-credits",min:0,onChange:b=>o(b.target.value),placeholder:"200000",type:"number",value:l})}),e.jsx(A,{label:"Price per billing cycle (USD)",children:e.jsx(w,{id:"legacy-dollar",onChange:b=>p(b.target.value),placeholder:"149.00",value:j})}),e.jsx(A,{label:"Expiry in days (optional)",children:e.jsx(w,{id:"legacy-expiry",min:1,onChange:b=>r(b.target.value),placeholder:"90",type:"number",value:N})}),h?e.jsx(U,{children:h}):null,e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(y,{level:"gray",onClick:s,children:"Cancel"}),e.jsx(y,{onClick:()=>{const b=ke({code:c,credits:l,dollarAmount:j,expiryDays:N});x(b),b||S(!0)},children:"Review"})]})]})}const _e=le;function St(){const[s,g]=a.useState(""),[c,u]=a.useState(""),[l,o]=a.useState(""),[j,p]=a.use
3State(!1),N=a.useCallback(async()=>{p(!0);try{const r=await L(_e,{input:{identityEmail:s,messagingServiceSid:c,phoneNumberOrSid:l}});M(r.migrateTwilioSMSMessagingService),D({label:"Messaging service migrated successfully",level:"success"})}catch(r){D({label:z(r),level:"danger"})}finally{p(!1)}},[l,c,s]);return e.jsx(O,{title:"Migrate user messaging service",children:e.jsxs(Ae,{className:"mx-auto my-16 w-full max-w-xl",children:[e.jsxs("div",{children:["This will migrate all SMS Twilio triggers using this phone number to the new messaging service input below. This is a potentially destructive action, but it should not affect existing integrations running for other phone numbers currently assigned to the messaging service.",e.jsx("br",{}),"This will:",e.jsx("br",{}),e.jsxs("ol",{children:[e.jsx("li",{children:"Remove the phone number from any other messaging service it was bound to."}),e.jsxs("li",{children:["Update the phone number SMS webhook configuration to point to our webhook:",e.jsx("pre",{className:"rounded-md bg-slate-2 p-2",children:"https://api.lindy.ai/api/webhooks/twilio/messagingService"}),"Notice, usually we do not even need to do this, as we do that every time the agent trigger is modified."]}),e.jsx("li",{children:"Change the messaging service configuration to always use the inbound webhook on the phone number."}),e.jsx("li",{children:"If there are other phone numbers assigned to the messaging service, update their SMS webhook configuration to point to the previous webhook configuration set on the messaging service."}),e.jsx("li",{children:"Replace the triggers configuration for all SMS triggers using that phone number to point to the new messaging service."})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(A,{description:"The email of the user on Lindy",label:"User email",children:e.jsx(w,{onChange:r=>g(r.target.value),value:s})}),e.jsx(A,{description:"The SID of the Messaging Service to migrate, this starts with MG",label:"Messaging Service SID",children:e.jsx(w,{onChange:r=>u(r.target.value),value:c})}),e.jsx(A,{description:"The phone number or SID of the phone number to migrate",label:"Phone Number or SID",children:e.jsx(w,{onChange:r=>o(r.target.value),value:l})}),e.jsx(y,{disabled:!s||!c||!l,loading:j,onClick:N,children:"Migrate"})]})]})})}function se(s){return{agentDescription:s.agentDescription??"",displayName:s.displayName??"",key:s.key,userDescription:s.userDescription??""}}function Be(s){return{...se(s),fields:s.fields?.map(se)??[],id:s.id,tool:s.tool,version:s.version}}const Fe=oe,Oe=pe,Ge=ue;function Dt(){const[s,g]=a.useState(null),[c,u]=a.useState([]),[l,o]=a.useState(null),j=a.useCallback(()=>L(Fe,{count:10,cursor:s}),[s]),{data:p,error:N,loading:r,reload:h}=J(j),x=a.useMemo(()=>(p?.actionTriggerCustomizations.edges??[]).map(n=>n?.node).filter(ve).map(Be),[p?.actionTriggerCustomizations.edges]),k=s?c.concat(x):x,S=[{header:"Tool",key:"tool",render:n=>n.tool,sorter:(n,i)=>n.tool.localeCompare(i.tool)},{header:"Action or Trigger name",key:"key",render:n=>n.key,sorter:(n,i)=>n.key.localeCompare(i.key)},{header:"Display name",key:"display-name",render:n=>n.displayName,sorter:(n,i)=>n.displayName.localeCompare(i.displayName)},{header:"User description",key:"user-description",render:n=>n.userDescription,sorter:(n,i)=>n.userDescription.localeCompare(i.userDescription)},{header:"Agent description",key:"agent-description",render:n=>n.agentDescription,sorter:(n,i)=>n.agentDescription.localeCompare(i.agentDescription)},{header:"Customized fields",key:"customized-fields",render:n=>n.fields.length,sorter:(n,i)=>n.fields.length-i.fields.length},{header:"Version",key:"version",render:n=>n.version,sorter:(n,i)=>n.version-i.version},{header:"Actions",key:"actions",render:n=>e.jsx(y,{level:"outline",onClick:()=>o(n),size:"sm",children:"Edit"})}];return r&&k.length===0?e.jsx(Z,{}):N?e.jsx(F,{message:N}):e.jsxs(O,{title:"Customizations",children:[e.jsxs("div",{className:"flex w-full flex-col px-4 sm:px-10",children:[e.jsxs("div",{className:"mb-4 flex items-center text-sm text-slate-10",children:[e.jsx(ye,{className:"mr-2 size-5 shrink-0"}),"Changes to triggers/actions apply globally to",e.jsx("span",{className:"ml-1 font-bold",children:"all agents and customers"}),". Double-check before proceeding."]}),e.jsx("div",{className:"mb-4 flex justify-end",children:e.jsx(y,{onClick:()=>o("create"),children:"New customization"})}),k.length?e.jsx(V,{columns:S,data:k,rowKey:n=>n.id}
3):e.jsx(q,{children:"No customizations found."}),p?.actionTriggerCustomizations.pageInfo.hasNextPage?e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx(y,{level:"outline",loading:r,onClick:()=>{u(k),g(p.actionTriggerCustomizations.pageInfo.endCursor)},children:"Load More"})}):null]}),e.jsx(R,{onClose:()=>o(null),open:!!l,title:l==="create"?"Create customization":"Edit customization",children:l?e.jsx(Qe,{customization:l==="create"?null:l,onCancel:()=>o(null),onSaved:()=>{o(null),u([]),g(null),h()}}):null})]})}function Qe({customization:s,onCancel:g,onSaved:c}){const[u,l]=a.useState(s?.tool??""),[o,j]=a.useState("trigger"),[p,N]=a.useState(s?.key??""),[r,h]=a.useState(s?.displayName??""),[x,k]=a.useState(s?.userDescription??""),[S,n]=a.useState(s?.agentDescription??""),[i,P]=a.useState(s?.fields??[]),[b,v]=a.useState(!1),E=a.useCallback(async f=>{if(f.preventDefault(),!(!u||!p)){v(!0);try{if(s){const C=await L(Ge,{input:{agentDescription:S,displayName:r,fields:i,id:s.id,userDescription:x}});M(C.editActionTriggerCustomization)}else{const C=await L(Oe,{input:{agentDescription:S,displayName:r,fields:i,key:p,tool:u,type:o,userDescription:x}});M(C.createActionTriggerCustomization)}D({label:"Customization saved",level:"success"}),c()}catch(C){D({label:z(C),level:"danger"})}finally{v(!1)}}},[S,s,r,i,p,c,u,o,x]);return e.jsxs("form",{className:"flex max-h-[70vh] flex-col gap-4 overflow-auto",onSubmit:E,children:[e.jsx(A,{label:"Tool",children:e.jsx(w,{disabled:!!s,onChange:f=>l(f.target.value),required:!0,value:u})}),s?null:e.jsx(A,{label:"Type",children:e.jsxs(De,{id:"type",name:"type",onChange:f=>j(f.target.value),required:!0,value:o,children:[e.jsx("option",{value:"trigger",children:"Trigger"}),e.jsx("option",{value:"action",children:"Action"})]})}),e.jsx(A,{label:"Name of the Trigger / Action",children:e.jsx(w,{disabled:!!s,onChange:f=>N(f.target.value),required:!0,value:p})}),e.jsx(A,{label:"DisplayName",children:e.jsx(w,{onChange:f=>h(f.target.value),value:r})}),e.jsx(A,{label:"User description",children:e.jsx(w,{onChange:f=>k(f.target.value),value:x})}),e.jsx(A,{label:"Agent description",children:e.jsx(w,{onChange:f=>n(f.target.value),value:S})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-medium",children:"Fields"}),e.jsx(y,{level:"outline",onClick:()=>P(f=>[...f,{agentDescription:"",displayName:"",key:"",userDescription:""}]),size:"sm",type:"button",children:"Add field"})]}),i.map((f,C)=>e.jsxs("details",{className:"rounded-md border border-slate-6 p-3",children:[e.jsx("summary",{className:"cursor-pointer font-medium",children:f.displayName||f.key||`Field ${C+1}`}),e.jsxs("div",{className:"mt-3 grid gap-3",children:[[["key","Key"],["displayName","Display name"],["userDescription","User description"],["agentDescription","Agent description"]].map(([I,T])=>e.jsx(A,{label:T,children:e.jsx(w,{onChange:$=>P(G=>G.map((t,m)=>m===C?{...t,[I]:$.target.value}:t)),value:f[I]})},I)),e.jsx(y,{level:"danger",onClick:()=>P(I=>I.filter((T,$)=>$!==C)),size:"sm",type:"button",children:"Remove field"})]})]},C))]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(y,{level:"gray",onClick:g,type:"button",children:"Cancel"}),e.jsx(y,{disabled:b,type:"submit",children:b?"Saving...":s?"Save changes":"Customize"})]})]})}const Ke=ie,Ve=xe,Xe=ge,qe=de;function Pt(){const[s,g]=a.useState(null),c=a.useCallback(()=>L(Ke),[]),{data:u,error:l,loading:o,setData:j}=J(c),p=u?.allInAppPromoCards.inAppPromoCards??[],N=a.useCallback(async r=>{if(window.confirm("Are you sure you want to delete this promo card?"))try{const h=await L(qe,{input:{id:r}});M(h.deleteInAppPromoCard),j(x=>x&&{allInAppPromoCards:{inAppPromoCards:x.allInAppPromoCards.inAppPromoCards.filter(k=>k.id!==r)}})}catch(h){D({label:z(h),level:"danger"})}},[j]);return o?e.jsx(Z,{}):l?e.jsx(F,{message:l}):e.jsxs(O,{title:"In-app Promo Cards",children:[e.jsxs("div",{className:"flex size-full flex-col gap-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-slate-12",children:"In-App Promo Cards"}),e.jsx("p",{className:"mt-1 text-sm text-slate-11",children:"Manage promotional cards shown to users. Drag to reorder."})]}),p.length>0?e.jsxs(y,{onClick:()=>g("create"),children:[e.jsx(B,{className:"h-5 w-5"}),"Add Card"]}):null]}),p.length===0?e.jsx("div",{className:"flex min-h-[400px] items-center justify-center rounded-lg border-2 border-dashed border-slate-5 bg-slate-1 p-8",children:e.jsxs("div",{className:"flex max-w-md flex-col items-center text-center",children:[e.jsx("div",{className:"mb-4 rounded-full bg-slate-3 p-4",children:e.jsx(fe,{className:"h-12 w-12 text-slate-9"})}),e.jsx("h3",{className:"mb-2 text-lg font-semibold text-slate-12",children:"No promo cards yet"}),e.jsx("p",{className:"mb-6 text-sm text-slate-11",children:"Get started by creating your first promotional card. Cards will be displayed to users in the order you specify."}),e.jsxs(y,{onClick:()=>g("create"),children:[e.jsx(B,{className:"h-5 w-5"}),"Create First Card"]})]})}):e.jsx("div",{className:"grid gap-4 xs:grid-cols-1 lg:grid-cols-7",children:p.toSorted((r,h)=>(r.order??Number.MAX_SAFE_INTEGER)-(h.order??Number.MAX_SAFE_INTEGER)).map(r=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"text-sm text-slate-11",children:["Order: ",r.order??"N/A"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{"aria-label":"Edit card",level:"outline",onClick:()=>g(r),size:"sm",children:[e.jsx(je,{className:"h-4 w-4"}),"Edit"]}),e.jsxs(y,{"aria-label":"Delete card",level:"danger",onClick:()=>N(r.id),size:"sm",children:[e.jsx(K,{className:"h-4 w-4"}),"Delete"]})]})]}),e.jsxs("div",{className:"flex w-full flex-col gap-2 overflow-hidden rounded-lg border-1 border-slate-5 bg-white p-2.5 text-slate-12 shadow-sm dark:bg-slate-3",children:[e.jsx("h3",{className:"text-wrap text-sm font-semibold text-slate-12",children:r.title}),r.imageUrl?e.jsx("img",{alt:r.title,className:"aspect-video h-auto w-full rounded-md object-cover shadow-sm",src:r.imageUrl}):null,r.subtitle?e.jsx("p",{className:"text-wrap px-1 text-xs font-medium text-slate-11",children:r.subtitle}):null,r.link?e.jsx("a",{className:"inline-flex h-8 w-fit items-center rounded-md border border-slate-7 px-3 text-sm font-medium text-slate-12 hover:bg-slate-2 hover:text-slate-11",href:r.link.url,rel:"noopener noreferrer",target:"_blank",children:r.link.label}):null]})]},r.id))})]}),e.jsx(R,{onClose:()=>g(null),open:!!s,title:s==="create"?"Create promo card":"Edit promo card",children:s?e.jsx(Ze,{card:s==="create"?null:s,onCancel:()=>g(null),onSaved:r=>
3{j(h=>h?{allInAppPromoCards:{inAppPromoCards:h.allInAppPromoCards.inAppPromoCards.some(k=>k.id===r.id)?h.allInAppPromoCards.inAppPromoCards.map(k=>k.id===r.id?r:k):[...h.allInAppPromoCards.inAppPromoCards,r]}}:{allInAppPromoCards:{inAppPromoCards:[r]}}),g(null)}}):null})]})}function Je({onChange:s,value:g}){const[c,u]=a.useState(!1),[l,o]=a.useState(null),j=a.useCallback(async r=>{if(r){if(!["image/jpeg","image/png"].includes(r.type)){D({label:"Upload a PNG or JPG image",level:"danger"});return}u(!0),o(r.name);try{const h=new FormData;h.append("file",r),h.append("field","promoCardImage");const x=await he.call(Ce,{body:h});if(x.error)throw new Error(z(x.error));if(!x.data)throw new Error("Image upload returned no URL");s(x.data.url)}catch(h){D({label:z(h,"Error uploading promoCardImage"),level:"danger"})}finally{u(!1),o(null)}}},[s]),p=a.useCallback(r=>j(r.target.files?.[0]),[j]),N=a.useCallback(r=>{r.preventDefault(),j(r.dataTransfer.files[0])},[j]);return e.jsx("div",{className:"my-2 w-full",children:e.jsxs("label",{className:`flex h-24 w-full cursor-pointer appearance-none justify-center rounded-md border-2 border-dashed px-4 text-slate-11 transition focus:outline-none hover:border-sky-200 hover:bg-slate-2 hover:text-sky-700 ${c?"border-sky-200 bg-sky-50":"border-slate-6"}`,onDragOver:r=>r.preventDefault(),onDrop:N,children:[e.jsx("div",{className:"flex items-center justify-end space-x-2",children:c?e.jsxs("div",{className:"flex-col items-center space-y-2",children:[e.jsx("div",{className:"mx-auto my-0 size-6 animate-spin rounded-full border-r-2 border-t-2 border-sky-500"}),e.jsx("div",{className:"text-sm font-normal text-sky-700",children:l})]}):g?e.jsxs("div",{className:"group relative",children:[e.jsx("img",{alt:"Uploaded file",className:"size-20 rounded-md object-cover",height:80,src:g,width:80}),e.jsx("button",{"aria-label":"Remove image",className:"absolute right-0 top-0 size-6 cursor-pointer rounded-full border border-slate-4 bg-slate-1 text-slate-9 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100",onClick:r=>{r.preventDefault(),s("")},type:"button",children:e.jsx("span",{className:"flex size-full items-center justify-center",children:e.jsx(be,{className:"size-4"})})})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"text-center text-sm text-slate-11",children:[e.jsx("p",{className:"font-semibold",children:"Click to upload"}),e.jsx("p",{className:"font-normal",children:"or drag and drop"})]}),e.jsx("div",{className:"text-center text-xs font-normal",children:"PNG or JPG (MAX. 1024x1024px)"})]})}),e.jsx("input",{accept:"image/png,image/jpeg",className:"hidden",name:"file-upload",onChange:p,type:"file"})]})})}function Ze({card:s,onCancel:g,onSaved:c}){const[u,l]=a.useState(s?.title??""),[o,j]=a.useState(s?.subtitle??""),[p,N]=a.useState(s?.imageUrl??""),[r,h]=a.useState(s?.link?.label??""),[x,k]=a.useState(s?.link?.url??""),[S,n]=a.useState(s?.order??0),[i,P]=a.useState({}),[b,v]=a.useState(!1),E=a.useCallback(async()=>{const C=we({imageUrl:p,linkLabel:r,linkUrl:x,title:u});if(P(C),Object.keys(C).length)return;v(!0);const I={imageUrl:p.trim()||null,link:r.trim()&&x.trim()?{label:r.trim(),url:x.trim()}:null,order:S,subtitle:o.trim()||null,title:u.trim()};try{const T=s?M((await L(Xe,{input:{id:s.id,...I}})).updateInAppPromoCard).inAppPromoCard:M((await L(Ve,{input:I})).createInAppPromoCard).inAppPromoCard;if(!T)throw new Error("Promo card mutation returned no card");c(T)}catch(T){D({label:z(T),level:"danger"})}finally{v(!1)}},[s,p,r,x,c,S,o,u]),f=a.useCallback(C=>{C.key==="Enter"&&(C.metaKey||C.ctrlKey)&&(C.preventDefault(),E())},[E]);return e.jsxs("div",{className:"flex max-h-[70vh] flex-col gap-4 overflow-y-auto",onKeyDown:f,children:[e.jsx("p",{className:"text-sm text-slate-11",children:s?"Update the details for this promotional card":"Add a new promotional card to display to users"}),e.jsxs(A,{label:"Title",children:[e.jsx(w,{autoFocus:!0,id:"title",onChange:C=>l(C.target.value),placeholder:"Enter card title",value:u}),i.title?e.jsx(U,{children:i.title}):null]}),e.jsx(A,{label:"Subtitle",children:e.jsx(w,{id:"subtitle",onCh
3ange:C=>j(C.target.value),placeholder:"Enter card subtitle (optional)",value:o})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-slate-12",children:"Image (Optional)"}),e.jsx(Je,{onChange:N,value:p}),i.imageUrl?e.jsx(U,{children:i.imageUrl}):null]}),e.jsx(A,{label:"Order",children:e.jsx(w,{id:"order",onChange:C=>n(Number(C.target.value)),type:"number",value:S})}),e.jsxs("div",{className:"border-t border-slate-5 pt-4",children:[e.jsx("p",{className:"mb-3 text-sm font-medium",children:"Link (Optional)"}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx(w,{onChange:C=>h(C.target.value),placeholder:"Link label (e.g., Learn more)",value:r}),i.linkLabel?e.jsx(U,{children:i.linkLabel}):null,e.jsx(w,{onChange:C=>k(C.target.value),placeholder:"https://example.com/page",value:x}),i.linkUrl?e.jsx(U,{children:i.linkUrl}):null]})]}),e.jsxs("div",{className:"flex justify-end gap-3 border-t border-slate-5 pt-4",children:[e.jsx(y,{disabled:b,level:"outline",onClick:g,children:"Cancel"}),e.jsx(y,{disabled:b,onClick:E,children:b?"Saving...":s?"Update card":"Create card"})]})]})}export{Dt as CustomizationsView,Pt as InAppPromoCardsView,At as PromoCodesView,St as TwilioMigrationView};
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.