1import{j as e,ay as N,S as w,ar as ut,T as h,a as H,M as pt,r,ag as Ne,ba as Se,B as Y,ck as ae,D as He,aO as mt,aP as ht,aU as Ge,H as gt,h as ft,k as xt,n as _t,f as we,w as le,b5 as Ce,b as yt,t as Z,x as vt}from"./index-BBY15sAj.js";import{H as bt}from"./Header-ClnXQq65.js";import{u as wt,R as Ct}from"./useSyncSearchParamsPayload-D1Lz934y.js";import{C as jt}from"./ConfirmDeleteModal-Jtn60Tga.js";import{d as St}from"./deepEqualNormalized-VIur5MJC.js";import{a as Pt}from"./intercomOffset-BqOunVEA.js";import{b as Rt,I as Et,T as $,a as ke}from"./TextField-8dAl8v62.js";import{S as ze}from"./Select-BcWdgGSa.js";import{M as je}from"./MenuItem-BqljAD2L.js";import{A as Te}from"./Autocomplete-Dybmme_b.js";import{D as ee,g as At,d as It,u as kt,c as Wt,a as Bt,b as Ut}from"./index-uSzT74J-.js";import{T as Mt}from"./Toolbar-B0_ovqE9.js";import{S as We}from"./Slider-CMrk443i.js";import{F as Be}from"./FormControlLabel-CRof4pPy.js";import{S as Ue}from"./Switch-Cz5SRIXz.js";import{C as Dt}from"./ContentCopy-ZqLo8qtX.js";import{M as Lt}from"./Menu-BmjpnJkl.js";import{g as Ot,K as Ft}from"./getTableMenuPosition-WuTxV5bS.js";import{u as Me}from"./urlQueryBuilder-B7FR08j4.js";import{A as $t}from"./AddOutlined-xp7vmzic.js";import"./Pagination-kJmwjW-c.js";import"./Checkbox-C7OkiWj7.js";import"./SwitchBase-BpCCQgwG.js";import"./useFormControl-D94OB1U5.js";import"./TableRow-Cs4Ck_0d.js";import"./isMuiElement-iu7bEC02.js";import"./isHostComponent-DVu5iVWx.js";import"./Close-Ch4GpVRF.js";import"./appendTeamSlug-DMTfDJv9.js";import"./visuallyHidden-Dan1xhjv.js";var y=(a=>(a.EVERYWHERE="everywhere",a.ONLY_SPECIFIC_PAGES="only_on",a.EXCEPT_PAGES="except_on",a))(y||{});const ye=a=>
1{const n=a.map(l=>l.trim()).filter(Boolean);return Array.from(new Set(n))},ve=a=>{const n=a.map(l=>l.trim().toLowerCase()).filter(Boolean);return Array.from(new Set(n)).sort()},De=a=>{const n=String(a??"").trim();return/^#[0-9A-Fa-f]{6}$/.test(n)?n.toUpperCase():n},Nt=2147483647,ie=a=>{const n=a??0;return n===Nt?0:n},Le="__reengage_modal",Oe="AddWebChatBotModal",Ht=a=>{switch(a){case y.EVERYWHERE:return"Everywhere";case y.ONLY_SPECIFIC_PAGES:return"Only on selected pages";case y.EXCEPT_PAGES:return"Everywhere except selected pages";default:return a}},Gt=({effectiveProfilePictureUrl:a,profilePictureError:n,profilePictureRemoved:l,profilePictureFile:u,profilePictureInputRef:t,onPickProfilePicture:p,onProfilePictureChange:g,onClearSelectedProfilePicture:m,onRemoveProfilePicture:f})=>e.jsx(N,{sx:{p:2},variant:"outlined",children:e.jsxs(w,{direction:"row",spacing:2,alignItems:"center",children:[e.jsx(ut,{src:a||void 0,sx:{width:40,height:40,bgcolor:"grey.300",flexShrink:0}}),e.jsxs(w,{flex:1,minWidth:0,children:[e.jsx(h,{variant:"subtitle2",color:"text.secondary",children:"Bot avatar"}),e.jsx(h,{variant:"body2",color:"text.secondary",children:"Bot avatar image. jpg, png, or webp; max 500 KB."}),n?e.jsx(h,{variant:"body2",color:"error",sx:{mt:.5},children:n}):null,l?e.jsx(h,{variant:"body2",color:"text.secondary",sx:{mt:.5},children:"Avatar will be removed after submit."}):null]}),e.jsxs(w,{direction:"row",spacing:1,flexShrink:0,children:[e.jsx("input",{ref:t,type:"file",accept:"image/jpeg,image/png,image/webp",onChange:g,hidden:!0,"aria-label":"Upload bot avatar",title:"Upload bot avatar"}),e.jsx(H,{variant:"outlined",onClick:p,children:"Upload"}),u?e.jsx(H,{variant:"text",onClick:m,children:"Clear"}):null,!u&&a?e.jsx(H,{variant:"text",color:"error",onClick:f,children:"Remove"}):null]})]})}),ce=({title:a})=>e.jsx(h,{variant:"subtitle2",color:"text.primary",fontWeight:600,children:a}),zt=({visibilityMode:a,setVisibilityMode:n,pageUrlPatterns:l,setPageUrlPatterns:u})=>{const t=pt(),p=r.useId(),[g,m]=r.useState(""),[f,S]=r.useState(!1);r.useEffect(()=>{S(a===y.ONLY_SPECIFIC_PAGES||a===y.EXCEPT_PAGES)},[a]);const E=()=>{const d=g.trim();d!==""&&!l.includes(d)&&(u([...l,d]),m(""))},v=(d,b)=>{const A=b.map(C=>C.trim()).filter(Boolean);u(Array.from(new Set(A)))};return e.jsx(N,{sx:{p:2},variant:"outlined",children:e.jsxs(w,{gap:2,children:[e.jsx(ce,{title:"Chat visibility"}),e.jsxs(Rt,{size:"small",fullWidth:!0,children:[e.jsx(Et,{id:p,children:"Display chat"}),e.jsx(ze,{labelId:p,value:a,label:"Display chat",onChange:d=>n(d.target.value),children:Object.values(y).map(d=>e.jsx(je,{value:d,children:Ht(d)},d))})]}),f&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{multiple:!0,freeSolo:!0,options:[],value:l,onChange:v,onBlur:E,inputValue:g,onInputChange:(d,b)=>m(b),renderTags:(d,b)=>d.map((A,C)=>{const{key:M,...I}=b({index:C});return e.jsx(Ne,{label:A,...I,deleteIcon:e.jsx(Se,{style:{color:t.palette.primary.main},onMouseDown:x=>x.stopPropagation()})},M)}),renderInput:d=>e.jsx($,{...d,size:"small",variant:"outlined",label:"Page patterns",placeholder:"Type and press Enter"})}),e.jsxs(w,{gap:.5,ml:2,children:[e.jsx(h,{variant:"body2",color:"textSecondary",children:"Supports exact paths, * (single segment) and ** (all nested pages)"}),e.jsx(w,{direction:"row",gap:1.5,children:Tt.map(d=>e.jsx(Y,{sx:{bgcolor:"#F3F4F6",p:1,borderRadius:1},children:e.jsx(h,{variant:"body2",color:"textSecondary",children:d})},d))})]})]})]})})},Tt=["/checkout","/products/*","/blogs/**"],Vt=({open:a,onClose:n,onSubmit:l,onGetCode:u,botToEdit:t})=>{const[p,g]=r.useState(""),[m,f]=r.useState([]),[S,E]=r.useState(""),[v,d]=r.useState(""),[b,A]=r.useState(""),[C,M]=r.useState(100),[I,x]=r.useState(!0),[P,G]=r.useState("right-bottom"),[D,K]=r.useState(!1),[k,z]=r.useState("0"),[L,q]=r.useState(ee),[j,i]=r.useState(Fe),[_,W]=r.useState(""),[c,O]=r.useState(y.EVERYWHERE),[B,de]=r.useState([]),[ue,X]=r.useState(null),[R,J]=r.useState(""),[Ye,pe]=r.useState(""),[Ke,T]=r.useState(""),[se,re]=r.useState(!1),[qe,Re]=r.useState(!1),U=r.useRef(null),ne=r.useRef(!1),oe=r.useRef(!1),Q=r.useCallback(()=>{n()},[n]);r.useEffect(()=>{if(!a)return;const s=setTimeout(()=>W(p.trim()||"Chat"),400);return()=>clearTimeout(s)},[a,p]),r.useEffect(()=>a?Pt():void 0,[a]),r.useEffect(()=>{if(a&&t){g(t.name),f(t.allowed_domains??[]),d(t.system_message??""),A(t.first_message??""),M(typeof t.activation_percentage=="number"?Math.max(0,Math.min(100,t.activation_percentage)):100),x(t.is_active??!0),G(t.placement??"right-bottom"),K(t.use_back_button??!1),z(String(t.auto_open_after_seconds??0)),q(t.widget_color??ee),W(t.name||"Chat"),i([ie(t.response_delay_min_ms),ie(t.response_delay_max_ms)]);const s=t.page_visibility_mode??y.EVERYWHERE;O(s),de(s===y.EVERYWHERE?[]:t.page_url_patterns??[]);const o=t.profile_picture_url??"";pe(o&&o.startsWith("/")?`${ae}${o}`:o),X(null),J(""),T(""),re(!1)}else a&&!t&&(g(""),f([]),E(""),d(""),A(""),M(100),x(!0),G("right-bottom"),K(!1),z("0"),q(ee),W("Chat"),i(Fe),O(y.EVERYWHERE),de([]),pe(""),X(null),J(""),T(""),re(!1))},[a,t]),r.useEffect(()=>()=>{R&&URL.revokeObjectURL(R)},[R]);const me=r.useCallback(()=>
1{if(typeof window<"u"&&oe.current){ne.current=!0,Q(),window.history.back();return}Q()},[Q]);r.useEffect(()=>{if(!a||typeof window>"u")return;if(!oe.current){const o=window.history.state,F=o&&typeof o=="object"?{...o,[Le]:Oe}:{[Le]:Oe};window.history.pushState(F,""),oe.current=!0}const s=()=>{if(a){if(ne.current){ne.current=!1;return}Q()}};return window.addEventListener("popstate",s),()=>{window.removeEventListener("popstate",s),oe.current=!1,ne.current=!1}},[a,Q]);const Xe=(s,o)=>{f(o)},Je=(s,o)=>{E(o)},Qe=()=>{const s=S.trim().toLowerCase();s&&!m.includes(s)&&(f(o=>[...o,s]),E(""))},Ze=()=>{const s=typeof window<"u"?window.location.hostname:"",o=ve([...m??[],...s?[s]:[]]),F=c===y.EVERYWHERE?[]:ye(B);return{name:p.trim(),allowed_domains:o,system_message:v.trim(),first_message:b.trim(),activation_percentage:Math.max(0,Math.min(100,C)),is_active:I,placement:P,use_back_button:D,auto_open_after_seconds:parseInt(k,10)||0,widget_color:L,response_delay_min_ms:j[0],response_delay_max_ms:j[1],page_visibility_mode:c,page_url_patterns:F}},he=r.useMemo(()=>{if(!t)return null;const s=t.page_visibility_mode??y.EVERYWHERE;return{name:(t.name??"").trim(),allowed_domains:ve(t.allowed_domains??[]),system_message:(t.system_message??"").trim(),first_message:(t.first_message??"").trim(),activation_percentage:typeof t.activation_percentage=="number"?Math.max(0,Math.min(100,t.activation_percentage)):100,is_active:t.is_active??!0,placement:t.placement??"right-bottom",use_back_button:t.use_back_button??!1,auto_open_after_seconds:parseInt(String(t.auto_open_after_seconds??0),10)||0,widget_color:De(t.widget_color??ee),response_delay_min_ms:ie(t.response_delay_min_ms),response_delay_max_ms:ie(t.response_delay_max_ms),page_visibility_mode:s,page_url_patterns:s===y.EVERYWHERE?[]:ye(t.page_url_patterns??[])}},[t]),Ee=r.useMemo(()=>({name:p.trim(),allowed_domains:ve(m??[]),system_message:v.trim(),first_message:b.trim(),activation_percentage:Math.max(0,Math.min(100,C)),is_active:I,placement:P??"right-bottom",use_back_button:D,auto_open_after_seconds:parseInt(k,10)||0,widget_color:De(L??ee),response_delay_min_ms:j[0],response_delay_max_ms:j[1],page_visibility_mode:c,page_url_patterns:c===y.EVERYWHERE?[]:ye(B)}),[p,m,v,b,C,I,P,D,k,L,j,c,B]),et=r.useMemo(()=>!t||!he?!1:!St(he,Ee),[t,he,Ee]),Ae=!(p.trim().length>0&&m.length>0&&v.trim().length>0)||!!t&&!et&&!ue&&!se,tt=async s=>{if(s.preventDefault(),!Ae){Re(!0);try{await l(Ze(),ue,se),me()}finally{Re(!1)}}},at=()=>{!t||!u||u(t)},st=r.useCallback(s=>{const o=s.target.value;/^\d*$/.test(o)&&z(String(o))},[]),rt=r.useCallback(()=>{let s=parseInt(k,10);isNaN(s)||s<0?s=0:s>300&&(s=300),z(String(s))},[k]),nt=()=>{var s;(s=U.current)==null||s.click()},ot=s=>{var Ie;const o=((Ie=s.target.files)==null?void 0:Ie[0])??null;if(!o)return;const F=500*1024,fe=["image/jpeg","image/png","image/webp"],xe=(o.name||"").toLowerCase(),_e=/\.(jpg|jpeg|png|webp)$/.test(xe),dt=fe.includes(o.type);if(o.size>F||!(dt||_e)){T("Bot avatar image must be JPG, PNG, or WEBP (max 500 KB)."),U.current&&(U.current.value="");return}T(""),re(!1),R&&URL.revokeObjectURL(R),X(o),J(URL.createObjectURL(o))},it=()=>{R&&URL.revokeObjectURL(R),X(null),J(""),T(""),U.current&&(U.current.value="")},lt=()=>{R&&URL.revokeObjectURL(R),X(null),J(""),pe(""),T(""),re(!0),U.current&&(U.current.value="")},ct=(t==null?void 0:t.uuid)??"",ge=R||(se?"":Ye);return e.jsxs(He,{fullScreen:!0,open:a,onClose:me,TransitionComponent:mt,PaperProps:{sx:{height:"100dvh",maxHeight:"100dvh",display:"flex",flexDirection:"column",overflow:"hidden"}},children:[e.jsx(ht,{position:"sticky",sx:{flexShrink:0},children:e.jsxs(Mt,{children:[e.jsx(Ge,{edge:"start",color:"inherit",onClick:me,"aria-label":"close",children:e.jsx(Se,{})}),e.jsx(h,{sx:{ml:2,flex:1},variant:"h6",component:"div",children:t?"Edit webchat agent":"Create webchat agent"})]})}),e.jsxs(w,{direction:"row",sx:{flex:1,minHeight:0,overflow:"hidden"},children:[e.jsxs(w,{component:"form",noValidate:!0,width:"50%",padding:"24px 20px",sx:{minHeight:0,overflowY:"auto",boxSizing:"border-box"},gap:3,children:[e.jsx(N,{sx:{p:2},variant:"outlined",children:e.jsxs(w,{gap:2,children:[e.jsx(ce,{title:"Chat basics"}),e.jsx($,{fullWidth:!0,label:"Chat name *",value:p,onChange:s=>g(s.target.value),placeholder:"e.g., Exit Intent Chat, Cart-Saver Bot"}),e.jsx(Te,{multiple:!0,freeSolo:!0,options:[],value:m,onChange:Xe,inputValue:S,onInputChange:Je,onBlur:Qe,renderTags:(s,o)=>s.map((F,fe)=>{const{key:xe,..._e}=o({index:fe});return e.jsx(Ne,{label:F,..._e},xe)}),renderInput:s=>e.jsx($,{...s,variant:"outlined",label:"Website domains *",placeholder:"Type domain and press Enter (e.g. example.com)"})}),e.jsx($,{fullWidth:!0,label:"Add AI response instructions *",value:v,onCh
1ange:s=>d(s.target.value),placeholder:"e.g., Greet the user and offer help. Keep replies concise and on-brand.",multiline:!0,minRows:4,maxRows:12}),e.jsx($,{fullWidth:!0,label:"First message (shown when chat opens)",value:b,onChange:s=>A(s.target.value),placeholder:"e.g., Hi! How can I help you today?",helperText:"Displayed when the chat opens and there are no messages yet.",multiline:!0,minRows:3,maxRows:10})]})}),e.jsx(zt,{visibilityMode:c,setVisibilityMode:O,pageUrlPatterns:B,setPageUrlPatterns:de}),e.jsx(N,{sx:{p:2},variant:"outlined",children:e.jsxs(w,{gap:2,children:[e.jsx(ce,{title:"Chat design"}),e.jsxs(ze,{size:"small",value:P,onChange:s=>G(s.target.value),displayEmpty:!0,fullWidth:!0,children:[e.jsx(je,{value:"right-bottom",children:"Bottom right"}),e.jsx(je,{value:"left-bottom",children:"Bottom left"})]}),e.jsx($,{size:"small",type:"color",label:"Chat color",value:L,onChange:s=>q(s.target.value),fullWidth:!0,slotProps:{input:{sx:{height:40}}}}),t?e.jsx(Gt,{effectiveProfilePictureUrl:ge,profilePictureError:Ke,profilePictureRemoved:se,profilePictureFile:ue,profilePictureInputRef:U,onPickProfilePicture:nt,onProfilePictureChange:ot,onClearSelectedProfilePicture:it,onRemoveProfilePicture:lt}):null]})}),e.jsx(N,{sx:{p:2},variant:"outlined",children:e.jsxs(w,{gap:2,children:[e.jsx(ce,{title:"Chat behavior"}),e.jsx(N,{sx:{p:2},variant:"outlined",children:e.jsxs(w,{children:[e.jsxs(h,{variant:"body1",color:"text.secondary",sx:{mb:1},children:["Traffic activation: ",C,"%"]}),e.jsx(Y,{sx:{px:"10px"},children:e.jsx(We,{value:C,onChange:(s,o)=>M(o),min:0,max:100,step:1,valueLabelDisplay:"auto",valueLabelFormat:s=>`${s}%`})}),e.jsx(ke,{children:"Controls what percentage of visitors will see the chat. Stable per visitor (same visitor always gets the same yes/no)."})]})}),e.jsx(Be,{control:e.jsx(Ue,{checked:D,onChange:(s,o)=>K(o),color:"primary"}),label:"Open when user hits back button",sx:{maxWidth:"fit-content"}}),e.jsx($,{size:"small",type:"text",label:"Auto-open after (seconds)",value:k,onChange:st,onBlur:rt,helperText:"Set to 0 to disable. Range: 0â300 seconds.",fullWidth:!0}),e.jsx(N,{sx:{p:2},variant:"outlined",children:e.jsxs(w,{children:[e.jsxs(h,{variant:"body1",color:"text.secondary",sx:{mb:1},children:["Delay to response: min = ",j[0]," ms; max = ",j[1]," ms"]}),e.jsx(Y,{sx:{px:"10px"},children:e.jsx(We,{value:j,onChange:(s,o)=>i(o),min:0,max:2e4,step:100,valueLabelDisplay:"auto",valueLabelFormat:s=>`${s} ms`,disableSwap:!0})}),e.jsx(ke,{children:"Set a delay range to make bot responses feel more natural. The actual delay will be randomly chosen between the min and max for each response."})]})}),e.jsx(Be,{control:e.jsx(Ue,{checked:I,onChange:(s,o)=>x(o),color:"primary"}),label:"Active",sx:{maxWidth:"fit-content"}})]})}),e.jsxs(w,{direction:"row",spacing:2,children:[e.jsx(H,{variant:"contained",color:"primary",onClick:tt,disabled:Ae||qe,fullWidth:!0,children:"Submit"}),t?e.jsx(H,{variant:"outlined",color:"primary",onClick:at,fullWidth:!0,children:"Get code"}):null]})]}),e.jsx(Y,{sx:{width:"4px",bgcolor:"#e5eaef",flexShrink:0}}),e.jsxs(Y,{sx:{width:"50%",minHeight:0,position:"relative",display:"flex",flexDirection:"column",bgcolor:"grey.100",p:2},children:[e.jsx(h,{variant:"subtitle2",color:"text.secondary",sx:{mb:1},children:"Your website preview"}),e.jsx(Yt,{title:"Chat widget preview",src:`/embed-preview.html?configUuid=${encodeURIComponent(ct)}&title=${encodeURIComponent(_)}&apiBase=${encodeURIComponent(ae)}&isActive=${I?"true":"false"}&placement=${P==="left-bottom"?"bottom-left":"bottom-right"}&exitOnBackButton=${D}&autoOpenAfterSeconds=${k}&widgetColor=${encodeURIComponent(L)}&activationPercentage=${encodeURIComponent(String(Math.max(0,Math.min(100,C))))}${b.trim()?`&firstMessage=${encodeURIComponent(b.trim())}`:""}${ge?`&profilePictureUrl=${encodeURIComponent(ge)}`:""}&minimal=1`})]})]})]})},Yt=gt("iframe")({flex:1,minHeight:0,width:"100%",border:"none",borderRadius:8,background:"#f5f5f5"}),Fe=[0,2e4],Kt="reengage-webchat-embed",Ve="/reengage-webchat.js";function $e(a){return a.replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function qt(a,n,l,u,t){const p=ae,g="",m=` data-api-base="${$e(p)}"`,f=t!=null&&t.trim()?t.trim():Ve;return`<!-- ReEngage Web Chat Widget --> 2<script id="${Kt}" src="${$e(f)}" data-config-uuid="${a}"${g}${m}><\/script>`}const Xt=({open:a,onClose:n,chatbot:l})=>{const u=!!(l!=null&&l.uuid),t="/".replace(/\/?$/,"/"),p=Ve.replace(/^\//,""),g=`${t}${p}`,m=typeof window<"u"?new URL(g,window.location.origin).toString():g,f=u?qt(l.uuid,void 0,void 0,void 0,m):"",S=()=>{navigator.clipboard.writeText(f),we("Code copied to clipboard")};return e.jsxs(He,{open:a,onClose:n,maxWidth:"sm",fullWidth:!0,children:[e.jsxs(ft,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(h,{variant:"h6",children:"Get embed code"}),e.jsx(Ge,{onClick:n,"aria-label":"close",size:"small",children:e.jsx(Se,{})})]}),e.jsxs(xt,{dividers:!0,children:[e.jsx(h,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"Add this code to your website to show the chat widget."}),u?e.jsxs(e.Fragment,{children:[e.jsx(h,{variant:"body2",color:"text.secondary",sx:{mt:1},children:"Widget settings (active, placement, back button, idle timeout, widget color) are loaded dynamically by config UUID. You can update them in the dashboard without changing the embed code on your website (changes apply after a page refresh)."}),e.jsx(h,{variant:"body2",color:"text.secondary",sx:{mt:2},children:"When the chat opens, the widget immediately renders the configured first message (if set) as the first assistant message."}),e.jsx(Y,{component:"pre",sx:{mt:2,p:2,bgcolor:"grey.100",borderRadius:1,overflow:"auto",fontSize:12,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:f})]}):e.jsx(h,{variant:"body2",color:"text.secondary",children:"Save the chatbot first to get the embed code."}),e.jsx(h,{variant:"subtitle2",sx:{mt:2},gutterBottom:!0,children:"Option 1: Add with Google Tag Manager (GTM)"}),e.jsxs(h,{variant:"body2",color:"text.secondary",paragraph:!0,children:["1. In GTM, create a new Custom HTML tag.",e.jsx("br",{}),"2. Paste the code above into the tag content.",e.jsx("br",{}),"3. Set the trigger to âAll Pagesâ (or the pages where you want the chat).",e.jsx("br",{}),"4. Save and publish your container."]}
2),e.jsx(h,{variant:"subtitle2",gutterBottom:!0,children:"Option 2: Add with code"}),e.jsx(h,{variant:"body2",color:"text.secondary",children:"Paste the script code in your siteâs <head> or just before the closing </body> tag on every page where the chat should appear."})]}),e.jsxs(_t,{sx:{px:3,py:2},children:[e.jsx(H,{startIcon:e.jsx(Dt,{}),variant:"contained",onClick:S,children:"Copy code"}),e.jsx(H,{onClick:n,children:"Close"})]})]})};var te=(a=>(a.DELETE="Delete",a.EDIT="Edit",a.GET_CODE="Get Code",a.PREVIEW_ON_TEST_WEBSITE="Preview on test website",a))(te||{});const Jt=[{id:"Edit",content:"Edit"},{id:"Get Code",content:"Get code"},{id:"Preview on test website",content:"Preview on test website"},{id:"Delete",content:"Delete",destructive:!0,dividerBefore:!0}],Qt=a=>[{accessorKey:"name",header:"Chatbot name",cell:({row:{original:n}})=>e.jsx(le,{variant:"b4-regular",children:n.name})},{accessorKey:"allowed_domains",header:"Website domains",cell:({row:{original:n}})=>{var l;return e.jsx(le,{variant:"b4-regular",children:(l=n.allowed_domains)!=null&&l.length?n.allowed_domains.join(", "):"â"})}},{accessorKey:"is_active",header:"Active",cell:({row:{original:n}})=>e.jsx(le,{variant:"b4-regular",children:n.is_active?"Yes":"No"})},{header:"Action",meta:{headerStyle:{textAlign:"right"},rowDataStyle:{textAlign:"right"}},cell:({row:{original:n,index:l},table:u})=>{const t=Ot(l,u);return e.jsx(Lt,{TriggerElement:e.jsx(Ft,{}),menuItems:Jt,menuPosition:t,onMenuItemClick:p=>a(p,n)})}}],Zt="_page_1xgd0_1",ea="_pageHeader_1xgd0_121",ta="_pageTitle_1xgd0_133",aa="_pageSubtitle_1xgd0_148",sa="_mainWrapper_1xgd0_156",ra="_tableWrapper_1xgd0_169",V={page:Zt,pageHeader:ea,pageTitle:ta,pageSubtitle:aa,mainWrapper:sa,tableWrapper:ra};var Pe=(a=>(a[a.UPDATE_PAGE_CONFIG_AND_FILTERS=0]="UPDATE_PAGE_CONFIG_AND_FILTERS",a))(Pe||{});const be={page:1,page_size:Ce[0]},na=(a,n)=>{switch(n.type){case Pe.UPDATE_PAGE_CONFIG_AND_FILTERS:return{...a,...n.payload};default:return a}},La=()=>{var j;const a=r.useRef(!0),[n,l]=r.useState(!1),[u,t]=r.useState(null),[p,g]=r.useState(!1),[m,f]=r.useState(null),[S,E]=r.useState(null),[v,d]=r.useReducer(na,be),{page:b,page_size:A}=r.useMemo(()=>v,[v]),{setSearchParams:C}=wt({defaults:{page:"1",page_size:Ce[0].toString()},actionType:Pe.UPDATE_PAGE_CONFIG_AND_FILTERS,dispatch:d,parse:i=>({page:Number(i.page)||be.page,page_size:Number(i.page_size)||be.page_size})}),{execute:M,loading:I,data:x,reload:P}=yt(At,{onError(){a.current&&Z("Failed to load chatbots")}});r.useEffect(()=>(a.current=!0,()=>{a.current=!1}),[]),r.useEffect(()=>{M(Me({...v}))},[v]);const G=r.useCallback(i=>{const _=typeof window<"u"?window.location.origin:"",W=_?`${_}/reengage-webchat.js`:"",c=new URLSearchParams;if(i.uuid&&c.set("configUuid",i.uuid),c.set("title",i.name||"Chat"),c.set("apiBase",ae),c.set("isActive",i.is_active===!1?"false":"true"),W&&c.set("widgetUrl",W),i.profile_picture_url){const B=i.profile_picture_url;c.set("profilePictureUrl",B.startsWith("/")?`${ae}${B}`:B)}typeof i.activation_percentage=="number"&&c.set("activationPercentage",String(i.activation_percentage)),i.first_message&&c.set("firstMessage",i.first_message);const O=i.placement==="left-bottom"?"bottom-left":"bottom-right";return c.set("placement",O),i.use_back_button&&c.set("exitOnBackButton","true"),i.auto_open_after_seconds!=null&&i.auto_open_after_seconds>0&&c.set("autoOpenAfterSeconds",String(i.auto_open_after_seconds)),i.widget_color&&/^#[0-9A-Fa-f]{6}$/.test(i.widget_color)&&c.set("widgetColor",i.widget_color),`${_}/embed-preview.html?${c.toString()}`},[]),D=r.useCallback((i,_)=>{switch(i){case te.DELETE:g(!0),f(_.id);break;case te.EDIT:t(_),l(!0);break;case te.GET_CODE:E(_);break;case te.PREVIEW_ON_TEST_WEBSITE:window.open(G(_),"_blank","noopener,noreferrer");break}},[G]),K=r.useCallback(async()=>{if(m!=null)try{await It(m),g(!1),f(null),we("Chatbot deleted"),P()}catch{Z("Failed to delete chatbot")}},[P,m]),k=r.useCallback(async(i,_,W)=>{try{const c=u?await kt(u.id,i):await Wt(i);if(we(u?"Chatbot updated":"Chatbot created"),u&&W)try{await Bt(c.id)}catch{Z("Failed to remove profile picture")}else if(u&&_)try{await Ut(c.id,_)}catch{Z("Failed to upload profile picture")}l(!1),t(null),P()}catch{Z(u?"Failed to update chatbot":"Failed to create chatbot")}},[u,P]),z=r.useCallback(i=>{E(i)},[]),L=r.useCallback(()=>
2{l(!1),t(null)},[]),q=r.useCallback((i,_)=>{const c=Me({...v,...{page:i,page_size:_}});C(c)},[C,v]);return e.jsxs("div",{className:V.page,children:[e.jsx(bt,{className:V.pageHeader,titleClassName:V.pageTitle,subtitleClassName:V.pageSubtitle,subTitle:"Manage web chat widgets and get embed code",title:"Chatbots",renderCustomComponent:e.jsx(vt,{size:"Small",variant:"Primary",onClick:()=>l(!0),children:e.jsxs(e.Fragment,{children:[e.jsx($t,{})," ",e.jsx(le,{children:"Add chatbot"})]})})}),e.jsx(Vt,{open:n,onClose:L,onSubmit:k,onGetCode:z,botToEdit:u}),e.jsx(Xt,{open:!!S,onClose:()=>E(null),chatbot:S??void 0}),e.jsx(jt,{openModal:p,setOpenModal:g,deleteItem:K,idToDelete:m,setIdToDelete:f}),e.jsx("main",{className:V.mainWrapper,children:e.jsx(Ct,{data:(x==null?void 0:x.results)??[],columns:Qt(D),handleSelectedRow:()=>{},className:V.tableWrapper,showErrorContainer:!1,isLoading:I,pagination:!0,paginationProps:{onPageChange:q,totalCount:Number(x==null?void 0:x.count)||(((j=x==null?void 0:x.results)==null?void 0:j.length)??0),currentPage:Number(b)||0,pageSize:Number(A)||0,pageSizeOptions:Ce}})})]})};export{La 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.