@botzki/react 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +36 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.mjs +36 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
`+
|
|
3
|
-
`);
|
|
4
|
-
`);w=xe.pop()||"";for(let Ne of xe){let Pe=Ne.trim();if(Pe.startsWith("data:")){let qe=Pe.slice(5).trim();if(!qe||qe==="[DONE]")continue;try{let ae=JSON.parse(qe);ae.delta&&(h+=ae.delta,f(Ye=>Ye.map(te=>te.id===A?{...te,content:h}:te)));}catch{}}}}}let z={id:A,role:"assistant",content:h,createdAt:new Date,isStreaming:!1};f(ue=>ue.map(re=>re.id===A?z:re)),N(!1),U(!1),Ft("\u{1F514} (1) New message from Support"),t.onFinish?.(z);}}else {let h="",x=null;if(s&&typeof s.chat=="function"){let B=await s.chat({message:P,sessionId:m,language:t.language});x=B,h=B.reply||B.answer;}else {let B=a?a.replace(/\/+$/,""):"https://api.botzki.com",z={"Content-Type":"application/json"};o&&(z.Authorization=`Bearer ${o}`);let re=await(await fetch(`${B}/api/v1/public/chat/${i}`,{method:"POST",headers:z,body:JSON.stringify({query:P,message:P,sessionId:m,language:t.language}),signal:l.signal})).json();x=re,h=re.reply||re.answer||"";}let M={id:A,role:"assistant",content:h,createdAt:new Date,isStreaming:!1,modelUsed:x?.modelUsed??x?.model_used,fallbackTriggered:x?.fallbackTriggered??x?.fallback_triggered,piiRedacted:x?.piiRedacted??x?.pii_redacted,redactionsCount:x?.redactionsCount??x?.redactions_count,localPrivacyMode:x?.localPrivacyMode??x?.local_privacy_mode};f(B=>B.map(z=>z.id===A?M:z)),N(!1),U(!1),t.onFinish?.(M);}}catch(h){if(h?.name==="AbortError")return;H(h),N(false),U(false),t.onError?.(h);}},[i,a,o,s,m,t]);useEffect(()=>{if(!_&&!le||!i)return;let E=true,d=a.replace(/\/+$/,""),W=async()=>{try{let O={};o&&(O.Authorization=`Bearer ${o}`);let de=await fetch(`${d}/api/v1/public/chat/${i}/handoff/status?sessionId=${m}`,{headers:O});if(!de.ok||!E)return;let P=await de.json();if(!E)return;P.status==="OperatorActive"?(Y(!0),q(!1),P.assignedOperator&&oe(A=>{if(!A||A.name!==P.assignedOperator.name){let l=P.assignedOperator.name||"Support Specialist";t.onOperatorJoined?.(P.assignedOperator),f(v=>v.some(x=>x.content&&x.content.includes(`${l} from Customer Support has joined`))?v:[...v,{id:ft(),role:"system",content:`${l} from Customer Support has joined the conversation.`,createdAt:new Date}]);}return P.assignedOperator})):P.status==="WaitingHuman"?(q(!0),Y(!1)):(P.status==="BotHandling"||P.status==="Closed"||P.status==="Resolved")&&(q(!1),Y(!1),oe(null),he(!1),P.status==="Resolved"&&P.ticketId&&!T.current.has(P.ticketId)&&R(A=>(A!==P.ticketId&&t.onTicketResolved?.(P.ticketId),P.ticketId))),Array.isArray(P.messages)&&f(A=>{let l=new Set(A.map(M=>M.id)),v=new Set(A.map(M=>M.content)),h=[...A],x=!1;for(let M of P.messages)if(M.senderType==="System"){if(M.content&&M.content.startsWith("Visitor requested"))continue;if(!l.has(M.id)&&!v.has(M.content)){let B=String(M.createdAtUtc||""),z=B?new Date(B.endsWith("Z")?B:B+"Z"):new Date;h.push({id:M.id,role:"system",content:M.content,createdAt:z}),l.add(M.id),v.add(M.content),x=!0,Ft("\u{1F514} (1) New message from Support Specialist",{enableSound:t.enableSoundAlert,enableTabTitle:t.enableTabTitleNotification});}}else if(M.senderType==="Operator"){if(l.has(M.id))continue;let B=h.findIndex(z=>z.senderType==="operator"&&z.content===M.content&&z.id.startsWith("msg_"));if(B!==-1){h[B]={...h[B],id:M.id},l.add(M.id),x=!0;continue}if(!v.has(M.content)){let z=String(M.createdAtUtc||""),ue=z?new Date(z.endsWith("Z")?z:z+"Z"):new Date;h.push({id:M.id,role:"assistant",senderType:"operator",senderName:M.senderName||"Support Specialist",content:M.content,audioUrl:M.audioUrl,audioDuration:M.audioDurationSeconds,imageUrl:M.imageUrl,fileUrl:M.fileUrl,fileName:M.fileName,fileSize:M.fileSize,deliveryStatus:M.deliveryStatus,deliveryChannel:M.deliveryChannel,createdAt:ue}),l.add(M.id),v.add(M.content),x=!0,Ft("\u{1F514} (1) New message from Support Specialist",{enableSound:t.enableSoundAlert,enableTabTitle:t.enableTabTitleNotification});}}return x?h:A});}catch{}};W();let ie=setInterval(W,3e3);return ()=>{E=false,clearInterval(ie);}},[_,le,i,a,o,m]);let At=useCallback(async(E,d,W,ie)=>{let O=a.replace(/\/+$/,"");try{let de={"Content-Type":"application/json"};o&&(de.Authorization=`Bearer ${o}`);let P=typeof Intl<"u"?Intl.DateTimeFormat().resolvedOptions().timeZone:void 0,A={...t.visitorData||{},...ie?.customData||{}},l=Array.from(new Set([...t.tags||[],...ie?.tags||[]])),v=ie?.lastBrowsedPages||j,h=S.filter(B=>(B.role==="user"||B.role==="assistant")&&B.content&&B.content.trim().length>0).map(B=>({role:B.role,content:B.content.trim(),createdAt:B.createdAt instanceof Date?B.createdAt.toISOString():B.createdAt?new Date(B.createdAt).toISOString():new Date().toISOString()})),x=await fetch(`${O}/api/v1/public/chat/${i}/handoff/request`,{method:"POST",headers:de,body:JSON.stringify({sessionId:m,reason:E,visitorName:d,visitorEmail:W,timezone:P,lastBrowsedPages:v.length>0?v:void 0,customData:Object.keys(A).length>0?A:void 0,tags:l.length>0?l:void 0,transcript:h.length>0?h:void 0})}),M=await x.json().catch(()=>({}));if(!x.ok){if(M?.code==="EMAIL_REQUIRED"){let B=new Error(M.message||"Email is required before handoff.");throw B.code="EMAIL_REQUIRED",B}throw new Error(M?.message||`Handoff request failed with status ${x.status}`)}if(M.isOnline===!1){f(B=>[...B,{id:ft(),role:"system",content:M.offlineMessage||"Our support team is currently offline. We will reply as soon as possible!",createdAt:new Date}]),M.behavior==="aiOnly"?q(!1):q(!0);return}q(!0),t.onEscalationRequest?.({reason:E,visitorName:d,visitorEmail:W}),f(B=>{let z=[...B];return z.some(re=>re.role==="system"&&re.content.includes("Connecting you with our support team"))||z.push({id:ft(),role:"system",content:"Connecting you with our support team... You are in queue for a live specialist.",createdAt:new Date}),M.welcomeMessage&&(z.some(w=>w.senderType==="operator"&&w.content===M.welcomeMessage)||z.push({id:ft(),role:"assistant",senderType:"operator",senderName:"Support Specialist",content:M.welcomeMessage,createdAt:new Date})),z});}catch(de){if(de?.code==="EMAIL_REQUIRED")throw de;console.warn("Human handoff request failed:",de);}},[a,i,o,m,j,t.visitorData,t.tags]),Je=useCallback(async()=>{q(false),Y(false),oe(null),he(false);let E=a.replace(/\/+$/,"");try{let d={"Content-Type":"application/json"};o&&(d.Authorization=`Bearer ${o}`),await fetch(`${E}/api/v1/public/chat/${i}/handoff/cancel`,{method:"POST",headers:d,body:JSON.stringify({sessionId:m})});}catch{}f(d=>[...d,{id:ft(),role:"system",content:"Returned to autonomous AI assistant mode.",createdAt:new Date}]);},[a,i,o,m]),Ae=useCallback(()=>{ke(),f([]),R(null),q(false),Y(false),oe(null);let E="sess_"+Math.random().toString(36).substring(2,9);if(u(E),g&&typeof window<"u")try{localStorage.removeItem(c),localStorage.setItem(`${c}_session_id`,E);}catch{}},[ke,g,c]),be=useCallback(async(E,d)=>{if(!(!ze||!i))try{let W=a?a.replace(/\/+$/,""):"https://api.botzki.com",ie={"Content-Type":"application/json"};o&&(ie.Authorization=`Bearer ${o}`),await fetch(`${W}/api/v1/public/chat/${i}/handoff/feedback`,{method:"POST",headers:ie,body:JSON.stringify({ticketId:ze,rating:E,feedback:d||null})}),T.current.add(ze),R(null),t.onCsatSubmit?.(E,d);}catch(W){console.warn("Failed to submit handoff feedback:",W);}},[ze,i,a,o]),Qe=useCallback(async(E,d,W)=>{let ie=a.replace(/\/+$/,""),O={"Content-Type":"application/json"};o&&(O.Authorization=`Bearer ${o}`);let P=He.current.find(A=>A.id===E)?.proposedAction;f(A=>A.map(l=>l.id===E&&l.proposedAction?{...l,proposedAction:{...l.proposedAction,status:"executing"}}:l));try{let A=await fetch(`${ie}/api/v1/public/chat/${i}/actions/execute`,{method:"POST",headers:O,body:JSON.stringify({actionToken:d,confirmedParameters:W,visitorSessionId:m})});if(!A.ok){let v=`Execution failed with status ${A.status}`;try{let h=await A.json();h?.message&&(v=h.message);}catch{}throw new Error(v)}let l=await A.json();return f(v=>v.map(h=>h.id===E&&h.proposedAction?{...h,proposedAction:{...h.proposedAction,status:"completed",result:l}}:h)),P&&t.onActionExecuted?.({...P,status:"completed",result:l},l),{success:!0,result:l}}catch(A){return f(l=>l.map(v=>v.id===E&&v.proposedAction?{...v,proposedAction:{...v.proposedAction,status:"failed",error:A.message}}:v)),{success:false,error:A.message}}},[i,a,o,m]),Ke=useCallback(async(E,d)=>{let ie=He.current.find(de=>de.id===E)?.proposedAction,O=ie?.token;if(f(de=>de.map(P=>P.id===E&&P.proposedAction?{...P,proposedAction:{...P.proposedAction,status:"cancelled"}}:P)),ie&&t.onActionCancelled?.({...ie,status:"cancelled"},d),O&&i)try{let de=a?a.replace(/\/+$/,""):"https://api.botzki.com",P={"Content-Type":"application/json"};o&&(P.Authorization=`Bearer ${o}`),await fetch(`${de}/api/v1/public/chat/${i}/actions/cancel`,{method:"POST",headers:P,body:JSON.stringify({actionToken:O,reason:d||"Cancelled by visitor"})});}catch{}},[i,a,o]),Be=rn({botId:i||"",baseUrl:a,sessionId:m,isHumanHandoffActive:le&&t.enableCoBrowse!==false}),Ve=useRef(false);return useEffect(()=>{Be.isActive&&!Ve.current?t.onCoBrowseStart?.(Be.operatorName):!Be.isActive&&Ve.current&&t.onCoBrowseEnd?.(),Ve.current=Be.isActive;},[Be.isActive,Be.operatorName]),{messages:S,input:C,setInput:y,handleInputChange:ye,handleSubmit:Ee,sendMessage:pe,sendVoiceMessage:wt,append:We,reload:Ue,stop:ke,clearMessages:Ae,setMessages:f,isLoading:L,isStreaming:Q,error:X,sessionId:m,setSessionId:u,isHumanHandoffActive:le,isWaitingForHuman:_,assignedOperator:Z,isOperatorTyping:J,requestHumanHandoff:At,cancelHumanHandoff:Je,pendingCsatTicketId:ze,submitHandoffFeedback:be,executeProposedAction:Qe,cancelProposedAction:Ke,coBrowse:Be}}function bo(){let{client:t,botId:e,baseUrl:i}=Mt(),[o,a]=useState(null),[s,c]=useState(true),[g,m]=useState(null),u=useCallback(async()=>{c(true),m(null);try{let S;if(typeof t.getBotInfo=="function")S=await t.getBotInfo();else {let f=i?i.replace(/\/+$/,""):"https://api.botzki.com";S=await(await fetch(`${f}/api/v1/public/chat/${e}`)).json();}a(S);}catch(S){m(S instanceof Error?S:new Error(String(S)));}finally{c(false);}},[t,e,i]);return useEffect(()=>{u();},[u,e]),{data:o,isLoading:s,error:g,refetch:u}}var Ei=["broken","terrible","worst","hate","refund","stuck","bug","crash","error","horrible","awful","scam","useless","ridiculous","frustrated","fail","failed","failing","not working","doesn't work","does not work","charge","charged","cancel","disaster","slow","unacceptable","angry","mad","waste","trash","annoying","cheat","sucks","disappointed","garbage","bad service","poor","rip off","ripoff","never works"],Pi=["wow","amazing","unbelievable","omg","best bot","love you","solved","fixed","works now","working now","you saved","fantastic","brilliant","yay","hooray","bingo","perfect","genius","incredible","love it","awesome bot","superb","outstanding"],$i=["thanks","thank you","thx","appreciate","helpful","good","great","nice","awesome","sweet","cool","super","glad","kind of you","very clear","got it","clear now","understood"],Li=["how","what","why","where","when","can you","could you","tell me","is there","wondering","curious","possible to","explain"];function Un(t){if(!t||typeof t!="string")return {sentiment:"neutral",score:0};let e=t.toLowerCase();for(let i of Pi)if(e.includes(i))return {sentiment:"delighted",score:.95,triggerWord:i};for(let i of Ei)if(e.includes(i))return {sentiment:"frustrated",score:-0.9,triggerWord:i};for(let i of $i)if(e.includes(i))return {sentiment:"happy",score:.65,triggerWord:i};return e.includes("?")||Li.some(i=>e.includes(i))?{sentiment:"curious",score:.2}:{sentiment:"neutral",score:0}}function yo({messages:t=[],isLoading:e=false,isStreaming:i=false,isWaitingForHuman:o=false,isHumanHandoffActive:a=false,feedbackRating:s=null,manualEmotion:c,manualMotion:g,enabled:m=true,reactionCooldownMs:u=5500}={}){let[S,f]=useState("neutral"),[C,y]=useState(void 0),[L,N]=useState(0),[Q,U]=useState("neutral"),[X,H]=useState(0),[le,Y]=useState("Calm attentive baseline"),_=useRef(null),q=useRef(null),Z=()=>{_.current&&(clearTimeout(_.current),_.current=null);},oe=(R=u)=>{Z(),_.current=setTimeout(()=>{f("neutral"),y(void 0),U("neutral"),H(0),Y("Returned to calm baseline");},R);},J=()=>{Z(),f("love"),y("jump"),N(R=>R+1),U("delighted"),H(1),Y("Celebration triggered: Issue resolved!"),oe(6e3);},he=()=>{Z(),f("sad"),y("float"),N(R=>R+1),U("frustrated"),H(-0.85),Y("Attentive & sympathetic listening active"),oe(7e3);},ze=()=>{Z(),f("neutral"),y(void 0),U("neutral"),H(0),Y("Reset to neutral");};return useEffect(()=>{c&&(f(c),Y(`Manual emotion override: ${c}`)),g&&(y(g),N(R=>R+1));},[c,g]),useEffect(()=>{m&&(s==="up"?J():s==="down"&&he());},[s,m]),useEffect(()=>{m&&(o?(Z(),f("sad"),y("float"),N(R=>R+1),U("frustrated"),H(-0.7),Y("Visitor requested human agent: Sympathetic attentive stance")):a&&(Z(),f("happy"),y("bounce"),N(R=>R+1),U("happy"),H(.8),Y("Live human operator connected: Reassuring welcome"),oe(6e3)));},[o,a,m]),useEffect(()=>{m&&(o||(e||i?(Z(),f("thinking"),y(void 0),U("thinking"),H(.1),Y("Synthesizing answer & reasoning...")):Q==="thinking"&&(f("happy"),y(void 0),U("happy"),H(.5),Y("Answer delivered with friendly attentive smile"),oe(4e3))));},[e,i,o,m]),useEffect(()=>{if(!m||t.length===0)return;let R=[...t].reverse().find(j=>j.role==="user");if(!R||R.id===q.current)return;q.current=R.id;let T=Un(R.content);T.sentiment==="frustrated"?(Z(),f("sad"),y("float"),N(j=>j+1),U("frustrated"),H(T.score),Y(`Detected distress trigger '${T.triggerWord}': Avatar shifts to apologetic listening posture`),oe(8e3)):T.sentiment==="delighted"?(Z(),f("love"),y("jump"),N(j=>j+1),U("delighted"),H(T.score),Y(`Detected delight trigger '${T.triggerWord}': Avatar celebrates`),oe(7e3)):T.sentiment==="happy"?(Z(),f("happy"),y("bounce"),N(j=>j+1),U("happy"),H(T.score),Y(`Detected gratitude trigger '${T.triggerWord}': Avatar perks up happily`),oe(6e3)):T.sentiment==="curious"&&(Z(),f("surprised"),y(void 0),U("curious"),H(T.score),Y("Inquisitive customer question: Attentive focus"),oe(5e3));},[t,m]),useEffect(()=>()=>Z(),[]),{emotion:c??S,motion:g??C,motionKey:L,sentiment:Q,sentimentScore:X,empathyReason:le,triggerCelebration:J,triggerSympathy:he,resetToNeutral:ze}}var $o=[-3.2,3.2],Lo=-2.6,Hi=2.4,Wi=5.4,Dn=4.4,Ui=380,Ni=13.4+.5,Po=4,xo=2800,Oi=2200,Di="M0 1C-0.6 0.55-1.3 0.1-1.3-0.45C-1.3-0.95-0.9-1.2-0.55-1.2C-0.25-1.2-0.05-1 0-0.8C0.05-1 0.25-1.2 0.55-1.2C0.9-1.2 1.3-0.95 1.3-0.45C1.3 0.1 0.6 0.55 0 1Z",Me=t=>t*t*(3-2*t),at=t=>Math.min(1,Math.max(0,t)),Fi=t=>t<.5?4*t*t*t:1-(-2*t+2)**3/2,Fn=t=>1-(1-t)**3,Fe=(t,e,i)=>t<=e||t>=i?0:Math.sin(Math.PI*(t-e)/(i-e)),je=(t,e,i,o,a)=>t<=e||t>=a?0:t<i?Me((t-e)/(i-e)):t<=o?1:1-Me((t-o)/(a-o)),cn=t=>{let e=Math.sin(t*127.1+311.7)*43758.5453;return e-Math.floor(e)};function ji(t,e,i,o){let a=Math.cos;switch(t){case "circle":return .97+(.012+o*.03)*a(3*e+i*.5)+.008*a(5*e-i*.6);case "squircle":{let s=Math.abs(a(e)),c=Math.abs(Math.sin(e));return .9/(s**4+c**4)**.25+(.008+o*.02)*a(4*e+i*.6)}case "flower":return .95+(.075+o*.03)*a(8*e)+.012*a(3*e+i*.6);case "blob":return .97+(.05+o*.025)*a(3*e+1.5*Math.PI+.75*Math.sin(i*.3)+.25*Math.sin(i*.71))+(.022+o*.012)*a(2*e-i*.36)+.01*a(5*e+i*.5);default:return 1+(.038+o*.03)*a(5*e+.5*Math.PI+.75*Math.sin(i*.27)+.25*Math.sin(i*.63))+(.02+o*.02)*a(3*e+i*.45)+.01*a(7*e-i*.6)}}function jn(t){let e="";for(let i=0;i<96;i++){let o=i/96*Math.PI*2,a=t[i]*13.4;e+=`${i?"L":"M"}${(a*Math.cos(o)).toFixed(2)} ${(a*Math.sin(o)).toFixed(2)}`;}return `${e}Z`}var _i=jn(new Float32Array(96).fill(1));function _n(t,e,i,o,a,s,c){let g=Hi/2*a,m=Math.max(.35,Wi/2*i*a)*(4/3),u=[t-g,e,t-g,e-m*(1-s),t+g,e-m*(1-c),t+g,e,t+g,e+m,t-g,e+m],S=e+.4,f=[t-1.7,S+1,t-1.5,S-1.6,t+1.5,S-1.6,t+1.7,S+1,t+1.1,S-.3,t-1.1,S-.3],C=u.map((y,L)=>(y+(f[L]-y)*o).toFixed(2));return `M${C[0]} ${C[1]}C${C[2]} ${C[3]} ${C[4]} ${C[5]} ${C[6]} ${C[7]}C${C[8]} ${C[9]} ${C[10]} ${C[11]} ${C[0]} ${C[1]}Z`}function Vn(t,e,i,o,a,s,c=0){let g=(2+o*.8-i*.3)*a,m=e-o*.4,u=e+.4+o*(o<0?2.4:1.6),S=u+i*1.8+c,f=u-i*2.4-c,C=N=>N.toFixed(2),y=m+s,L=m-s;return `M${C(t-g)} ${C(y)}Q${C(t)} ${C(S)} ${C(t+g)} ${C(L)}Q${C(t)} ${C(f)} ${C(t-g)} ${C(y)}Z`}var gt={openL:1,openR:1,laughL:0,laughR:0,eyeScale:1,eyeY:0,heavy:0,droop:0,smile:.4,mouth:0,mouthW:1,mouthX:0,skew:0,taper:0,blush:0,gazeX:Number.NaN,gazeY:Number.NaN,wobble:0,bob:0,tilt:0,spin:1},Nn={neutral:gt,happy:{...gt,openL:.9,openR:.9,laughL:.45,laughR:.45,smile:1,wobble:.15,bob:-0.3},love:{...gt,openL:.88,openR:.88,laughL:.55,laughR:.55,eyeScale:1.03,smile:1,mouthW:.9,blush:1,gazeX:-0.6,gazeY:-0.7,wobble:.12,bob:-0.2,tilt:-3,spin:.7},laugh:{...gt,openL:.9,openR:.9,laughL:.5,laughR:.5,smile:1,mouth:.1,wobble:.3,spin:1.4},surprised:{...gt,openL:1.03,openR:1.03,eyeScale:1.07,eyeY:-0.5,smile:0,mouth:1,mouthW:.95,wobble:.12,bob:-0.6},wow:{...gt,openL:.98,openR:.98,eyeScale:1.15,eyeY:-0.5,smile:.15,mouth:.75,mouthW:1.35,wobble:.15,bob:-0.5},sad:{...gt,openL:.75,openR:.75,eyeScale:.92,droop:.85,eyeY:.5,smile:-1,mouthW:1.75,gazeX:0,gazeY:.75,bob:.8,tilt:-4,spin:.35},thinking:{...gt,openL:.95,openR:.8,heavy:.2,smile:.1,mouthW:.6,mouthX:.9,skew:.5,tilt:5,spin:.6},sleepy:{...gt,openL:.6,openR:.6,heavy:.65,eyeY:.5,smile:-0.04,mouthW:.8,taper:.3,gazeX:0,gazeY:.6,bob:.5,spin:.3},wink:{...gt,smile:.9,skew:.1,tilt:2,wobble:.1}},Vi={surprised:16,wow:18,sad:3.5,sleepy:2.5},qi=Object.keys(gt),qn=()=>({dy:0,sy:0,tilt:0,faceY:0,scale:0,openL:1,openR:1,laughL:0,laughR:0,mouth:0,smile:0,width:1,skew:0,mouthX:0,yawn:0,blink:0,steady:false,gaze:null}),sn=[[.75,-0.85],[.4,-1],[-0.35,-0.85]];function Yi(t,e,i){let o=qn();switch(t){case "happy":{e<520&&(o.dy=-1.6*Math.abs(Math.sin(Math.PI*2*e/520))),o.tilt=3*Math.sin(Math.PI*2*e/3600);let a=je(e%3600,1600,1900,2500,2900);o.laughL=o.laughR=.3*a,o.mouth=.22*a,o.dy-=.6*a;break}case "love":{e<600&&(o.dy=-1.4*Fe(e,0,600)),o.tilt=5*Math.sin(Math.PI*2*e/4e3);let a=je(e%4e3,1400,1900,2500,3200);o.laughL=o.laughR=.3*a,o.scale+=.05*a,o.sy+=.03*a,o.dy-=.8*a,o.mouth+=.1*a;break}case "laugh":{let s=Math.floor(e/5600),c=e%5600,g=cn(s)<.5?-1:1,m=Fe(c,0,340);o.dy-=1.2*m,o.sy+=.04*m,o.scale+=.1*m,o.laughL=o.laughR=-0.5*m,o.mouth+=.25*m;let u=je(c,220,380,3e3,3700);if(o.laughL+=.5*u,o.laughR+=.5*u,o.mouth+=.25*je(c,220,400,3400,4400),c>260&&c<2900){let S=(c-260)/2640,f=15*S-3*S*S,C=Math.abs(Math.sin(Math.PI*f))**.8,y=(1-.7*S)*(.6+.4*cn(s*17+Math.floor(f)))*Me(Math.min(1,(c-260)/120));o.mouth+=.6*C*y,o.dy-=1.4*C*y,o.sy-=.035*C*y,o.scale-=.1*C*y,o.tilt+=2.5*C*y*g;}else if(c>=2900&&c<4300){let S=(c-2900)/1400,f=Math.abs(Math.sin(Math.PI*S*4.2)),C=.4*(1-S);o.mouth+=.4*f*C,o.dy-=.8*f*C;}o.tilt-=7*g*je(c,260,600,1800,2900),o.sy-=.02*Fe(c,4300,5300),c>4300&&(o.gaze=[0,0]),o.steady=c<3600;break}case "surprised":{let a=e<900?e<120?Me(e/120):1-Me((e-120)/780):0;o.scale+=.12*a,o.dy-=3*Fe(e,0,420),o.sy+=.06*Fe(e,0,380),o.mouth+=.3*a,o.steady=e<1800;let s=e<600?-1:(e-600)%4200,c=je(s,300,380,640,720),g=je(s,700,780,1090,1170);o.gaze=s>=300&&s<700?[-0.85,-0.1]:s>=700&&s<1150?[.85,-0.1]:[0,0],o.tilt+=-3*c+3*g,o.blink=Math.max(Fe(s,1700,1850),Fe(s,1950,2100));let m=Me(at((e-2600)/900));o.mouth-=.45*m,o.width*=1-.2*m;break}case "wow":{let a=.08*Math.sin(Math.PI*2*e/2800);o.scale+=.04+a*.3,o.mouth+=.05+a*.3,o.openL+=a*.15,o.openR+=a*.15,o.dy-=.8+a*3,o.tilt=1.5*Math.sin(Math.PI*2*e/3400),o.steady=true;break}case "sad":{let a=e%7e3;o.sy-=.045*Fe(a,0,1400),o.dy+=.5*je(a,700,1100,1800,2400);let s=je(a,3e3,3200,3800,4100);o.gaze=[0,.75-.9*s],o.openL=o.openR=1+.15*s,o.dy-=.4*s;let c=je(a,4400,4600,5300,5600);o.skew+=.12*Math.sin(i/40)*c,o.mouth+=.05*c,o.smile-=.15*c,o.tilt+=1.5*Math.sin(i/2200);break}case "thinking":{let a=e%6400;o.gaze=a<1200?sn[0]:a<2400?sn[1]:sn[2];let s=je(a,1200,1500,2100,2400);o.mouthX-=1.8*s,o.skew-=s,o.tilt-=9*s;let c=je(a,4100,4250,5600,6200);c>.3&&(o.gaze=[0,0]),o.openL*=1+.2*c,o.openR*=1+.4*c,o.scale+=.08*c,o.smile+=.8*c,o.mouthX-=.9*c,o.skew-=.5*c,o.width*=1+.5*c,o.mouth+=.15*c,o.tilt-=5*c,o.dy-=1.6*Fe(a,4100,4500),o.tilt+=1.5*Math.sin(i/900);break}case "sleepy":{let a=e%9200,s=a<3e3?Me(a/3e3):a<3200?1-Me((a-3e3)/200):0;o.openL=o.openR=1-.8*s,o.dy+=1.6*s,o.tilt+=6*s,o.gaze=[0,.6+.4*s];let c=Fe(a,3e3,3350);o.openL*=1+.9*c,o.openR*=1+.9*c,o.dy-=1.4*c,o.scale+=.1*c,a>=3e3&&a<4200&&(o.gaze=[0,0]),o.blink=Math.max(Fe(a,3550,3780),Fe(a,3900,4130)),o.yawn=je(a,5400,6200,6800,7600),o.tilt+=2*Math.sin(i/1700),o.steady=a<3e3;break}case "wink":{let a=e%3200,s=0;if(a>150&&a<950){let c=(a-150)/800;s=c<.2?Me(c/.2):c<.75?1:1-Me((c-.75)/.25);}o.laughR+=s,o.laughL+=.25*s,o.openL*=1-.12*s,o.skew+=.45*s,o.smile+=.1*s,o.tilt+=5*s,o.dy-=.9*Fe(a,150,450),s>0&&(o.gaze=[0,0]),o.steady=s>0;break}}return o}var Yn={jump:950,spin:600,bounce:1200,wiggle:800,float:2200},et={dy:0,rot:0,sx:1,sy:1,yaw:0,joy:0,gaze:null};function Gi(t,e){let i=at(e/Yn[t]);switch(t){case "jump":{if(e<160){let s=Me(e/160);return {...et,sx:1+.1*s,sy:1-.14*s,joy:s*.6}}if(e<560){let s=(e-160)/400,c=.09*Math.abs(Math.cos(Math.PI*s));return {...et,dy:-44*s*(1-s),sx:1-c*.6,sy:1+c,joy:1}}let o=(e-560)/390,a=.16*Math.exp(-5*o)*Math.cos(10*o);return {...et,sx:1+a*.7,sy:1-a,joy:1-Me(o)}}case "spin":{if(e<90){let s=Me(e/90);return {...et,yaw:-30*s,sx:1+.06*s,sy:1-.08*s,joy:.3*s,gaze:[-0.6*s,0]}}if(e<440){let s=(e-90)/350,c=Math.sin(Math.PI*s)**2,g=1-Me(Math.min(1,s*4));return {...et,yaw:-30+390*Fi(s),dy:-2.6*c,sx:1+.06*g,sy:1-.08*g+.04*c,joy:.8,gaze:[.8*c,0]}}let o=(e-440)/160,a=.025*Math.sin(Math.PI*o)*(1-o);return {...et,yaw:360,sx:1+a*.7,sy:1-a,joy:.8*(1-o)}}case "bounce":{let o=Math.abs(Math.sin(Math.PI*3*i)),a=.08*(1-o)**6;return {...et,dy:-5*o,sx:1+a*.8,sy:1-a,joy:Math.sin(Math.PI*i)}}case "wiggle":return {...et,rot:14*Math.sin(Math.PI*8*i)*(1-i),joy:.6*Math.sin(Math.PI*i)};case "float":{let o=[0,.9];if(e<520){let c=e/520,g=.05*Math.sin(Math.PI*c);return {...et,dy:-4.5*Fn(c),sx:1-g*.6,sy:1+g,joy:.5*c,gaze:c>.4?o:null}}if(e<1500){let c=(e-520)/980;return {...et,dy:-4.5+.8*Math.sin(Math.PI*3*c),rot:4*Math.sin(Math.PI*2*c),joy:.5,gaze:o}}if(e<1820){let c=(e-1500)/320;return {...et,dy:-4.5*(1-c*c),sx:1-.02*c,sy:1+.04*c,joy:.5,gaze:o}}let a=(e-1820)/380,s=.12*Math.exp(-5*a)*Math.cos(10*a)*(1-a);return {...et,sx:1+s*.7,sy:1-s,joy:.5*(1-a)}}}}var bt={viewBox:"-24 -24 48 48",body:_i,eyes:$o.map(t=>_n(t,Lo,1,0,1,0,0)),blush:$o.map(t=>({cx:t*1.6,cy:Lo+4.6})),mouth:Vn(0,Dn,0,.4,1,0),groundY:Ni,heart:Di,hearts:Po},On=t=>({emotion:t.emotion??"neutral",activity:t.activity??"idle",shape:t.shape??"pebble",lookAround:t.lookAround??true,followCursor:t.followCursor??false,hoverGiggle:t.hoverGiggle??true});function Gn(t,e={}){let i={config:On(e),playing:e.motion?{name:e.motion,start:performance.now()}:null,morph:null,onMotionEnd:e.onMotionEnd,onTickle:e.onTickle,tickledAt:-1/0,chuckledAt:-1/0},o=new Float32Array(96).fill(1),a=i.config.shape,s=e.motion??null,c=e.motionKey??0,g=e.chuckleKey??0,m=()=>{let d=performance.now();i.config.hoverGiggle&&d-i.tickledAt>1300&&(i.tickledAt=d,i.onTickle?.());};t.mover.addEventListener("pointerenter",m);let u=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)").matches:false,S=null,f=d=>{S=d.pointerType==="mouse"?{x:d.clientX,y:d.clientY}:null;},C=()=>{S=null;};window.addEventListener("pointermove",f,{passive:true}),document.documentElement.addEventListener("pointerleave",C);let y={...Nn[i.config.emotion]},L=Math.random()*1e3,N=0,Q=performance.now(),U=0,X=0,H=0,le=0,Y=Q+600+Math.random()*1800,_=Q+800+Math.random()*2600,q=-1,Z=false,oe=-1/0,J=0,he=0,ze=Q+4e3+Math.random()*4e3,R=Math.random()*360,T=13.4,j=0,F=7,G=0,ee=0,ce=0,He=5.5,ke=1,pe=1,ye=0,Ee=0,We=6,Ue=false,wt=-1/0,At=Q+900,Je=-1/0,Ae=0,be=null,Qe=Q,Ke=-1/0,Be=-1/0,Ve=d=>{let W=Math.min(.064,(d-Q)/1e3);Q=d;let ie=u?0:d/1e3+L,O=i.config;O.emotion!==be&&(be==="love"&&(Be=d),be=O.emotion,Qe=d,be==="love"&&(Ke=d,Be=1/0));let de=d-Qe,P=Nn[be],A=Math.min(1,W*(Vi[be]??8));for(let $ of qi){let D=P[$];Number.isNaN(D)?y[$]=Number.NaN:Number.isNaN(y[$])?y[$]=D:y[$]+=(D-y[$])*A;}let l=u?qn():Yi(be,de,d),v=0,h=0;if(O.activity==="speaking"){d>Ee&&d>ye&&(ye=d+160+Math.random()*260,We-=1,Ue=We<=0,Ee=ye+(Ue?520+Math.random()*420:60+Math.random()*120),Ue&&(We=4+Math.floor(Math.random()*5)),Math.random()<.3&&(wt=d));let $=d<ye;v=$?.55+.35*Math.abs(Math.sin(d/70)):0,$?(ce+=W*He*Math.PI*2,ce>=Math.PI*2&&(ce-=Math.PI*2,He=4.6+Math.random()*2,ke=Math.random()<.18?.12:.55+Math.random()*.45,pe=Math.random()<.4?.62+Math.random()*.12:1+Math.random()*.2),h=Math.min(1,(.35+G)*ke*(.5-.5*Math.cos(ce)))):ce=0;let D=Fe(d-wt,0,280);l.dy-=.7*D,l.scale+=.06*D;}else O.activity==="listening"&&(v=.18+.14*Math.sin(d/240)*Math.sin(d/610));G+=(v-G)*Math.min(1,W*12),ee+=(h-ee)*Math.min(1,W*(h>ee?30:20));let x=et,M=i.playing;if(M&&!u){let $=d-M.start;$>=Yn[M.name]?(i.playing=null,i.onMotionEnd?.(M.name)):x=Gi(M.name,$);}let B=O.activity==="listening"?1:0;if(B&&!M&&d>At&&(Je=d,Ae+=1,At=d+2400+Math.random()*1800),B&&!u){let $=d-Je;if(Ae%3===0){let D=je($,0,160,700,1e3);l.scale+=.08*D,l.faceY-=.6*D,l.mouth+=.18*D,l.smile-=.3*D,l.dy-=.5*D;}else {let D=Fe($,0,300)+.7*Fe($,340,640);l.dy+=1.6*D,l.faceY+=1.2*D,l.sy-=.02*D,l.openL*=1-.15*D,l.openR*=1-.15*D,l.smile+=.1*D;}l.tilt+=4+1.5*Math.sin(d/2600);}let z=false,ue=O.followCursor&&S?t.svg.getBoundingClientRect():void 0;if(S&&ue&&ue.width>0){let $=S.x-(ue.left+ue.width/2),D=S.y-(ue.top+ue.height/2),Se=ue.width*.9;z=true,H=$/(Math.abs($)+Se),le=D/(Math.abs(D)+Se),Y=d+700;}let re=x.gaze??l.gaze;z||(re?(H=re[0],le=re[1]):Number.isNaN(y.gazeX)?d>Y&&(O.activity==="listening"?(H=(Math.random()-.5)*.3,le=-0.05+(Math.random()-.5)*.15):O.activity==="speaking"?(H=Ue?Math.random()<.5?-0.7:.7:(Math.random()-.5)*.5,le=Ue?-0.5:(Math.random()-.5)*.3):O.lookAround?(H=[-1,-0.6,0,0,.6,1][Math.floor(Math.random()*6)],le=(Math.random()-.5)*1.2):(H=0,le=0),Y=d+(O.activity==="speaking"?500+Math.random()*900:900+Math.random()*2300)):(H=y.gazeX,le=y.gazeY));let w=Math.min(1,W*(z?14:16));U+=(H-U)*w,X+=(le-X)*w;let me=Math.min(1,W*5);J+=(U-J)*me,he+=(X-he)*me,l.steady&&q<0&&(_=Math.max(_,d+400)),q<0&&d>_&&(q=d);let fe=1;if(q>=0){let $=(d-q)/(be==="sleepy"?460:be==="sad"?280:170);$>=1?(q=-1,!Z&&Math.random()<.22?(Z=true,_=d+90):(Z=false,_=d+2e3+Math.random()*3200)):fe=1-Math.sin($*Math.PI)*.88;}fe*=1-l.blink*.9;let xe=d-i.tickledAt,Ne=0,Pe=0;O.hoverGiggle&&xe<1300&&(Ne=xe<180?Me(xe/180):xe<800?1:1-Me((xe-800)/500),Pe=Math.sin(xe/42)*Math.max(0,1-xe/520));let qe=d-i.chuckledAt,ae=qe>0&&qe<1700?.45*je(qe,0,260,1e3,1700):0;Ne=Math.max(Ne,ae),be==="neutral"&&O.activity==="idle"&&d>ze&&(oe=d,ze=d+5e3+Math.random()*6e3);let Ye=be==="neutral"?je(d-oe,0,380,1100,1600):0,te=be==="sleepy"?1:0,Oe=l.yawn,Ie=O.shape,Ut=y.wobble+G*.6+Ne*.25,Ge=Ie==="squircle"?90:Ie==="blob"?120:Ie==="pebble"?72:0,lt=Ge?0:3.5+G*18;R=u?R:(R+W*lt*y.spin)%360,Ge&&(R+=(Math.round(R/Ge)*Ge-R)*Math.min(1,W*4));let It=i.morph,ct=It?Me(at((d-It.start)/Ui)):1,Co=R*Math.PI/180,_t=o;for(let $=0;$<96;$++){let D=ji(Ie,$/96*Math.PI*2-Co,ie,Ut);_t[$]=It&&ct<1?It.from[$]+(D-It.from[$])*ct:D;}It&&ct>=1&&(i.morph=null);let ro=1+(u?0:te?.03*Math.sin(ie/1.1):.015*Math.sin(ie/.9))+G*.04;t.body.setAttribute("d",jn(_t)),t.bodyGroup.setAttribute("transform",`scale(${ro.toFixed(4)})`);let Vt=x.yaw*Math.PI/180,Nt=y.bob+te*.4*Math.sin(d/1100)-Ne*.5+ee*.25-Oe*.5,ht=y.tilt+l.tilt+Pe*4+x.rot,ao=x.dy+Nt+l.dy,mt=Math.min(0,ao),Tt=.7*Math.max(0,ao)/(2*13.4),No=x.sy*(1+l.sy+Oe*.03)*(1-Tt),so=x.sx*(1-(l.sy+Oe*.03)*.5)*(1-.04*Math.abs(Math.sin(Vt)))*(1+Tt*.5),Et=ht*Math.PI/180,dt=0;for(let $=0;$<96;$++)dt=Math.max(dt,_t[$]*Math.sin($/96*Math.PI*2+Et));dt*=13.4*ro;let $e=1/0,ut=-1/0;for(let $=0;$<96;$++){let D=$/96*Math.PI*2+Et,Se=_t[$]*13.4*ro;Se*Math.sin(D)<dt-2.2||($e=Math.min($e,Se*Math.cos(D)),ut=Math.max(ut,Se*Math.cos(D)));}T+=(dt-T)*Math.min(1,W*12),t.mover.setAttribute("transform",`translate(0 ${mt.toFixed(2)}) translate(0 ${13.4}) scale(${so.toFixed(4)} ${No.toFixed(4)}) translate(0 ${(-T).toFixed(2)}) rotate(${ht.toFixed(2)})`);let we=at(-mt/10),qt=(ut-$e)/2*so,Oo=($e+ut)/2*so;j+=(Oo-j)*Math.min(1,W*12),F+=(qt-F)*Math.min(1,W*12);let Pt=t.ground;Pt&&(Pt.setAttribute("cx",(j*(1-we)).toFixed(2)),Pt.setAttribute("rx",((F+3.2)*(1+.25*we)).toFixed(2)),Pt.setAttribute("ry",(2*(1+.2*we)).toFixed(2)),Pt.setAttribute("opacity",((1-.65*we)*(.9+2*Tt)).toFixed(3)));let $t=t.core;$t&&($t.setAttribute("cx",j.toFixed(2)),$t.setAttribute("rx",(F*.95*(1-.4*we)).toFixed(2)),$t.setAttribute("ry",(.85*(1-.3*we)).toFixed(2)),$t.setAttribute("opacity",((1-we)**2*(.9+3*Tt)).toFixed(3)));let pt=t.face;if(pt){let $=Math.cos(Vt);pt.setAttribute("transform",`translate(${(Math.sin(Vt)*13.4*.72).toFixed(2)} 0) scale(${Math.max(.001,Math.abs($)).toFixed(3)} 1)`),pt.setAttribute("opacity",Me(at(($+.1)/.35)).toFixed(3));}let vt=1-Me(at((d-Be)/200));t.hearts.forEach(($,D)=>{if(!$)return;let Se=d-Ke-250-D*(xo/Po),ot=Math.floor(Se/xo),Ce=(Se-ot*xo)/Oi,Xt=Ke+250+D*(xo/Po)+ot*xo;if(u||!(Se>=0&&Se<1/0)||Ce>=1||Xt>Be||vt<=0){$.setAttribute("opacity","0");return}let Ht=(D+ot)%2?1:-1,nt=cn(ot*Po+D),St=Ht*(12+1.5*nt+2*Ce)+.9*Math.sin(Math.PI*2*(1.1*Ce+nt)),co=mt-4-nt*2-14*Fn(Ce),Ot=(.75+.35*nt)*(.5+.5*Me(at(Ce/.18))),Jt=Ht*10+14*Math.sin(Math.PI*2*(.9*Ce+nt));$.setAttribute("transform",`translate(${St.toFixed(2)} ${co.toFixed(2)}) rotate(${Jt.toFixed(1)}) scale(${Ot.toFixed(3)})`),$.setAttribute("opacity",(vt*Me(at(Ce/.12))*(1-Me(at((Ce-.55)/.45)))).toFixed(3));});let Mo=Math.max(x.joy,Ye),kt=1-Ne,lo=Math.min(1,y.smile+l.smile+(1-y.smile)*Mo+B*.15),Yt=Math.max(-1,(lo+(1-lo)*Ne)*(1-Oe)),zo=1-.18*Math.max(0,(Yt-.6)/.4),Bo=[y.openL*l.openL,y.openR*l.openR],Ro=[y.laughL+l.laughL,y.laughR+l.laughR];t.eyes.forEach(($,D)=>{if(!$)return;let Se=$o[D]+U*1.8*kt,ot=Lo+y.eyeY+l.faceY+X*1.1*kt,Ce=at(Math.max(Ro[D],Ne,x.joy*.8)),Xt=Math.min(.9,y.heavy+y.droop),Ht=Math.min(.9,y.heavy),nt=Bo[D]*fe*zo*(1-Oe*.85);$.setAttribute("d",_n(Se,ot,nt,Ce,y.eyeScale+l.scale+B*.04,D===0?Xt:Ht,D===0?Ht:Xt)),$.setAttribute("stroke-width",(Ce*.7).toFixed(2));let St=t.blush[D];St&&(St.setAttribute("cx",($o[D]*1.6+U*1.2*kt).toFixed(2)),St.setAttribute("cy",(Lo+4.6+l.faceY+X*.7*kt).toFixed(2)),St.setAttribute("opacity",at(y.blush).toFixed(3)));});let Ao=Ne*(.3+.25*Math.abs(Math.sin(d/85))),Gt=y.mouthW*l.width*(1+(pe-1)*ee)*(1-Oe*.1),Kt=at(-Yt+y.taper*(1-Oe)),Lt=t.mouth;if(Lt){Lt.setAttribute("d",Vn((y.mouthX+l.mouthX)*(1-Oe)+J*1.2*kt,Dn+y.eyeY*.5+l.faceY+he*.6*kt,Math.max(0,y.mouth+l.mouth,ee,Ao,x.joy*.35,Oe*2.1),Yt,Gt,(y.skew+l.skew)*(1-Oe),.9*Kt));let $=Math.min(1,.55+.45*Gt);Lt.setAttribute("stroke-width",(1.4*$*(1-.6*Kt)).toFixed(2));}N=requestAnimationFrame(Ve);};N=requestAnimationFrame(Ve);let E=()=>{cancelAnimationFrame(N),window.removeEventListener("pointermove",f),document.documentElement.removeEventListener("pointerleave",C);};return {update(d){i.config=On(d),i.onMotionEnd=d.onMotionEnd,i.onTickle=d.onTickle,i.config.shape!==a&&(a=i.config.shape,i.morph={from:o.slice(),start:performance.now()});let W=d.motion??null,ie=d.motionKey??0;(W!==s||ie!==c)&&(s=W,c=ie,i.playing=W?{name:W,start:performance.now()}:null);let O=d.chuckleKey??0;O!==g&&(g=O,i.chuckledAt=performance.now()+140+Math.random()*160);},destroy(){E(),t.mover.removeEventListener("pointerenter",m);}}}function zt({colors:t=["#66a6ff","#0059d4"],faceColor:e="#ffffff",eyeColor:i,mouthColor:o,outlineColor:a,outlineWidth:s=0,size:c=36,label:g="Botzki AI",className:m,style:u,shape:S="pebble",followCursor:f=true,...C}){let y=`bot-${useId().replace(/:/g,"")}`,L=useRef(null),N=useRef(null),Q=useRef(null),U=useRef(null),X=useRef(null),H=useRef(null),le=useRef(null),Y=useRef(null),_=useRef([]),q=useRef([]),Z=useRef([]),oe=useRef(null),J={shape:S,followCursor:f,...C},he=useRef(J);useEffect(()=>{he.current=J,oe.current?.update(J);}),useEffect(()=>{if(typeof window>"u")return;let F=L.current,G=N.current,ee=Q.current,ce=U.current,He=X.current,ke=H.current,pe=le.current,ye=Y.current;if(!(!F||!G||!ee||!ce||!He||!ke||!pe||!ye))return oe.current=Gn({svg:F,mover:G,bodyGroup:ee,body:ce,face:He,mouth:ke,ground:pe,core:ye,eyes:_.current,blush:q.current,hearts:Z.current},he.current),()=>{oe.current?.destroy(),oe.current=null;}},[]);let ze=i??e,R=o??e,T=a||"none",j=s?Number(s):0;return jsx("span",{className:m,style:{position:"relative",display:"inline-block",flex:"none",width:`${c}px`,height:`${c}px`,verticalAlign:"middle",...u},role:"img","aria-label":g,children:jsxs("svg",{ref:L,style:{position:"absolute",inset:"-25%",display:"block",width:"150%",height:"150%",overflow:"visible"},viewBox:bt.viewBox,"aria-hidden":true,children:[jsxs("defs",{children:[jsxs("radialGradient",{id:y,gradientUnits:"userSpaceOnUse",cx:"-4.8",cy:"-6.4",r:"24",children:[jsx("stop",{offset:"0",stopColor:t[0]}),jsx("stop",{offset:"1",stopColor:t[1]})]}),jsx("filter",{id:`${y}-soft`,x:"-50%",y:"-300%",width:"200%",height:"700%",children:jsx("feGaussianBlur",{stdDeviation:"1.3"})}),jsx("filter",{id:`${y}-core`,x:"-50%",y:"-300%",width:"200%",height:"700%",children:jsx("feGaussianBlur",{stdDeviation:"0.8"})}),jsx("filter",{id:`${y}-blush`,x:"-100%",y:"-100%",width:"300%",height:"300%",children:jsx("feGaussianBlur",{stdDeviation:"0.55"})})]}),jsx("ellipse",{ref:le,cx:"0",cy:bt.groundY,rx:"10",ry:"2.1",fill:"rgba(0, 0, 0, 0.08)",filter:`url(#${y}-soft)`}),jsx("ellipse",{ref:Y,cx:"0",cy:bt.groundY,rx:"6.5",ry:"0.9",fill:"rgba(0, 0, 0, 0.12)",filter:`url(#${y}-core)`}),jsxs("g",{ref:N,children:[jsx("g",{ref:Q,children:jsx("path",{ref:U,d:bt.body,fill:`url(#${y})`,stroke:T,strokeWidth:j,strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"})}),jsxs("g",{ref:X,children:[bt.blush.map((F,G)=>jsx("ellipse",{ref:ee=>{q.current[G]=ee;},cx:F.cx,cy:F.cy,rx:"1.9",ry:"1.1",opacity:"0",fill:"rgba(255, 110, 150, 0.55)",filter:`url(#${y}-blush)`},`blush${G}`)),bt.eyes.map((F,G)=>jsx("path",{ref:ee=>{_.current[G]=ee;},d:F,strokeWidth:0,strokeLinejoin:"round",fill:ze,stroke:ze},`eye${G}`)),jsx("path",{ref:H,d:bt.mouth,strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round",fill:R,stroke:R})]})]}),Array.from({length:bt.hearts},(F,G)=>jsx("path",{ref:ee=>{Z.current[G]=ee;},d:bt.heart,opacity:"0",fill:"#ff4f7e"},G))]})})}var Xi=zt;function Wo({content:t,isUser:e=false,primaryColor:i="#0ea5e9",isDark:o=false}){if(!t)return null;let a=Qi(t);return jsx("div",{className:"botzki-markdown",style:{lineHeight:1.5,wordBreak:"break-word",fontSize:"inherit"},children:a.map((s,c)=>s.type==="code"?jsx(Zi,{code:s.code,lang:s.lang,isDark:o},c):jsx(er,{lines:s.lines,isUser:e,primaryColor:i,isDark:o},c))})}function Qi(t){let e=t.split(/\r?\n/),i=[],o=false,a="",s=[],c=[];for(let g=0;g<e.length;g++){let m=e[g],u=m.trim();u.startsWith("```")?o?(o=false,i.push({type:"code",code:s.join(`
|
|
5
|
-
`),lang:a||void 0}),s=[],a=""):(c.length>0&&(
|
|
6
|
-
`),lang:a||void 0}):c.length>0&&
|
|
7
|
-
`);a.push(jsx("p",{style:{margin:"0 0 8px 0",whiteSpace:"pre-line"},children:Ho(
|
|
1
|
+
import hn,{createContext,forwardRef,useState,useEffect,useRef,useCallback,useImperativeHandle,useMemo,useContext,useId}from'react';import {Botzki}from'@botzki/js';import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';var tn=createContext(null);function en(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"sess_"+Math.random().toString(36).substring(2,11)+"_"+Date.now()}function zi({botId:o,publishableKey:e,baseUrl:n,apiHost:t,user:a,defaultSessionId:s,client:c,children:u}){let y=t||n||"https://api.botzki.com",[p,R]=useState(()=>{if(s)return s;if(typeof window<"u")try{let b=localStorage.getItem(`botzki_session_${o}`);if(b)return b;let $=en();return localStorage.setItem(`botzki_session_${o}`,$),$}catch{return en()}return s||en()}),m=useMemo(()=>c||new Botzki({botId:o,publishableKey:e,apiHost:y}),[c,o,e,y]);useEffect(()=>{a&&m&&typeof m.setUser=="function"&&m.setUser(a);},[m,a]);let C=useMemo(()=>({client:m,botId:o,publishableKey:e,baseUrl:y,apiHost:y,user:a,sessionId:p,setSessionId:R}),[m,o,e,y,a,p]);return jsx(tn.Provider,{value:C,children:u})}function zt(){let o=useContext(tn);if(!o)throw new Error("useBotzki must be used within a <BotzkiProvider>. Wrap your application or component with <BotzkiProvider botId='...' publishableKey='...'>.");return o}function Dt(){return useContext(tn)}function on(o={}){let{maskInputs:e=true,maxHtmlBytes:n=1.5*1024*1024}=o;if(typeof window>"u"||typeof document>"u")return {url:"",pathname:"",title:"",viewportWidth:1280,viewportHeight:800,scrollX:0,scrollY:0,htmlSnapshot:"<html><body>Co-browsing not supported in this environment</body></html>",timestamp:Date.now()};let t=document.documentElement.cloneNode(true);t.querySelectorAll("script, noscript, iframe, object, embed, audio, video").forEach(m=>m.remove()),t.querySelectorAll("*").forEach(m=>{let C=Array.from(m.attributes);for(let b of C)b.name.toLowerCase().startsWith("on")&&m.removeAttribute(b.name);}),e&&(t.querySelectorAll("input").forEach($=>{let F=($.getAttribute("type")||"text").toLowerCase(),te=($.getAttribute("autocomplete")||"").toLowerCase();F==="password"||te.includes("cc-")||te.includes("cvv")||$.classList.contains("botzki-mask")||$.hasAttribute("data-private")||F==="password"?$.setAttribute("value","\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"):$.value&&$.setAttribute("value",$.value);}),t.querySelectorAll("textarea").forEach($=>{($.classList.contains("botzki-mask")||$.hasAttribute("data-private"))&&($.textContent="\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022");}),t.querySelectorAll("[data-private], .botzki-mask").forEach($=>{$.textContent="\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";}));let c=window.location.href;t.querySelectorAll("link[rel='stylesheet'], link[rel='preload']").forEach(m=>{let C=m.getAttribute("href");if(C&&!C.startsWith("http://")&&!C.startsWith("https://")&&!C.startsWith("//")&&!C.startsWith("data:"))try{m.setAttribute("href",new URL(C,c).href);}catch{}}),t.querySelectorAll("img").forEach(m=>{let C=m.getAttribute("src");if(C&&!C.startsWith("http://")&&!C.startsWith("https://")&&!C.startsWith("//")&&!C.startsWith("data:"))try{m.setAttribute("src",new URL(C,c).href);}catch{}});let p=t.querySelector("head");if(p&&!p.querySelector("base")){let m=document.createElement("base");m.setAttribute("href",c),p.insertBefore(m,p.firstChild);}let R=`<!DOCTYPE html>
|
|
2
|
+
`+t.outerHTML;return R.length>n&&(R=R.slice(0,n)),{url:window.location.href,pathname:window.location.pathname+window.location.search,title:document.title||"Visitor Page",viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,scrollX:window.scrollX||window.pageXOffset||0,scrollY:window.scrollY||window.pageYOffset||0,htmlSnapshot:R,timestamp:Date.now()}}function an({botId:o,baseUrl:e="",sessionId:n,isHumanHandoffActive:t=false}){let[a,s]=useState(true),[c,u]=useState(false),[y,p]=useState(false),[R,m]=useState(null),[C,b]=useState(null),[$,F]=useState(null),[te,U]=useState(null),de=useRef(0),H=useRef(""),X=useRef(false);X.current=y;let N=e.replace(/\/$/,"");useEffect(()=>{if(!o||!n)return;let j=true,ne=null,me=async()=>{try{let ye=await fetch(`${N}/api/v1/public/chat/${o}/cobrowse/status?sessionId=${encodeURIComponent(n)}`);if(!ye.ok)return;let v=await ye.json();if(!j)return;if(s(v.enabled!==!1),v.requested&&!X.current?(u(!0),m(v.operatorName||"Support Specialist")):!v.requested&&!v.active&&(u(!1),X.current&&(p(!1),b(null),U(null))),v.active&&!X.current&&(p(!0),u(!1)),v.active&&v.latestPointer&&(v.latestPointer.action==="leave"?b(null):(b(v.latestPointer),v.latestPointer.selector&&U(v.latestPointer.selector))),v.active&&v.latestHighlight&&(Date.now()-(v.latestHighlight.timestamp||0)<12e3?(F(v.latestHighlight),v.latestHighlight.selector&&U(v.latestHighlight.selector)):F(null)),v.active&&v.allowRemoteScroll&&v.latestScroll){let I=v.latestScroll,V=`${I.scrollY}_${I.scrollX??0}_${I.timestamp??""}`;if(V!==H.current){H.current=V;let D=I.scrollY;typeof D=="number"&&window.scrollTo({top:D,behavior:"smooth"});}}}catch{}finally{j&&(ne=setTimeout(me,X.current?400:2e3));}};return me(),()=>{j=false,ne&&clearTimeout(ne);}},[o,n,N,t]),useEffect(()=>{if(!y||!o||!n)return;let j=async()=>{let ne=Date.now();if(!(ne-de.current<150)){de.current=ne;try{await fetch(`${N}/api/v1/public/chat/${o}/cobrowse/viewport?sessionId=${encodeURIComponent(n)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:window.location.href,title:document.title||"Visitor Page",viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,scrollX:window.scrollX||window.pageXOffset||0,scrollY:window.scrollY||window.pageYOffset||0,timestamp:ne})});}catch{}}};return window.addEventListener("scroll",j,{passive:true}),window.addEventListener("resize",j,{passive:true}),()=>{window.removeEventListener("scroll",j),window.removeEventListener("resize",j);}},[y,o,n,N]);let ue=useCallback(async()=>{if(!(!o||!n))try{await fetch(`${N}/api/v1/public/chat/${o}/cobrowse/respond`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:n,accept:!0})}),p(!0),u(!1);let j=on({maskInputs:!0});await fetch(`${N}/api/v1/public/chat/${o}/cobrowse/snapshot?sessionId=${encodeURIComponent(n)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(j)});}catch(j){console.error("Failed to accept co-browsing:",j);}},[o,n,N]),Q=useCallback(async j=>{if(!(!o||!n))try{await fetch(`${N}/api/v1/public/chat/${o}/cobrowse/respond`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:n,accept:!1,reason:j||"Visitor declined"})});}catch(ne){console.error("Failed to decline co-browsing:",ne);}finally{u(false);}},[o,n,N]),oe=useCallback(async j=>{if(!(!o||!n))try{await fetch(`${N}/api/v1/public/chat/${o}/cobrowse/stop`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:n,reason:j||"Visitor ended session"})});}catch(ne){console.error("Failed to stop co-browsing:",ne);}finally{p(false),u(false),b(null),U(null);}},[o,n,N]);return {enabled:a,isRequested:c,isActive:y,operatorName:R,pointer:C,highlight:$,highlightedSelector:te,accept:ue,decline:Q,stop:oe}}var ho=null,Eo="";function Ln(){if(!(typeof window>"u"))try{let o=window.AudioContext||window.webkitAudioContext;if(!o)return;let e=new o;e.state==="suspended"&&e.resume().catch(()=>{});let n=e.currentTime,t=e.createGain();t.gain.setValueAtTime(.001,n),t.gain.linearRampToValueAtTime(.12,n+.02),t.gain.exponentialRampToValueAtTime(.001,n+.4),t.connect(e.destination);let a=e.createOscillator();a.type="sine",a.frequency.setValueAtTime(587.33,n),a.connect(t),a.start(n),a.stop(n+.15);let s=e.createOscillator();s.type="sine",s.frequency.setValueAtTime(880,n+.1),s.connect(t),s.start(n+.1),s.stop(n+.4),setTimeout(()=>{e.close().catch(()=>{});},500);}catch{}}function Hn(o="\u{1F514} (1) New message from Support"){if(!(typeof document>"u"||!document.hidden)&&!ho){Eo=document.title;let e=true;document.title=o,ho=setInterval(()=>{document.title=e?o:Eo,e=!e;},1e3);let n=()=>{ho&&(clearInterval(ho),ho=null,Eo&&(document.title=Eo)),window.removeEventListener("focus",n),document.removeEventListener("visibilitychange",n);};window.addEventListener("focus",n),document.addEventListener("visibilitychange",n);}}function jt(o,e){typeof document<"u"&&document.hidden&&(e?.enableSound!==false&&Ln(),e?.enableTabTitle!==false&&Hn(o));}function mt(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"msg_"+Math.random().toString(36).substring(2,11)+"_"+Date.now()}function mo(o={}){let e=Dt(),n=o.botId||e?.botId,t=o.publishableKey||e?.publishableKey,a=o.baseUrl||e?.baseUrl||"https://api.botzki.com",s=useMemo(()=>e?.client&&(!o.botId||o.botId===e.botId)?e.client:n&&t?new Botzki({botId:n,publishableKey:t,apiHost:a}):null,[e?.client,e?.botId,o.botId,n,t,a]),c=o.storageKey||(n?`botzki_chat_history_${n}`:"botzki_chat_history"),u=o.persistSession??false,[y,p]=useState(()=>o.sessionId?o.sessionId:e?.sessionId?e.sessionId:"sess_"+Math.random().toString(36).substring(2,9)),[R,m]=useState(o.initialMessages||[]),[C,b]=useState(""),[$,F]=useState(false),[te,U]=useState(false),[de,H]=useState(null),[X,N]=useState(false),[ue,Q]=useState(false),[oe,j]=useState(null),[ne,me]=useState(false),[ye,v]=useState(null),I=useRef(new Set),[V,D]=useState(()=>typeof window<"u"?[window.location.pathname+(window.location.search||"")]:[]);useEffect(()=>{if(typeof window>"u")return;let T=window.location.pathname+(window.location.search||"");D(d=>d.length>0&&d[d.length-1]===T?d:[...d.slice(-9),T]);},[]);let G=useRef(X);G.current=X;let Z=useRef(ue);Z.current=ue;let le=useRef(null),He=useRef(R);He.current=R,useEffect(()=>{if(!(!u||typeof window>"u"||o.initialMessages?.length))try{let T=localStorage.getItem(c);if(T){let d=JSON.parse(T);Array.isArray(d)&&m(d.map(W=>({...W,createdAt:new Date(W.createdAt)})));}}catch{}},[u,c,o.initialMessages?.length]),useEffect(()=>{if(!(!u||typeof window>"u"))try{R.length>0&&localStorage.setItem(c,JSON.stringify(R));}catch{}},[R,u,c]);let Se=useCallback(()=>{le.current&&(le.current.abort(),le.current=null),F(false),U(false);},[]),pe=useCallback(async(T,d)=>{let W=T.trim();if(!W&&!d?.imageBase64&&!d?.audioUrl)return;if(!n){let A=new Error("botId is required. Provide botId in options or wrap your component tree in <BotzkiProvider botId='...'>");H(A),o.onError?.(A);return}if(H(null),G.current||Z.current){let A={id:mt(),role:"user",content:W,createdAt:new Date,imageBase64:d?.imageBase64,imageUrl:d?.imageUrl,audioUrl:d?.audioUrl,audioDuration:d?.audioDuration,fileUrl:d?.fileUrl,fileName:d?.fileName,fileSize:d?.fileSize};m(l=>[...l,A]),o.onSendMessage?.(A),F(false),U(false);try{let l=a?a.replace(/\/+$/,""):"https://api.botzki.com",k={"Content-Type":"application/json"};t&&(k.Authorization=`Bearer ${t}`);let f=await fetch(`${l}/api/v1/public/chat/${n}/handoff/message`,{method:"POST",headers:k,body:JSON.stringify({sessionId:y,content:W||(d?.audioUrl?"\u{1F3A4} Voice message":d?.imageUrl||d?.imageBase64?"\u{1F4F7} Image attachment":d?.fileName?`\u{1F4CE} File: ${d.fileName}`:""),audioUrl:d?.audioUrl,audioDurationSeconds:d?.audioDuration,imageUrl:d?.imageUrl||d?.imageBase64,fileUrl:d?.fileUrl,fileName:d?.fileName,fileSize:d?.fileSize})});if(!f.ok){let h=await f.json().catch(()=>({}));console.warn(`Handoff message delivery failed (${f.status}):`,h);}}catch(l){console.warn("Failed to deliver handoff message:",l);}return}F(true),U(o.stream!==false);let J={id:mt(),role:"user",content:W,createdAt:new Date,imageBase64:d?.imageBase64,audioUrl:d?.audioUrl,audioDuration:d?.audioDuration},O=mt(),q={id:O,role:"assistant",content:"",createdAt:new Date,isStreaming:o.stream!==false};m(A=>[...A,J,q]),o.onSendMessage?.(J);let P=new AbortController;le.current=P;try{if(o.stream!==!1){let A="";if(s&&typeof s.chatStream=="function")await s.chatStream({message:W,sessionId:y,language:o.language,imageBase64:d?.imageBase64,imageMimeType:d?.imageMimeType,onDelta:l=>{P.signal.aborted||(A+=l,m(k=>k.map(f=>f.id===O?{...f,content:A}:f)));},onDone:l=>{if(P.signal.aborted)return;let k={id:O,role:"assistant",content:l.reply||A,createdAt:new Date,citations:l.citations,isStreaming:!1};m(f=>f.map(h=>h.id===O?k:h)),F(!1),U(!1),o.onResponse?.(l),o.onFinish?.(k);},onError:l=>{P.signal.aborted||(H(l),F(!1),U(!1),m(k=>k.map(f=>f.id===O?{...f,isStreaming:!1,error:l.message}:f)),o.onError?.(l));}});else {let l=a?a.replace(/\/+$/,""):"https://api.botzki.com",k={"Content-Type":"application/json"};t&&(k.Authorization=`Bearer ${t}`);let f=await fetch(`${l}/api/v1/public/chat/${n}/stream`,{method:"POST",headers:k,body:JSON.stringify({query:W,message:W,sessionId:y,language:o.language,imageBase64:d?.imageBase64,imageMimeType:d?.imageMimeType}),signal:P.signal});if(!f.ok){let fe=`Chat request failed with status ${f.status}`;try{let we=await f.json();we?.message&&(fe=we.message);}catch{}throw new Error(fe)}let h=f.body?.getReader();if(!h)throw new Error("Response body is not readable.");let S=new TextDecoder("utf-8"),z="",B=[],ce,re,w=null;for(;;){let{done:fe,value:we}=await h.read();if(fe||P.signal.aborted)break;z+=S.decode(we,{stream:!0});let Oe=z.split(`
|
|
3
|
+
`);z=Oe.pop()||"";for(let Pe of Oe)if(Pe=Pe.trim(),Pe.startsWith("data: ")){let qe=Pe.slice(6).trim();if(qe==="[DONE]")continue;try{let ae=JSON.parse(qe),Ye=ae.delta??ae.token??ae.text??ae.content??"";Ye&&(A+=Ye,m(Ue=>Ue.map(Ie=>Ie.id===O?{...Ie,content:A}:Ie))),ae.answer&&(A=ae.answer,m(Ue=>Ue.map(Ie=>Ie.id===O?{...Ie,content:A}:Ie))),ae.citations&&(B=ae.citations),ae.escalation&&(ce=ae.escalation),(ae.modelUsed||ae.model_used||ae.piiRedacted||ae.pii_redacted)&&(w=ae);let ee=ae.proposedAction??ae.proposed_action??ae.action;ee&&(ee.actionId||ee.action_id||ee.actionName||ee.action_name)&&(re={actionId:ee.actionId??ee.action_id??"",actionName:ee.actionName??ee.action_name??"",displayName:ee.displayName??ee.display_name??ee.actionName??ee.action_name??"",description:ee.description,executionType:ee.executionType??ee.execution_type??"ServerWebhook",parameters:ee.parameters,requiresConfirmation:ee.requiresConfirmation??ee.requires_confirmation??!0,confirmationPrompt:ee.confirmationPrompt??ee.confirmation_prompt,successMessage:ee.successMessage??ee.success_message,token:ee.token??ee.actionToken??"",status:"pending"});}catch{qe&&(A+=qe,m(ae=>ae.map(Ye=>Ye.id===O?{...Ye,content:A}:Ye)));}}}let he={id:O,role:"assistant",content:A,createdAt:new Date,citations:B.length>0?B:void 0,isStreaming:!1,escalation:ce,proposedAction:re,modelUsed:w?.modelUsed??w?.model_used,fallbackTriggered:w?.fallbackTriggered??w?.fallback_triggered,piiRedacted:w?.piiRedacted??w?.pii_redacted,redactionsCount:w?.redactionsCount??w?.redactions_count,localPrivacyMode:w?.localPrivacyMode??w?.local_privacy_mode};m(fe=>fe.map(we=>we.id===O?he:we)),F(!1),U(!1),jt("\u{1F514} (1) New message from Support",{enableSound:o.enableSoundAlert,enableTabTitle:o.enableTabTitleNotification}),re&&o.onActionProposed?.(re),o.onResponse?.({reply:A,answer:A,citations:B,insufficientEvidence:!1,sessionId:y}),o.onFinish?.(he);}}else {let A="",l=[],k,f,h=null;if(s&&typeof s.chat=="function"){let z=await s.chat({message:W,sessionId:y,language:o.language,imageBase64:d?.imageBase64,imageMimeType:d?.imageMimeType});h=z,A=z.reply||z.answer,l=z.citations||[],z.escalation&&(k=z.escalation);let B=z.proposedAction??z.proposed_action??z.action;B&&(B.actionId||B.action_id||B.actionName||B.action_name)&&(f={actionId:B.actionId??B.action_id??"",actionName:B.actionName??B.action_name??"",displayName:B.displayName??B.display_name??B.actionName??B.action_name??"",description:B.description,executionType:B.executionType??B.execution_type??"ServerWebhook",parameters:B.parameters,requiresConfirmation:B.requiresConfirmation??B.requires_confirmation??!0,confirmationPrompt:B.confirmationPrompt??B.confirmation_prompt,successMessage:B.successMessage??B.success_message,token:B.token??B.actionToken??"",status:"pending"});}else {let z=a?a.replace(/\/+$/,""):"https://api.botzki.com",B={"Content-Type":"application/json"};t&&(B.Authorization=`Bearer ${t}`);let ce=await fetch(`${z}/api/v1/public/chat/${n}`,{method:"POST",headers:B,body:JSON.stringify({query:W,message:W,sessionId:y,language:o.language,imageBase64:d?.imageBase64,imageMimeType:d?.imageMimeType}),signal:P.signal});if(!ce.ok){let he=`Chat request failed with status ${ce.status}`;try{let fe=await ce.json();fe?.message&&(he=fe.message);}catch{}throw new Error(he)}let re=await ce.json();h=re,A=re.reply||re.answer||"",l=re.citations||[],re.escalation&&(k=re.escalation);let w=re.proposedAction??re.proposed_action??re.action;w&&(w.actionId||w.action_id||w.actionName||w.action_name)&&(f={actionId:w.actionId??w.action_id??"",actionName:w.actionName??w.action_name??"",displayName:w.displayName??w.display_name??w.actionName??w.action_name??"",description:w.description,executionType:w.executionType??w.execution_type??"ServerWebhook",parameters:w.parameters,requiresConfirmation:w.requiresConfirmation??w.requires_confirmation??!0,confirmationPrompt:w.confirmationPrompt??w.confirmation_prompt,successMessage:w.successMessage??w.success_message,token:w.token??w.actionToken??"",status:"pending"});}let S={id:O,role:"assistant",content:A,createdAt:new Date,citations:l.length>0?l:void 0,isStreaming:!1,escalation:k,proposedAction:f,modelUsed:h?.modelUsed??h?.model_used,fallbackTriggered:h?.fallbackTriggered??h?.fallback_triggered,piiRedacted:h?.piiRedacted??h?.pii_redacted,redactionsCount:h?.redactionsCount??h?.redactions_count,localPrivacyMode:h?.localPrivacyMode??h?.local_privacy_mode};m(z=>z.map(B=>B.id===O?S:B)),F(!1),U(!1),jt("\u{1F514} (1) New message from Support",{enableSound:o.enableSoundAlert,enableTabTitle:o.enableTabTitleNotification}),f&&o.onActionProposed?.(f),o.onResponse?.({reply:A,answer:A,citations:l,insufficientEvidence:!1,sessionId:y}),o.onFinish?.(S);}}catch(A){if(!P.signal.aborted){let l=A instanceof Error?A:new Error(String(A));H(l),F(false),U(false),m(k=>k.map(f=>f.id===O?{...f,isStreaming:false,error:l.message}:f)),o.onError?.(l);}}finally{le.current===P&&(le.current=null);}},[s,o,y]),xe=useCallback(T=>{b(T.target.value);},[]),Ee=useCallback(async(T,d)=>{T&&typeof T.preventDefault=="function"&&T.preventDefault();let W=C;b(""),await pe(W,d);},[C,pe]),We=useCallback(T=>{let d={id:T.id||mt(),role:T.role||"user",content:T.content,createdAt:T.createdAt||new Date,citations:T.citations,isStreaming:T.isStreaming,error:T.error};m(W=>[...W,d]);},[]),Ne=useCallback(async()=>{let T=He.current;if(T.length===0)return;let d=T.map(J=>J.role).lastIndexOf("user");if(d===-1)return;let W=T[d];m(T.slice(0,d)),await pe(W.content);},[pe]),vt=useCallback(async(T,d)=>{if(!n){let f=new Error("botId is required. Provide botId in options or wrap your component tree in <BotzkiProvider botId='...'>");H(f),o.onError?.(f);return}let W=d?.audioUrl||URL.createObjectURL(T),J=mt();H(null),F(true);let O={id:J,role:"user",content:"",audioUrl:W,audioDuration:d?.audioDuration,isTranscribing:true,createdAt:new Date};m(f=>[...f,O]);let q="";try{if(s&&typeof s.transcribeAudio=="function")q=(await s.transcribeAudio(T))?.text||"";else {let f=a?a.replace(/\/+$/,""):"https://api.botzki.com",h=new FormData;h.append("file",T,"voice_recording.webm");let S={};t&&(S.Authorization=`Bearer ${t}`);let z=await fetch(`${f}/api/v1/public/chat/${n}/transcribe`,{method:"POST",headers:S,body:h});z.ok&&(q=(await z.json()).text||"");}}catch(f){console.warn("Audio transcription error:",f);}m(f=>f.map(h=>h.id===J?{...h,content:q||"(Voice message)",isTranscribing:false}:h));let P=q||"Voice message recorded",A=mt(),l=new AbortController;le.current=l,U(o.stream!==false);let k={id:A,role:"assistant",content:"",createdAt:new Date,isStreaming:o.stream!==false};m(f=>[...f,k]);try{if(o.stream!==!1){let f="";if(s&&typeof s.chatStream=="function")await s.chatStream({message:P,sessionId:y,language:o.language,onDelta:h=>{l.signal.aborted||(f+=h,m(S=>S.map(z=>z.id===A?{...z,content:f}:z)));},onDone:h=>{if(l.signal.aborted)return;let S={id:A,role:"assistant",content:h.reply||f,createdAt:new Date,citations:h.citations,isStreaming:!1};m(z=>z.map(B=>B.id===A?S:B)),F(!1),U(!1),o.onResponse?.(h),o.onFinish?.(S);},onError:h=>{l.signal.aborted||(H(h),F(!1),U(!1),o.onError?.(h));}});else {let h=a?a.replace(/\/+$/,""):"https://api.botzki.com",S={"Content-Type":"application/json"};t&&(S.Authorization=`Bearer ${t}`);let z=await fetch(`${h}/api/v1/public/chat/${n}/stream`,{method:"POST",headers:S,body:JSON.stringify({query:P,message:P,sessionId:y,language:o.language}),signal:l.signal});if(!z.ok)throw new Error(`Chat stream failed with status ${z.status}`);if(z.body){let ce=z.body.getReader(),re=new TextDecoder,w="";for(;;){let{done:he,value:fe}=await ce.read();if(he)break;w+=re.decode(fe,{stream:!0});let we=w.split(`
|
|
4
|
+
`);w=we.pop()||"";for(let Oe of we){let Pe=Oe.trim();if(Pe.startsWith("data:")){let qe=Pe.slice(5).trim();if(!qe||qe==="[DONE]")continue;try{let ae=JSON.parse(qe);ae.delta&&(f+=ae.delta,m(Ye=>Ye.map(ee=>ee.id===A?{...ee,content:f}:ee)));}catch{}}}}}let B={id:A,role:"assistant",content:f,createdAt:new Date,isStreaming:!1};m(ce=>ce.map(re=>re.id===A?B:re)),F(!1),U(!1),jt("\u{1F514} (1) New message from Support"),o.onFinish?.(B);}}else {let f="",h=null;if(s&&typeof s.chat=="function"){let z=await s.chat({message:P,sessionId:y,language:o.language});h=z,f=z.reply||z.answer;}else {let z=a?a.replace(/\/+$/,""):"https://api.botzki.com",B={"Content-Type":"application/json"};t&&(B.Authorization=`Bearer ${t}`);let re=await(await fetch(`${z}/api/v1/public/chat/${n}`,{method:"POST",headers:B,body:JSON.stringify({query:P,message:P,sessionId:y,language:o.language}),signal:l.signal})).json();h=re,f=re.reply||re.answer||"";}let S={id:A,role:"assistant",content:f,createdAt:new Date,isStreaming:!1,modelUsed:h?.modelUsed??h?.model_used,fallbackTriggered:h?.fallbackTriggered??h?.fallback_triggered,piiRedacted:h?.piiRedacted??h?.pii_redacted,redactionsCount:h?.redactionsCount??h?.redactions_count,localPrivacyMode:h?.localPrivacyMode??h?.local_privacy_mode};m(z=>z.map(B=>B.id===A?S:B)),F(!1),U(!1),o.onFinish?.(S);}}catch(f){if(f?.name==="AbortError")return;H(f),F(false),U(false),o.onError?.(f);}},[n,a,t,s,y,o]);useEffect(()=>{if(!n||!y)return;let T=true,d=a.replace(/\/+$/,"");return (async()=>{try{let J={};t&&(J.Authorization=`Bearer ${t}`);let O=await fetch(`${d}/api/v1/public/chat/${n}/handoff/status?sessionId=${y}`,{headers:J});if(!O.ok||!T)return;let q=await O.json();if(!T)return;q.status==="OperatorActive"?(N(!0),Q(!1),q.assignedOperator&&j(q.assignedOperator)):q.status==="WaitingHuman"?(Q(!0),N(!1)):q.status==="Resolved"&&q.ticketId&&!I.current.has(q.ticketId)&&(Q(!1),N(!1),v(q.ticketId)),Array.isArray(q.messages)&&q.messages.length>0&&m(P=>{let A=new Set(P.map(h=>h.id)),l=new Set(P.map(h=>h.content)),k=[...P],f=!1;for(let h of q.messages)if(!(h.senderType==="System"&&h.content?.startsWith("Visitor requested"))&&!(h.content&&h.content.includes("joined")&&k.some(z=>z.role==="system"&&z.content&&z.content.includes("joined")))&&!A.has(h.id)&&!l.has(h.content)){let S=String(h.createdAtUtc||""),z=S?new Date(S.endsWith("Z")?S:S+"Z"):new Date;k.push({id:h.id,role:h.senderType==="Operator"?"assistant":h.senderType==="Visitor"?"user":"system",content:h.content||"",createdAt:z,senderType:h.senderType,senderName:h.senderName,isStreaming:!1}),f=!0;}return f?k:P});}catch{}})(),()=>{T=false;}},[n,y,a,t]),useEffect(()=>{if(!ue&&!X||!n)return;let T=true,d=a.replace(/\/+$/,""),W=async()=>{try{let O={};t&&(O.Authorization=`Bearer ${t}`);let q=await fetch(`${d}/api/v1/public/chat/${n}/handoff/status?sessionId=${y}`,{headers:O});if(!q.ok||!T)return;let P=await q.json();if(!T)return;P.status==="OperatorActive"?(N(!0),Q(!1),P.assignedOperator&&j(A=>((!A||A.name!==P.assignedOperator.name)&&o.onOperatorJoined?.(P.assignedOperator),P.assignedOperator))):P.status==="WaitingHuman"?(Q(!0),N(!1)):(P.status==="BotHandling"||P.status==="Closed"||P.status==="Resolved")&&(Q(!1),N(!1),j(null),me(!1),P.status==="Resolved"&&P.ticketId&&!I.current.has(P.ticketId)&&v(A=>(A!==P.ticketId&&o.onTicketResolved?.(P.ticketId),P.ticketId))),Array.isArray(P.messages)&&m(A=>{let l=new Set(A.map(S=>S.id)),k=new Set(A.map(S=>S.content)),f=[...A],h=!1;for(let S of P.messages)if(S.senderType==="System"){if(S.content&&S.content.startsWith("Visitor requested")||S.content&&S.content.includes("joined")&&f.some(B=>B.role==="system"&&B.content&&B.content.includes("joined")))continue;if(!l.has(S.id)&&!k.has(S.content)){let z=String(S.createdAtUtc||""),B=z?new Date(z.endsWith("Z")?z:z+"Z"):new Date;f.push({id:S.id,role:"system",content:S.content,createdAt:B}),l.add(S.id),k.add(S.content),h=!0,jt("\u{1F514} (1) New message from Support Specialist",{enableSound:o.enableSoundAlert,enableTabTitle:o.enableTabTitleNotification});}}else if(S.senderType==="Operator"){if(l.has(S.id))continue;let z=f.findIndex(B=>B.senderType==="operator"&&B.content===S.content&&B.id.startsWith("msg_"));if(z!==-1){f[z]={...f[z],id:S.id},l.add(S.id),h=!0;continue}if(!k.has(S.content)){let B=String(S.createdAtUtc||""),ce=B?new Date(B.endsWith("Z")?B:B+"Z"):new Date;f.push({id:S.id,role:"assistant",senderType:"operator",senderName:S.senderName||"Support Specialist",content:S.content,audioUrl:S.audioUrl,audioDuration:S.audioDurationSeconds,imageUrl:S.imageUrl,fileUrl:S.fileUrl,fileName:S.fileName,fileSize:S.fileSize,deliveryStatus:S.deliveryStatus,deliveryChannel:S.deliveryChannel,createdAt:ce}),l.add(S.id),k.add(S.content),h=!0,jt("\u{1F514} (1) New message from Support Specialist",{enableSound:o.enableSoundAlert,enableTabTitle:o.enableTabTitleNotification});}}return h?f:A});}catch{}};W();let J=setInterval(W,3e3);return ()=>{T=false,clearInterval(J);}},[ue,X,n,a,t,y]);let At=useCallback(async(T,d,W,J)=>{let O=a.replace(/\/+$/,"");try{let q={"Content-Type":"application/json"};t&&(q.Authorization=`Bearer ${t}`);let P=typeof Intl<"u"?Intl.DateTimeFormat().resolvedOptions().timeZone:void 0,A={...o.visitorData||{},...J?.customData||{}},l=Array.from(new Set([...o.tags||[],...J?.tags||[]])),k=J?.lastBrowsedPages||V,f=R.filter(z=>(z.role==="user"||z.role==="assistant")&&z.content&&z.content.trim().length>0).map(z=>({role:z.role,content:z.content.trim(),createdAt:z.createdAt instanceof Date?z.createdAt.toISOString():z.createdAt?new Date(z.createdAt).toISOString():new Date().toISOString()})),h=await fetch(`${O}/api/v1/public/chat/${n}/handoff/request`,{method:"POST",headers:q,body:JSON.stringify({sessionId:y,reason:T,visitorName:d,visitorEmail:W,timezone:P,lastBrowsedPages:k.length>0?k:void 0,customData:Object.keys(A).length>0?A:void 0,tags:l.length>0?l:void 0,transcript:f.length>0?f:void 0})}),S=await h.json().catch(()=>({}));if(!h.ok){if(S?.code==="EMAIL_REQUIRED"){let z=new Error(S.message||"Email is required before handoff.");throw z.code="EMAIL_REQUIRED",z}throw new Error(S?.message||`Handoff request failed with status ${h.status}`)}if(S.isOnline===!1){m(z=>[...z,{id:mt(),role:"system",content:S.offlineMessage||"Our support team is currently offline. We will reply as soon as possible!",createdAt:new Date}]),S.behavior==="aiOnly"?Q(!1):Q(!0);return}Q(!0),o.onEscalationRequest?.({reason:T,visitorName:d,visitorEmail:W}),m(z=>{let B=[...z];return B.some(re=>re.role==="system"&&re.content.includes("Connecting you with our support team"))||B.push({id:mt(),role:"system",content:"Connecting you with our support team... You are in queue for a live specialist.",createdAt:new Date}),S.welcomeMessage&&(B.some(w=>w.senderType==="operator"&&w.content===S.welcomeMessage)||B.push({id:mt(),role:"assistant",senderType:"operator",senderName:"Support Specialist",content:S.welcomeMessage,createdAt:new Date})),B});}catch(q){if(q?.code==="EMAIL_REQUIRED")throw q;console.warn("Human handoff request failed:",q);}},[a,n,t,y,V,o.visitorData,o.tags]),Xe=useCallback(async()=>{Q(false),N(false),j(null),me(false);let T=a.replace(/\/+$/,"");try{let d={"Content-Type":"application/json"};t&&(d.Authorization=`Bearer ${t}`),await fetch(`${T}/api/v1/public/chat/${n}/handoff/cancel`,{method:"POST",headers:d,body:JSON.stringify({sessionId:y})});}catch{}m(d=>[...d,{id:mt(),role:"system",content:"Returned to autonomous AI assistant mode.",createdAt:new Date}]);},[a,n,t,y]),Ae=useCallback(()=>{Se(),m([]),v(null),Q(false),N(false),j(null);let T="sess_"+Math.random().toString(36).substring(2,9);if(p(T),u&&typeof window<"u")try{localStorage.removeItem(c),localStorage.setItem(`${c}_session_id`,T);}catch{}},[Se,u,c]),be=useCallback(async(T,d)=>{if(!(!ye||!n))try{let W=a?a.replace(/\/+$/,""):"https://api.botzki.com",J={"Content-Type":"application/json"};t&&(J.Authorization=`Bearer ${t}`),await fetch(`${W}/api/v1/public/chat/${n}/handoff/feedback`,{method:"POST",headers:J,body:JSON.stringify({ticketId:ye,rating:T,feedback:d||null})}),I.current.add(ye),v(null),o.onCsatSubmit?.(T,d);}catch(W){console.warn("Failed to submit handoff feedback:",W);}},[ye,n,a,t]),Qe=useCallback(async(T,d,W)=>{let J=a.replace(/\/+$/,""),O={"Content-Type":"application/json"};t&&(O.Authorization=`Bearer ${t}`);let P=He.current.find(A=>A.id===T)?.proposedAction;m(A=>A.map(l=>l.id===T&&l.proposedAction?{...l,proposedAction:{...l.proposedAction,status:"executing"}}:l));try{let A=await fetch(`${J}/api/v1/public/chat/${n}/actions/execute`,{method:"POST",headers:O,body:JSON.stringify({actionToken:d,confirmedParameters:W,visitorSessionId:y})});if(!A.ok){let k=`Execution failed with status ${A.status}`;try{let f=await A.json();f?.message&&(k=f.message);}catch{}throw new Error(k)}let l=await A.json();return m(k=>k.map(f=>f.id===T&&f.proposedAction?{...f,proposedAction:{...f.proposedAction,status:"completed",result:l}}:f)),P&&o.onActionExecuted?.({...P,status:"completed",result:l},l),{success:!0,result:l}}catch(A){return m(l=>l.map(k=>k.id===T&&k.proposedAction?{...k,proposedAction:{...k.proposedAction,status:"failed",error:A.message}}:k)),{success:false,error:A.message}}},[n,a,t,y]),Ke=useCallback(async(T,d)=>{let J=He.current.find(q=>q.id===T)?.proposedAction,O=J?.token;if(m(q=>q.map(P=>P.id===T&&P.proposedAction?{...P,proposedAction:{...P.proposedAction,status:"cancelled"}}:P)),J&&o.onActionCancelled?.({...J,status:"cancelled"},d),O&&n)try{let q=a?a.replace(/\/+$/,""):"https://api.botzki.com",P={"Content-Type":"application/json"};t&&(P.Authorization=`Bearer ${t}`),await fetch(`${q}/api/v1/public/chat/${n}/actions/cancel`,{method:"POST",headers:P,body:JSON.stringify({actionToken:O,reason:d||"Cancelled by visitor"})});}catch{}},[n,a,t]),Be=an({botId:n||"",baseUrl:a,sessionId:y,isHumanHandoffActive:X&&o.enableCoBrowse!==false}),Ve=useRef(false);return useEffect(()=>{Be.isActive&&!Ve.current?o.onCoBrowseStart?.(Be.operatorName):!Be.isActive&&Ve.current&&o.onCoBrowseEnd?.(),Ve.current=Be.isActive;},[Be.isActive,Be.operatorName]),{messages:R,input:C,setInput:b,handleInputChange:xe,handleSubmit:Ee,sendMessage:pe,sendVoiceMessage:vt,append:We,reload:Ne,stop:Se,clearMessages:Ae,setMessages:m,isLoading:$,isStreaming:te,error:de,sessionId:y,setSessionId:p,isHumanHandoffActive:X,isWaitingForHuman:ue,assignedOperator:oe,isOperatorTyping:ne,requestHumanHandoff:At,cancelHumanHandoff:Xe,pendingCsatTicketId:ye,submitHandoffFeedback:be,executeProposedAction:Qe,cancelProposedAction:Ke,coBrowse:Be}}function bo(){let{client:o,botId:e,baseUrl:n}=zt(),[t,a]=useState(null),[s,c]=useState(true),[u,y]=useState(null),p=useCallback(async()=>{c(true),y(null);try{let R;if(typeof o.getBotInfo=="function")R=await o.getBotInfo();else {let m=n?n.replace(/\/+$/,""):"https://api.botzki.com";R=await(await fetch(`${m}/api/v1/public/chat/${e}`)).json();}a(R);}catch(R){y(R instanceof Error?R:new Error(String(R)));}finally{c(false);}},[o,e,n]);return useEffect(()=>{p();},[p,e]),{data:t,isLoading:s,error:u,refetch:p}}var Ei=["broken","terrible","worst","hate","refund","stuck","bug","crash","error","horrible","awful","scam","useless","ridiculous","frustrated","fail","failed","failing","not working","doesn't work","does not work","charge","charged","cancel","disaster","slow","unacceptable","angry","mad","waste","trash","annoying","cheat","sucks","disappointed","garbage","bad service","poor","rip off","ripoff","never works"],Pi=["wow","amazing","unbelievable","omg","best bot","love you","solved","fixed","works now","working now","you saved","fantastic","brilliant","yay","hooray","bingo","perfect","genius","incredible","love it","awesome bot","superb","outstanding"],$i=["thanks","thank you","thx","appreciate","helpful","good","great","nice","awesome","sweet","cool","super","glad","kind of you","very clear","got it","clear now","understood"],Li=["how","what","why","where","when","can you","could you","tell me","is there","wondering","curious","possible to","explain"];function Nn(o){if(!o||typeof o!="string")return {sentiment:"neutral",score:0};let e=o.toLowerCase();for(let n of Pi)if(e.includes(n))return {sentiment:"delighted",score:.95,triggerWord:n};for(let n of Ei)if(e.includes(n))return {sentiment:"frustrated",score:-0.9,triggerWord:n};for(let n of $i)if(e.includes(n))return {sentiment:"happy",score:.65,triggerWord:n};return e.includes("?")||Li.some(n=>e.includes(n))?{sentiment:"curious",score:.2}:{sentiment:"neutral",score:0}}function yo({messages:o=[],isLoading:e=false,isStreaming:n=false,isWaitingForHuman:t=false,isHumanHandoffActive:a=false,feedbackRating:s=null,manualEmotion:c,manualMotion:u,enabled:y=true,reactionCooldownMs:p=5500}={}){let[R,m]=useState("neutral"),[C,b]=useState(void 0),[$,F]=useState(0),[te,U]=useState("neutral"),[de,H]=useState(0),[X,N]=useState("Calm attentive baseline"),ue=useRef(null),Q=useRef(null),oe=()=>{ue.current&&(clearTimeout(ue.current),ue.current=null);},j=(v=p)=>{oe(),ue.current=setTimeout(()=>{m("neutral"),b(void 0),U("neutral"),H(0),N("Returned to calm baseline");},v);},ne=()=>{oe(),m("love"),b("jump"),F(v=>v+1),U("delighted"),H(1),N("Celebration triggered: Issue resolved!"),j(6e3);},me=()=>{oe(),m("sad"),b("float"),F(v=>v+1),U("frustrated"),H(-0.85),N("Attentive & sympathetic listening active"),j(7e3);},ye=()=>{oe(),m("neutral"),b(void 0),U("neutral"),H(0),N("Reset to neutral");};return useEffect(()=>{c&&(m(c),N(`Manual emotion override: ${c}`)),u&&(b(u),F(v=>v+1));},[c,u]),useEffect(()=>{y&&(s==="up"?ne():s==="down"&&me());},[s,y]),useEffect(()=>{y&&(t?(oe(),m("sad"),b("float"),F(v=>v+1),U("frustrated"),H(-0.7),N("Visitor requested human agent: Sympathetic attentive stance")):a&&(oe(),m("happy"),b("bounce"),F(v=>v+1),U("happy"),H(.8),N("Live human operator connected: Reassuring welcome"),j(6e3)));},[t,a,y]),useEffect(()=>{y&&(t||(e||n?(oe(),m("thinking"),b(void 0),U("thinking"),H(.1),N("Synthesizing answer & reasoning...")):te==="thinking"&&(m("happy"),b(void 0),U("happy"),H(.5),N("Answer delivered with friendly attentive smile"),j(4e3))));},[e,n,t,y]),useEffect(()=>{if(!y||o.length===0)return;let v=[...o].reverse().find(V=>V.role==="user");if(!v||v.id===Q.current)return;Q.current=v.id;let I=Nn(v.content);I.sentiment==="frustrated"?(oe(),m("sad"),b("float"),F(V=>V+1),U("frustrated"),H(I.score),N(`Detected distress trigger '${I.triggerWord}': Avatar shifts to apologetic listening posture`),j(8e3)):I.sentiment==="delighted"?(oe(),m("love"),b("jump"),F(V=>V+1),U("delighted"),H(I.score),N(`Detected delight trigger '${I.triggerWord}': Avatar celebrates`),j(7e3)):I.sentiment==="happy"?(oe(),m("happy"),b("bounce"),F(V=>V+1),U("happy"),H(I.score),N(`Detected gratitude trigger '${I.triggerWord}': Avatar perks up happily`),j(6e3)):I.sentiment==="curious"&&(oe(),m("surprised"),b(void 0),U("curious"),H(I.score),N("Inquisitive customer question: Attentive focus"),j(5e3));},[o,y]),useEffect(()=>()=>oe(),[]),{emotion:c??R,motion:u??C,motionKey:$,sentiment:te,sentimentScore:de,empathyReason:X,triggerCelebration:ne,triggerSympathy:me,resetToNeutral:ye}}var $o=[-3.2,3.2],Lo=-2.6,Hi=2.4,Wi=5.4,Dn=4.4,Ni=380,Oi=13.4+.5,Po=4,xo=2800,Ui=2200,Di="M0 1C-0.6 0.55-1.3 0.1-1.3-0.45C-1.3-0.95-0.9-1.2-0.55-1.2C-0.25-1.2-0.05-1 0-0.8C0.05-1 0.25-1.2 0.55-1.2C0.9-1.2 1.3-0.95 1.3-0.45C1.3 0.1 0.6 0.55 0 1Z",ze=o=>o*o*(3-2*o),at=o=>Math.min(1,Math.max(0,o)),Fi=o=>o<.5?4*o*o*o:1-(-2*o+2)**3/2,Fn=o=>1-(1-o)**3,Fe=(o,e,n)=>o<=e||o>=n?0:Math.sin(Math.PI*(o-e)/(n-e)),je=(o,e,n,t,a)=>o<=e||o>=a?0:o<n?ze((o-e)/(n-e)):o<=t?1:1-ze((o-t)/(a-t)),dn=o=>{let e=Math.sin(o*127.1+311.7)*43758.5453;return e-Math.floor(e)};function ji(o,e,n,t){let a=Math.cos;switch(o){case "circle":return .97+(.012+t*.03)*a(3*e+n*.5)+.008*a(5*e-n*.6);case "squircle":{let s=Math.abs(a(e)),c=Math.abs(Math.sin(e));return .9/(s**4+c**4)**.25+(.008+t*.02)*a(4*e+n*.6)}case "flower":return .95+(.075+t*.03)*a(8*e)+.012*a(3*e+n*.6);case "blob":return .97+(.05+t*.025)*a(3*e+1.5*Math.PI+.75*Math.sin(n*.3)+.25*Math.sin(n*.71))+(.022+t*.012)*a(2*e-n*.36)+.01*a(5*e+n*.5);default:return 1+(.038+t*.03)*a(5*e+.5*Math.PI+.75*Math.sin(n*.27)+.25*Math.sin(n*.63))+(.02+t*.02)*a(3*e+n*.45)+.01*a(7*e-n*.6)}}function jn(o){let e="";for(let n=0;n<96;n++){let t=n/96*Math.PI*2,a=o[n]*13.4;e+=`${n?"L":"M"}${(a*Math.cos(t)).toFixed(2)} ${(a*Math.sin(t)).toFixed(2)}`;}return `${e}Z`}var _i=jn(new Float32Array(96).fill(1));function _n(o,e,n,t,a,s,c){let u=Hi/2*a,y=Math.max(.35,Wi/2*n*a)*(4/3),p=[o-u,e,o-u,e-y*(1-s),o+u,e-y*(1-c),o+u,e,o+u,e+y,o-u,e+y],R=e+.4,m=[o-1.7,R+1,o-1.5,R-1.6,o+1.5,R-1.6,o+1.7,R+1,o+1.1,R-.3,o-1.1,R-.3],C=p.map((b,$)=>(b+(m[$]-b)*t).toFixed(2));return `M${C[0]} ${C[1]}C${C[2]} ${C[3]} ${C[4]} ${C[5]} ${C[6]} ${C[7]}C${C[8]} ${C[9]} ${C[10]} ${C[11]} ${C[0]} ${C[1]}Z`}function Vn(o,e,n,t,a,s,c=0){let u=(2+t*.8-n*.3)*a,y=e-t*.4,p=e+.4+t*(t<0?2.4:1.6),R=p+n*1.8+c,m=p-n*2.4-c,C=F=>F.toFixed(2),b=y+s,$=y-s;return `M${C(o-u)} ${C(b)}Q${C(o)} ${C(R)} ${C(o+u)} ${C($)}Q${C(o)} ${C(m)} ${C(o-u)} ${C(b)}Z`}var ft={openL:1,openR:1,laughL:0,laughR:0,eyeScale:1,eyeY:0,heavy:0,droop:0,smile:.4,mouth:0,mouthW:1,mouthX:0,skew:0,taper:0,blush:0,gazeX:Number.NaN,gazeY:Number.NaN,wobble:0,bob:0,tilt:0,spin:1},On={neutral:ft,happy:{...ft,openL:.9,openR:.9,laughL:.45,laughR:.45,smile:1,wobble:.15,bob:-0.3},love:{...ft,openL:.88,openR:.88,laughL:.55,laughR:.55,eyeScale:1.03,smile:1,mouthW:.9,blush:1,gazeX:-0.6,gazeY:-0.7,wobble:.12,bob:-0.2,tilt:-3,spin:.7},laugh:{...ft,openL:.9,openR:.9,laughL:.5,laughR:.5,smile:1,mouth:.1,wobble:.3,spin:1.4},surprised:{...ft,openL:1.03,openR:1.03,eyeScale:1.07,eyeY:-0.5,smile:0,mouth:1,mouthW:.95,wobble:.12,bob:-0.6},wow:{...ft,openL:.98,openR:.98,eyeScale:1.15,eyeY:-0.5,smile:.15,mouth:.75,mouthW:1.35,wobble:.15,bob:-0.5},sad:{...ft,openL:.75,openR:.75,eyeScale:.92,droop:.85,eyeY:.5,smile:-1,mouthW:1.75,gazeX:0,gazeY:.75,bob:.8,tilt:-4,spin:.35},thinking:{...ft,openL:.95,openR:.8,heavy:.2,smile:.1,mouthW:.6,mouthX:.9,skew:.5,tilt:5,spin:.6},sleepy:{...ft,openL:.6,openR:.6,heavy:.65,eyeY:.5,smile:-0.04,mouthW:.8,taper:.3,gazeX:0,gazeY:.6,bob:.5,spin:.3},wink:{...ft,smile:.9,skew:.1,tilt:2,wobble:.1}},Vi={surprised:16,wow:18,sad:3.5,sleepy:2.5},qi=Object.keys(ft),qn=()=>({dy:0,sy:0,tilt:0,faceY:0,scale:0,openL:1,openR:1,laughL:0,laughR:0,mouth:0,smile:0,width:1,skew:0,mouthX:0,yawn:0,blink:0,steady:false,gaze:null}),ln=[[.75,-0.85],[.4,-1],[-0.35,-0.85]];function Yi(o,e,n){let t=qn();switch(o){case "happy":{e<520&&(t.dy=-1.6*Math.abs(Math.sin(Math.PI*2*e/520))),t.tilt=3*Math.sin(Math.PI*2*e/3600);let a=je(e%3600,1600,1900,2500,2900);t.laughL=t.laughR=.3*a,t.mouth=.22*a,t.dy-=.6*a;break}case "love":{e<600&&(t.dy=-1.4*Fe(e,0,600)),t.tilt=5*Math.sin(Math.PI*2*e/4e3);let a=je(e%4e3,1400,1900,2500,3200);t.laughL=t.laughR=.3*a,t.scale+=.05*a,t.sy+=.03*a,t.dy-=.8*a,t.mouth+=.1*a;break}case "laugh":{let s=Math.floor(e/5600),c=e%5600,u=dn(s)<.5?-1:1,y=Fe(c,0,340);t.dy-=1.2*y,t.sy+=.04*y,t.scale+=.1*y,t.laughL=t.laughR=-0.5*y,t.mouth+=.25*y;let p=je(c,220,380,3e3,3700);if(t.laughL+=.5*p,t.laughR+=.5*p,t.mouth+=.25*je(c,220,400,3400,4400),c>260&&c<2900){let R=(c-260)/2640,m=15*R-3*R*R,C=Math.abs(Math.sin(Math.PI*m))**.8,b=(1-.7*R)*(.6+.4*dn(s*17+Math.floor(m)))*ze(Math.min(1,(c-260)/120));t.mouth+=.6*C*b,t.dy-=1.4*C*b,t.sy-=.035*C*b,t.scale-=.1*C*b,t.tilt+=2.5*C*b*u;}else if(c>=2900&&c<4300){let R=(c-2900)/1400,m=Math.abs(Math.sin(Math.PI*R*4.2)),C=.4*(1-R);t.mouth+=.4*m*C,t.dy-=.8*m*C;}t.tilt-=7*u*je(c,260,600,1800,2900),t.sy-=.02*Fe(c,4300,5300),c>4300&&(t.gaze=[0,0]),t.steady=c<3600;break}case "surprised":{let a=e<900?e<120?ze(e/120):1-ze((e-120)/780):0;t.scale+=.12*a,t.dy-=3*Fe(e,0,420),t.sy+=.06*Fe(e,0,380),t.mouth+=.3*a,t.steady=e<1800;let s=e<600?-1:(e-600)%4200,c=je(s,300,380,640,720),u=je(s,700,780,1090,1170);t.gaze=s>=300&&s<700?[-0.85,-0.1]:s>=700&&s<1150?[.85,-0.1]:[0,0],t.tilt+=-3*c+3*u,t.blink=Math.max(Fe(s,1700,1850),Fe(s,1950,2100));let y=ze(at((e-2600)/900));t.mouth-=.45*y,t.width*=1-.2*y;break}case "wow":{let a=.08*Math.sin(Math.PI*2*e/2800);t.scale+=.04+a*.3,t.mouth+=.05+a*.3,t.openL+=a*.15,t.openR+=a*.15,t.dy-=.8+a*3,t.tilt=1.5*Math.sin(Math.PI*2*e/3400),t.steady=true;break}case "sad":{let a=e%7e3;t.sy-=.045*Fe(a,0,1400),t.dy+=.5*je(a,700,1100,1800,2400);let s=je(a,3e3,3200,3800,4100);t.gaze=[0,.75-.9*s],t.openL=t.openR=1+.15*s,t.dy-=.4*s;let c=je(a,4400,4600,5300,5600);t.skew+=.12*Math.sin(n/40)*c,t.mouth+=.05*c,t.smile-=.15*c,t.tilt+=1.5*Math.sin(n/2200);break}case "thinking":{let a=e%6400;t.gaze=a<1200?ln[0]:a<2400?ln[1]:ln[2];let s=je(a,1200,1500,2100,2400);t.mouthX-=1.8*s,t.skew-=s,t.tilt-=9*s;let c=je(a,4100,4250,5600,6200);c>.3&&(t.gaze=[0,0]),t.openL*=1+.2*c,t.openR*=1+.4*c,t.scale+=.08*c,t.smile+=.8*c,t.mouthX-=.9*c,t.skew-=.5*c,t.width*=1+.5*c,t.mouth+=.15*c,t.tilt-=5*c,t.dy-=1.6*Fe(a,4100,4500),t.tilt+=1.5*Math.sin(n/900);break}case "sleepy":{let a=e%9200,s=a<3e3?ze(a/3e3):a<3200?1-ze((a-3e3)/200):0;t.openL=t.openR=1-.8*s,t.dy+=1.6*s,t.tilt+=6*s,t.gaze=[0,.6+.4*s];let c=Fe(a,3e3,3350);t.openL*=1+.9*c,t.openR*=1+.9*c,t.dy-=1.4*c,t.scale+=.1*c,a>=3e3&&a<4200&&(t.gaze=[0,0]),t.blink=Math.max(Fe(a,3550,3780),Fe(a,3900,4130)),t.yawn=je(a,5400,6200,6800,7600),t.tilt+=2*Math.sin(n/1700),t.steady=a<3e3;break}case "wink":{let a=e%3200,s=0;if(a>150&&a<950){let c=(a-150)/800;s=c<.2?ze(c/.2):c<.75?1:1-ze((c-.75)/.25);}t.laughR+=s,t.laughL+=.25*s,t.openL*=1-.12*s,t.skew+=.45*s,t.smile+=.1*s,t.tilt+=5*s,t.dy-=.9*Fe(a,150,450),s>0&&(t.gaze=[0,0]),t.steady=s>0;break}}return t}var Yn={jump:950,spin:600,bounce:1200,wiggle:800,float:2200},et={dy:0,rot:0,sx:1,sy:1,yaw:0,joy:0,gaze:null};function Gi(o,e){let n=at(e/Yn[o]);switch(o){case "jump":{if(e<160){let s=ze(e/160);return {...et,sx:1+.1*s,sy:1-.14*s,joy:s*.6}}if(e<560){let s=(e-160)/400,c=.09*Math.abs(Math.cos(Math.PI*s));return {...et,dy:-44*s*(1-s),sx:1-c*.6,sy:1+c,joy:1}}let t=(e-560)/390,a=.16*Math.exp(-5*t)*Math.cos(10*t);return {...et,sx:1+a*.7,sy:1-a,joy:1-ze(t)}}case "spin":{if(e<90){let s=ze(e/90);return {...et,yaw:-30*s,sx:1+.06*s,sy:1-.08*s,joy:.3*s,gaze:[-0.6*s,0]}}if(e<440){let s=(e-90)/350,c=Math.sin(Math.PI*s)**2,u=1-ze(Math.min(1,s*4));return {...et,yaw:-30+390*Fi(s),dy:-2.6*c,sx:1+.06*u,sy:1-.08*u+.04*c,joy:.8,gaze:[.8*c,0]}}let t=(e-440)/160,a=.025*Math.sin(Math.PI*t)*(1-t);return {...et,yaw:360,sx:1+a*.7,sy:1-a,joy:.8*(1-t)}}case "bounce":{let t=Math.abs(Math.sin(Math.PI*3*n)),a=.08*(1-t)**6;return {...et,dy:-5*t,sx:1+a*.8,sy:1-a,joy:Math.sin(Math.PI*n)}}case "wiggle":return {...et,rot:14*Math.sin(Math.PI*8*n)*(1-n),joy:.6*Math.sin(Math.PI*n)};case "float":{let t=[0,.9];if(e<520){let c=e/520,u=.05*Math.sin(Math.PI*c);return {...et,dy:-4.5*Fn(c),sx:1-u*.6,sy:1+u,joy:.5*c,gaze:c>.4?t:null}}if(e<1500){let c=(e-520)/980;return {...et,dy:-4.5+.8*Math.sin(Math.PI*3*c),rot:4*Math.sin(Math.PI*2*c),joy:.5,gaze:t}}if(e<1820){let c=(e-1500)/320;return {...et,dy:-4.5*(1-c*c),sx:1-.02*c,sy:1+.04*c,joy:.5,gaze:t}}let a=(e-1820)/380,s=.12*Math.exp(-5*a)*Math.cos(10*a)*(1-a);return {...et,sx:1+s*.7,sy:1-s,joy:.5*(1-a)}}}}var bt={viewBox:"-24 -24 48 48",body:_i,eyes:$o.map(o=>_n(o,Lo,1,0,1,0,0)),blush:$o.map(o=>({cx:o*1.6,cy:Lo+4.6})),mouth:Vn(0,Dn,0,.4,1,0),groundY:Oi,heart:Di,hearts:Po},Un=o=>({emotion:o.emotion??"neutral",activity:o.activity??"idle",shape:o.shape??"pebble",lookAround:o.lookAround??true,followCursor:o.followCursor??false,hoverGiggle:o.hoverGiggle??true});function Gn(o,e={}){let n={config:Un(e),playing:e.motion?{name:e.motion,start:performance.now()}:null,morph:null,onMotionEnd:e.onMotionEnd,onTickle:e.onTickle,tickledAt:-1/0,chuckledAt:-1/0},t=new Float32Array(96).fill(1),a=n.config.shape,s=e.motion??null,c=e.motionKey??0,u=e.chuckleKey??0,y=()=>{let d=performance.now();n.config.hoverGiggle&&d-n.tickledAt>1300&&(n.tickledAt=d,n.onTickle?.());};o.mover.addEventListener("pointerenter",y);let p=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)").matches:false,R=null,m=d=>{R=d.pointerType==="mouse"?{x:d.clientX,y:d.clientY}:null;},C=()=>{R=null;};window.addEventListener("pointermove",m,{passive:true}),document.documentElement.addEventListener("pointerleave",C);let b={...On[n.config.emotion]},$=Math.random()*1e3,F=0,te=performance.now(),U=0,de=0,H=0,X=0,N=te+600+Math.random()*1800,ue=te+800+Math.random()*2600,Q=-1,oe=false,j=-1/0,ne=0,me=0,ye=te+4e3+Math.random()*4e3,v=Math.random()*360,I=13.4,V=0,D=7,G=0,Z=0,le=0,He=5.5,Se=1,pe=1,xe=0,Ee=0,We=6,Ne=false,vt=-1/0,At=te+900,Xe=-1/0,Ae=0,be=null,Qe=te,Ke=-1/0,Be=-1/0,Ve=d=>{let W=Math.min(.064,(d-te)/1e3);te=d;let J=p?0:d/1e3+$,O=n.config;O.emotion!==be&&(be==="love"&&(Be=d),be=O.emotion,Qe=d,be==="love"&&(Ke=d,Be=1/0));let q=d-Qe,P=On[be],A=Math.min(1,W*(Vi[be]??8));for(let L of qi){let _=P[L];Number.isNaN(_)?b[L]=Number.NaN:Number.isNaN(b[L])?b[L]=_:b[L]+=(_-b[L])*A;}let l=p?qn():Yi(be,q,d),k=0,f=0;if(O.activity==="speaking"){d>Ee&&d>xe&&(xe=d+160+Math.random()*260,We-=1,Ne=We<=0,Ee=xe+(Ne?520+Math.random()*420:60+Math.random()*120),Ne&&(We=4+Math.floor(Math.random()*5)),Math.random()<.3&&(vt=d));let L=d<xe;k=L?.55+.35*Math.abs(Math.sin(d/70)):0,L?(le+=W*He*Math.PI*2,le>=Math.PI*2&&(le-=Math.PI*2,He=4.6+Math.random()*2,Se=Math.random()<.18?.12:.55+Math.random()*.45,pe=Math.random()<.4?.62+Math.random()*.12:1+Math.random()*.2),f=Math.min(1,(.35+G)*Se*(.5-.5*Math.cos(le)))):le=0;let _=Fe(d-vt,0,280);l.dy-=.7*_,l.scale+=.06*_;}else O.activity==="listening"&&(k=.18+.14*Math.sin(d/240)*Math.sin(d/610));G+=(k-G)*Math.min(1,W*12),Z+=(f-Z)*Math.min(1,W*(f>Z?30:20));let h=et,S=n.playing;if(S&&!p){let L=d-S.start;L>=Yn[S.name]?(n.playing=null,n.onMotionEnd?.(S.name)):h=Gi(S.name,L);}let z=O.activity==="listening"?1:0;if(z&&!S&&d>At&&(Xe=d,Ae+=1,At=d+2400+Math.random()*1800),z&&!p){let L=d-Xe;if(Ae%3===0){let _=je(L,0,160,700,1e3);l.scale+=.08*_,l.faceY-=.6*_,l.mouth+=.18*_,l.smile-=.3*_,l.dy-=.5*_;}else {let _=Fe(L,0,300)+.7*Fe(L,340,640);l.dy+=1.6*_,l.faceY+=1.2*_,l.sy-=.02*_,l.openL*=1-.15*_,l.openR*=1-.15*_,l.smile+=.1*_;}l.tilt+=4+1.5*Math.sin(d/2600);}let B=false,ce=O.followCursor&&R?o.svg.getBoundingClientRect():void 0;if(R&&ce&&ce.width>0){let L=R.x-(ce.left+ce.width/2),_=R.y-(ce.top+ce.height/2),Ce=ce.width*.9;B=true,H=L/(Math.abs(L)+Ce),X=_/(Math.abs(_)+Ce),N=d+700;}let re=h.gaze??l.gaze;B||(re?(H=re[0],X=re[1]):Number.isNaN(b.gazeX)?d>N&&(O.activity==="listening"?(H=(Math.random()-.5)*.3,X=-0.05+(Math.random()-.5)*.15):O.activity==="speaking"?(H=Ne?Math.random()<.5?-0.7:.7:(Math.random()-.5)*.5,X=Ne?-0.5:(Math.random()-.5)*.3):O.lookAround?(H=[-1,-0.6,0,0,.6,1][Math.floor(Math.random()*6)],X=(Math.random()-.5)*1.2):(H=0,X=0),N=d+(O.activity==="speaking"?500+Math.random()*900:900+Math.random()*2300)):(H=b.gazeX,X=b.gazeY));let w=Math.min(1,W*(B?14:16));U+=(H-U)*w,de+=(X-de)*w;let he=Math.min(1,W*5);ne+=(U-ne)*he,me+=(de-me)*he,l.steady&&Q<0&&(ue=Math.max(ue,d+400)),Q<0&&d>ue&&(Q=d);let fe=1;if(Q>=0){let L=(d-Q)/(be==="sleepy"?460:be==="sad"?280:170);L>=1?(Q=-1,!oe&&Math.random()<.22?(oe=true,ue=d+90):(oe=false,ue=d+2e3+Math.random()*3200)):fe=1-Math.sin(L*Math.PI)*.88;}fe*=1-l.blink*.9;let we=d-n.tickledAt,Oe=0,Pe=0;O.hoverGiggle&&we<1300&&(Oe=we<180?ze(we/180):we<800?1:1-ze((we-800)/500),Pe=Math.sin(we/42)*Math.max(0,1-we/520));let qe=d-n.chuckledAt,ae=qe>0&&qe<1700?.45*je(qe,0,260,1e3,1700):0;Oe=Math.max(Oe,ae),be==="neutral"&&O.activity==="idle"&&d>ye&&(j=d,ye=d+5e3+Math.random()*6e3);let Ye=be==="neutral"?je(d-j,0,380,1100,1600):0,ee=be==="sleepy"?1:0,Ue=l.yawn,Ie=O.shape,Nt=b.wobble+G*.6+Oe*.25,Ge=Ie==="squircle"?90:Ie==="blob"?120:Ie==="pebble"?72:0,lt=Ge?0:3.5+G*18;v=p?v:(v+W*lt*b.spin)%360,Ge&&(v+=(Math.round(v/Ge)*Ge-v)*Math.min(1,W*4));let It=n.morph,ct=It?ze(at((d-It.start)/Ni)):1,Co=v*Math.PI/180,Vt=t;for(let L=0;L<96;L++){let _=ji(Ie,L/96*Math.PI*2-Co,J,Nt);Vt[L]=It&&ct<1?It.from[L]+(_-It.from[L])*ct:_;}It&&ct>=1&&(n.morph=null);let ao=1+(p?0:ee?.03*Math.sin(J/1.1):.015*Math.sin(J/.9))+G*.04;o.body.setAttribute("d",jn(Vt)),o.bodyGroup.setAttribute("transform",`scale(${ao.toFixed(4)})`);let qt=h.yaw*Math.PI/180,Ot=b.bob+ee*.4*Math.sin(d/1100)-Oe*.5+Z*.25-Ue*.5,gt=b.tilt+l.tilt+Pe*4+h.rot,so=h.dy+Ot+l.dy,ht=Math.min(0,so),Tt=.7*Math.max(0,so)/(2*13.4),Oo=h.sy*(1+l.sy+Ue*.03)*(1-Tt),lo=h.sx*(1-(l.sy+Ue*.03)*.5)*(1-.04*Math.abs(Math.sin(qt)))*(1+Tt*.5),Et=gt*Math.PI/180,dt=0;for(let L=0;L<96;L++)dt=Math.max(dt,Vt[L]*Math.sin(L/96*Math.PI*2+Et));dt*=13.4*ao;let $e=1/0,ut=-1/0;for(let L=0;L<96;L++){let _=L/96*Math.PI*2+Et,Ce=Vt[L]*13.4*ao;Ce*Math.sin(_)<dt-2.2||($e=Math.min($e,Ce*Math.cos(_)),ut=Math.max(ut,Ce*Math.cos(_)));}I+=(dt-I)*Math.min(1,W*12),o.mover.setAttribute("transform",`translate(0 ${ht.toFixed(2)}) translate(0 ${13.4}) scale(${lo.toFixed(4)} ${Oo.toFixed(4)}) translate(0 ${(-I).toFixed(2)}) rotate(${gt.toFixed(2)})`);let ve=at(-ht/10),Yt=(ut-$e)/2*lo,Uo=($e+ut)/2*lo;V+=(Uo-V)*Math.min(1,W*12),D+=(Yt-D)*Math.min(1,W*12);let Pt=o.ground;Pt&&(Pt.setAttribute("cx",(V*(1-ve)).toFixed(2)),Pt.setAttribute("rx",((D+3.2)*(1+.25*ve)).toFixed(2)),Pt.setAttribute("ry",(2*(1+.2*ve)).toFixed(2)),Pt.setAttribute("opacity",((1-.65*ve)*(.9+2*Tt)).toFixed(3)));let $t=o.core;$t&&($t.setAttribute("cx",V.toFixed(2)),$t.setAttribute("rx",(D*.95*(1-.4*ve)).toFixed(2)),$t.setAttribute("ry",(.85*(1-.3*ve)).toFixed(2)),$t.setAttribute("opacity",((1-ve)**2*(.9+3*Tt)).toFixed(3)));let pt=o.face;if(pt){let L=Math.cos(qt);pt.setAttribute("transform",`translate(${(Math.sin(qt)*13.4*.72).toFixed(2)} 0) scale(${Math.max(.001,Math.abs(L)).toFixed(3)} 1)`),pt.setAttribute("opacity",ze(at((L+.1)/.35)).toFixed(3));}let kt=1-ze(at((d-Be)/200));o.hearts.forEach((L,_)=>{if(!L)return;let Ce=d-Ke-250-_*(xo/Po),ot=Math.floor(Ce/xo),Me=(Ce-ot*xo)/Ui,Xt=Ke+250+_*(xo/Po)+ot*xo;if(p||!(Ce>=0&&Ce<1/0)||Me>=1||Xt>Be||kt<=0){L.setAttribute("opacity","0");return}let Ht=(_+ot)%2?1:-1,nt=dn(ot*Po+_),Ct=Ht*(12+1.5*nt+2*Me)+.9*Math.sin(Math.PI*2*(1.1*Me+nt)),uo=ht-4-nt*2-14*Fn(Me),Ut=(.75+.35*nt)*(.5+.5*ze(at(Me/.18))),Qt=Ht*10+14*Math.sin(Math.PI*2*(.9*Me+nt));L.setAttribute("transform",`translate(${Ct.toFixed(2)} ${uo.toFixed(2)}) rotate(${Qt.toFixed(1)}) scale(${Ut.toFixed(3)})`),L.setAttribute("opacity",(kt*ze(at(Me/.12))*(1-ze(at((Me-.55)/.45)))).toFixed(3));});let Mo=Math.max(h.joy,Ye),St=1-Oe,co=Math.min(1,b.smile+l.smile+(1-b.smile)*Mo+z*.15),Gt=Math.max(-1,(co+(1-co)*Oe)*(1-Ue)),zo=1-.18*Math.max(0,(Gt-.6)/.4),Bo=[b.openL*l.openL,b.openR*l.openR],Ro=[b.laughL+l.laughL,b.laughR+l.laughR];o.eyes.forEach((L,_)=>{if(!L)return;let Ce=$o[_]+U*1.8*St,ot=Lo+b.eyeY+l.faceY+de*1.1*St,Me=at(Math.max(Ro[_],Oe,h.joy*.8)),Xt=Math.min(.9,b.heavy+b.droop),Ht=Math.min(.9,b.heavy),nt=Bo[_]*fe*zo*(1-Ue*.85);L.setAttribute("d",_n(Ce,ot,nt,Me,b.eyeScale+l.scale+z*.04,_===0?Xt:Ht,_===0?Ht:Xt)),L.setAttribute("stroke-width",(Me*.7).toFixed(2));let Ct=o.blush[_];Ct&&(Ct.setAttribute("cx",($o[_]*1.6+U*1.2*St).toFixed(2)),Ct.setAttribute("cy",(Lo+4.6+l.faceY+de*.7*St).toFixed(2)),Ct.setAttribute("opacity",at(b.blush).toFixed(3)));});let Ao=Oe*(.3+.25*Math.abs(Math.sin(d/85))),Kt=b.mouthW*l.width*(1+(pe-1)*Z)*(1-Ue*.1),Jt=at(-Gt+b.taper*(1-Ue)),Lt=o.mouth;if(Lt){Lt.setAttribute("d",Vn((b.mouthX+l.mouthX)*(1-Ue)+ne*1.2*St,Dn+b.eyeY*.5+l.faceY+me*.6*St,Math.max(0,b.mouth+l.mouth,Z,Ao,h.joy*.35,Ue*2.1),Gt,Kt,(b.skew+l.skew)*(1-Ue),.9*Jt));let L=Math.min(1,.55+.45*Kt);Lt.setAttribute("stroke-width",(1.4*L*(1-.6*Jt)).toFixed(2));}F=requestAnimationFrame(Ve);};F=requestAnimationFrame(Ve);let T=()=>{cancelAnimationFrame(F),window.removeEventListener("pointermove",m),document.documentElement.removeEventListener("pointerleave",C);};return {update(d){n.config=Un(d),n.onMotionEnd=d.onMotionEnd,n.onTickle=d.onTickle,n.config.shape!==a&&(a=n.config.shape,n.morph={from:t.slice(),start:performance.now()});let W=d.motion??null,J=d.motionKey??0;(W!==s||J!==c)&&(s=W,c=J,n.playing=W?{name:W,start:performance.now()}:null);let O=d.chuckleKey??0;O!==u&&(u=O,n.chuckledAt=performance.now()+140+Math.random()*160);},destroy(){T(),o.mover.removeEventListener("pointerenter",y);}}}function Bt({colors:o=["#66a6ff","#0059d4"],faceColor:e="#ffffff",eyeColor:n,mouthColor:t,outlineColor:a,outlineWidth:s=0,size:c=36,label:u="Botzki AI",className:y,style:p,shape:R="pebble",followCursor:m=true,...C}){let b=`bot-${useId().replace(/:/g,"")}`,$=useRef(null),F=useRef(null),te=useRef(null),U=useRef(null),de=useRef(null),H=useRef(null),X=useRef(null),N=useRef(null),ue=useRef([]),Q=useRef([]),oe=useRef([]),j=useRef(null),ne={shape:R,followCursor:m,...C},me=useRef(ne);useEffect(()=>{me.current=ne,j.current?.update(ne);}),useEffect(()=>{if(typeof window>"u")return;let D=$.current,G=F.current,Z=te.current,le=U.current,He=de.current,Se=H.current,pe=X.current,xe=N.current;if(!(!D||!G||!Z||!le||!He||!Se||!pe||!xe))return j.current=Gn({svg:D,mover:G,bodyGroup:Z,body:le,face:He,mouth:Se,ground:pe,core:xe,eyes:ue.current,blush:Q.current,hearts:oe.current},me.current),()=>{j.current?.destroy(),j.current=null;}},[]);let ye=n??e,v=t??e,I=a||"none",V=s?Number(s):0;return jsx("span",{className:y,style:{position:"relative",display:"inline-block",flex:"none",width:`${c}px`,height:`${c}px`,verticalAlign:"middle",...p},role:"img","aria-label":u,children:jsxs("svg",{ref:$,style:{position:"absolute",inset:"-25%",display:"block",width:"150%",height:"150%",overflow:"visible"},viewBox:bt.viewBox,"aria-hidden":true,children:[jsxs("defs",{children:[jsxs("radialGradient",{id:b,gradientUnits:"userSpaceOnUse",cx:"-4.8",cy:"-6.4",r:"24",children:[jsx("stop",{offset:"0",stopColor:o[0]}),jsx("stop",{offset:"1",stopColor:o[1]})]}),jsx("filter",{id:`${b}-soft`,x:"-50%",y:"-300%",width:"200%",height:"700%",children:jsx("feGaussianBlur",{stdDeviation:"1.3"})}),jsx("filter",{id:`${b}-core`,x:"-50%",y:"-300%",width:"200%",height:"700%",children:jsx("feGaussianBlur",{stdDeviation:"0.8"})}),jsx("filter",{id:`${b}-blush`,x:"-100%",y:"-100%",width:"300%",height:"300%",children:jsx("feGaussianBlur",{stdDeviation:"0.55"})})]}),jsx("ellipse",{ref:X,cx:"0",cy:bt.groundY,rx:"10",ry:"2.1",fill:"rgba(0, 0, 0, 0.08)",filter:`url(#${b}-soft)`}),jsx("ellipse",{ref:N,cx:"0",cy:bt.groundY,rx:"6.5",ry:"0.9",fill:"rgba(0, 0, 0, 0.12)",filter:`url(#${b}-core)`}),jsxs("g",{ref:F,children:[jsx("g",{ref:te,children:jsx("path",{ref:U,d:bt.body,fill:`url(#${b})`,stroke:I,strokeWidth:V,strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"})}),jsxs("g",{ref:de,children:[bt.blush.map((D,G)=>jsx("ellipse",{ref:Z=>{Q.current[G]=Z;},cx:D.cx,cy:D.cy,rx:"1.9",ry:"1.1",opacity:"0",fill:"rgba(255, 110, 150, 0.55)",filter:`url(#${b}-blush)`},`blush${G}`)),bt.eyes.map((D,G)=>jsx("path",{ref:Z=>{ue.current[G]=Z;},d:D,strokeWidth:0,strokeLinejoin:"round",fill:ye,stroke:ye},`eye${G}`)),jsx("path",{ref:H,d:bt.mouth,strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round",fill:v,stroke:v})]})]}),Array.from({length:bt.hearts},(D,G)=>jsx("path",{ref:Z=>{oe.current[G]=Z;},d:bt.heart,opacity:"0",fill:"#ff4f7e"},G))]})})}var Ji=Bt;function Wo({content:o,isUser:e=false,primaryColor:n="#0ea5e9",isDark:t=false}){if(!o)return null;let a=Qi(o);return jsx("div",{className:"botzki-markdown",style:{lineHeight:1.5,wordBreak:"break-word",fontSize:"inherit"},children:a.map((s,c)=>s.type==="code"?jsx(Zi,{code:s.code,lang:s.lang,isDark:t},c):jsx(er,{lines:s.lines,isUser:e,primaryColor:n,isDark:t},c))})}function Qi(o){let e=o.split(/\r?\n/),n=[],t=false,a="",s=[],c=[];for(let u=0;u<e.length;u++){let y=e[u],p=y.trim();p.startsWith("```")?t?(t=false,n.push({type:"code",code:s.join(`
|
|
5
|
+
`),lang:a||void 0}),s=[],a=""):(c.length>0&&(n.push({type:"text",lines:c}),c=[]),t=true,a=p.slice(3).trim(),s=[]):t?s.push(y):c.push(y);}return t?n.push({type:"code",code:s.join(`
|
|
6
|
+
`),lang:a||void 0}):c.length>0&&n.push({type:"text",lines:c}),n}function Zi({code:o,lang:e,isDark:n}){let[t,a]=useState(false);return jsxs("div",{style:{margin:"10px 0",borderRadius:"8px",overflow:"hidden",backgroundColor:n?"#0f172a":"#1e293b",border:"1px solid rgba(255, 255, 255, 0.1)",fontSize:"12px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 12px",backgroundColor:"rgba(0, 0, 0, 0.25)",color:"#94a3b8",fontSize:"11px",fontFamily:"monospace",borderBottom:"1px solid rgba(255, 255, 255, 0.08)"},children:[jsx("span",{children:e||"code"}),jsx("button",{type:"button",onClick:()=>{typeof navigator<"u"&&navigator.clipboard&&(navigator.clipboard.writeText(o),a(true),setTimeout(()=>a(false),2e3));},style:{background:"transparent",border:"none",color:t?"#34d399":"#cbd5e1",cursor:"pointer",fontSize:"11px",padding:"2px 6px",borderRadius:"4px"},children:t?"\u2713 Copied":"Copy"})]}),jsx("pre",{style:{margin:0,padding:"12px",overflowX:"auto",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',color:"#f8fafc",lineHeight:1.45},children:jsx("code",{children:o})})]})}function er({lines:o,isUser:e,primaryColor:n,isDark:t}){let a=[],s=null,c=[],u=p=>{if(c.length>0){let R=c.join(`
|
|
7
|
+
`);a.push(jsx("p",{style:{margin:"0 0 8px 0",whiteSpace:"pre-line"},children:Ho(R,e,n,t)},p)),c=[];}},y=p=>{if(s){let R=s.type;a.push(jsx(R,{style:{margin:"4px 0 10px 0",paddingLeft:"20px",display:"flex",flexDirection:"column",gap:"4px"},children:s.items.map((m,C)=>jsx("li",{style:{lineHeight:1.5},children:Ho(m,e,n,t)},C))},p)),s=null;}};for(let p=0;p<o.length;p++){let R=o[p],m=R.trim();if(!m){u(`p-${p}`),y(`list-${p}`);continue}let C=R.match(/^(#{1,6})\s+(.*)$/);if(C){u(`p-${p}`),y(`list-${p}`);let F=C[1].length,te=C[2],U=F===1?"18px":F===2?"16px":F===3?"15px":"14px";a.push(jsx("div",{style:{fontWeight:700,fontSize:U,margin:"12px 0 6px 0",lineHeight:1.3},children:Ho(te,e,n,t)},`h-${p}`));continue}if(m.startsWith("> ")){u(`p-${p}`),y(`list-${p}`),a.push(jsx("blockquote",{style:{margin:"8px 0",paddingLeft:"10px",borderLeft:`3px solid ${e?"rgba(255,255,255,0.4)":n}`,fontStyle:"italic",opacity:.9},children:Ho(m.slice(2),e,n,t)},`quote-${p}`));continue}let b=R.match(/^(\s*)[-*+]\s+(.*)$/);if(b){u(`p-${p}`),(!s||s.type!=="ul")&&(y(`list-prev-${p}`),s={type:"ul",items:[]}),s.items.push(b[2]);continue}let $=R.match(/^(\s*)\d+\.\s+(.*)$/);if($){u(`p-${p}`),(!s||s.type!=="ol")&&(y(`list-prev-${p}`),s={type:"ol",items:[]}),s.items.push($[2]);continue}s&&y(`list-${p}`),c.push(R);}return u("p-final"),y("list-final"),jsx(Fragment,{children:a})}function Ho(o,e,n,t){if(!o)return null;let a=/(`[^`]+`)|(\[([^\]]+)\]\(([^)]+)\))|(\*\*\*([^*]+)\*\*\*)|(\*\*([^*]+)\*\*|__([^_]+)__)|(\*([^*]+)\*|_([^_]+)_)|(~~([^~]+)~~)/g,s=[],c=0,u;for(;(u=a.exec(o))!==null;){u.index>c&&s.push(o.slice(c,u.index));let y=u[0];if(y.startsWith("`")&&y.endsWith("`")){let p=y.slice(1,-1);s.push(jsx("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:"0.88em",padding:"2px 5px",borderRadius:"4px",backgroundColor:e?"rgba(255, 255, 255, 0.25)":t?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.06)",color:e?"#ffffff":t?"#38bdf8":"#0284c7"},children:p},u.index));}else if(u[2]){let p=u[3],R=u[4];s.push(jsx("a",{href:R,target:"_blank",rel:"noopener noreferrer",style:{color:e?"#ffffff":n,textDecoration:"underline",textUnderlineOffset:"2px",fontWeight:500},children:p},u.index));}else if(u[5])s.push(jsx("strong",{style:{fontWeight:700},children:jsx("em",{children:u[6]})},u.index));else if(u[7]){let p=u[8]||u[9];s.push(jsx("strong",{style:{fontWeight:700},children:p},u.index));}else if(u[10]){let p=u[11]||u[12];s.push(jsx("em",{children:p},u.index));}else u[13]&&s.push(jsx("del",{children:u[14]},u.index));c=u.index+y.length;}return c<o.length&&s.push(o.slice(c)),s.length===1?s[0]:jsx(Fragment,{children:s})}var Zn=[35,65,40,85,100,70,45,90,60,40,80,95,75,50,65,85,40,70,90,55,35,60,30,20];function pn(o){if(typeof o!="number"||isNaN(o)||!isFinite(o)||o<=0)return "0:00";let e=Math.floor(o/60),n=Math.floor(o%60);return `${e}:${n.toString().padStart(2,"0")}`}function fn({audioUrl:o,duration:e,isUser:n=false,primaryColor:t="#0ea5e9",isDark:a=false,className:s,style:c}){let u=useRef(null),y=useRef(null),[p,R]=useState(false),[m,C]=useState(0),b=e&&isFinite(e)&&e>0?e:0,[$,F]=useState(b),[te,U]=useState(1),[de,H]=useState(false);useEffect(()=>{e&&isFinite(e)&&e>0&&F(e);},[e]);let X=()=>{let V=u.current;if(!V)return;let D=V.duration;D&&isFinite(D)&&!isNaN(D)&&D>0?F(D):D===1/0&&(V.currentTime=1e101,V.ontimeupdate=()=>{V.ontimeupdate=null,isFinite(V.duration)&&V.duration>0&&F(V.duration),V.currentTime=0;});},N=useCallback(()=>{let V=u.current;V&&(p?V.pause():V.play().catch(()=>{}));},[p]),ue=useCallback(V=>{V.stopPropagation();let D=[1,1.5,2],G=(D.indexOf(te)+1)%D.length,Z=D[G];U(Z),u.current&&(u.current.playbackRate=Z);},[te]),Q=useCallback(V=>{let D=y.current,G=u.current;if(!D||!G||$<=0)return;let Z=D.getBoundingClientRect(),Se=Math.max(0,Math.min(V-Z.left,Z.width))/Z.width*$;G.currentTime=Se,C(Se);},[$]),oe=V=>{V.stopPropagation(),H(true),Q(V.clientX);let D=Z=>{Q(Z.clientX);},G=()=>{H(false),window.removeEventListener("mousemove",D),window.removeEventListener("mouseup",G);};window.addEventListener("mousemove",D),window.addEventListener("mouseup",G);},j=useMemo(()=>$<=0?0:Math.min(1,Math.max(0,m/$)),[m,$]),ne=n?"rgba(255, 255, 255, 0.25)":a?"rgba(255, 255, 255, 0.12)":t,me="#ffffff",ye=n?"#ffffff":t,v=n?"rgba(255, 255, 255, 0.35)":a?"rgba(255, 255, 255, 0.22)":"rgba(100, 116, 139, 0.35)",I=n?"rgba(255, 255, 255, 0.85)":a?"#94a3b8":"#64748b";return jsxs("div",{className:s,style:{display:"flex",alignItems:"center",gap:"10px",minWidth:"210px",maxWidth:"280px",padding:"6px 2px",userSelect:"none",...c},children:[jsx("audio",{ref:u,src:o,preload:"metadata",onPlay:()=>R(true),onPause:()=>R(false),onEnded:()=>{R(false),C(0);},onLoadedMetadata:X,onDurationChange:X,onTimeUpdate:()=>{!de&&u.current&&C(u.current.currentTime);}}),jsx("button",{type:"button",onClick:N,"aria-label":p?"Pause voice message":"Play voice message",title:p?"Pause":"Play",style:{width:"34px",height:"34px",borderRadius:"50%",backgroundColor:ne,color:me,border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"transform 0.12s ease, opacity 0.15s ease",boxShadow:n?"none":"0 2px 6px rgba(0,0,0,0.1)"},children:p?jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor",children:[jsx("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),jsx("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]}):jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor",style:{marginLeft:"2px"},children:jsx("polygon",{points:"5 3 19 12 5 21 5 3"})})}),jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:"4px"},children:[jsx("div",{ref:y,onMouseDown:oe,role:"slider","aria-valuemin":0,"aria-valuemax":$,"aria-valuenow":m,tabIndex:0,style:{display:"flex",alignItems:"center",gap:"2px",height:"24px",cursor:"pointer",padding:"2px 0"},children:Zn.map((V,D)=>{let G=(D+1)/Zn.length,Z=j>=G;return jsx("div",{style:{flex:1,height:`${Math.max(15,V)}%`,backgroundColor:Z?ye:v,borderRadius:"2px",transition:de?"none":"background-color 0.1s ease"}},D)})}),jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"11px",color:I,fontVariantNumeric:"tabular-nums"},children:[jsx("span",{children:p||m>0?`${pn(m)} / ${pn($)}`:pn($)}),jsxs("button",{type:"button",onClick:ue,title:"Playback speed","aria-label":`Playback speed: ${te}x`,style:{background:n?"rgba(255,255,255,0.2)":a?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)",border:"none",color:n?"#ffffff":a?"#cbd5e1":"#475569",padding:"1px 5px",borderRadius:"4px",fontSize:"10px",fontWeight:600,cursor:"pointer",lineHeight:1.2},children:[te,"x"]})]})]})]})}var gn=({coBrowse:o})=>{let{isActive:e,operatorName:n,pointer:t,highlight:a,highlightedSelector:s,stop:c}=o,[u,y]=useState(null);if(useEffect(()=>{if(!e||!s){y(null);return}if(!(s.startsWith("#")||s.startsWith("[data-testid="))){y(null);return}let m;try{let C=document.querySelector(s);if(C){let b=()=>{let $=C.getBoundingClientRect();y({top:$.top+window.scrollY,left:$.left+window.scrollX,width:$.width,height:$.height});};b(),window.addEventListener("scroll",b,{passive:!0}),window.addEventListener("resize",b,{passive:!0}),m=()=>{window.removeEventListener("scroll",b),window.removeEventListener("resize",b);};}else y(null);}catch{y(null);}return ()=>{m&&m();}},[e,s]),!e)return null;let p=jsxs(Fragment,{children:[jsx("style",{children:`
|
|
8
8
|
@keyframes cobrowse-pulse-ring {
|
|
9
9
|
0% {
|
|
10
10
|
transform: scale(0.6);
|
|
@@ -25,17 +25,32 @@ import gn,{createContext,forwardRef,useState,useEffect,useRef,useCallback,useImp
|
|
|
25
25
|
border-color: #c084fc;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
`}),jsxs("div",{style:{position:"fixed",top:"16px",left:"50%",transform:"translateX(-50%)",zIndex:999999,display:"flex",alignItems:"center",gap:"12px",padding:"8px 16px",borderRadius:"9999px",background:"rgba(15, 23, 42, 0.95)",color:"#ffffff",boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.2)",backdropFilter:"blur(12px)",border:"1px solid rgba(255, 255, 255, 0.15)",fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",fontSize:"13px",pointerEvents:"auto"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",backgroundColor:"#10b981",boxShadow:"0 0 8px #10b981"}}),jsx("span",{style:{fontWeight:600},children:"Screen Assist Active"}),jsxs("span",{style:{color:"#94a3b8"},children:["with ",i||"Support Specialist"]})]}),jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"6px",background:"rgba(255, 255, 255, 0.1)",color:"#cbd5e1"},children:"\u{1F512} Inputs Masked"}),jsx("button",{type:"button",onClick:()=>s("User clicked Stop button"),style:{background:"#ef4444",color:"#ffffff",border:"none",borderRadius:"9999px",padding:"4px 12px",fontSize:"12px",fontWeight:600,cursor:"pointer",transition:"background 0.15s ease"},onMouseEnter:m=>m.target.style.background="#dc2626",onMouseLeave:m=>m.target.style.background="#ef4444",children:"End Assist"})]}),c&&jsx("div",{style:{position:"absolute",top:`${c.top-6}px`,left:`${c.left-6}px`,width:`${c.width+12}px`,height:`${c.height+12}px`,borderRadius:"8px",border:"2px solid #a855f7",pointerEvents:"none",zIndex:999990,animation:"cobrowse-spotlight-pulse 1.8s infinite ease-in-out",transition:"all 0.2s cubic-bezier(0.16, 1, 0.3, 1)"},children:jsxs("div",{style:{position:"absolute",bottom:"100%",left:"50%",transform:"translateX(-50%) translateY(-6px)",background:"#9333ea",color:"#ffffff",padding:"3px 10px",borderRadius:"6px",fontSize:"11px",fontWeight:600,whiteSpace:"nowrap",boxShadow:"0 4px 12px rgba(147, 51, 234, 0.4)"},children:[i||"Agent"," points here \u{1F446}"]})}),o&&jsxs("div",{style:{position:"fixed",left:`${o.xPercent*100}%`,top:`${o.yPercent*100}%`,pointerEvents:"none",zIndex:999998,transform:"translate(-50%, -50%)",transition:"left 0.08s linear, top 0.08s linear"},children:[jsx("div",{style:{width:"16px",height:"16px",borderRadius:"50%",backgroundColor:"#ef4444",boxShadow:"0 0 12px 3px rgba(239, 68, 68, 0.9), 0 0 24px 6px rgba(249, 115, 22, 0.6)",position:"relative"},children:jsx("div",{style:{position:"absolute",top:"-8px",left:"-8px",width:"32px",height:"32px",borderRadius:"50%",border:"2px solid #ef4444",animation:"cobrowse-pulse-ring 1.2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite"}})}),o.label&&jsx("div",{style:{position:"absolute",top:"20px",left:"14px",background:"rgba(15, 23, 42, 0.9)",color:"#f8fafc",fontSize:"11px",fontWeight:500,padding:"3px 8px",borderRadius:"6px",whiteSpace:"nowrap",border:"1px solid rgba(255, 255, 255, 0.15)",boxShadow:"0 4px 10px rgba(0, 0, 0, 0.25)"},children:o.label})]})]}):null};var ar=["\u{1F60A}","\u{1F44B}","\u{1F44D}","\u2764\uFE0F","\u{1F389}","\u{1F525}","\u{1F680}","\u{1F4A1}","\u2728","\u{1F64C}","\u{1F91D}","\u{1F60D}","\u{1F64F}","\u{1F60E}","\u{1F4AF}"];function ti(t){return !t||t<=0?"":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function oi(t){let e=(t||"").split(".").pop()?.toLowerCase();return e==="zip"||e==="tar"||e==="gz"||e==="rar"||e==="7z"?jsxs("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M21 8v13H3V8"}),jsx("path",{d:"M1 3h22v5H1z"}),jsx("path",{d:"M10 12h4"})]}):e==="pdf"?jsxs("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"#ef4444",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),jsx("polyline",{points:"14 2 14 8 20 8"}),jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]}):e==="csv"||e==="xlsx"||e==="xls"?jsxs("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"#10b981",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),jsx("polyline",{points:"14 2 14 8 20 8"}),jsx("path",{d:"M8 13h8"}),jsx("path",{d:"M8 17h8"})]}):jsxs("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),jsx("polyline",{points:"14 2 14 8 20 8"}),jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}function hn({title:t,avatar:e,botAvatar:i,userAvatar:o,showAvatars:a=true,enableImageUpload:s=true,enableVoiceInput:c=true,enableVoiceOutput:g=true,enableVoiceNotes:m=true,enableHumanHandoff:u=true,enableActionEngine:S=true,showFeedback:f=true,showCitations:C=true,showBranding:y=true,showCopyButton:L=true,showExportButton:N=true,avatarColors:Q,avatarFaceColor:U,avatarEyeColor:X,avatarMouthColor:H,avatarShape:le,avatarSize:Y,headerAvatarBackground:_,avatarFollowCursor:q,avatarProps:Z,enableEmpathyEngine:oe=true,subtitle:J="Online",greeting:he="Hello! How can I help you today?",starterQuestions:ze,theme:R="auto",primaryColor:T="#0ea5e9",className:j="",style:F,placeholder:G="Compose your message...",onClose:ee,showCloseButton:ce=false,showClearButton:He=false,showNewChatButton:ke=false,showHistoryButton:pe=false,allowExpand:ye=false,isExpanded:Ee=false,onToggleExpand:We,onNewChat:Ue,isHistoryOpen:wt,onHistoryOpenChange:At,onFeedbackSubmit:Je,onCitationClick:Ae,renderHeader:be,customHeader:Qe,renderMessage:Ke,renderComposer:Be,renderWelcome:Ve,unreadCount:E,unreadFromIndex:d,inputStyle:W,composerStyle:ie,userBubbleColor:O,userTextColor:de,assistantBubbleColor:P,assistantTextColor:A,fontFamily:l,fontSize:v,headerStyle:h,messagesContainerStyle:x,sendButtonStyle:M,chat:B,...z}){let ue=Dt(),re=mo(z),w=B||re,{messages:me,input:fe,setInput:xe,handleInputChange:Ne,sendMessage:Pe,clearMessages:qe,isLoading:ae,isStreaming:Ye,error:te}=w,Oe=z.botId||ue?.botId||"default",Ie=z.persistSession??false,Ut=`botzki_sessions_${Oe}`,{data:Ge}=bo(),lt=useRef(null),[It,ct]=useState(false),[Co,_t]=useState(""),[Uo,ro]=useState(""),[Vt,Nt]=useState(null),[ht,ao]=useState(false),[mt,Tt]=useState(()=>{if(!Ie||typeof window>"u"||!window.localStorage)return [];try{let r=localStorage.getItem(Ut);return r?JSON.parse(r):[]}catch{return []}}),[No,so]=useState(false),Et=wt!==void 0?wt:No,dt=r=>{let k=typeof r=="function"?r(Et):r;so(k),At?.(k);},[$e,ut]=useState(null),[we,qt]=useState(null),Oo=useMemo(()=>!fe||fe.length<8?false:/(?:\d[ -]*?){13,19}|\b\d{3}[- ]\d{2}[- ]\d{4}\b|sk-[A-Za-z0-9]{15,}|Bearer\s+[A-Za-z0-9_\-\.]{15,}/i.test(fe),[fe]),[Pt,$t]=useState(false),pt=useRef(null),[vt,Mo]=useState(0),[kt,lo]=useState(""),[Yt,zo]=useState(false),[Bo,Ro]=useState(false),[Ao,Gt]=useState(false),[Kt,Lt]=useState(0),$=useRef(0),D=useRef(null),Se=useRef(null),ot=useRef([]),Ce=useRef(null),Xt=r=>{let k=Math.floor(r/60),I=Math.floor(r%60);return `${k}:${I.toString().padStart(2,"0")}`},Ht=async()=>{if(typeof window>"u"||!navigator.mediaDevices?.getUserMedia){alert("Microphone recording is not supported in this browser environment.");return}try{let r=await navigator.mediaDevices.getUserMedia({audio:!0});Se.current=r,ot.current=[];let k="";typeof MediaRecorder<"u"&&(MediaRecorder.isTypeSupported("audio/webm;codecs=opus")?k="audio/webm;codecs=opus":MediaRecorder.isTypeSupported("audio/webm")?k="audio/webm":MediaRecorder.isTypeSupported("audio/mp4")&&(k="audio/mp4"));let I=k?new MediaRecorder(r,{mimeType:k}):new MediaRecorder(r);I.ondataavailable=K=>{K.data&&K.data.size>0&&ot.current.push(K.data);},D.current=I,I.start(250),$.current=Date.now(),Gt(!0),Lt(0),Ce.current&&clearInterval(Ce.current),Ce.current=setInterval(()=>{Lt(K=>K+1);},1e3);}catch(r){console.warn("Failed to start voice recording:",r),alert("Could not access microphone. Please grant microphone permissions to send voice messages.");}},nt=()=>{if(Ce.current&&(clearInterval(Ce.current),Ce.current=null),D.current&&D.current.state!=="inactive"){D.current.onstop=null;try{D.current.stop();}catch{}}Se.current&&(Se.current.getTracks().forEach(r=>r.stop()),Se.current=null),ot.current=[],Gt(false),Lt(0);},St=()=>{Ce.current&&(clearInterval(Ce.current),Ce.current=null);let r=$.current?(Date.now()-$.current)/1e3:Kt,k=Math.max(1,Math.round(r)),I=D.current;if(I&&I.state!=="inactive"){I.onstop=()=>{let K=I.mimeType||"audio/webm",ge=new Blob(ot.current,{type:K});if(Se.current&&(Se.current.getTracks().forEach(V=>V.stop()),Se.current=null),ot.current=[],Gt(false),Lt(0),ge.size>0)if(typeof w.sendVoiceMessage=="function")w.sendVoiceMessage(ge,{audioDuration:k});else {let V=URL.createObjectURL(ge);w.sendMessage("",{audioUrl:V,audioDuration:k});}};try{I.stop();}catch{nt();}}else nt();};useEffect(()=>()=>{Ce.current&&clearInterval(Ce.current),Se.current&&Se.current.getTracks().forEach(r=>r.stop());},[]);let[co,Ot]=useState(false),Jt=useRef(null),[uo,Qt]=useState(null),[Do,li]=useState({}),[ci,wn]=useState(null),[Io,Fo]=useState(false),jo=useRef(null),di=r=>{xe(fe+r),Fo(false),Zt.current?.focus();};useEffect(()=>{if(!Io)return;let r=k=>{jo.current&&!jo.current.contains(k.target)&&Fo(false);};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[Io]);let Zt=useRef(null),[vn,kn]=useState(false);useEffect(()=>{if(Zt.current){Zt.current.style.height="auto";let r=Zt.current.scrollHeight,k=Math.min(Math.max(r,38),120);Zt.current.style.height=`${k}px`;}},[fe]);let ui=r=>{r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),!ae&&(fe.trim()||$e)&&Bn(r));},Ct=yo({messages:w.messages,isLoading:w.isLoading,isStreaming:w.isStreaming,isWaitingForHuman:w.isWaitingForHuman,isHumanHandoffActive:w.isHumanHandoffActive,feedbackRating:Bo?vt>=4?"up":"down":null,manualEmotion:e?.emotion,manualMotion:e?.motion??void 0,enabled:oe}),se=useMemo(()=>({colors:e?.colors??Q??["#66a6ff","#0059d4"],faceColor:e?.faceColor??U??"#ffffff",eyeColor:e?.eyeColor??X,mouthColor:e?.mouthColor??H,shape:e?.shape??le??"pebble",size:e?.size??Y,followCursor:e?.followCursor??q??true,motion:e?.motion??(oe?Ct.motion:void 0),emotion:e?.emotion??(oe?Ct.emotion:"neutral"),outlineColor:e?.outlineColor,outlineWidth:e?.outlineWidth,background:e?.background??_,props:{...Z,...e?.props,motionKey:Ct.motionKey}}),[e,Q,U,X,H,le,Y,q,Z,_,oe,Ct.emotion,Ct.motion,Ct.motionKey]);useEffect(()=>{if(me.length===0)return;let r=w.sessionId,k=me.find(K=>K.role==="user"),I=k?k.content.slice(0,36)+(k.content.length>36?"...":""):"Conversation";Tt(K=>{let ge=new Date().toISOString(),V=K.findIndex(fo=>fo.id===r),De;V>=0?(De=[...K],De[V]={...De[V],title:De[V].title==="Conversation"||!De[V].title?I:De[V].title,updatedAt:ge,messages:me}):De=[{id:r,title:I,createdAt:ge,updatedAt:ge,messages:me},...K];try{Ie&&typeof window<"u"&&window.localStorage&&localStorage.setItem(Ut,JSON.stringify(De));}catch{}return De});},[me,w.sessionId,Ut,Ie]);let[_o,Sn]=useState(true),[Vo,qo]=useState(0),Yo=useRef(me.length),Go=useRef(null),Wt=d!==void 0?d:E&&E>0&&me.length>=E?me.length-E:void 0;useEffect(()=>{Wt!==void 0&&Go.current&&Go.current.scrollIntoView({behavior:"smooth",block:"start"});},[Wt]);let pi=()=>{if(!lt.current)return;let{scrollTop:r,scrollHeight:k,clientHeight:I}=lt.current,K=k-r-I<60;Sn(K),K&&qo(0);},fi=()=>{lt.current&&(lt.current.scrollTo({top:lt.current.scrollHeight,behavior:"smooth"}),Sn(true),qo(0));};useEffect(()=>{lt.current&&(Wt!==void 0&&Wt<me.length||(_o?lt.current.scrollTop=lt.current.scrollHeight:me.length>Yo.current&&qo(r=>r+(me.length-Yo.current)),Yo.current=me.length));},[me,Ye,$e,_o,Wt]),useEffect(()=>()=>{if(typeof window<"u"&&window.speechSynthesis&&window.speechSynthesis.cancel(),Jt.current)try{Jt.current.stop();}catch{}},[]);let po=()=>{typeof window<"u"&&window.speechSynthesis&&(window.speechSynthesis.cancel(),Qt(null));let r=`session_${Date.now()}_${Math.random().toString(36).substring(2,9)}`;w.clearMessages(),w.setSessionId(r),ut(null),dt(false),Ue?.();},gi=r=>{typeof window<"u"&&window.speechSynthesis&&(window.speechSynthesis.cancel(),Qt(null)),w.setSessionId(r.id),w.setMessages(r.messages),dt(false);},hi=(r,k)=>{k.stopPropagation(),Tt(I=>{let K=I.filter(ge=>ge.id!==r);try{Ie&&typeof window<"u"&&window.localStorage&&localStorage.setItem(Ut,JSON.stringify(K));}catch{}return K}),w.sessionId===r&&po();},mi=()=>{Tt([]);try{Ie&&typeof window<"u"&&window.localStorage&&localStorage.removeItem(Ut);}catch{}po();},Cn=(r="markdown")=>{let k=t||Ge?.name||"Botzki AI Assistant",I="";if(r==="json"?I=JSON.stringify({sessionId:w.sessionId,botTitle:k,exportedAt:new Date().toISOString(),messages:w.messages},null,2):(I=`# Conversation with ${k}
|
|
28
|
+
@media (max-width: 640px) {
|
|
29
|
+
.botzki-cobrowse-topbar {
|
|
30
|
+
top: 10px !important;
|
|
31
|
+
padding: 6px 12px !important;
|
|
32
|
+
gap: 8px !important;
|
|
33
|
+
font-size: 11px !important;
|
|
34
|
+
}
|
|
35
|
+
.botzki-cobrowse-operator-name {
|
|
36
|
+
display: none !important;
|
|
37
|
+
}
|
|
38
|
+
.botzki-cobrowse-mask-badge {
|
|
39
|
+
font-size: 10px !important;
|
|
40
|
+
padding: 2px 6px !important;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`}),jsxs("div",{className:"botzki-cobrowse-topbar",style:{position:"fixed",top:"16px",left:"50%",transform:"translateX(-50%)",zIndex:2147483640,display:"flex",alignItems:"center",gap:"12px",padding:"7px 16px",borderRadius:"9999px",background:"rgba(15, 23, 42, 0.94)",color:"#ffffff",boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",border:"1px solid rgba(255, 255, 255, 0.15)",fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",fontSize:"12px",lineHeight:1.3,pointerEvents:"auto",maxWidth:"calc(100vw - 32px)",boxSizing:"border-box",whiteSpace:"nowrap",userSelect:"none"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0,flexShrink:0},children:[jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",backgroundColor:"#10b981",boxShadow:"0 0 8px #10b981",flexShrink:0}}),jsx("span",{style:{fontWeight:600,color:"#f8fafc"},children:"Screen Assist Active"}),jsxs("span",{className:"botzki-cobrowse-operator-name",style:{color:"#94a3b8",maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:n?`with ${n}`:void 0,children:["with ",n||"Support Specialist"]})]}),jsx("span",{className:"botzki-cobrowse-mask-badge",style:{fontSize:"11px",fontWeight:500,padding:"2px 8px",borderRadius:"6px",background:"rgba(255, 255, 255, 0.1)",color:"#cbd5e1",flexShrink:0,whiteSpace:"nowrap"},children:"\u{1F512} Inputs Masked"}),jsx("button",{type:"button",onClick:()=>c("User clicked Stop button"),style:{background:"#ef4444",color:"#ffffff",border:"none",borderRadius:"9999px",padding:"4px 12px",fontSize:"11px",fontWeight:600,cursor:"pointer",flexShrink:0,whiteSpace:"nowrap",transition:"background 0.15s ease, transform 0.1s ease",boxShadow:"0 2px 6px rgba(239, 68, 68, 0.3)"},onMouseEnter:R=>R.target.style.background="#dc2626",onMouseLeave:R=>R.target.style.background="#ef4444",children:"End Assist"})]}),(a||u||t?.action==="highlight")&&jsxs("div",{style:{position:u?"absolute":"fixed",top:u?`${u.top-6}px`:`${(a?.yPercent??t?.yPercent??0)*100}%`,left:u?`${u.left-6}px`:`${(a?.xPercent??t?.xPercent??0)*100}%`,width:u?`${u.width+12}px`:"72px",height:u?`${u.height+12}px`:"72px",borderRadius:u?"10px":"50%",border:"3px solid #a855f7",boxShadow:"0 0 28px rgba(168, 85, 247, 0.8), inset 0 0 16px rgba(168, 85, 247, 0.35)",pointerEvents:"none",zIndex:2147483630,transform:u?"none":"translate(-50%, -50%)",animation:"cobrowse-spotlight-pulse 1.8s infinite ease-in-out",transition:"all 0.15s cubic-bezier(0.16, 1, 0.3, 1)"},children:[jsx("div",{style:{position:"absolute",inset:"-10px",borderRadius:u?"14px":"50%",border:"2px solid rgba(168, 85, 247, 0.6)",animation:"cobrowse-pulse-ring 1.5s cubic-bezier(0.215, 0.61, 0.355, 1) infinite"}}),jsx("div",{style:{position:"absolute",bottom:"100%",left:"50%",transform:"translateX(-50%) translateY(-8px)",background:"linear-gradient(135deg, #9333ea 0%, #7c3aed 100%)",color:"#ffffff",padding:"4px 12px",borderRadius:"9999px",fontSize:"11px",fontWeight:700,whiteSpace:"nowrap",boxShadow:"0 4px 14px rgba(147, 51, 234, 0.5)",letterSpacing:"0.3px"},children:a?.label||(n?`${n} highlighted this \u{1F446}`:"Support Specialist highlighted this \u{1F446}")})]}),t&&t.action!=="leave"&&jsxs("div",{style:{position:"fixed",left:`${t.xPercent*100}%`,top:`${t.yPercent*100}%`,pointerEvents:"none",zIndex:2147483635,transform:"translate(-50%, -50%)",transition:"left 0.06s linear, top 0.06s linear"},children:[jsx("div",{style:{width:"16px",height:"16px",borderRadius:"50%",backgroundColor:t.action==="highlight"?"#a855f7":"#ef4444",boxShadow:t.action==="highlight"?"0 0 16px 4px rgba(168, 85, 247, 0.95), 0 0 28px 8px rgba(147, 51, 234, 0.7)":"0 0 12px 3px rgba(239, 68, 68, 0.9), 0 0 24px 6px rgba(249, 115, 22, 0.6)",position:"relative"},children:jsx("div",{style:{position:"absolute",top:"-8px",left:"-8px",width:"32px",height:"32px",borderRadius:"50%",border:`2px solid ${t.action==="highlight"?"#c084fc":"#ef4444"}`,animation:"cobrowse-pulse-ring 1.2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite"}})}),t.label&&jsx("div",{style:{position:"absolute",top:"20px",left:"14px",background:"rgba(15, 23, 42, 0.9)",color:"#f8fafc",fontSize:"11px",fontWeight:500,padding:"3px 8px",borderRadius:"6px",whiteSpace:"nowrap",border:"1px solid rgba(255, 255, 255, 0.15)",boxShadow:"0 4px 10px rgba(0, 0, 0, 0.25)"},children:t.label})]})]});return typeof document<"u"&&document.body?createPortal(p,document.body):p};var sr=["\u{1F60A}","\u{1F44B}","\u{1F44D}","\u2764\uFE0F","\u{1F389}","\u{1F525}","\u{1F680}","\u{1F4A1}","\u2728","\u{1F64C}","\u{1F91D}","\u{1F60D}","\u{1F64F}","\u{1F60E}","\u{1F4AF}"];function ti(o){return !o||o<=0?"":o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(1)} KB`:`${(o/(1024*1024)).toFixed(1)} MB`}function oi(o){let e=(o||"").split(".").pop()?.toLowerCase();return e==="zip"||e==="tar"||e==="gz"||e==="rar"||e==="7z"?jsxs("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M21 8v13H3V8"}),jsx("path",{d:"M1 3h22v5H1z"}),jsx("path",{d:"M10 12h4"})]}):e==="pdf"?jsxs("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"#ef4444",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),jsx("polyline",{points:"14 2 14 8 20 8"}),jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]}):e==="csv"||e==="xlsx"||e==="xls"?jsxs("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"#10b981",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),jsx("polyline",{points:"14 2 14 8 20 8"}),jsx("path",{d:"M8 13h8"}),jsx("path",{d:"M8 17h8"})]}):jsxs("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),jsx("polyline",{points:"14 2 14 8 20 8"}),jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}function mn({title:o,avatar:e,botAvatar:n,userAvatar:t,showAvatars:a=true,enableImageUpload:s=true,enableVoiceInput:c=true,enableVoiceOutput:u=true,enableVoiceNotes:y=true,enableHumanHandoff:p=true,enableActionEngine:R=true,showFeedback:m=true,showCitations:C=true,showBranding:b=true,showCopyButton:$=true,showExportButton:F=true,avatarColors:te,avatarFaceColor:U,avatarEyeColor:de,avatarMouthColor:H,avatarShape:X,avatarSize:N,headerAvatarBackground:ue,avatarFollowCursor:Q,avatarProps:oe,enableEmpathyEngine:j=true,subtitle:ne="Online",greeting:me="Hello! How can I help you today?",starterQuestions:ye,theme:v="auto",primaryColor:I="#0ea5e9",className:V="",style:D,placeholder:G="Compose your message...",onClose:Z,showCloseButton:le=false,showClearButton:He=false,showNewChatButton:Se=false,showHistoryButton:pe=false,allowExpand:xe=false,isExpanded:Ee=false,onToggleExpand:We,onNewChat:Ne,isHistoryOpen:vt,onHistoryOpenChange:At,onFeedbackSubmit:Xe,onCitationClick:Ae,renderHeader:be,customHeader:Qe,renderMessage:Ke,renderComposer:Be,renderWelcome:Ve,unreadCount:T,unreadFromIndex:d,inputStyle:W,composerStyle:J,userBubbleColor:O,userTextColor:q,assistantBubbleColor:P,assistantTextColor:A,fontFamily:l,fontSize:k,headerStyle:f,messagesContainerStyle:h,sendButtonStyle:S,chat:z,...B}){let ce=Dt(),re=mo(B),w=z||re,{messages:he,input:fe,setInput:we,handleInputChange:Oe,sendMessage:Pe,clearMessages:qe,isLoading:ae,isStreaming:Ye,error:ee}=w,Ue=B.botId||ce?.botId||"default",Ie=B.persistSession??false,Nt=`botzki_sessions_${Ue}`,{data:Ge}=bo(),lt=useRef(null),[It,ct]=useState(false),[Co,Vt]=useState(""),[No,ao]=useState(""),[qt,Ot]=useState(null),[gt,so]=useState(false),[ht,Tt]=useState(()=>{if(!Ie||typeof window>"u"||!window.localStorage)return [];try{let r=localStorage.getItem(Nt);return r?JSON.parse(r):[]}catch{return []}}),[Oo,lo]=useState(false),Et=vt!==void 0?vt:Oo,dt=r=>{let M=typeof r=="function"?r(Et):r;lo(M),At?.(M);},[$e,ut]=useState(null),[ve,Yt]=useState(null),Uo=useMemo(()=>!fe||fe.length<8?false:/(?:\d[ -]*?){13,19}|\b\d{3}[- ]\d{2}[- ]\d{4}\b|sk-[A-Za-z0-9]{15,}|Bearer\s+[A-Za-z0-9_\-\.]{15,}/i.test(fe),[fe]),[Pt,$t]=useState(false),pt=useRef(null),[kt,Mo]=useState(0),[St,co]=useState(""),[Gt,zo]=useState(false),[Bo,Ro]=useState(false),[Ao,Kt]=useState(false),[Jt,Lt]=useState(0),L=useRef(0),_=useRef(null),Ce=useRef(null),ot=useRef([]),Me=useRef(null),Xt=r=>{let M=Math.floor(r/60),E=Math.floor(r%60);return `${M}:${E.toString().padStart(2,"0")}`},Ht=async()=>{if(typeof window>"u"||!navigator.mediaDevices?.getUserMedia){alert("Microphone recording is not supported in this browser environment.");return}try{let r=await navigator.mediaDevices.getUserMedia({audio:!0});Ce.current=r,ot.current=[];let M="";typeof MediaRecorder<"u"&&(MediaRecorder.isTypeSupported("audio/webm;codecs=opus")?M="audio/webm;codecs=opus":MediaRecorder.isTypeSupported("audio/webm")?M="audio/webm":MediaRecorder.isTypeSupported("audio/mp4")&&(M="audio/mp4"));let E=M?new MediaRecorder(r,{mimeType:M}):new MediaRecorder(r);E.ondataavailable=K=>{K.data&&K.data.size>0&&ot.current.push(K.data);},_.current=E,E.start(250),L.current=Date.now(),Kt(!0),Lt(0),Me.current&&clearInterval(Me.current),Me.current=setInterval(()=>{Lt(K=>K+1);},1e3);}catch(r){console.warn("Failed to start voice recording:",r),alert("Could not access microphone. Please grant microphone permissions to send voice messages.");}},nt=()=>{if(Me.current&&(clearInterval(Me.current),Me.current=null),_.current&&_.current.state!=="inactive"){_.current.onstop=null;try{_.current.stop();}catch{}}Ce.current&&(Ce.current.getTracks().forEach(r=>r.stop()),Ce.current=null),ot.current=[],Kt(false),Lt(0);},Ct=()=>{Me.current&&(clearInterval(Me.current),Me.current=null);let r=L.current?(Date.now()-L.current)/1e3:Jt,M=Math.max(1,Math.round(r)),E=_.current;if(E&&E.state!=="inactive"){E.onstop=()=>{let K=E.mimeType||"audio/webm",ge=new Blob(ot.current,{type:K});if(Ce.current&&(Ce.current.getTracks().forEach(Y=>Y.stop()),Ce.current=null),ot.current=[],Kt(false),Lt(0),ge.size>0)if(typeof w.sendVoiceMessage=="function")w.sendVoiceMessage(ge,{audioDuration:M});else {let Y=URL.createObjectURL(ge);w.sendMessage("",{audioUrl:Y,audioDuration:M});}};try{E.stop();}catch{nt();}}else nt();};useEffect(()=>()=>{Me.current&&clearInterval(Me.current),Ce.current&&Ce.current.getTracks().forEach(r=>r.stop());},[]);let[uo,Ut]=useState(false),Qt=useRef(null),[po,Zt]=useState(null),[Do,li]=useState({}),[ci,vn]=useState(null),[Io,Fo]=useState(false),jo=useRef(null),di=r=>{we(fe+r),Fo(false),eo.current?.focus();};useEffect(()=>{if(!Io)return;let r=M=>{jo.current&&!jo.current.contains(M.target)&&Fo(false);};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[Io]);let eo=useRef(null),[kn,Sn]=useState(false);useEffect(()=>{if(eo.current){eo.current.style.height="auto";let r=eo.current.scrollHeight,M=Math.min(Math.max(r,38),120);eo.current.style.height=`${M}px`;}},[fe]);let ui=r=>{r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),!ae&&(fe.trim()||$e)&&Rn(r));},Mt=yo({messages:w.messages,isLoading:w.isLoading,isStreaming:w.isStreaming,isWaitingForHuman:w.isWaitingForHuman,isHumanHandoffActive:w.isHumanHandoffActive,feedbackRating:Bo?kt>=4?"up":"down":null,manualEmotion:e?.emotion,manualMotion:e?.motion??void 0,enabled:j}),se=useMemo(()=>({colors:e?.colors??te??["#66a6ff","#0059d4"],faceColor:e?.faceColor??U??"#ffffff",eyeColor:e?.eyeColor??de,mouthColor:e?.mouthColor??H,shape:e?.shape??X??"pebble",size:e?.size??N,followCursor:e?.followCursor??Q??true,motion:e?.motion??(j?Mt.motion:void 0),emotion:e?.emotion??(j?Mt.emotion:"neutral"),outlineColor:e?.outlineColor,outlineWidth:e?.outlineWidth,background:e?.background??ue,props:{...oe,...e?.props,motionKey:Mt.motionKey}}),[e,te,U,de,H,X,N,Q,oe,ue,j,Mt.emotion,Mt.motion,Mt.motionKey]);useEffect(()=>{if(he.length===0)return;let r=w.sessionId,M=he.find(K=>K.role==="user"),E=M?M.content.slice(0,36)+(M.content.length>36?"...":""):"Conversation";Tt(K=>{let ge=new Date().toISOString(),Y=K.findIndex(go=>go.id===r),De;Y>=0?(De=[...K],De[Y]={...De[Y],title:De[Y].title==="Conversation"||!De[Y].title?E:De[Y].title,updatedAt:ge,messages:he}):De=[{id:r,title:E,createdAt:ge,updatedAt:ge,messages:he},...K];try{Ie&&typeof window<"u"&&window.localStorage&&localStorage.setItem(Nt,JSON.stringify(De));}catch{}return De});},[he,w.sessionId,Nt,Ie]);let[_o,Cn]=useState(true),[Vo,qo]=useState(0),Yo=useRef(he.length),Go=useRef(null),Wt=d!==void 0?d:T&&T>0&&he.length>=T?he.length-T:void 0;useEffect(()=>{Wt!==void 0&&Go.current&&Go.current.scrollIntoView({behavior:"smooth",block:"start"});},[Wt]);let pi=()=>{if(!lt.current)return;let{scrollTop:r,scrollHeight:M,clientHeight:E}=lt.current,K=M-r-E<60;Cn(K),K&&qo(0);},fi=()=>{lt.current&&(lt.current.scrollTo({top:lt.current.scrollHeight,behavior:"smooth"}),Cn(true),qo(0));};useEffect(()=>{lt.current&&(Wt!==void 0&&Wt<he.length||(_o?lt.current.scrollTop=lt.current.scrollHeight:he.length>Yo.current&&qo(r=>r+(he.length-Yo.current)),Yo.current=he.length));},[he,Ye,$e,_o,Wt]),useEffect(()=>()=>{if(typeof window<"u"&&window.speechSynthesis&&window.speechSynthesis.cancel(),Qt.current)try{Qt.current.stop();}catch{}},[]);let fo=()=>{typeof window<"u"&&window.speechSynthesis&&(window.speechSynthesis.cancel(),Zt(null));let r=`session_${Date.now()}_${Math.random().toString(36).substring(2,9)}`;w.clearMessages(),w.setSessionId(r),ut(null),dt(false),Ne?.();},gi=r=>{typeof window<"u"&&window.speechSynthesis&&(window.speechSynthesis.cancel(),Zt(null)),w.setSessionId(r.id),w.setMessages(r.messages),dt(false);},hi=(r,M)=>{M.stopPropagation(),Tt(E=>{let K=E.filter(ge=>ge.id!==r);try{Ie&&typeof window<"u"&&window.localStorage&&localStorage.setItem(Nt,JSON.stringify(K));}catch{}return K}),w.sessionId===r&&fo();},mi=()=>{Tt([]);try{Ie&&typeof window<"u"&&window.localStorage&&localStorage.removeItem(Nt);}catch{}fo();},Mn=(r="markdown")=>{let M=o||Ge?.name||"Botzki AI Assistant",E="";if(r==="json"?E=JSON.stringify({sessionId:w.sessionId,botTitle:M,exportedAt:new Date().toISOString(),messages:w.messages},null,2):(E=`# Conversation with ${M}
|
|
29
44
|
|
|
30
|
-
`,
|
|
31
|
-
`,
|
|
45
|
+
`,E+=`- **Date:** ${new Date().toLocaleString()}
|
|
46
|
+
`,E+=`- **Session ID:** \`${w.sessionId}\`
|
|
32
47
|
|
|
33
48
|
---
|
|
34
49
|
|
|
35
|
-
`,w.messages.forEach(K=>{let ge=K.role==="user"?"User":
|
|
50
|
+
`,w.messages.forEach(K=>{let ge=K.role==="user"?"User":M;E+=`### ${ge} (${new Date(K.createdAt).toLocaleTimeString()}):
|
|
36
51
|
${K.content}
|
|
37
52
|
|
|
38
|
-
`;})),typeof window<"u"&&typeof document<"u"){let K=new Blob([
|
|
53
|
+
`;})),typeof window<"u"&&typeof document<"u"){let K=new Blob([E],{type:r==="json"?"application/json":"text/markdown;charset=utf-8"}),ge=URL.createObjectURL(K),Y=document.createElement("a");Y.href=ge,Y.download=`botzki-chat-${Date.now()}.${r==="json"?"json":"md"}`,document.body.appendChild(Y),Y.click(),document.body.removeChild(Y),URL.revokeObjectURL(ge);}return E},bi=r=>{let M=r.target.files?.[0];if(M){if(M.size>25*1024*1024){alert("Attachment size must be less than 25MB."),pt.current&&(pt.current.value="");return}if(M.type.startsWith("image/")){let E=new FileReader;E.onload=()=>{ut({dataUrl:E.result,name:M.name}),Yt(null);},E.readAsDataURL(M);}else Yt({file:M,name:M.name,size:M.size}),ut(null);pt.current&&(pt.current.value="");}},yi=()=>{if(uo){Qt.current?.stop(),Ut(false);return}let r=window.SpeechRecognition||window.webkitSpeechRecognition;if(!r){alert("Voice input is not supported in this browser. Please use Chrome, Edge, or Safari.");return}try{let M=new r;M.continuous=!1,M.interimResults=!0,M.lang="en-US",M.onstart=()=>Ut(!0),M.onresult=E=>{let K="";for(let ge=E.resultIndex;ge<E.results.length;ge++)K+=E.results[ge][0].transcript;we(K);},M.onerror=()=>Ut(!1),M.onend=()=>Ut(!1),Qt.current=M,M.start();}catch{Ut(false);}},zn=(r,M)=>{if(typeof window>"u"||!window.speechSynthesis)return;if(po===r){window.speechSynthesis.cancel(),Zt(null);return}window.speechSynthesis.cancel();let E=M.replace(/[*_#`\[\]\(\)]/g," "),K=new SpeechSynthesisUtterance(E);K.onend=()=>Zt(null),K.onerror=()=>Zt(null),window.speechSynthesis.speak(K),Zt(r);},Ko=async(r,M)=>{li(Y=>({...Y,[r]:M})),Xe?.(r,M);let E=B.botId||ce?.botId,K=B.baseUrl||ce?.baseUrl||"https://api.botzki.com",ge=B.publishableKey||ce?.publishableKey;if(E)try{await fetch(`${K.replace(/\/+$/,"")}/api/v1/public/chat/${E}/messages/${r}/reaction`,{method:"POST",headers:{"Content-Type":"application/json",...ge?{Authorization:`Bearer ${ge}`}:{}},body:JSON.stringify({rating:M,reaction:M,sessionId:w.sessionId})});}catch{}},Bn=(r,M)=>{navigator.clipboard&&(navigator.clipboard.writeText(M),vn(r),setTimeout(()=>vn(null),2e3));},Rn=async r=>{r.preventDefault();let M=fe.trim();if(!(!M&&!$e&&!ve)){if(ve){$t(true);try{let E=B.botId||ce?.botId,K=B.baseUrl||ce?.baseUrl||"https://api.botzki.com",ge=B.publishableKey||ce?.publishableKey,Y=new FormData;Y.append("file",ve.file);let De=K?K.replace(/\/+$/,""):"https://api.botzki.com",go={};ge&&(go.Authorization=`Bearer ${ge}`);let Tn=await fetch(`${De}/api/v1/public/bots/${E}/handoff/upload`,{method:"POST",headers:go,body:Y});if(Tn.ok){let Zo=await Tn.json(),vi=Zo.mediaUrl.startsWith("http")?Zo.mediaUrl:`${De}${Zo.mediaUrl}`;await Pe(M||`\u{1F4CE} ${ve.name}`,{fileUrl:vi,fileName:ve.name,fileSize:ve.size});}else await Pe(M||`\u{1F4CE} ${ve.name}`);}catch(E){console.warn("Failed to upload document attachment:",E),await Pe(M||`\u{1F4CE} ${ve.name}`);}finally{$t(false),Yt(null),we("");}return}Pe(M||"Please analyze this image.",{imageBase64:$e?.dataUrl}),we(""),ut(null);}},Jo=o||Ge?.name||"AI Assistant",An=ye||Ge?.starterQuestions||[],x=v==="dark"||v==="auto"&&typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches,To=x?"#0f172a":"#ffffff",Xo=x?"#1e293b":"#f8fafc",it=x?"#f8fafc":"#0f172a",ie=x?"#94a3b8":"#64748b",Te=x?"#334155":"#e2e8f0",xi=O||I,wi=q||"#ffffff",Qo=P||(x?"#1e293b":"#f1f5f9"),In=A||(x?"#f1f5f9":"#1e293b");return jsxs("div",{className:V,style:{position:"relative",display:"flex",flexDirection:"column",width:"100%",height:"100%",minHeight:"450px",backgroundColor:To,color:it,borderRadius:"16px",border:`1px solid ${Te}`,overflow:"hidden",boxSizing:"border-box",fontFamily:l||'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:typeof k=="number"?`${k}px`:k||"14px",...D},children:[jsx("style",{children:`
|
|
39
54
|
.botzki-chat-scroll::-webkit-scrollbar {
|
|
40
55
|
width: 5px;
|
|
41
56
|
height: 5px;
|
|
@@ -44,11 +59,11 @@ ${K.content}
|
|
|
44
59
|
background: transparent;
|
|
45
60
|
}
|
|
46
61
|
.botzki-chat-scroll::-webkit-scrollbar-thumb {
|
|
47
|
-
background: ${
|
|
62
|
+
background: ${x?"rgba(255, 255, 255, 0.2)":"rgba(0, 0, 0, 0.2)"};
|
|
48
63
|
border-radius: 9999px;
|
|
49
64
|
}
|
|
50
65
|
.botzki-chat-scroll::-webkit-scrollbar-thumb:hover {
|
|
51
|
-
background: ${
|
|
66
|
+
background: ${x?"rgba(255, 255, 255, 0.38)":"rgba(0, 0, 0, 0.38)"};
|
|
52
67
|
}
|
|
53
68
|
.botzki-composer-textarea::-webkit-scrollbar {
|
|
54
69
|
display: none !important;
|
|
@@ -122,18 +137,18 @@ ${K.content}
|
|
|
122
137
|
.botzki-starter-btn:hover {
|
|
123
138
|
transform: translateY(-2px);
|
|
124
139
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
125
|
-
border-color: ${
|
|
140
|
+
border-color: ${I} !important;
|
|
126
141
|
}
|
|
127
|
-
`}),Et&&jsxs("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:To,zIndex:20,display:"flex",flexDirection:"column",overflow:"hidden",animation:"botzki-fade-in 0.2s ease-out"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 18px",backgroundColor:Jo,borderBottom:`1px solid ${Te}`},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("circle",{cx:"12",cy:"12",r:"10"}),jsx("polyline",{points:"12 6 12 12 16 14"})]}),jsx("span",{style:{fontWeight:600,fontSize:"14px"},children:"Chat History"}),jsx("span",{style:{fontSize:"11px",color:ne,padding:"2px 6px",borderRadius:"10px",backgroundColor:b?"#334155":"#e2e8f0"},children:mt.length})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[jsx("button",{type:"button",onClick:po,style:{background:T,color:"#ffffff",border:"none",borderRadius:"6px",padding:"5px 10px",fontSize:"12px",fontWeight:600,cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},children:"+ New Chat"}),jsx("button",{type:"button",onClick:()=>dt(false),title:"Close History",style:{background:"transparent",border:"none",color:ne,cursor:"pointer",fontSize:"16px",padding:"4px 8px",borderRadius:"6px"},children:"\u2715"})]})]}),jsx("div",{className:"botzki-chat-scroll",style:{flex:1,overflowY:"auto",padding:"12px 14px",display:"flex",flexDirection:"column",gap:"8px"},children:mt.length===0?jsx("div",{style:{textAlign:"center",color:ne,fontSize:"13px",marginTop:"40px"},children:"No saved chat sessions yet."}):mt.map(r=>{let k=r.id===w.sessionId;return jsxs("div",{onClick:()=>gi(r),style:{padding:"10px 12px",borderRadius:"8px",backgroundColor:k?b?"rgba(14, 165, 233, 0.15)":"rgba(14, 165, 233, 0.1)":b?"#1e293b":"#f8fafc",border:`1px solid ${k?T:Te}`,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"border-color 0.15s ease"},children:[jsxs("div",{style:{flex:1,overflow:"hidden",marginRight:"8px"},children:[jsx("div",{style:{fontWeight:600,fontSize:"13px",color:it,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r.title||"Conversation"}),jsxs("div",{style:{fontSize:"11px",color:ne,marginTop:"2px"},children:[new Date(r.updatedAt).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})," ","\xB7 ",r.messages.length," messages"]})]}),jsx("button",{type:"button",onClick:I=>hi(r.id,I),title:"Delete session",style:{background:"transparent",border:"none",color:ne,cursor:"pointer",padding:"4px 6px",borderRadius:"4px",fontSize:"13px"},children:"\u{1F5D1}"})]},r.id)})}),jsxs("div",{style:{padding:"10px 16px",borderTop:`1px solid ${Te}`,backgroundColor:Jo,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsx("button",{type:"button",onClick:()=>Cn("markdown"),disabled:w.messages.length===0,style:{background:"transparent",border:`1px solid ${Te}`,color:it,borderRadius:"6px",padding:"5px 10px",fontSize:"12px",cursor:w.messages.length===0?"not-allowed":"pointer",opacity:w.messages.length===0?.5:1,display:"flex",alignItems:"center",gap:"4px"},children:"\u{1F4E5} Export Chat (.md)"}),mt.length>0&&jsx("button",{type:"button",onClick:mi,style:{background:"transparent",border:"none",color:"#ef4444",fontSize:"12px",cursor:"pointer",padding:"5px 8px"},children:"Clear All"})]})]}),be?be({title:Xo,subtitle:J,isDark:b,primaryColor:T,isOpen:true,isExpanded:Ee,isHistoryOpen:Et,botAvatar:i,onClose:ee,onClear:qe,onNewChat:po,toggleHistory:()=>dt(r=>!r),toggleExpand:We}):Qe||jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 18px",backgroundColor:Jo,borderBottom:`1px solid ${Te}`,...h},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[i?typeof i=="string"?jsx("img",{src:i,alt:Xo,style:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0}}):i:jsx("div",{style:{width:"36px",height:"36px",borderRadius:"50%",backgroundColor:se.background??(b?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.05)"),display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexShrink:0},children:jsx(zt,{size:se.size??28,shape:se.shape??"pebble",followCursor:se.followCursor,colors:se.colors??["#66a6ff","#0059d4"],faceColor:se.faceColor??"#ffffff",eyeColor:se.eyeColor,mouthColor:se.mouthColor,motion:se.motion,emotion:se.emotion,outlineColor:se.outlineColor,outlineWidth:se.outlineWidth,...se.props})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontWeight:600,fontSize:"14px",lineHeight:1.2,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:Xo}),jsxs("div",{style:{fontSize:"12px",color:ne,display:"flex",alignItems:"center",gap:"5px",marginTop:"2px"},children:[jsx("span",{style:{width:"7px",height:"7px",borderRadius:"50%",backgroundColor:"#22c55e",display:"inline-block"}}),J]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[ke&&jsxs("button",{onClick:po,title:"Start New Chat",type:"button",style:{background:"transparent",border:"none",color:ne,cursor:"pointer",fontSize:"12px",padding:"4px 7px",borderRadius:"6px",display:"flex",alignItems:"center",gap:"3px"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),jsx("span",{children:"New"})]}),pe&&jsxs("button",{onClick:()=>dt(r=>!r),title:Et?"Close History":"Chat History",type:"button",style:{background:Et?b?"#334155":"#e2e8f0":"transparent",border:"none",color:ne,cursor:"pointer",fontSize:"12px",padding:"4px 7px",borderRadius:"6px",display:"flex",alignItems:"center",gap:"3px"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("circle",{cx:"12",cy:"12",r:"10"}),jsx("polyline",{points:"12 6 12 12 16 14"})]}),mt.length>0&&jsx("span",{style:{fontSize:"10px",opacity:.85},children:mt.length})]}),ye&&We&&jsx("button",{onClick:We,title:Ee?"Collapse Widget":"Expand Widget",type:"button",style:{background:"transparent",border:"none",color:ne,cursor:"pointer",fontSize:"13px",padding:"4px 6px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center"},children:Ee?jsxs("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("polyline",{points:"4 14 10 14 10 20"}),jsx("polyline",{points:"20 10 14 10 14 4"}),jsx("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}):jsxs("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("polyline",{points:"15 3 21 3 21 9"}),jsx("polyline",{points:"9 21 3 21 3 15"}),jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}),me.length>0&&N&&jsx("button",{onClick:()=>Cn("markdown"),title:"Download Chat Transcript",type:"button",style:{background:"transparent",border:"none",color:ne,cursor:"pointer",fontSize:"12px",padding:"4px 6px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center"},children:jsxs("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),jsx("polyline",{points:"7 10 12 15 17 10"}),jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}),me.length>0&&He&&jsx("button",{onClick:qe,title:"Clear Chat",type:"button",style:{background:"transparent",border:"none",color:ne,cursor:"pointer",fontSize:"12px",padding:"4px 7px",borderRadius:"6px"},children:"Clear"}),(()=>{let r=u!==false&&Ge?.liveChatEnabled!==false&&Ge?.humanHandoffEnabled!==false,k=Ge?.liveChatIsOnline===false&&Ge?.liveChatOutOfHoursBehavior==="aiOnly",I=r&&!k&&!w.isHumanHandoffActive&&!w.isWaitingForHuman,K=Ge?.handoffButtonText||"Talk to Support";return I?jsxs("button",{onClick:async()=>{if(Ge?.liveChatRequireEmail){ct(true);return}try{await w.requestHumanHandoff?.("User requested from widget header");}catch(V){V?.code==="EMAIL_REQUIRED"&&ct(true);}},title:K,type:"button",style:{background:b?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.05)",border:`1px solid ${b?"rgba(255, 255, 255, 0.12)":"rgba(0, 0, 0, 0.08)"}`,color:b?"#e2e8f0":"#334155",cursor:"pointer",fontSize:"11px",fontWeight:600,padding:"4px 9px",borderRadius:"9999px",display:"flex",alignItems:"center",gap:"4px",transition:"all 0.15s ease"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M3 18v-6a9 9 0 0 1 18 0v6"}),jsx("path",{d:"M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"})]}),jsx("span",{children:K})]}):null})(),ce&&ee&&jsx("button",{onClick:ee,title:"Close Chat",type:"button",style:{background:"transparent",border:"none",color:ne,cursor:"pointer",fontSize:"16px",padding:"4px 8px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center"},children:"\u2715"})]})]}),w.coBrowse?.isRequested&&!w.coBrowse?.isActive&&jsxs("div",{style:{padding:"12px 14px",backgroundColor:b?"rgba(30, 41, 59, 0.95)":"rgba(240, 253, 250, 0.95)",borderBottom:`1px solid ${b?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)"}`,display:"flex",flexDirection:"column",gap:"10px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.05)"},children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"10px"},children:[jsx("div",{style:{width:"32px",height:"32px",borderRadius:"8px",backgroundColor:b?"rgba(16, 185, 129, 0.2)":"#d1fae5",color:"#10b981",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,fontSize:"16px"},children:"\u{1F6E1}\uFE0F"}),jsxs("div",{style:{flex:1},children:[jsx("div",{style:{fontSize:"12px",fontWeight:600,color:it},children:"Live Screen Assist Request"}),jsxs("div",{style:{fontSize:"11px",color:ne,marginTop:"2px",lineHeight:"1.4"},children:[jsx("strong",{children:w.coBrowse.operatorName||"Support Specialist"})," requested permission to view your screen to guide you."]}),jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginTop:"4px",fontSize:"10px",color:b?"#34d399":"#059669"},children:jsx("span",{children:"\u{1F512} Privacy Shield Active \u2022 Form inputs & passwords masked"})})]})]}),jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[jsx("button",{type:"button",onClick:()=>w.coBrowse?.decline("Visitor declined"),style:{padding:"5px 12px",borderRadius:"6px",border:`1px solid ${Te}`,background:"transparent",color:ne,fontSize:"11px",fontWeight:500,cursor:"pointer"},children:"Decline"}),jsx("button",{type:"button",onClick:()=>w.coBrowse?.accept(),style:{padding:"5px 14px",borderRadius:"6px",border:"none",background:"linear-gradient(135deg, #10b981 0%, #059669 100%)",color:"#ffffff",fontSize:"11px",fontWeight:600,cursor:"pointer",boxShadow:"0 2px 6px rgba(16, 185, 129, 0.3)"},children:"Allow Live Assist"})]})]}),It&&jsxs("form",{onSubmit:async r=>{r.preventDefault();let k=Co.trim();if(!k||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(k)){Nt("Please enter a valid email address.");return}ao(true),Nt(null);try{await w.requestHumanHandoff?.("User requested live support via email gate",Uo.trim()||void 0,k),ct(!1);}catch(I){Nt(I?.message||"Failed to join live support queue.");}finally{ao(false);}},style:{padding:"12px 14px",backgroundColor:b?"#1e293b":"#f8fafc",borderBottom:`1px solid ${Te}`,display:"flex",flexDirection:"column",gap:"9px",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.04)"},children:[jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[jsxs("div",{children:[jsx("div",{style:{fontSize:"12px",fontWeight:600,color:it},children:"Connect with Live Specialist"}),jsx("div",{style:{fontSize:"11px",color:ne,marginTop:"1px"},children:"Enter your details to join the live support queue."})]}),jsx("button",{type:"button",onClick:()=>{ct(false),Nt(null);},style:{background:"transparent",border:"none",color:ne,cursor:"pointer",fontSize:"14px",padding:"2px 6px",borderRadius:"4px"},children:"\u2715"})]}),Vt&&jsx("div",{style:{fontSize:"11px",color:"#ef4444",fontWeight:500},children:Vt}),jsxs("div",{style:{display:"flex",gap:"8px"},children:[jsx("input",{type:"text",placeholder:"Name (optional)",value:Uo,onChange:r=>ro(r.target.value),disabled:ht,style:{flex:1,fontSize:"12px",padding:"6px 9px",borderRadius:"6px",border:`1px solid ${Te}`,backgroundColor:b?"#0f172a":"#ffffff",color:it,outline:"none"}}),jsx("input",{type:"email",placeholder:"Email address *",required:true,value:Co,onChange:r=>_t(r.target.value),disabled:ht,style:{flex:1.2,fontSize:"12px",padding:"6px 9px",borderRadius:"6px",border:`1px solid ${Te}`,backgroundColor:b?"#0f172a":"#ffffff",color:it,outline:"none"}})]}),jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[jsx("button",{type:"button",onClick:()=>{ct(false),Nt(null);},disabled:ht,style:{background:"transparent",border:"none",fontSize:"11px",color:ne,cursor:"pointer",padding:"4px 8px"},children:"Cancel"}),jsx("button",{type:"submit",disabled:ht,style:{backgroundColor:T,color:"#ffffff",border:"none",borderRadius:"6px",padding:"5px 12px",fontSize:"11px",fontWeight:600,cursor:ht?"wait":"pointer",opacity:ht?.7:1,display:"inline-flex",alignItems:"center",gap:"5px"},children:ht?"Connecting...":"Join Queue"})]})]}),w.isWaitingForHuman&&jsxs("div",{style:{padding:"9px 14px",backgroundColor:b?"rgba(245, 158, 11, 0.15)":"#fef3c7",borderBottom:"1px solid rgba(245, 158, 11, 0.3)",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"12px",color:b?"#fbbf24":"#b45309"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx("span",{style:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:"#f59e0b",display:"inline-block"}}),jsx("span",{children:"Connecting you with support team..."})]}),jsx("button",{onClick:()=>w.cancelHumanHandoff?.(),type:"button",style:{background:"transparent",border:"none",fontSize:"11px",fontWeight:600,color:"inherit",cursor:"pointer",textDecoration:"underline"},children:"Cancel"})]}),w.isHumanHandoffActive&&jsxs("div",{style:{padding:"9px 14px",backgroundColor:b?"rgba(14, 165, 233, 0.15)":"#e0f2fe",borderBottom:"1px solid rgba(14, 165, 233, 0.3)",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"12px",color:b?"#38bdf8":"#0284c7"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx("span",{style:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:"#0284c7",display:"inline-block"}}),jsxs("span",{children:[jsx("strong",{children:"Live Agent:"})," ",w.assignedOperator?.name||"Support Specialist"]})]}),jsx("button",{onClick:()=>w.cancelHumanHandoff?.(),type:"button",style:{background:"transparent",border:"none",fontSize:"11px",fontWeight:600,color:"inherit",cursor:"pointer",textDecoration:"underline"},children:"Back to Bot"})]}),jsxs("div",{ref:lt,onScroll:pi,className:"botzki-chat-scroll",style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"14px",scrollbarWidth:"thin",scrollbarColor:b?"rgba(255, 255, 255, 0.2) transparent":"rgba(0, 0, 0, 0.2) transparent",...x},children:[me.length===0?Ve?Ve():jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"14px",animation:"botzki-greeting-pop 0.45s cubic-bezier(0.16, 1, 0.3, 1) both"},children:[he&&jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"10px"},children:[a&&jsx("div",{style:{width:"32px",height:"32px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexShrink:0,marginTop:"2px",animation:"botzki-avatar-entrance 0.5s cubic-bezier(0.16, 1, 0.3, 1) both"},children:i?typeof i=="string"?jsx("img",{src:i,alt:"Bot",style:{width:"32px",height:"32px",borderRadius:"50%",objectFit:"cover"}}):i:jsx(zt,{size:28,shape:se.shape??"pebble",colors:se.colors??["#66a6ff","#0059d4"],faceColor:se.faceColor??"#ffffff",eyeColor:se.eyeColor,mouthColor:se.mouthColor,motion:se.motion??"jump",emotion:se.emotion??"laugh",followCursor:se.followCursor})}),jsxs("div",{style:{maxWidth:"84%",padding:"12px 16px",borderRadius:"16px",borderTopLeftRadius:a?"4px":"16px",backgroundColor:Qo,color:An,fontSize:"14px",lineHeight:1.5,boxShadow:b?"0 4px 14px rgba(0, 0, 0, 0.25)":"0 4px 14px rgba(0, 0, 0, 0.05)",border:`1px solid ${Te}`},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginBottom:"4px"},children:[jsx("span",{style:{display:"inline-block",transformOrigin:"70% 70%",animation:"botzki-wave 1.6s ease-in-out infinite",fontSize:"16px"},children:"\u{1F44B}"}),jsx("span",{style:{fontWeight:600,fontSize:"11px",color:T,textTransform:"uppercase",letterSpacing:"0.5px"},children:"Welcome"})]}),jsx(Wo,{content:he,isUser:false,primaryColor:T,isDark:b})]})]}),Rn.length>0&&jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",marginTop:"4px",marginLeft:a?"42px":0},children:[jsx("span",{style:{fontSize:"11px",color:ne,fontWeight:600,letterSpacing:"0.5px"},children:"SUGGESTED QUESTIONS"}),jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px"},children:Rn.map((r,k)=>jsx("button",{className:"botzki-starter-btn",onClick:()=>Pe(r),style:{backgroundColor:b?"#1e293b":"#f1f5f9",color:it,border:`1px solid ${Te}`,padding:"8px 14px",borderRadius:"20px",fontSize:"12px",fontWeight:500,cursor:"pointer",textAlign:"left",animation:`botzki-starter-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) ${.12+k*.08}s both`},children:r},k))})]})]}):null,me.map((r,k)=>{let I=r.role==="user",ge=Wt!==void 0&&Wt>=0&&k===Wt?jsxs("div",{ref:Go,style:{display:"flex",alignItems:"center",gap:"12px",margin:"18px 0 14px",width:"100%",padding:"0 4px"},children:[jsx("div",{style:{flex:1,height:"1px",background:b?"rgba(239, 68, 68, 0.45)":"rgba(239, 68, 68, 0.35)"}}),jsxs("span",{style:{fontSize:"11px",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.5px",color:"#ef4444",background:b?"rgba(239, 68, 68, 0.15)":"#fee2e2",padding:"3px 10px",borderRadius:"9999px",border:`1px solid ${b?"rgba(239, 68, 68, 0.4)":"rgba(239, 68, 68, 0.3)"}`,display:"inline-flex",alignItems:"center",gap:"6px",lineHeight:1.2,boxShadow:"0 1px 3px rgba(0, 0, 0, 0.08)"},children:[jsx("span",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#ef4444"}}),"New Messages"]}),jsx("div",{style:{flex:1,height:"1px",background:b?"rgba(239, 68, 68, 0.45)":"rgba(239, 68, 68, 0.35)"}})]},"botzki-unread-messages-separator"):null;return r.role==="system"?jsxs(gn.Fragment,{children:[ge,jsx("div",{style:{display:"flex",justifyContent:"center",margin:"8px 0",width:"100%"},children:jsx("div",{style:{fontSize:"11px",color:b?"#94a3b8":"#64748b",backgroundColor:b?"rgba(255, 255, 255, 0.05)":"rgba(0, 0, 0, 0.04)",padding:"4px 12px",borderRadius:"9999px",border:`1px solid ${b?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.06)"}`,maxWidth:"85%",textAlign:"center",lineHeight:1.4},children:r.content})})]},r.id):Ke?jsxs(gn.Fragment,{children:[ge,Ke({message:r,index:k,isUser:I,isDark:b,primaryColor:T,onCopy:()=>zn(r.id,r.content),onSpeak:()=>Mn(r.id,r.content),onFeedback:V=>Ko(r.id,V)})]},r.id):jsxs(gn.Fragment,{children:[ge,jsxs("div",{style:{display:"flex",flexDirection:I?"row-reverse":"row",alignItems:"flex-start",gap:"8px",width:"100%"},children:[a&&jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexShrink:0,marginTop:"2px",backgroundColor:I?b?"#334155":"#e2e8f0":"transparent"},children:I?o?typeof o=="string"?jsx("img",{src:o,alt:"User",style:{width:"28px",height:"28px",borderRadius:"50%",objectFit:"cover"}}):o:jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:b?"#cbd5e1":"#475569",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),jsx("circle",{cx:"12",cy:"7",r:"4"})]}):i?typeof i=="string"?jsx("img",{src:i,alt:"Bot",style:{width:"28px",height:"28px",borderRadius:"50%",objectFit:"cover"}}):i:jsx(zt,{size:24,shape:se.shape??"pebble",colors:se.colors??["#66a6ff","#0059d4"],faceColor:se.faceColor??"#ffffff",eyeColor:se.eyeColor,mouthColor:se.mouthColor,followCursor:se.followCursor})}),jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:I?"flex-end":"flex-start",maxWidth:"80%"},children:[jsxs("div",{style:{padding:"10px 14px",borderRadius:"14px",backgroundColor:I?xi:Qo,color:I?wi:An,fontSize:"14px",lineHeight:1.5,wordBreak:"break-word"},children:[r.senderType==="operator"&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginBottom:"6px"},children:[jsx("span",{style:{fontSize:"11px",fontWeight:600,color:b?"#38bdf8":"#0284c7"},children:r.senderName||w.assignedOperator?.name||"Support Specialist"}),jsx("span",{style:{fontSize:"9px",fontWeight:700,letterSpacing:"0.5px",textTransform:"uppercase",padding:"1px 5px",borderRadius:"4px",backgroundColor:b?"rgba(14, 165, 233, 0.2)":"#e0f2fe",color:b?"#38bdf8":"#0284c7"},children:"Operator"})]}),(r.imageUrl||r.imageBase64)&&jsx("img",{src:r.imageUrl||r.imageBase64,alt:"Attachment",style:{maxWidth:"100%",maxHeight:"180px",borderRadius:"8px",marginBottom:"8px",display:"block",cursor:"pointer"},onClick:()=>{typeof window<"u"&&window.open(r.imageUrl||r.imageBase64,"_blank");}}),r.audioUrl&&jsx("div",{style:{marginBottom:r.content||r.isTranscribing?"6px":0},children:jsx(pn,{audioUrl:r.audioUrl,duration:r.audioDuration,isUser:I,primaryColor:T,isDark:b})}),r.fileUrl&&jsxs("div",{style:{margin:"8px 0",padding:"10px 12px",borderRadius:"12px",backgroundColor:b?"rgba(255, 255, 255, 0.08)":"#f8fafc",border:`1px solid ${b?"rgba(255, 255, 255, 0.15)":"#e2e8f0"}`,display:"flex",flexDirection:"column",gap:"8px",minWidth:"190px",maxWidth:"260px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[jsx("div",{style:{width:"36px",height:"36px",borderRadius:"8px",backgroundColor:b?"rgba(255, 255, 255, 0.12)":"#e0f2fe",color:b?"#ffffff":T,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:oi(r.fileName)}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"12px",fontWeight:600,color:b?"#f1f5f9":"#0f172a",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:r.fileName||"File",children:r.fileName||"Attachment"}),r.fileSize&&jsx("div",{style:{fontSize:"10.5px",color:b?"#94a3b8":"#64748b",marginTop:"1px"},children:ti(r.fileSize)})]})]}),jsxs("a",{href:`${r.fileUrl}${r.fileUrl.includes("?")?"&":"?"}download=true&name=${encodeURIComponent(r.fileName||"download")}`,target:"_blank",rel:"noreferrer",download:r.fileName||true,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",backgroundColor:b?"#38bdf8":"#0f172a",color:b?"#0f172a":"#ffffff",fontSize:"11px",fontWeight:600,textDecoration:"none",cursor:"pointer",transition:"opacity 0.15s ease"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),jsx("polyline",{points:"7 10 12 15 17 10"}),jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),jsx("span",{children:"Download file"})]})]}),r.isTranscribing&&jsxs("div",{style:{fontSize:"11px",opacity:.85,display:"flex",alignItems:"center",gap:"6px",paddingTop:"2px"},children:[jsx("span",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:I?"#ffffff":T,animation:"botzki-pulse 1s infinite"}}),jsx("span",{children:"Transcribing audio..."})]}),I?r.content?jsxs("div",{style:{whiteSpace:"pre-wrap"},children:[r.audioUrl&&jsx("span",{style:{display:"block",fontSize:"11px",opacity:.75,marginBottom:"2px",fontStyle:"italic"},children:"Transcription:"}),r.content]}):null:r.content?jsx(Wo,{content:r.content,isUser:false,primaryColor:T,isDark:b}):null,C&&r.citations&&r.citations.length>0&&jsxs("div",{style:{marginTop:"8px",paddingTop:"6px",borderTop:`1px solid ${I?"rgba(255,255,255,0.2)":Te}`,fontSize:"11px",display:"flex",flexWrap:"wrap",gap:"4px"},children:[jsx("span",{style:{opacity:.8},children:"Sources:"}),r.citations.map((V,De)=>jsxs("span",{style:{backgroundColor:I?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.06)",padding:"2px 6px",borderRadius:"4px",fontWeight:500},children:[V.source," ",V.page_number?`p.${V.page_number}`:""]},De))]}),!I&&r.escalation&&jsxs("div",{style:{marginTop:"10px",padding:"10px 12px",borderRadius:"10px",backgroundColor:b?"rgba(14, 165, 233, 0.12)":"rgba(14, 165, 233, 0.08)",border:"1px solid rgba(14, 165, 233, 0.25)",display:"flex",flexDirection:"column",gap:"6px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontWeight:600,fontSize:"12px",color:b?"#38bdf8":"#0284c7"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("path",{d:"M3 18v-6a9 9 0 0 1 18 0v6"}),jsx("path",{d:"M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"})]}),jsx("span",{children:r.escalation.title||"Live Support Specialist"})]}),r.escalation.description&&jsx("p",{style:{margin:0,fontSize:"11px",opacity:.85,lineHeight:1.4},children:r.escalation.description}),jsxs("button",{type:"button",onClick:async()=>{if(Ge?.liveChatRequireEmail){ct(true);return}try{await w.requestHumanHandoff?.(r.escalation?.title||"Visitor accepted AI escalation offer");}catch(V){V?.code==="EMAIL_REQUIRED"&&ct(true);}},style:{marginTop:"4px",padding:"6px 12px",backgroundColor:T,color:"#ffffff",border:"none",borderRadius:"6px",fontSize:"12px",fontWeight:600,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"opacity 0.15s ease"},onMouseEnter:V=>V.currentTarget.style.opacity="0.9",onMouseLeave:V=>V.currentTarget.style.opacity="1",children:[jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("path",{d:"M3 18v-6a9 9 0 0 1 18 0v6"}),jsx("path",{d:"M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"})]}),jsx("span",{children:r.escalation.buttonText||"Connect with Support Agent"})]})]}),!I&&S!==false&&r.proposedAction&&jsxs("div",{style:{marginTop:"10px",padding:"12px 14px",borderRadius:"12px",backgroundColor:b?"rgba(99, 102, 241, 0.12)":"rgba(99, 102, 241, 0.07)",border:b?"1px solid rgba(99, 102, 241, 0.35)":"1px solid rgba(99, 102, 241, 0.25)",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.04)",display:"flex",flexDirection:"column",gap:"8px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:b?"1px solid rgba(99, 102, 241, 0.2)":"1px solid rgba(99, 102, 241, 0.15)",paddingBottom:"6px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontWeight:700,fontSize:"12px",color:b?"#818cf8":"#4f46e5"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),jsx("span",{children:"Autonomous Action Guardrail"})]}),jsx("span",{style:{fontSize:"10px",fontFamily:"monospace",textTransform:"uppercase",padding:"2px 6px",borderRadius:"4px",backgroundColor:b?"rgba(99, 102, 241, 0.2)":"rgba(99, 102, 241, 0.12)",color:b?"#a5b4fc":"#4338ca",fontWeight:600},children:r.proposedAction.status==="completed"?"\u2713 Executed":r.proposedAction.status==="executing"?"Executing...":r.proposedAction.status==="cancelled"?"Cancelled":r.proposedAction.status==="failed"?"Failed":"2-Step Confirmation"})]}),jsxs("div",{children:[jsx("div",{style:{fontWeight:600,fontSize:"13px",color:b?"#f8fafc":"#0f172a"},children:r.proposedAction.displayName||r.proposedAction.actionName}),r.proposedAction.description&&jsx("div",{style:{fontSize:"11px",color:b?"#94a3b8":"#64748b",marginTop:"2px"},children:r.proposedAction.description})]}),jsx("div",{style:{fontSize:"12px",lineHeight:1.45,padding:"8px 10px",borderRadius:"8px",backgroundColor:b?"rgba(0, 0, 0, 0.25)":"rgba(255, 255, 255, 0.7)",border:b?"1px solid rgba(255, 255, 255, 0.08)":"1px solid rgba(0, 0, 0, 0.06)",color:b?"#e2e8f0":"#1e293b"},children:r.proposedAction.confirmationPrompt||"Do you confirm executing this autonomous action?"}),r.proposedAction.parameters&&Object.keys(r.proposedAction.parameters).length>0&&jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:Object.entries(r.proposedAction.parameters).map(([V,De])=>jsxs("span",{style:{fontSize:"10px",fontFamily:"monospace",padding:"2px 6px",borderRadius:"4px",backgroundColor:b?"rgba(255, 255, 255, 0.06)":"rgba(0, 0, 0, 0.05)",color:b?"#cbd5e1":"#475569"},children:[jsxs("strong",{children:[V,":"]})," ",String(De)]},V))}),r.proposedAction.status==="completed"?jsxs("div",{style:{padding:"8px 10px",borderRadius:"8px",backgroundColor:b?"rgba(16, 185, 129, 0.15)":"rgba(16, 185, 129, 0.1)",border:"1px solid rgba(16, 185, 129, 0.3)",color:b?"#34d399":"#059669",fontSize:"12px",fontWeight:600,display:"flex",alignItems:"center",gap:"6px"},children:[jsx("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),jsx("span",{children:r.proposedAction.successMessage||"Action executed successfully with zero operator intervention."})]}):r.proposedAction.status==="executing"?jsx("div",{style:{padding:"8px 10px",borderRadius:"8px",backgroundColor:b?"rgba(99, 102, 241, 0.15)":"rgba(99, 102, 241, 0.1)",color:b?"#a5b4fc":"#4f46e5",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px"},children:jsx("span",{children:"\u23F3 Executing action safely via signed token..."})}):r.proposedAction.status==="cancelled"?jsx("div",{style:{padding:"6px 10px",borderRadius:"6px",backgroundColor:b?"rgba(255, 255, 255, 0.05)":"rgba(0, 0, 0, 0.04)",color:b?"#94a3b8":"#64748b",fontSize:"11px",fontStyle:"italic"},children:"Action cancelled by visitor. No changes were made."}):r.proposedAction.status==="failed"?jsxs("div",{style:{padding:"8px 10px",borderRadius:"8px",backgroundColor:b?"rgba(239, 68, 68, 0.15)":"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:b?"#f87171":"#dc2626",fontSize:"12px"},children:["Execution failed: ",r.proposedAction.error||"Unknown server error."]}):jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"4px"},children:[jsxs("button",{type:"button",onClick:async()=>{(await w.executeProposedAction?.(r.id,r.proposedAction.token,r.proposedAction.parameters))?.success&&Ct.triggerCelebration();},style:{flex:1,padding:"7px 12px",backgroundColor:"#4f46e5",color:"#ffffff",border:"none",borderRadius:"8px",fontSize:"12px",fontWeight:600,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",boxShadow:"0 2px 4px rgba(79, 70, 229, 0.25)",transition:"opacity 0.15s ease"},onMouseEnter:V=>V.currentTarget.style.opacity="0.9",onMouseLeave:V=>V.currentTarget.style.opacity="1",children:[jsx("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),jsx("span",{children:"Confirm & Execute"})]}),jsx("button",{type:"button",onClick:()=>{w.cancelProposedAction?.(r.id,"Cancelled by user");},style:{padding:"7px 12px",backgroundColor:b?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.05)",color:b?"#cbd5e1":"#475569",border:`1px solid ${b?"rgba(255, 255, 255, 0.12)":"rgba(0, 0, 0, 0.1)"}`,borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"background-color 0.15s ease"},children:"Cancel"})]})]}),!I&&r.piiRedacted&&jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"4px",marginTop:"6px",fontSize:"10px",fontWeight:500,color:b?"#34d399":"#059669",backgroundColor:b?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.06)",padding:"2px 6px",borderRadius:"4px",border:"1px solid rgba(16, 185, 129, 0.2)"},title:"Sensitive personal identifiers were redacted before transmission",children:[jsx("span",{children:"\u{1F6E1}\uFE0F"}),jsx("span",{children:"PII Protected"})]}),r.error&&jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"#ef4444"},children:["Error: ",r.error]})]}),!I&&r.content&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginTop:"4px",paddingLeft:"4px"},children:[L&&jsxs("button",{type:"button",onClick:()=>zn(r.id,r.content),title:"Copy message",style:{background:"transparent",border:"none",cursor:"pointer",color:ne,fontSize:"11px",display:"inline-flex",alignItems:"center",gap:"3px",padding:"2px 6px",borderRadius:"4px"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),jsx("span",{children:ci===r.id?"Copied":"Copy"})]}),g&&typeof window<"u"&&window.speechSynthesis&&jsxs("button",{type:"button",onClick:()=>Mn(r.id,r.content),title:uo===r.id?"Stop speaking":"Read aloud",style:{background:uo===r.id?"rgba(14, 165, 233, 0.15)":"transparent",border:"none",cursor:"pointer",color:uo===r.id?T:ne,fontSize:"11px",display:"inline-flex",alignItems:"center",gap:"3px",padding:"2px 6px",borderRadius:"4px"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"})]}),jsx("span",{children:uo===r.id?"Stop":"Read"})]}),f&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"2px"},children:[jsx("button",{type:"button",onClick:()=>Ko(r.id,"up"),title:"Helpful",style:{background:"transparent",border:"none",cursor:"pointer",color:Do[r.id]==="up"?"#10b981":ne,padding:"2px 4px",borderRadius:"4px",display:"flex",alignItems:"center"},children:jsx("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"})})}),jsx("button",{type:"button",onClick:()=>Ko(r.id,"down"),title:"Not helpful",style:{background:"transparent",border:"none",cursor:"pointer",color:Do[r.id]==="down"?"#ef4444":ne,padding:"2px 4px",borderRadius:"4px",display:"flex",alignItems:"center"},children:jsx("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h3a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-3"})})}),Do[r.id]&&jsx("span",{style:{fontSize:"10px",color:ne,marginLeft:"2px"},children:"Thanks!"})]})]}),!I&&jsxs("div",{style:{fontSize:"10px",color:ne,marginTop:"2px",paddingLeft:"6px",display:"flex",alignItems:"center",gap:"4px",opacity:.85},children:[jsx("svg",{viewBox:"0 0 24 24",width:"11",height:"11",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),jsx("span",{children:r.deliveryStatus==="Read"?"Read in chat":r.deliveryChannel==="Email"?"Delivered to email":"Delivered"})]})]})]})]},r.id)}),w.pendingCsatTicketId&&jsxs("div",{style:{margin:"12px 0 16px 0",padding:"16px",borderRadius:"14px",backgroundColor:b?"rgba(14, 165, 233, 0.08)":"#f0f9ff",border:`1px solid ${b?"rgba(14, 165, 233, 0.25)":"#bae6fd"}`,textAlign:"center"},children:[jsx("div",{style:{fontSize:"13px",fontWeight:600,color:b?"#f0f9ff":"#0c4a6e",marginBottom:"4px"},children:"How was your support experience today?"}),jsx("p",{style:{fontSize:"11px",color:ne,margin:"0 0 12px 0"},children:"Your feedback helps us continuously improve our live support service."}),Bo?jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"6px",color:"#10b981",fontSize:"12px",fontWeight:600},children:[jsx("span",{children:"\u2713 Thank you for your feedback!"}),jsx("span",{style:{fontSize:"11px",fontWeight:400,color:ne},children:"Our support team appreciates your review."})]}):jsxs("div",{children:[jsx("div",{style:{display:"flex",justifyContent:"center",gap:"8px",marginBottom:"10px"},children:[1,2,3,4,5].map(r=>jsx("button",{type:"button",onClick:()=>Mo(r),style:{background:"transparent",border:"none",fontSize:"22px",cursor:"pointer",transform:vt>=r?"scale(1.15)":"scale(1)",transition:"transform 0.15s ease",color:vt>=r?"#f59e0b":b?"#475569":"#cbd5e1"},title:`${r} star${r>1?"s":""}`,children:"\u2605"},r))}),vt>0&&jsxs("div",{style:{marginTop:"8px",display:"flex",flexDirection:"column",gap:"8px"},children:[jsx("input",{type:"text",value:kt,onChange:r=>lo(r.target.value),placeholder:"Add an optional comment (e.g. fast, helpful)...",style:{width:"100%",padding:"8px 12px",fontSize:"12px",borderRadius:"8px",border:`1px solid ${b?"#334155":"#e2e8f0"}`,background:b?"#1e293b":"#ffffff",color:b?"#f8fafc":"#0f172a",boxSizing:"border-box"}}),jsx("div",{style:{display:"flex",justifyContent:"flex-end",gap:"6px"},children:jsx("button",{type:"button",onClick:async()=>{zo(true),await w.submitHandoffFeedback?.(vt,kt),zo(false),Ro(true),vt>=4?Ct.triggerCelebration():Ct.triggerSympathy();},disabled:Yt,style:{background:T,color:"#ffffff",border:"none",borderRadius:"6px",padding:"6px 14px",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:Yt?"Submitting...":"Submit Rating"})})]})]}),jsx("div",{style:{marginTop:"12px",borderTop:`1px solid ${b?"rgba(14, 165, 233, 0.2)":"#e0f2fe"}`,paddingTop:"10px",display:"flex",justifyContent:"center"},children:jsx("button",{type:"button",onClick:()=>{w.clearMessages?.(),Ro(false),Mo(0),lo("");},style:{background:b?"rgba(255,255,255,0.06)":"#ffffff",color:b?"#e2e8f0":"#334155",border:`1px solid ${b?"#334155":"#cbd5e1"}`,borderRadius:"8px",padding:"6px 14px",fontSize:"11px",fontWeight:600,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"6px"},children:jsx("span",{children:"\u{1F4AC} Start New Conversation"})})})]}),ae&&!Ye&&jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[a&&jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexShrink:0},children:jsx(zt,{size:24,shape:se.shape??"pebble",colors:se.colors??["#66a6ff","#0059d4"],faceColor:se.faceColor??"#ffffff",eyeColor:se.eyeColor,mouthColor:se.mouthColor,motion:"bounce"})}),jsx("div",{style:{padding:"8px 14px",borderRadius:"14px",backgroundColor:Qo,color:ne,fontSize:"13px"},children:"Thinking..."})]}),te&&jsx("div",{style:{padding:"8px 12px",borderRadius:"8px",backgroundColor:"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:"#ef4444",fontSize:"12px"},children:te.message})]}),Vo>0&&!_o&&jsxs("button",{type:"button",onClick:fi,style:{position:"absolute",bottom:"74px",left:"50%",transform:"translateX(-50%)",backgroundColor:T,color:"#ffffff",border:"none",borderRadius:"20px",padding:"6px 14px",fontSize:"12px",fontWeight:600,boxShadow:"0 4px 14px rgba(0, 0, 0, 0.35)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",zIndex:15,animation:"botzki-fade-in 0.2s ease-out"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsx("polyline",{points:"19 12 12 19 5 12"})]}),jsxs("span",{children:[Vo," new ",Vo===1?"message":"messages"]})]}),Be?Be({input:fe,setInput:xe,sendMessage:(r,k)=>Pe(r,k),isLoading:ae,isStreaming:Ye,primaryColor:T,isDark:b,attachImage:()=>pt.current?.click(),pendingImage:$e,removeImage:()=>ut(null),isListening:co,toggleListening:yi,isRecordingVoiceNote:Ao,startVoiceRecording:Ht,stopVoiceRecording:St,cancelVoiceRecording:nt,voiceRecordingDuration:Kt,sendVoiceMessage:(r,k)=>w.sendVoiceMessage?w.sendVoiceMessage(r,k):w.sendMessage("",{audioUrl:URL.createObjectURL(r),audioDuration:k?.audioDuration})}):jsxs("div",{style:{padding:"8px 14px 4px 14px",backgroundColor:To,position:"relative"},children:[Io&&jsx("div",{ref:jo,style:{position:"absolute",bottom:"calc(100% - 2px)",left:"14px",backgroundColor:b?"#1e293b":"#ffffff",border:`1px solid ${Te}`,borderRadius:"14px",padding:"8px 10px",boxShadow:b?"0 8px 24px rgba(0, 0, 0, 0.45)":"0 8px 24px rgba(0, 0, 0, 0.12)",display:"flex",flexWrap:"wrap",gap:"6px",maxWidth:"260px",zIndex:30,animation:"botzki-fade-in 0.15s ease-out"},children:ar.map(r=>jsx("button",{type:"button",onClick:()=>di(r),style:{background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",padding:"4px",borderRadius:"6px",lineHeight:1,transition:"transform 0.1s ease"},onMouseEnter:k=>k.currentTarget.style.transform="scale(1.2)",onMouseLeave:k=>k.currentTarget.style.transform="scale(1)",children:r},r))}),jsx("form",{onSubmit:Bn,style:{display:"flex",flexDirection:"column",borderRadius:"16px",border:`1px solid ${vn?T:Te}`,boxShadow:vn?`0 0 0 2px ${T}20, 0 2px 8px rgba(0, 0, 0, 0.05)`:b?"0 2px 6px rgba(0, 0, 0, 0.2)":"0 2px 6px rgba(0, 0, 0, 0.04)",backgroundColor:b?"#1e293b":"#ffffff",padding:"10px 12px 8px 12px",transition:"border-color 0.15s ease, box-shadow 0.15s ease",...ie},children:Ao?jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 4px",minHeight:"44px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx("span",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#ef4444",boxShadow:"0 0 8px rgba(239, 68, 68, 0.7)",animation:"botzki-pulse 1.2s infinite ease-in-out"}}),jsx("span",{style:{fontSize:"13px",fontWeight:600,color:b?"#f1f5f9":"#1e293b",fontVariantNumeric:"tabular-nums"},children:Xt(Kt)}),jsx("div",{style:{display:"flex",alignItems:"center",gap:"2.5px",marginLeft:"6px",height:"18px"},children:[6,12,18,10,15,8,16,14,9,17,11,7].map((r,k)=>jsx("div",{style:{width:"2.5px",height:`${r}px`,borderRadius:"2px",backgroundColor:T,animation:"botzki-equalizer 0.8s ease-in-out infinite alternate",animationDelay:`${(k*.08).toFixed(2)}s`}},k))})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx("button",{type:"button",onClick:nt,title:"Discard recording","aria-label":"Discard recording",style:{background:"transparent",border:"none",color:b?"#94a3b8":"#64748b",cursor:"pointer",padding:"6px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s ease, background 0.15s ease"},children:jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),jsx("button",{type:"button",onClick:St,title:"Send voice message","aria-label":"Send voice message",style:{width:"32px",height:"32px",borderRadius:"50%",backgroundColor:T,color:"#ffffff",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:`0 2px 8px ${T}55`,transition:"transform 0.12s ease, opacity 0.15s ease"},children:jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor",children:jsx("path",{d:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"})})})]})]}):jsxs(Fragment,{children:[$e&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"4px 6px 8px 6px",marginBottom:"4px",borderBottom:`1px solid ${Te}`,fontSize:"12px"},children:[jsx("img",{src:$e.dataUrl,alt:"Thumbnail",style:{width:"28px",height:"28px",objectFit:"cover",borderRadius:"6px",border:`1px solid ${Te}`}}),jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:it,fontSize:"11px",fontWeight:500},children:$e.name}),jsx("button",{type:"button",onClick:()=>ut(null),title:"Remove attachment",style:{background:"transparent",border:"none",color:ne,cursor:"pointer",fontSize:"12px",padding:"2px 4px",borderRadius:"4px"},children:"\u2715"})]}),we&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"4px 6px 8px 6px",marginBottom:"4px",borderBottom:`1px solid ${Te}`,fontSize:"12px"},children:[jsx("div",{style:{width:"28px",height:"28px",borderRadius:"6px",backgroundColor:b?"rgba(255, 255, 255, 0.1)":"#f1f5f9",display:"flex",alignItems:"center",justifyContent:"center",color:b?"#ffffff":T,flexShrink:0},children:oi(we.name)}),jsxs("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:it,fontSize:"11px",fontWeight:500},children:[we.name,jsxs("span",{style:{opacity:.7,marginLeft:"4px"},children:["(",ti(we.size),")"]})]}),jsx("button",{type:"button",onClick:()=>qt(null),title:"Remove attachment",style:{background:"transparent",border:"none",color:ne,cursor:"pointer",fontSize:"12px",padding:"2px 4px",borderRadius:"4px"},children:"\u2715"})]}),Oo&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"5px 8px",marginBottom:"6px",borderRadius:"6px",backgroundColor:b?"rgba(16, 185, 129, 0.12)":"rgba(16, 185, 129, 0.08)",border:"1px solid rgba(16, 185, 129, 0.25)",color:b?"#34d399":"#059669",fontSize:"11px",fontWeight:500},children:[jsx("span",{children:"\u{1F6E1}\uFE0F"}),jsx("span",{children:"PII Firewall Active: Sensitive numbers & credentials are encrypted & redacted in transit."})]}),jsx("textarea",{ref:Zt,rows:1,className:"botzki-composer-textarea",value:fe,onChange:Ne,onKeyDown:ui,onFocus:()=>kn(true),onBlur:()=>kn(false),placeholder:co?"Listening... Speak now":G||"Compose your message...",disabled:ae,style:{width:"100%",background:"transparent",border:"none",outline:"none",padding:"2px 4px",color:it,fontSize:"14px",lineHeight:"20px",resize:"none",boxSizing:"border-box",minHeight:"36px",maxHeight:"120px",overflowY:"auto",scrollbarWidth:"none",msOverflowStyle:"none",fontFamily:"inherit",...W}}),jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:"4px",paddingTop:"4px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[jsx("button",{type:"button",onClick:()=>Fo(r=>!r),title:"Insert emoji","aria-label":"Insert emoji",style:{background:"transparent",border:"none",color:Io?T:ne,cursor:"pointer",padding:"4px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s ease"},children:jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("circle",{cx:"12",cy:"12",r:"10"}),jsx("path",{d:"M8 14s1.5 2 4 2 4-2 4-2"}),jsx("line",{x1:"9",y1:"9",x2:"9.01",y2:"9"}),jsx("line",{x1:"15",y1:"9",x2:"15.01",y2:"9"})]})}),s&&jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>pt.current?.click(),title:"Attach file, document, or image","aria-label":"Attach file, document, or image",style:{background:"transparent",border:"none",color:$e||we?T:ne,cursor:"pointer",padding:"4px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s ease"},children:jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),jsx("input",{ref:pt,type:"file",accept:"image/*,.pdf,.zip,.csv,.docx,.xlsx,.txt,.tar,.gz,.json",onChange:bi,style:{display:"none"}})]}),c&&m!==false&&jsx("button",{type:"button",onClick:Ht,title:"Record voice message","aria-label":"Voice input / Record voice message",style:{background:"transparent",border:"none",color:ne,cursor:"pointer",padding:"4px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s ease"},onMouseEnter:r=>{r.currentTarget.style.color=T;},onMouseLeave:r=>{r.currentTarget.style.color=ne;},children:jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[jsx("line",{x1:"4",y1:"9",x2:"4",y2:"15"}),jsx("line",{x1:"8",y1:"5",x2:"8",y2:"19"}),jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"}),jsx("line",{x1:"16",y1:"7",x2:"16",y2:"17"}),jsx("line",{x1:"20",y1:"10",x2:"20",y2:"14"})]})})]}),Ye?jsx("button",{type:"button",onClick:()=>w.stop(),"aria-label":"Stop generating",title:"Stop generating",style:{width:"28px",height:"28px",backgroundColor:"#ef4444",color:"#ffffff",border:"none",borderRadius:"50%",padding:0,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"opacity 0.2s ease, transform 0.1s ease",...M},children:jsx("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"currentColor",children:jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}):jsx("button",{type:"submit",disabled:ae||Pt||!fe.trim()&&!$e&&!we,"aria-label":"Send message",title:"Send message",style:{background:"transparent",border:"none",color:!fe.trim()&&!$e&&!we?b?"#475569":"#cbd5e1":T,cursor:ae||Pt||!fe.trim()&&!$e&&!we?"not-allowed":"pointer",padding:"4px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"color 0.15s ease, transform 0.1s ease",...M},children:jsx("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"currentColor",children:jsx("path",{d:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"})})})]})]})})]}),y&&jsxs("div",{style:{textAlign:"center",padding:"4px 12px 10px 12px",backgroundColor:To,fontSize:"11px",color:ne,display:"flex",alignItems:"center",justifyContent:"center",gap:"4px"},children:[jsx("span",{children:"Powered by "}),jsxs("a",{href:"https://botzki.com",target:"_blank",rel:"noopener noreferrer",style:{color:it,fontWeight:600,textDecoration:"none",display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx("span",{style:{color:T},children:"\u26A1"})," Botzki"]})]}),w.coBrowse&&jsx(fn,{coBrowse:w.coBrowse})]})}function dr(t){if(!t||t.trim()===""||t.trim()==="*")return true;if(typeof window>"u")return false;let e=window.location.href,i=window.location.pathname,o=t.trim();if(o.includes("*")){let a=o.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*"),s=new RegExp(`^${a}$`,"i");return s.test(e)||s.test(i)}return e.toLowerCase().includes(o.toLowerCase())||i.toLowerCase().includes(o.toLowerCase())}var ur=forwardRef(function(e,i){let o=Dt(),a=e.botId||o?.botId,s=e.publishableKey||o?.publishableKey,c=e.baseUrl||o?.baseUrl||"https://api.botzki.com",[g,m]=useState(false),[u,S]=useState(e.defaultOpen??false),[f,C]=useState(true),[y,L]=useState(e.defaultExpanded??false),[N,Q]=useState(false),[U,X]=useState(false),[H,le]=useState(e.theme||"dark"),[Y,_]=useState(e.primaryColor||"#0ea5e9"),[,q]=useState(e.user||o?.user),[Z,oe]=useState(false);useEffect(()=>{e.theme&&le(e.theme);},[e.theme]),useEffect(()=>{e.primaryColor&&_(e.primaryColor);},[e.primaryColor]),useEffect(()=>{e.user&&q(e.user);},[e.user]),useEffect(()=>{m(true);},[]);let{data:J}=bo(),[he,ze]=useState(null);useEffect(()=>{if(u){X(false);return}try{if(typeof window<"u"&&window.sessionStorage&&sessionStorage.getItem(`botzki_proactive_dismissed_${a||"default"}`)==="true")return}catch{}if(e.proactiveMessage){let h=e.proactiveDelay??3e3,x=setTimeout(()=>{X(true);},h);return ()=>clearTimeout(x)}if(e.enableTriggers===false||!J?.activeTriggers||J.activeTriggers.length===0)return;let l=J.activeTriggers.find(h=>dr(h.urlPattern));if(!l)return;let v=l.triggerType||"TimeOnPage";if(v==="TimeOnPage"){let h=(l.delaySeconds??5)*1e3,x=setTimeout(()=>{ze(l),X(true),e.onTriggerActivated?.(l);},h);return ()=>clearTimeout(x)}if(v==="ScrollPercentage"){let h=l.scrollPercentage??50,x=()=>{if(typeof window>"u")return;let M=document.documentElement.scrollHeight-window.innerHeight;if(M<=0)return;window.scrollY/M*100>=h&&(ze(l),X(true),e.onTriggerActivated?.(l),window.removeEventListener("scroll",x));};return window.addEventListener("scroll",x,{passive:true}),()=>window.removeEventListener("scroll",x)}if(v==="ExitIntent"){let h=x=>{!x.relatedTarget&&x.clientY<=10&&(ze(l),X(true),e.onTriggerActivated?.(l),document.removeEventListener("mouseout",h));};return document.addEventListener("mouseout",h),()=>document.removeEventListener("mouseout",h)}},[e.proactiveMessage,e.proactiveDelay,e.enableTriggers,J?.activeTriggers,u,a]);let R=mo({botId:a,publishableKey:s,baseUrl:c,persistSession:e.persistSession??false,visitorData:e.visitorData,tags:e.tags,enableSoundAlert:e.enableSoundAlert,enableTabTitleNotification:e.enableTabTitleNotification,enableCoBrowse:e.enableCoBrowse,onSendMessage:e.onSendMessage,onResponse:l=>{e.onResponse?.(l),e.onMessage?.({role:"assistant",content:l.reply});},onFinish:e.onFinish,onError:e.onError,onEscalationRequest:e.onEscalationRequest,onOperatorJoined:e.onOperatorJoined,onTicketResolved:e.onTicketResolved,onCsatSubmit:e.onCsatSubmit,onActionProposed:e.onActionProposed,onActionExecuted:e.onActionExecuted,onActionCancelled:e.onActionCancelled,onCoBrowseStart:e.onCoBrowseStart,onCoBrowseEnd:e.onCoBrowseEnd}),T=useRef(new Set),j=useRef(false),[F,G]=useState(0),[ee,ce]=useState(void 0),[He,ke]=useState(null),pe=useRef(""),ye=e.unreadCount!==void 0?e.unreadCount:F;useEffect(()=>{!j.current&&R.messages.length>0&&(j.current=true,R.messages.forEach(l=>{l.isStreaming||T.current.add(l.id);}));},[R.messages]),useEffect(()=>{u&&(R.messages.forEach(l=>{l.role==="assistant"&&!l.isStreaming&&T.current.add(l.id);}),F!==0&&(G(0),e.onUnreadCountChange?.(0)),ke(null));},[u,R.messages,F,e.onUnreadCountChange]),useEffect(()=>{if(u)return;let l=R.messages.filter(h=>h.role==="assistant"&&!T.current.has(h.id)&&(h.content.trim().length>0||!h.isStreaming)),v=l.length;if(v!==F&&(G(v),e.onUnreadCountChange?.(v),v>F&&v>0)){if(e.enableSoundAlert!==false)try{if(typeof window<"u"){let x=window.AudioContext||window.webkitAudioContext;if(x){let M=new x,B=M.createOscillator(),z=M.createGain();B.type="sine",B.frequency.setValueAtTime(587.33,M.currentTime),B.frequency.exponentialRampToValueAtTime(880,M.currentTime+.12),z.gain.setValueAtTime(.08,M.currentTime),z.gain.exponentialRampToValueAtTime(.001,M.currentTime+.35),B.connect(z),z.connect(M.destination),B.start(),B.stop(M.currentTime+.35);}}}catch{}let h=l[l.length-1];if(h&&h.content){let x=h.content.length>90?h.content.slice(0,87)+"...":h.content;ke(x);}}},[R.messages,u,F,e.onUnreadCountChange]),useEffect(()=>{if(typeof document>"u"||e.enableTabTitleNotification===false)return;pe.current||(pe.current=document.title),ye>0&&!u?document.title=`(${ye}) ${pe.current}`:pe.current&&(document.title=pe.current);let l=()=>{u&&pe.current&&(document.title=pe.current);};return window.addEventListener("focus",l),()=>{window.removeEventListener("focus",l),pe.current&&(document.title=pe.current);}},[ye,u,e.enableTabTitleNotification]);let Ee=useCallback(()=>{let l=R.messages.findIndex(v=>v.role==="assistant"&&!T.current.has(v.id)&&(v.content.trim().length>0||!v.isStreaming));if(l>=0)ce(l);else {let v=e.unreadCount!==void 0?e.unreadCount:F;v>0&&R.messages.length>0?ce(Math.max(0,R.messages.length-v)):ce(void 0);}R.messages.forEach(v=>{v.role==="assistant"&&T.current.add(v.id);}),S(true),X(false),ke(null),G(0),typeof document<"u"&&pe.current&&(document.title=pe.current),e.onUnreadCountChange?.(0),e.onOpen?.();},[e.onOpen,e.onUnreadCountChange,e.unreadCount,F,R.messages]),We=useCallback(()=>{S(false),ce(void 0),e.onClose?.();},[e.onClose]),Ue=useCallback(()=>{S(l=>{let v=!l;if(v){let h=R.messages.findIndex(x=>x.role==="assistant"&&!T.current.has(x.id)&&(x.content.trim().length>0||!x.isStreaming));if(h>=0)ce(h);else {let x=e.unreadCount!==void 0?e.unreadCount:F;x>0&&R.messages.length>0?ce(Math.max(0,R.messages.length-x)):ce(void 0);}R.messages.forEach(x=>{x.role==="assistant"&&T.current.add(x.id);}),X(false),ke(null),G(0),typeof document<"u"&&pe.current&&(document.title=pe.current),e.onUnreadCountChange?.(0),e.onOpen?.();}else ce(void 0),e.onClose?.();return v});},[e.onOpen,e.onClose,e.onUnreadCountChange,e.unreadCount,F,R.messages]),wt=useCallback(()=>{L(l=>{let v=!l;return e.onExpandChange?.(v),v});},[e.onExpandChange]),At=useCallback(l=>{l.stopPropagation(),X(false);try{typeof window<"u"&&window.sessionStorage&&sessionStorage.setItem(`botzki_proactive_dismissed_${a||"default"}`,"true");}catch{}},[a]);useEffect(()=>{if(e.enableHotkey===false||typeof window>"u")return;let l=v=>{(v.metaKey||v.ctrlKey)&&v.key.toLowerCase()==="k"?(v.preventDefault(),Ue()):v.key==="Escape"&&u&&We();};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e.enableHotkey,u,Ue,We]),useImperativeHandle(i,()=>({open:Ee,close:We,toggle:Ue,isOpen:()=>u,show:()=>C(true),hide:()=>{C(false),We();},sendMessage:async(l,v)=>{Ee(),await R.sendMessage(l,v?{imageBase64:v}:void 0);},clearMessages:()=>{R.clearMessages(),T.current.clear(),G(0),ce(void 0),ke(null);},newChat:()=>{R.clearMessages(),T.current.clear(),G(0),ce(void 0),ke(null),R.setSessionId(`session_${Date.now()}_${Math.random().toString(36).substring(2,9)}`),e.onNewChat?.();},expand:()=>{L(true),e.onExpandChange?.(true);},collapse:()=>{L(false),e.onExpandChange?.(false);},isExpanded:()=>y,openHistory:()=>{Ee(),Q(true);},closeHistory:()=>{Q(false);},exportChat:(l="markdown")=>{let v="";return l==="json"?v=JSON.stringify(R.messages,null,2):(v=`# Conversation
|
|
142
|
+
`}),Et&&jsxs("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:To,zIndex:20,display:"flex",flexDirection:"column",overflow:"hidden",animation:"botzki-fade-in 0.2s ease-out"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 18px",backgroundColor:Xo,borderBottom:`1px solid ${Te}`},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("circle",{cx:"12",cy:"12",r:"10"}),jsx("polyline",{points:"12 6 12 12 16 14"})]}),jsx("span",{style:{fontWeight:600,fontSize:"14px"},children:"Chat History"}),jsx("span",{style:{fontSize:"11px",color:ie,padding:"2px 6px",borderRadius:"10px",backgroundColor:x?"#334155":"#e2e8f0"},children:ht.length})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[jsx("button",{type:"button",onClick:fo,style:{background:I,color:"#ffffff",border:"none",borderRadius:"6px",padding:"5px 10px",fontSize:"12px",fontWeight:600,cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},children:"+ New Chat"}),jsx("button",{type:"button",onClick:()=>dt(false),title:"Close History",style:{background:"transparent",border:"none",color:ie,cursor:"pointer",fontSize:"16px",padding:"4px 8px",borderRadius:"6px"},children:"\u2715"})]})]}),jsx("div",{className:"botzki-chat-scroll",style:{flex:1,overflowY:"auto",padding:"12px 14px",display:"flex",flexDirection:"column",gap:"8px"},children:ht.length===0?jsx("div",{style:{textAlign:"center",color:ie,fontSize:"13px",marginTop:"40px"},children:"No saved chat sessions yet."}):ht.map(r=>{let M=r.id===w.sessionId;return jsxs("div",{onClick:()=>gi(r),style:{padding:"10px 12px",borderRadius:"8px",backgroundColor:M?x?"rgba(14, 165, 233, 0.15)":"rgba(14, 165, 233, 0.1)":x?"#1e293b":"#f8fafc",border:`1px solid ${M?I:Te}`,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"border-color 0.15s ease"},children:[jsxs("div",{style:{flex:1,overflow:"hidden",marginRight:"8px"},children:[jsx("div",{style:{fontWeight:600,fontSize:"13px",color:it,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r.title||"Conversation"}),jsxs("div",{style:{fontSize:"11px",color:ie,marginTop:"2px"},children:[new Date(r.updatedAt).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})," ","\xB7 ",r.messages.length," messages"]})]}),jsx("button",{type:"button",onClick:E=>hi(r.id,E),title:"Delete session",style:{background:"transparent",border:"none",color:ie,cursor:"pointer",padding:"4px 6px",borderRadius:"4px",fontSize:"13px"},children:"\u{1F5D1}"})]},r.id)})}),jsxs("div",{style:{padding:"10px 16px",borderTop:`1px solid ${Te}`,backgroundColor:Xo,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsx("button",{type:"button",onClick:()=>Mn("markdown"),disabled:w.messages.length===0,style:{background:"transparent",border:`1px solid ${Te}`,color:it,borderRadius:"6px",padding:"5px 10px",fontSize:"12px",cursor:w.messages.length===0?"not-allowed":"pointer",opacity:w.messages.length===0?.5:1,display:"flex",alignItems:"center",gap:"4px"},children:"\u{1F4E5} Export Chat (.md)"}),ht.length>0&&jsx("button",{type:"button",onClick:mi,style:{background:"transparent",border:"none",color:"#ef4444",fontSize:"12px",cursor:"pointer",padding:"5px 8px"},children:"Clear All"})]})]}),be?be({title:Jo,subtitle:ne,isDark:x,primaryColor:I,isOpen:true,isExpanded:Ee,isHistoryOpen:Et,botAvatar:n,onClose:Z,onClear:qe,onNewChat:fo,toggleHistory:()=>dt(r=>!r),toggleExpand:We}):Qe||jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 18px",backgroundColor:Xo,borderBottom:`1px solid ${Te}`,...f},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[n?typeof n=="string"?jsx("img",{src:n,alt:Jo,style:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0}}):n:jsx("div",{style:{width:"36px",height:"36px",borderRadius:"50%",backgroundColor:se.background??(x?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.05)"),display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexShrink:0},children:jsx(Bt,{size:se.size??28,shape:se.shape??"pebble",followCursor:se.followCursor,colors:se.colors??["#66a6ff","#0059d4"],faceColor:se.faceColor??"#ffffff",eyeColor:se.eyeColor,mouthColor:se.mouthColor,motion:se.motion,emotion:se.emotion,outlineColor:se.outlineColor,outlineWidth:se.outlineWidth,...se.props})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontWeight:600,fontSize:"14px",lineHeight:1.2,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:Jo}),jsxs("div",{style:{fontSize:"12px",color:ie,display:"flex",alignItems:"center",gap:"5px",marginTop:"2px"},children:[jsx("span",{style:{width:"7px",height:"7px",borderRadius:"50%",backgroundColor:"#22c55e",display:"inline-block"}}),ne]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[Se&&jsxs("button",{onClick:fo,title:"Start New Chat",type:"button",style:{background:"transparent",border:"none",color:ie,cursor:"pointer",fontSize:"12px",padding:"4px 7px",borderRadius:"6px",display:"flex",alignItems:"center",gap:"3px"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),jsx("span",{children:"New"})]}),pe&&jsxs("button",{onClick:()=>dt(r=>!r),title:Et?"Close History":"Chat History",type:"button",style:{background:Et?x?"#334155":"#e2e8f0":"transparent",border:"none",color:ie,cursor:"pointer",fontSize:"12px",padding:"4px 7px",borderRadius:"6px",display:"flex",alignItems:"center",gap:"3px"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("circle",{cx:"12",cy:"12",r:"10"}),jsx("polyline",{points:"12 6 12 12 16 14"})]}),ht.length>0&&jsx("span",{style:{fontSize:"10px",opacity:.85},children:ht.length})]}),xe&&We&&jsx("button",{onClick:We,title:Ee?"Collapse Widget":"Expand Widget",type:"button",style:{background:"transparent",border:"none",color:ie,cursor:"pointer",fontSize:"13px",padding:"4px 6px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center"},children:Ee?jsxs("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("polyline",{points:"4 14 10 14 10 20"}),jsx("polyline",{points:"20 10 14 10 14 4"}),jsx("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}):jsxs("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("polyline",{points:"15 3 21 3 21 9"}),jsx("polyline",{points:"9 21 3 21 3 15"}),jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}),he.length>0&&F&&jsx("button",{onClick:()=>Mn("markdown"),title:"Download Chat Transcript",type:"button",style:{background:"transparent",border:"none",color:ie,cursor:"pointer",fontSize:"12px",padding:"4px 6px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center"},children:jsxs("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),jsx("polyline",{points:"7 10 12 15 17 10"}),jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}),he.length>0&&He&&jsx("button",{onClick:qe,title:"Clear Chat",type:"button",style:{background:"transparent",border:"none",color:ie,cursor:"pointer",fontSize:"12px",padding:"4px 7px",borderRadius:"6px"},children:"Clear"}),(()=>{let r=p!==false&&Ge?.liveChatEnabled!==false&&Ge?.humanHandoffEnabled!==false,M=Ge?.liveChatIsOnline===false&&Ge?.liveChatOutOfHoursBehavior==="aiOnly",E=r&&!M&&!w.isHumanHandoffActive&&!w.isWaitingForHuman,K=Ge?.handoffButtonText||"Talk to Support";return E?jsxs("button",{onClick:async()=>{if(Ge?.liveChatRequireEmail){ct(true);return}try{await w.requestHumanHandoff?.("User requested from widget header");}catch(Y){Y?.code==="EMAIL_REQUIRED"&&ct(true);}},title:K,type:"button",style:{background:x?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.05)",border:`1px solid ${x?"rgba(255, 255, 255, 0.12)":"rgba(0, 0, 0, 0.08)"}`,color:x?"#e2e8f0":"#334155",cursor:"pointer",fontSize:"11px",fontWeight:600,padding:"4px 9px",borderRadius:"9999px",display:"flex",alignItems:"center",gap:"4px",transition:"all 0.15s ease"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M3 18v-6a9 9 0 0 1 18 0v6"}),jsx("path",{d:"M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"})]}),jsx("span",{children:K})]}):null})(),le&&Z&&jsx("button",{onClick:Z,title:"Close Chat",type:"button",style:{background:"transparent",border:"none",color:ie,cursor:"pointer",fontSize:"16px",padding:"4px 8px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center"},children:"\u2715"})]})]}),w.coBrowse?.isRequested&&!w.coBrowse?.isActive&&jsxs("div",{style:{padding:"12px 14px",backgroundColor:x?"rgba(30, 41, 59, 0.95)":"rgba(240, 253, 250, 0.95)",borderBottom:`1px solid ${x?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)"}`,display:"flex",flexDirection:"column",gap:"10px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.05)"},children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"10px"},children:[jsx("div",{style:{width:"32px",height:"32px",borderRadius:"8px",backgroundColor:x?"rgba(16, 185, 129, 0.2)":"#d1fae5",color:"#10b981",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,fontSize:"16px"},children:"\u{1F6E1}\uFE0F"}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:{fontSize:"12.5px",fontWeight:600,color:it},children:"Live Screen Assist Request"}),jsxs("div",{style:{fontSize:"11px",color:ie,marginTop:"2px",lineHeight:"1.4",wordBreak:"break-word"},children:[jsx("strong",{children:w.coBrowse.operatorName||"Support Specialist"})," requested permission to view your screen to guide you."]}),jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginTop:"4px",fontSize:"10px",color:x?"#34d399":"#059669",flexWrap:"wrap"},children:jsx("span",{children:"\u{1F512} Privacy Shield Active \u2022 Form inputs & passwords masked"})})]})]}),jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end",flexWrap:"wrap"},children:[jsx("button",{type:"button",onClick:()=>w.coBrowse?.decline("Visitor declined"),style:{padding:"6px 14px",borderRadius:"8px",border:`1px solid ${Te}`,background:"transparent",color:ie,fontSize:"11.5px",fontWeight:500,cursor:"pointer",transition:"all 0.15s ease"},children:"Decline"}),jsx("button",{type:"button",onClick:()=>w.coBrowse?.accept(),style:{padding:"6px 16px",borderRadius:"8px",border:"none",background:"linear-gradient(135deg, #10b981 0%, #059669 100%)",color:"#ffffff",fontSize:"11.5px",fontWeight:600,cursor:"pointer",boxShadow:"0 2px 6px rgba(16, 185, 129, 0.3)",transition:"all 0.15s ease"},children:"Allow Live Assist"})]})]}),It&&jsxs("form",{onSubmit:async r=>{r.preventDefault();let M=Co.trim();if(!M||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(M)){Ot("Please enter a valid email address.");return}so(true),Ot(null);try{await w.requestHumanHandoff?.("User requested live support via email gate",No.trim()||void 0,M),ct(!1);}catch(E){Ot(E?.message||"Failed to join live support queue.");}finally{so(false);}},style:{padding:"12px 14px",backgroundColor:x?"#1e293b":"#f8fafc",borderBottom:`1px solid ${Te}`,display:"flex",flexDirection:"column",gap:"9px",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.04)"},children:[jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[jsxs("div",{children:[jsx("div",{style:{fontSize:"12px",fontWeight:600,color:it},children:"Connect with Live Specialist"}),jsx("div",{style:{fontSize:"11px",color:ie,marginTop:"1px"},children:"Enter your details to join the live support queue."})]}),jsx("button",{type:"button",onClick:()=>{ct(false),Ot(null);},style:{background:"transparent",border:"none",color:ie,cursor:"pointer",fontSize:"14px",padding:"2px 6px",borderRadius:"4px"},children:"\u2715"})]}),qt&&jsx("div",{style:{fontSize:"11px",color:"#ef4444",fontWeight:500},children:qt}),jsxs("div",{style:{display:"flex",gap:"8px"},children:[jsx("input",{type:"text",placeholder:"Name (optional)",value:No,onChange:r=>ao(r.target.value),disabled:gt,style:{flex:1,fontSize:"12px",padding:"6px 9px",borderRadius:"6px",border:`1px solid ${Te}`,backgroundColor:x?"#0f172a":"#ffffff",color:it,outline:"none"}}),jsx("input",{type:"email",placeholder:"Email address *",required:true,value:Co,onChange:r=>Vt(r.target.value),disabled:gt,style:{flex:1.2,fontSize:"12px",padding:"6px 9px",borderRadius:"6px",border:`1px solid ${Te}`,backgroundColor:x?"#0f172a":"#ffffff",color:it,outline:"none"}})]}),jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[jsx("button",{type:"button",onClick:()=>{ct(false),Ot(null);},disabled:gt,style:{background:"transparent",border:"none",fontSize:"11px",color:ie,cursor:"pointer",padding:"4px 8px"},children:"Cancel"}),jsx("button",{type:"submit",disabled:gt,style:{backgroundColor:I,color:"#ffffff",border:"none",borderRadius:"6px",padding:"5px 12px",fontSize:"11px",fontWeight:600,cursor:gt?"wait":"pointer",opacity:gt?.7:1,display:"inline-flex",alignItems:"center",gap:"5px"},children:gt?"Connecting...":"Join Queue"})]})]}),w.isWaitingForHuman&&jsxs("div",{style:{padding:"9px 14px",backgroundColor:x?"rgba(245, 158, 11, 0.15)":"#fef3c7",borderBottom:"1px solid rgba(245, 158, 11, 0.3)",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"12px",color:x?"#fbbf24":"#b45309"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx("span",{style:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:"#f59e0b",display:"inline-block"}}),jsx("span",{children:"Connecting you with support team..."})]}),jsx("button",{onClick:()=>w.cancelHumanHandoff?.(),type:"button",style:{background:"transparent",border:"none",fontSize:"11px",fontWeight:600,color:"inherit",cursor:"pointer",textDecoration:"underline"},children:"Cancel"})]}),w.isHumanHandoffActive&&jsxs("div",{style:{padding:"8px 14px",backgroundColor:x?"rgba(14, 165, 233, 0.15)":"#e0f2fe",borderBottom:"1px solid rgba(14, 165, 233, 0.3)",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"12px",color:x?"#38bdf8":"#0284c7",gap:"8px",minHeight:"36px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0,flex:1,overflow:"hidden"},children:[jsx("span",{style:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:"#0284c7",display:"inline-block",flexShrink:0}}),jsxs("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},title:w.assignedOperator?.name||"Support Specialist",children:[jsx("strong",{children:"Live Agent:"})," ",w.assignedOperator?.name||"Support Specialist"]})]}),jsx("button",{onClick:()=>w.cancelHumanHandoff?.(),type:"button",style:{background:"transparent",border:"none",fontSize:"11px",fontWeight:600,color:"inherit",cursor:"pointer",textDecoration:"underline",flexShrink:0,padding:"2px 4px"},children:"Back to Bot"})]}),jsxs("div",{ref:lt,onScroll:pi,className:"botzki-chat-scroll",style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"14px",scrollbarWidth:"thin",scrollbarColor:x?"rgba(255, 255, 255, 0.2) transparent":"rgba(0, 0, 0, 0.2) transparent",...h},children:[he.length===0?Ve?Ve():jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"14px",animation:"botzki-greeting-pop 0.45s cubic-bezier(0.16, 1, 0.3, 1) both"},children:[me&&jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"10px"},children:[a&&jsx("div",{style:{width:"32px",height:"32px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexShrink:0,marginTop:"2px",animation:"botzki-avatar-entrance 0.5s cubic-bezier(0.16, 1, 0.3, 1) both"},children:n?typeof n=="string"?jsx("img",{src:n,alt:"Bot",style:{width:"32px",height:"32px",borderRadius:"50%",objectFit:"cover"}}):n:jsx(Bt,{size:28,shape:se.shape??"pebble",colors:se.colors??["#66a6ff","#0059d4"],faceColor:se.faceColor??"#ffffff",eyeColor:se.eyeColor,mouthColor:se.mouthColor,motion:se.motion??"jump",emotion:se.emotion??"laugh",followCursor:se.followCursor})}),jsxs("div",{style:{maxWidth:"84%",padding:"12px 16px",borderRadius:"16px",borderTopLeftRadius:a?"4px":"16px",backgroundColor:Qo,color:In,fontSize:"14px",lineHeight:1.5,boxShadow:x?"0 4px 14px rgba(0, 0, 0, 0.25)":"0 4px 14px rgba(0, 0, 0, 0.05)",border:`1px solid ${Te}`},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginBottom:"4px"},children:[jsx("span",{style:{display:"inline-block",transformOrigin:"70% 70%",animation:"botzki-wave 1.6s ease-in-out infinite",fontSize:"16px"},children:"\u{1F44B}"}),jsx("span",{style:{fontWeight:600,fontSize:"11px",color:I,textTransform:"uppercase",letterSpacing:"0.5px"},children:"Welcome"})]}),jsx(Wo,{content:me,isUser:false,primaryColor:I,isDark:x})]})]}),An.length>0&&jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",marginTop:"4px",marginLeft:a?"42px":0},children:[jsx("span",{style:{fontSize:"11px",color:ie,fontWeight:600,letterSpacing:"0.5px"},children:"SUGGESTED QUESTIONS"}),jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px"},children:An.map((r,M)=>jsx("button",{className:"botzki-starter-btn",onClick:()=>Pe(r),style:{backgroundColor:x?"#1e293b":"#f1f5f9",color:it,border:`1px solid ${Te}`,padding:"8px 14px",borderRadius:"20px",fontSize:"12px",fontWeight:500,cursor:"pointer",textAlign:"left",animation:`botzki-starter-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) ${.12+M*.08}s both`},children:r},M))})]})]}):null,he.map((r,M)=>{let E=r.role==="user",ge=Wt!==void 0&&Wt>=0&&M===Wt?jsxs("div",{ref:Go,style:{display:"flex",alignItems:"center",gap:"12px",margin:"18px 0 14px",width:"100%",padding:"0 4px"},children:[jsx("div",{style:{flex:1,height:"1px",background:x?"rgba(239, 68, 68, 0.45)":"rgba(239, 68, 68, 0.35)"}}),jsxs("span",{style:{fontSize:"11px",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.5px",color:"#ef4444",background:x?"rgba(239, 68, 68, 0.15)":"#fee2e2",padding:"3px 10px",borderRadius:"9999px",border:`1px solid ${x?"rgba(239, 68, 68, 0.4)":"rgba(239, 68, 68, 0.3)"}`,display:"inline-flex",alignItems:"center",gap:"6px",lineHeight:1.2,boxShadow:"0 1px 3px rgba(0, 0, 0, 0.08)"},children:[jsx("span",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#ef4444"}}),"New Messages"]}),jsx("div",{style:{flex:1,height:"1px",background:x?"rgba(239, 68, 68, 0.45)":"rgba(239, 68, 68, 0.35)"}})]},"botzki-unread-messages-separator"):null;return r.role==="system"?jsxs(hn.Fragment,{children:[ge,jsx("div",{style:{display:"flex",justifyContent:"center",margin:"8px 0",width:"100%"},children:jsx("div",{style:{fontSize:"11.5px",color:x?"#94a3b8":"#64748b",backgroundColor:x?"rgba(255, 255, 255, 0.06)":"rgba(0, 0, 0, 0.04)",padding:"6px 14px",borderRadius:"10px",border:`1px solid ${x?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.06)"}`,maxWidth:"88%",textAlign:"center",lineHeight:1.45,wordBreak:"break-word",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.04)"},children:r.content})})]},r.id):Ke?jsxs(hn.Fragment,{children:[ge,Ke({message:r,index:M,isUser:E,isDark:x,primaryColor:I,onCopy:()=>Bn(r.id,r.content),onSpeak:()=>zn(r.id,r.content),onFeedback:Y=>Ko(r.id,Y)})]},r.id):jsxs(hn.Fragment,{children:[ge,jsxs("div",{style:{display:"flex",flexDirection:E?"row-reverse":"row",alignItems:"flex-start",gap:"8px",width:"100%"},children:[a&&jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexShrink:0,marginTop:"2px",backgroundColor:E?x?"#334155":"#e2e8f0":"transparent"},children:E?t?typeof t=="string"?jsx("img",{src:t,alt:"User",style:{width:"28px",height:"28px",borderRadius:"50%",objectFit:"cover"}}):t:jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:x?"#cbd5e1":"#475569",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),jsx("circle",{cx:"12",cy:"7",r:"4"})]}):n?typeof n=="string"?jsx("img",{src:n,alt:"Bot",style:{width:"28px",height:"28px",borderRadius:"50%",objectFit:"cover"}}):n:jsx(Bt,{size:24,shape:se.shape??"pebble",colors:se.colors??["#66a6ff","#0059d4"],faceColor:se.faceColor??"#ffffff",eyeColor:se.eyeColor,mouthColor:se.mouthColor,followCursor:se.followCursor})}),jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:E?"flex-end":"flex-start",maxWidth:"80%"},children:[jsxs("div",{style:{padding:"10px 14px",borderRadius:"14px",backgroundColor:E?xi:Qo,color:E?wi:In,fontSize:"14px",lineHeight:1.5,wordBreak:"break-word"},children:[r.senderType==="operator"&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginBottom:"6px",maxWidth:"100%",flexWrap:"wrap"},children:[jsx("span",{style:{fontSize:"11.5px",fontWeight:600,color:x?"#38bdf8":"#0284c7",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:r.senderName||w.assignedOperator?.name||"Support Specialist",children:r.senderName||w.assignedOperator?.name||"Support Specialist"}),jsx("span",{style:{fontSize:"9px",fontWeight:700,letterSpacing:"0.5px",textTransform:"uppercase",padding:"2px 6px",borderRadius:"4px",backgroundColor:x?"rgba(14, 165, 233, 0.2)":"#e0f2fe",color:x?"#38bdf8":"#0284c7",flexShrink:0},children:"Operator"})]}),(r.imageUrl||r.imageBase64)&&jsx("img",{src:r.imageUrl||r.imageBase64,alt:"Attachment",style:{maxWidth:"100%",maxHeight:"180px",borderRadius:"8px",marginBottom:"8px",display:"block",cursor:"pointer"},onClick:()=>{typeof window<"u"&&window.open(r.imageUrl||r.imageBase64,"_blank");}}),r.audioUrl&&jsx("div",{style:{marginBottom:r.content||r.isTranscribing?"6px":0},children:jsx(fn,{audioUrl:r.audioUrl,duration:r.audioDuration,isUser:E,primaryColor:I,isDark:x})}),r.fileUrl&&jsxs("div",{style:{margin:"8px 0",padding:"10px 12px",borderRadius:"12px",backgroundColor:x?"rgba(255, 255, 255, 0.08)":"#f8fafc",border:`1px solid ${x?"rgba(255, 255, 255, 0.15)":"#e2e8f0"}`,display:"flex",flexDirection:"column",gap:"8px",minWidth:"190px",maxWidth:"260px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[jsx("div",{style:{width:"36px",height:"36px",borderRadius:"8px",backgroundColor:x?"rgba(255, 255, 255, 0.12)":"#e0f2fe",color:x?"#ffffff":I,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:oi(r.fileName)}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"12px",fontWeight:600,color:x?"#f1f5f9":"#0f172a",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:r.fileName||"File",children:r.fileName||"Attachment"}),r.fileSize&&jsx("div",{style:{fontSize:"10.5px",color:x?"#94a3b8":"#64748b",marginTop:"1px"},children:ti(r.fileSize)})]})]}),jsxs("a",{href:`${r.fileUrl}${r.fileUrl.includes("?")?"&":"?"}download=true&name=${encodeURIComponent(r.fileName||"download")}`,target:"_blank",rel:"noreferrer",download:r.fileName||true,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",backgroundColor:x?"#38bdf8":"#0f172a",color:x?"#0f172a":"#ffffff",fontSize:"11px",fontWeight:600,textDecoration:"none",cursor:"pointer",transition:"opacity 0.15s ease"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),jsx("polyline",{points:"7 10 12 15 17 10"}),jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),jsx("span",{children:"Download file"})]})]}),r.isTranscribing&&jsxs("div",{style:{fontSize:"11px",opacity:.85,display:"flex",alignItems:"center",gap:"6px",paddingTop:"2px"},children:[jsx("span",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:E?"#ffffff":I,animation:"botzki-pulse 1s infinite"}}),jsx("span",{children:"Transcribing audio..."})]}),E?r.content?jsxs("div",{style:{whiteSpace:"pre-wrap"},children:[r.audioUrl&&jsx("span",{style:{display:"block",fontSize:"11px",opacity:.75,marginBottom:"2px",fontStyle:"italic"},children:"Transcription:"}),r.content]}):null:r.content?jsx(Wo,{content:r.content,isUser:false,primaryColor:I,isDark:x}):null,C&&r.citations&&r.citations.length>0&&jsxs("div",{style:{marginTop:"8px",paddingTop:"6px",borderTop:`1px solid ${E?"rgba(255,255,255,0.2)":Te}`,fontSize:"11px",display:"flex",flexWrap:"wrap",gap:"4px"},children:[jsx("span",{style:{opacity:.8},children:"Sources:"}),r.citations.map((Y,De)=>jsxs("span",{style:{backgroundColor:E?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.06)",padding:"2px 6px",borderRadius:"4px",fontWeight:500},children:[Y.source," ",Y.page_number?`p.${Y.page_number}`:""]},De))]}),!E&&r.escalation&&jsxs("div",{style:{marginTop:"10px",padding:"10px 12px",borderRadius:"10px",backgroundColor:x?"rgba(14, 165, 233, 0.12)":"rgba(14, 165, 233, 0.08)",border:"1px solid rgba(14, 165, 233, 0.25)",display:"flex",flexDirection:"column",gap:"6px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontWeight:600,fontSize:"12px",color:x?"#38bdf8":"#0284c7"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("path",{d:"M3 18v-6a9 9 0 0 1 18 0v6"}),jsx("path",{d:"M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"})]}),jsx("span",{children:r.escalation.title||"Live Support Specialist"})]}),r.escalation.description&&jsx("p",{style:{margin:0,fontSize:"11px",opacity:.85,lineHeight:1.4},children:r.escalation.description}),jsxs("button",{type:"button",onClick:async()=>{if(Ge?.liveChatRequireEmail){ct(true);return}try{await w.requestHumanHandoff?.(r.escalation?.title||"Visitor accepted AI escalation offer");}catch(Y){Y?.code==="EMAIL_REQUIRED"&&ct(true);}},style:{marginTop:"6px",padding:"8px 14px",backgroundColor:I,color:"#ffffff",border:"none",borderRadius:"8px",fontSize:"12px",fontWeight:600,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:"8px",width:"100%",boxSizing:"border-box",transition:"opacity 0.15s ease"},onMouseEnter:Y=>Y.currentTarget.style.opacity="0.9",onMouseLeave:Y=>Y.currentTarget.style.opacity="1",children:[jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("path",{d:"M3 18v-6a9 9 0 0 1 18 0v6"}),jsx("path",{d:"M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"})]}),jsx("span",{children:r.escalation.buttonText||"Connect with Support Agent"})]})]}),!E&&R!==false&&r.proposedAction&&jsxs("div",{style:{marginTop:"10px",padding:"12px 14px",borderRadius:"12px",backgroundColor:x?"rgba(99, 102, 241, 0.12)":"rgba(99, 102, 241, 0.07)",border:x?"1px solid rgba(99, 102, 241, 0.35)":"1px solid rgba(99, 102, 241, 0.25)",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.04)",display:"flex",flexDirection:"column",gap:"8px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:x?"1px solid rgba(99, 102, 241, 0.2)":"1px solid rgba(99, 102, 241, 0.15)",paddingBottom:"6px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontWeight:700,fontSize:"12px",color:x?"#818cf8":"#4f46e5"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),jsx("span",{children:"Autonomous Action Guardrail"})]}),jsx("span",{style:{fontSize:"10px",fontFamily:"monospace",textTransform:"uppercase",padding:"2px 6px",borderRadius:"4px",backgroundColor:x?"rgba(99, 102, 241, 0.2)":"rgba(99, 102, 241, 0.12)",color:x?"#a5b4fc":"#4338ca",fontWeight:600},children:r.proposedAction.status==="completed"?"\u2713 Executed":r.proposedAction.status==="executing"?"Executing...":r.proposedAction.status==="cancelled"?"Cancelled":r.proposedAction.status==="failed"?"Failed":"2-Step Confirmation"})]}),jsxs("div",{children:[jsx("div",{style:{fontWeight:600,fontSize:"13px",color:x?"#f8fafc":"#0f172a"},children:r.proposedAction.displayName||r.proposedAction.actionName}),r.proposedAction.description&&jsx("div",{style:{fontSize:"11px",color:x?"#94a3b8":"#64748b",marginTop:"2px"},children:r.proposedAction.description})]}),jsx("div",{style:{fontSize:"12px",lineHeight:1.45,padding:"8px 10px",borderRadius:"8px",backgroundColor:x?"rgba(0, 0, 0, 0.25)":"rgba(255, 255, 255, 0.7)",border:x?"1px solid rgba(255, 255, 255, 0.08)":"1px solid rgba(0, 0, 0, 0.06)",color:x?"#e2e8f0":"#1e293b"},children:r.proposedAction.confirmationPrompt||"Do you confirm executing this autonomous action?"}),r.proposedAction.parameters&&Object.keys(r.proposedAction.parameters).length>0&&jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:Object.entries(r.proposedAction.parameters).map(([Y,De])=>jsxs("span",{style:{fontSize:"10px",fontFamily:"monospace",padding:"2px 6px",borderRadius:"4px",backgroundColor:x?"rgba(255, 255, 255, 0.06)":"rgba(0, 0, 0, 0.05)",color:x?"#cbd5e1":"#475569"},children:[jsxs("strong",{children:[Y,":"]})," ",String(De)]},Y))}),r.proposedAction.status==="completed"?jsxs("div",{style:{padding:"8px 10px",borderRadius:"8px",backgroundColor:x?"rgba(16, 185, 129, 0.15)":"rgba(16, 185, 129, 0.1)",border:"1px solid rgba(16, 185, 129, 0.3)",color:x?"#34d399":"#059669",fontSize:"12px",fontWeight:600,display:"flex",alignItems:"center",gap:"6px"},children:[jsx("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),jsx("span",{children:r.proposedAction.successMessage||"Action executed successfully with zero operator intervention."})]}):r.proposedAction.status==="executing"?jsx("div",{style:{padding:"8px 10px",borderRadius:"8px",backgroundColor:x?"rgba(99, 102, 241, 0.15)":"rgba(99, 102, 241, 0.1)",color:x?"#a5b4fc":"#4f46e5",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px"},children:jsx("span",{children:"\u23F3 Executing action safely via signed token..."})}):r.proposedAction.status==="cancelled"?jsx("div",{style:{padding:"6px 10px",borderRadius:"6px",backgroundColor:x?"rgba(255, 255, 255, 0.05)":"rgba(0, 0, 0, 0.04)",color:x?"#94a3b8":"#64748b",fontSize:"11px",fontStyle:"italic"},children:"Action cancelled by visitor. No changes were made."}):r.proposedAction.status==="failed"?jsxs("div",{style:{padding:"8px 10px",borderRadius:"8px",backgroundColor:x?"rgba(239, 68, 68, 0.15)":"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:x?"#f87171":"#dc2626",fontSize:"12px"},children:["Execution failed: ",r.proposedAction.error||"Unknown server error."]}):jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"4px"},children:[jsxs("button",{type:"button",onClick:async()=>{(await w.executeProposedAction?.(r.id,r.proposedAction.token,r.proposedAction.parameters))?.success&&Mt.triggerCelebration();},style:{flex:1,padding:"7px 12px",backgroundColor:"#4f46e5",color:"#ffffff",border:"none",borderRadius:"8px",fontSize:"12px",fontWeight:600,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",boxShadow:"0 2px 4px rgba(79, 70, 229, 0.25)",transition:"opacity 0.15s ease"},onMouseEnter:Y=>Y.currentTarget.style.opacity="0.9",onMouseLeave:Y=>Y.currentTarget.style.opacity="1",children:[jsx("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),jsx("span",{children:"Confirm & Execute"})]}),jsx("button",{type:"button",onClick:()=>{w.cancelProposedAction?.(r.id,"Cancelled by user");},style:{padding:"7px 12px",backgroundColor:x?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.05)",color:x?"#cbd5e1":"#475569",border:`1px solid ${x?"rgba(255, 255, 255, 0.12)":"rgba(0, 0, 0, 0.1)"}`,borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"background-color 0.15s ease"},children:"Cancel"})]})]}),!E&&r.piiRedacted&&jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"4px",marginTop:"6px",fontSize:"10px",fontWeight:500,color:x?"#34d399":"#059669",backgroundColor:x?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.06)",padding:"2px 6px",borderRadius:"4px",border:"1px solid rgba(16, 185, 129, 0.2)"},title:"Sensitive personal identifiers were redacted before transmission",children:[jsx("span",{children:"\u{1F6E1}\uFE0F"}),jsx("span",{children:"PII Protected"})]}),r.error&&jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"#ef4444"},children:["Error: ",r.error]})]}),!E&&r.content&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginTop:"4px",paddingLeft:"4px"},children:[$&&jsxs("button",{type:"button",onClick:()=>Bn(r.id,r.content),title:"Copy message",style:{background:"transparent",border:"none",cursor:"pointer",color:ie,fontSize:"11px",display:"inline-flex",alignItems:"center",gap:"3px",padding:"2px 6px",borderRadius:"4px"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),jsx("span",{children:ci===r.id?"Copied":"Copy"})]}),u&&typeof window<"u"&&window.speechSynthesis&&jsxs("button",{type:"button",onClick:()=>zn(r.id,r.content),title:po===r.id?"Stop speaking":"Read aloud",style:{background:po===r.id?"rgba(14, 165, 233, 0.15)":"transparent",border:"none",cursor:"pointer",color:po===r.id?I:ie,fontSize:"11px",display:"inline-flex",alignItems:"center",gap:"3px",padding:"2px 6px",borderRadius:"4px"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"})]}),jsx("span",{children:po===r.id?"Stop":"Read"})]}),m&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"2px"},children:[jsx("button",{type:"button",onClick:()=>Ko(r.id,"up"),title:"Helpful",style:{background:"transparent",border:"none",cursor:"pointer",color:Do[r.id]==="up"?"#10b981":ie,padding:"2px 4px",borderRadius:"4px",display:"flex",alignItems:"center"},children:jsx("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"})})}),jsx("button",{type:"button",onClick:()=>Ko(r.id,"down"),title:"Not helpful",style:{background:"transparent",border:"none",cursor:"pointer",color:Do[r.id]==="down"?"#ef4444":ie,padding:"2px 4px",borderRadius:"4px",display:"flex",alignItems:"center"},children:jsx("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h3a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-3"})})}),Do[r.id]&&jsx("span",{style:{fontSize:"10px",color:ie,marginLeft:"2px"},children:"Thanks!"})]})]}),!E&&jsxs("div",{style:{fontSize:"10px",color:ie,marginTop:"2px",paddingLeft:"6px",display:"flex",alignItems:"center",gap:"4px",opacity:.85},children:[jsx("svg",{viewBox:"0 0 24 24",width:"11",height:"11",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),jsx("span",{children:r.deliveryStatus==="Read"?"Read in chat":r.deliveryChannel==="Email"?"Delivered to email":"Delivered"})]})]})]})]},r.id)}),w.pendingCsatTicketId&&jsxs("div",{style:{margin:"12px 0 16px 0",padding:"16px",borderRadius:"14px",backgroundColor:x?"rgba(14, 165, 233, 0.08)":"#f0f9ff",border:`1px solid ${x?"rgba(14, 165, 233, 0.25)":"#bae6fd"}`,textAlign:"center"},children:[jsx("div",{style:{fontSize:"13px",fontWeight:600,color:x?"#f0f9ff":"#0c4a6e",marginBottom:"4px"},children:"How was your support experience today?"}),jsx("p",{style:{fontSize:"11px",color:ie,margin:"0 0 12px 0"},children:"Your feedback helps us continuously improve our live support service."}),Bo?jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"6px",color:"#10b981",fontSize:"12px",fontWeight:600},children:[jsx("span",{children:"\u2713 Thank you for your feedback!"}),jsx("span",{style:{fontSize:"11px",fontWeight:400,color:ie},children:"Our support team appreciates your review."})]}):jsxs("div",{children:[jsx("div",{style:{display:"flex",justifyContent:"center",gap:"8px",marginBottom:"10px"},children:[1,2,3,4,5].map(r=>jsx("button",{type:"button",onClick:()=>Mo(r),style:{background:"transparent",border:"none",fontSize:"22px",cursor:"pointer",transform:kt>=r?"scale(1.15)":"scale(1)",transition:"transform 0.15s ease",color:kt>=r?"#f59e0b":x?"#475569":"#cbd5e1"},title:`${r} star${r>1?"s":""}`,children:"\u2605"},r))}),kt>0&&jsxs("div",{style:{marginTop:"8px",display:"flex",flexDirection:"column",gap:"8px"},children:[jsx("input",{type:"text",value:St,onChange:r=>co(r.target.value),placeholder:"Add an optional comment (e.g. fast, helpful)...",style:{width:"100%",padding:"8px 12px",fontSize:"12px",borderRadius:"8px",border:`1px solid ${x?"#334155":"#e2e8f0"}`,background:x?"#1e293b":"#ffffff",color:x?"#f8fafc":"#0f172a",boxSizing:"border-box"}}),jsx("div",{style:{display:"flex",justifyContent:"flex-end",gap:"6px"},children:jsx("button",{type:"button",onClick:async()=>{zo(true),await w.submitHandoffFeedback?.(kt,St),zo(false),Ro(true),kt>=4?Mt.triggerCelebration():Mt.triggerSympathy();},disabled:Gt,style:{background:I,color:"#ffffff",border:"none",borderRadius:"6px",padding:"6px 14px",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:Gt?"Submitting...":"Submit Rating"})})]})]}),jsx("div",{style:{marginTop:"12px",borderTop:`1px solid ${x?"rgba(14, 165, 233, 0.2)":"#e0f2fe"}`,paddingTop:"10px",display:"flex",justifyContent:"center"},children:jsx("button",{type:"button",onClick:()=>{w.clearMessages?.(),Ro(false),Mo(0),co("");},style:{background:x?"rgba(255,255,255,0.06)":"#ffffff",color:x?"#e2e8f0":"#334155",border:`1px solid ${x?"#334155":"#cbd5e1"}`,borderRadius:"8px",padding:"6px 14px",fontSize:"11px",fontWeight:600,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"6px"},children:jsx("span",{children:"\u{1F4AC} Start New Conversation"})})})]}),ae&&!Ye&&jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[a&&jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexShrink:0},children:jsx(Bt,{size:24,shape:se.shape??"pebble",colors:se.colors??["#66a6ff","#0059d4"],faceColor:se.faceColor??"#ffffff",eyeColor:se.eyeColor,mouthColor:se.mouthColor,motion:"bounce"})}),jsx("div",{style:{padding:"8px 14px",borderRadius:"14px",backgroundColor:Qo,color:ie,fontSize:"13px"},children:"Thinking..."})]}),ee&&jsx("div",{style:{padding:"8px 12px",borderRadius:"8px",backgroundColor:"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:"#ef4444",fontSize:"12px"},children:ee.message})]}),Vo>0&&!_o&&jsxs("button",{type:"button",onClick:fi,style:{position:"absolute",bottom:"74px",left:"50%",transform:"translateX(-50%)",backgroundColor:I,color:"#ffffff",border:"none",borderRadius:"20px",padding:"6px 14px",fontSize:"12px",fontWeight:600,boxShadow:"0 4px 14px rgba(0, 0, 0, 0.35)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",zIndex:15,animation:"botzki-fade-in 0.2s ease-out"},children:[jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsx("polyline",{points:"19 12 12 19 5 12"})]}),jsxs("span",{children:[Vo," new ",Vo===1?"message":"messages"]})]}),Be?Be({input:fe,setInput:we,sendMessage:(r,M)=>Pe(r,M),isLoading:ae,isStreaming:Ye,primaryColor:I,isDark:x,attachImage:()=>pt.current?.click(),pendingImage:$e,removeImage:()=>ut(null),isListening:uo,toggleListening:yi,isRecordingVoiceNote:Ao,startVoiceRecording:Ht,stopVoiceRecording:Ct,cancelVoiceRecording:nt,voiceRecordingDuration:Jt,sendVoiceMessage:(r,M)=>w.sendVoiceMessage?w.sendVoiceMessage(r,M):w.sendMessage("",{audioUrl:URL.createObjectURL(r),audioDuration:M?.audioDuration})}):jsxs("div",{style:{padding:"8px 14px 4px 14px",backgroundColor:To,position:"relative"},children:[Io&&jsx("div",{ref:jo,style:{position:"absolute",bottom:"calc(100% - 2px)",left:"14px",backgroundColor:x?"#1e293b":"#ffffff",border:`1px solid ${Te}`,borderRadius:"14px",padding:"8px 10px",boxShadow:x?"0 8px 24px rgba(0, 0, 0, 0.45)":"0 8px 24px rgba(0, 0, 0, 0.12)",display:"flex",flexWrap:"wrap",gap:"6px",maxWidth:"260px",zIndex:30,animation:"botzki-fade-in 0.15s ease-out"},children:sr.map(r=>jsx("button",{type:"button",onClick:()=>di(r),style:{background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",padding:"4px",borderRadius:"6px",lineHeight:1,transition:"transform 0.1s ease"},onMouseEnter:M=>M.currentTarget.style.transform="scale(1.2)",onMouseLeave:M=>M.currentTarget.style.transform="scale(1)",children:r},r))}),jsx("form",{onSubmit:Rn,style:{display:"flex",flexDirection:"column",borderRadius:"16px",border:`1px solid ${kn?I:Te}`,boxShadow:kn?`0 0 0 2px ${I}20, 0 2px 8px rgba(0, 0, 0, 0.05)`:x?"0 2px 6px rgba(0, 0, 0, 0.2)":"0 2px 6px rgba(0, 0, 0, 0.04)",backgroundColor:x?"#1e293b":"#ffffff",padding:"10px 12px 8px 12px",transition:"border-color 0.15s ease, box-shadow 0.15s ease",...J},children:Ao?jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 4px",minHeight:"44px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx("span",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#ef4444",boxShadow:"0 0 8px rgba(239, 68, 68, 0.7)",animation:"botzki-pulse 1.2s infinite ease-in-out"}}),jsx("span",{style:{fontSize:"13px",fontWeight:600,color:x?"#f1f5f9":"#1e293b",fontVariantNumeric:"tabular-nums"},children:Xt(Jt)}),jsx("div",{style:{display:"flex",alignItems:"center",gap:"2.5px",marginLeft:"6px",height:"18px"},children:[6,12,18,10,15,8,16,14,9,17,11,7].map((r,M)=>jsx("div",{style:{width:"2.5px",height:`${r}px`,borderRadius:"2px",backgroundColor:I,animation:"botzki-equalizer 0.8s ease-in-out infinite alternate",animationDelay:`${(M*.08).toFixed(2)}s`}},M))})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx("button",{type:"button",onClick:nt,title:"Discard recording","aria-label":"Discard recording",style:{background:"transparent",border:"none",color:x?"#94a3b8":"#64748b",cursor:"pointer",padding:"6px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s ease, background 0.15s ease"},children:jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),jsx("button",{type:"button",onClick:Ct,title:"Send voice message","aria-label":"Send voice message",style:{width:"32px",height:"32px",borderRadius:"50%",backgroundColor:I,color:"#ffffff",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:`0 2px 8px ${I}55`,transition:"transform 0.12s ease, opacity 0.15s ease"},children:jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor",children:jsx("path",{d:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"})})})]})]}):jsxs(Fragment,{children:[$e&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"4px 6px 8px 6px",marginBottom:"4px",borderBottom:`1px solid ${Te}`,fontSize:"12px"},children:[jsx("img",{src:$e.dataUrl,alt:"Thumbnail",style:{width:"28px",height:"28px",objectFit:"cover",borderRadius:"6px",border:`1px solid ${Te}`}}),jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:it,fontSize:"11px",fontWeight:500},children:$e.name}),jsx("button",{type:"button",onClick:()=>ut(null),title:"Remove attachment",style:{background:"transparent",border:"none",color:ie,cursor:"pointer",fontSize:"12px",padding:"2px 4px",borderRadius:"4px"},children:"\u2715"})]}),ve&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"4px 6px 8px 6px",marginBottom:"4px",borderBottom:`1px solid ${Te}`,fontSize:"12px"},children:[jsx("div",{style:{width:"28px",height:"28px",borderRadius:"6px",backgroundColor:x?"rgba(255, 255, 255, 0.1)":"#f1f5f9",display:"flex",alignItems:"center",justifyContent:"center",color:x?"#ffffff":I,flexShrink:0},children:oi(ve.name)}),jsxs("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:it,fontSize:"11px",fontWeight:500},children:[ve.name,jsxs("span",{style:{opacity:.7,marginLeft:"4px"},children:["(",ti(ve.size),")"]})]}),jsx("button",{type:"button",onClick:()=>Yt(null),title:"Remove attachment",style:{background:"transparent",border:"none",color:ie,cursor:"pointer",fontSize:"12px",padding:"2px 4px",borderRadius:"4px"},children:"\u2715"})]}),Uo&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"5px 8px",marginBottom:"6px",borderRadius:"6px",backgroundColor:x?"rgba(16, 185, 129, 0.12)":"rgba(16, 185, 129, 0.08)",border:"1px solid rgba(16, 185, 129, 0.25)",color:x?"#34d399":"#059669",fontSize:"11px",fontWeight:500},children:[jsx("span",{children:"\u{1F6E1}\uFE0F"}),jsx("span",{children:"PII Firewall Active: Sensitive numbers & credentials are encrypted & redacted in transit."})]}),jsx("textarea",{ref:eo,rows:1,className:"botzki-composer-textarea",value:fe,onChange:Oe,onKeyDown:ui,onFocus:()=>Sn(true),onBlur:()=>Sn(false),placeholder:uo?"Listening... Speak now":G||"Compose your message...",disabled:ae,style:{width:"100%",background:"transparent",border:"none",outline:"none",padding:"2px 4px",color:it,fontSize:"14px",lineHeight:"20px",resize:"none",boxSizing:"border-box",minHeight:"36px",maxHeight:"120px",overflowY:"auto",scrollbarWidth:"none",msOverflowStyle:"none",fontFamily:"inherit",...W}}),jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:"4px",paddingTop:"4px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[jsx("button",{type:"button",onClick:()=>Fo(r=>!r),title:"Insert emoji","aria-label":"Insert emoji",style:{background:"transparent",border:"none",color:Io?I:ie,cursor:"pointer",padding:"4px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s ease"},children:jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("circle",{cx:"12",cy:"12",r:"10"}),jsx("path",{d:"M8 14s1.5 2 4 2 4-2 4-2"}),jsx("line",{x1:"9",y1:"9",x2:"9.01",y2:"9"}),jsx("line",{x1:"15",y1:"9",x2:"15.01",y2:"9"})]})}),s&&jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>pt.current?.click(),title:"Attach file, document, or image","aria-label":"Attach file, document, or image",style:{background:"transparent",border:"none",color:$e||ve?I:ie,cursor:"pointer",padding:"4px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s ease"},children:jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),jsx("input",{ref:pt,type:"file",accept:"image/*,.pdf,.zip,.csv,.docx,.xlsx,.txt,.tar,.gz,.json",onChange:bi,style:{display:"none"}})]}),c&&y!==false&&jsx("button",{type:"button",onClick:Ht,title:"Record voice message","aria-label":"Voice input / Record voice message",style:{background:"transparent",border:"none",color:ie,cursor:"pointer",padding:"4px",borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s ease"},onMouseEnter:r=>{r.currentTarget.style.color=I;},onMouseLeave:r=>{r.currentTarget.style.color=ie;},children:jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[jsx("line",{x1:"4",y1:"9",x2:"4",y2:"15"}),jsx("line",{x1:"8",y1:"5",x2:"8",y2:"19"}),jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"}),jsx("line",{x1:"16",y1:"7",x2:"16",y2:"17"}),jsx("line",{x1:"20",y1:"10",x2:"20",y2:"14"})]})})]}),Ye?jsx("button",{type:"button",onClick:()=>w.stop(),"aria-label":"Stop generating",title:"Stop generating",style:{width:"28px",height:"28px",backgroundColor:"#ef4444",color:"#ffffff",border:"none",borderRadius:"50%",padding:0,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"opacity 0.2s ease, transform 0.1s ease",...S},children:jsx("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"currentColor",children:jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}):jsx("button",{type:"submit",disabled:ae||Pt||!fe.trim()&&!$e&&!ve,"aria-label":"Send message",title:"Send message",style:{background:"transparent",border:"none",color:!fe.trim()&&!$e&&!ve?x?"#475569":"#cbd5e1":I,cursor:ae||Pt||!fe.trim()&&!$e&&!ve?"not-allowed":"pointer",padding:"4px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"color 0.15s ease, transform 0.1s ease",...S},children:jsx("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"currentColor",children:jsx("path",{d:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"})})})]})]})})]}),b&&jsxs("div",{style:{textAlign:"center",padding:"4px 12px 10px 12px",backgroundColor:To,fontSize:"11px",color:ie,display:"flex",alignItems:"center",justifyContent:"center",gap:"4px"},children:[jsx("span",{children:"Powered by "}),jsxs("a",{href:"https://botzki.com",target:"_blank",rel:"noopener noreferrer",style:{color:it,fontWeight:600,textDecoration:"none",display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx("span",{style:{color:I},children:"\u26A1"})," Botzki"]})]}),w.coBrowse&&jsx(gn,{coBrowse:w.coBrowse})]})}function ur(o){if(!o||o.trim()===""||o.trim()==="*")return true;if(typeof window>"u")return false;let e=window.location.href,n=window.location.pathname,t=o.trim();if(t.includes("*")){let a=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*"),s=new RegExp(`^${a}$`,"i");return s.test(e)||s.test(n)}return e.toLowerCase().includes(t.toLowerCase())||n.toLowerCase().includes(t.toLowerCase())}var pr=forwardRef(function(e,n){let t=Dt(),a=e.botId||t?.botId,s=e.publishableKey||t?.publishableKey,c=e.baseUrl||t?.baseUrl||"https://api.botzki.com",[u,y]=useState(false),[p,R]=useState(e.defaultOpen??false),[m,C]=useState(true),[b,$]=useState(e.defaultExpanded??false),[F,te]=useState(false),[U,de]=useState(false),[H,X]=useState(e.theme||"dark"),[N,ue]=useState(e.primaryColor||"#0ea5e9"),[,Q]=useState(e.user||t?.user),[oe,j]=useState(false);useEffect(()=>{e.theme&&X(e.theme);},[e.theme]),useEffect(()=>{e.primaryColor&&ue(e.primaryColor);},[e.primaryColor]),useEffect(()=>{e.user&&Q(e.user);},[e.user]),useEffect(()=>{y(true);},[]);let{data:ne}=bo(),[me,ye]=useState(null);useEffect(()=>{if(p){de(false);return}try{if(typeof window<"u"&&window.sessionStorage&&sessionStorage.getItem(`botzki_proactive_dismissed_${a||"default"}`)==="true")return}catch{}if(e.proactiveMessage){let f=e.proactiveDelay??3e3,h=setTimeout(()=>{de(true);},f);return ()=>clearTimeout(h)}if(e.enableTriggers===false||!ne?.activeTriggers||ne.activeTriggers.length===0)return;let l=ne.activeTriggers.find(f=>ur(f.urlPattern));if(!l)return;let k=l.triggerType||"TimeOnPage";if(k==="TimeOnPage"){let f=(l.delaySeconds??5)*1e3,h=setTimeout(()=>{ye(l),de(true),e.onTriggerActivated?.(l);},f);return ()=>clearTimeout(h)}if(k==="ScrollPercentage"){let f=l.scrollPercentage??50,h=()=>{if(typeof window>"u")return;let S=document.documentElement.scrollHeight-window.innerHeight;if(S<=0)return;window.scrollY/S*100>=f&&(ye(l),de(true),e.onTriggerActivated?.(l),window.removeEventListener("scroll",h));};return window.addEventListener("scroll",h,{passive:true}),()=>window.removeEventListener("scroll",h)}if(k==="ExitIntent"){let f=h=>{!h.relatedTarget&&h.clientY<=10&&(ye(l),de(true),e.onTriggerActivated?.(l),document.removeEventListener("mouseout",f));};return document.addEventListener("mouseout",f),()=>document.removeEventListener("mouseout",f)}},[e.proactiveMessage,e.proactiveDelay,e.enableTriggers,ne?.activeTriggers,p,a]);let v=mo({botId:a,publishableKey:s,baseUrl:c,persistSession:e.persistSession??false,visitorData:e.visitorData,tags:e.tags,enableSoundAlert:e.enableSoundAlert,enableTabTitleNotification:e.enableTabTitleNotification,enableCoBrowse:e.enableCoBrowse,onSendMessage:e.onSendMessage,onResponse:l=>{e.onResponse?.(l),e.onMessage?.({role:"assistant",content:l.reply});},onFinish:e.onFinish,onError:e.onError,onEscalationRequest:e.onEscalationRequest,onOperatorJoined:e.onOperatorJoined,onTicketResolved:e.onTicketResolved,onCsatSubmit:e.onCsatSubmit,onActionProposed:e.onActionProposed,onActionExecuted:e.onActionExecuted,onActionCancelled:e.onActionCancelled,onCoBrowseStart:e.onCoBrowseStart,onCoBrowseEnd:e.onCoBrowseEnd}),I=useRef(new Set),V=useRef(false),[D,G]=useState(0),[Z,le]=useState(void 0),[He,Se]=useState(null),pe=useRef(""),xe=e.unreadCount!==void 0?e.unreadCount:D;useEffect(()=>{!V.current&&v.messages.length>0&&(V.current=true,v.messages.forEach(l=>{l.isStreaming||I.current.add(l.id);}));},[v.messages]),useEffect(()=>{p&&(v.messages.forEach(l=>{l.role==="assistant"&&!l.isStreaming&&I.current.add(l.id);}),D!==0&&(G(0),e.onUnreadCountChange?.(0)),Se(null));},[p,v.messages,D,e.onUnreadCountChange]),useEffect(()=>{if(p)return;let l=v.messages.filter(f=>f.role==="assistant"&&!I.current.has(f.id)&&(f.content.trim().length>0||!f.isStreaming)),k=l.length;if(k!==D&&(G(k),e.onUnreadCountChange?.(k),k>D&&k>0)){if(e.enableSoundAlert!==false)try{if(typeof window<"u"){let h=window.AudioContext||window.webkitAudioContext;if(h){let S=new h,z=S.createOscillator(),B=S.createGain();z.type="sine",z.frequency.setValueAtTime(587.33,S.currentTime),z.frequency.exponentialRampToValueAtTime(880,S.currentTime+.12),B.gain.setValueAtTime(.08,S.currentTime),B.gain.exponentialRampToValueAtTime(.001,S.currentTime+.35),z.connect(B),B.connect(S.destination),z.start(),z.stop(S.currentTime+.35);}}}catch{}let f=l[l.length-1];if(f&&f.content){let h=f.content.length>90?f.content.slice(0,87)+"...":f.content;Se(h);}}},[v.messages,p,D,e.onUnreadCountChange]),useEffect(()=>{if(typeof document>"u"||e.enableTabTitleNotification===false)return;pe.current||(pe.current=document.title),xe>0&&!p?document.title=`(${xe}) ${pe.current}`:pe.current&&(document.title=pe.current);let l=()=>{p&&pe.current&&(document.title=pe.current);};return window.addEventListener("focus",l),()=>{window.removeEventListener("focus",l),pe.current&&(document.title=pe.current);}},[xe,p,e.enableTabTitleNotification]);let Ee=useCallback(()=>{let l=v.messages.findIndex(k=>k.role==="assistant"&&!I.current.has(k.id)&&(k.content.trim().length>0||!k.isStreaming));if(l>=0)le(l);else {let k=e.unreadCount!==void 0?e.unreadCount:D;k>0&&v.messages.length>0?le(Math.max(0,v.messages.length-k)):le(void 0);}v.messages.forEach(k=>{k.role==="assistant"&&I.current.add(k.id);}),R(true),de(false),Se(null),G(0),typeof document<"u"&&pe.current&&(document.title=pe.current),e.onUnreadCountChange?.(0),e.onOpen?.();},[e.onOpen,e.onUnreadCountChange,e.unreadCount,D,v.messages]),We=useCallback(()=>{R(false),le(void 0),e.onClose?.();},[e.onClose]),Ne=useCallback(()=>{R(l=>{let k=!l;if(k){let f=v.messages.findIndex(h=>h.role==="assistant"&&!I.current.has(h.id)&&(h.content.trim().length>0||!h.isStreaming));if(f>=0)le(f);else {let h=e.unreadCount!==void 0?e.unreadCount:D;h>0&&v.messages.length>0?le(Math.max(0,v.messages.length-h)):le(void 0);}v.messages.forEach(h=>{h.role==="assistant"&&I.current.add(h.id);}),de(false),Se(null),G(0),typeof document<"u"&&pe.current&&(document.title=pe.current),e.onUnreadCountChange?.(0),e.onOpen?.();}else le(void 0),e.onClose?.();return k});},[e.onOpen,e.onClose,e.onUnreadCountChange,e.unreadCount,D,v.messages]),vt=useCallback(()=>{$(l=>{let k=!l;return e.onExpandChange?.(k),k});},[e.onExpandChange]),At=useCallback(l=>{l.stopPropagation(),de(false);try{typeof window<"u"&&window.sessionStorage&&sessionStorage.setItem(`botzki_proactive_dismissed_${a||"default"}`,"true");}catch{}},[a]);useEffect(()=>{if(e.enableHotkey===false||typeof window>"u")return;let l=k=>{(k.metaKey||k.ctrlKey)&&k.key.toLowerCase()==="k"?(k.preventDefault(),Ne()):k.key==="Escape"&&p&&We();};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e.enableHotkey,p,Ne,We]),useImperativeHandle(n,()=>({open:Ee,close:We,toggle:Ne,isOpen:()=>p,show:()=>C(true),hide:()=>{C(false),We();},sendMessage:async(l,k)=>{Ee(),await v.sendMessage(l,k?{imageBase64:k}:void 0);},clearMessages:()=>{v.clearMessages(),I.current.clear(),G(0),le(void 0),Se(null);},newChat:()=>{v.clearMessages(),I.current.clear(),G(0),le(void 0),Se(null),v.setSessionId(`session_${Date.now()}_${Math.random().toString(36).substring(2,9)}`),e.onNewChat?.();},expand:()=>{$(true),e.onExpandChange?.(true);},collapse:()=>{$(false),e.onExpandChange?.(false);},isExpanded:()=>b,openHistory:()=>{Ee(),te(true);},closeHistory:()=>{te(false);},exportChat:(l="markdown")=>{let k="";return l==="json"?k=JSON.stringify(v.messages,null,2):(k=`# Conversation
|
|
128
143
|
|
|
129
|
-
`,
|
|
130
|
-
${
|
|
144
|
+
`,v.messages.forEach(f=>{k+=`### ${f.role==="user"?"User":"Assistant"}:
|
|
145
|
+
${f.content}
|
|
131
146
|
|
|
132
|
-
`;})),
|
|
147
|
+
`;})),k},setTheme:l=>X(l),setPrimaryColor:l=>ue(l),setUser:l=>Q(l),getUnreadCount:()=>xe,markAsRead:()=>{G(0),le(void 0),Se(null),v.messages.forEach(l=>{l.role==="assistant"&&I.current.add(l.id);}),typeof document<"u"&&pe.current&&(document.title=pe.current),e.onUnreadCountChange?.(0);},requestHumanHandoff:async(l,k,f)=>{Ee(),await v.requestHumanHandoff?.(l,k,f);},cancelHumanHandoff:async()=>{await v.cancelHumanHandoff?.();},getMessages:()=>v.messages,getSessionId:()=>v.sessionId,setSessionId:l=>v.setSessionId(l),stopStreaming:()=>v.stop(),reloadLastMessage:()=>v.reload()}),[Ee,We,Ne,p,b,v,e.onNewChat,e.onExpandChange,xe,e.onUnreadCountChange]);let Xe=yo({messages:v.messages,isLoading:v.isLoading,isStreaming:v.isStreaming,isWaitingForHuman:v.isWaitingForHuman,isHumanHandoffActive:v.isHumanHandoffActive,manualEmotion:e.avatar?.emotion,manualMotion:e.avatar?.motion??void 0,enabled:e.enableEmpathyEngine??true}),Ae=useMemo(()=>({colors:e.avatar?.colors??e.avatarColors??["#66a6ff","#0059d4"],faceColor:e.avatar?.faceColor??e.avatarFaceColor??"#ffffff",eyeColor:e.avatar?.eyeColor??e.avatarEyeColor,mouthColor:e.avatar?.mouthColor??e.avatarMouthColor,shape:e.avatar?.shape??e.avatarShape??"pebble",size:e.avatar?.size??e.avatarSize??50,followCursor:e.avatar?.followCursor??e.avatarFollowCursor??true,motion:e.avatar?.motion??(e.enableEmpathyEngine??true?Xe.motion:void 0),emotion:e.avatar?.emotion??(e.enableEmpathyEngine??true?Xe.emotion:"neutral"),outlineColor:e.avatar?.outlineColor,outlineWidth:e.avatar?.outlineWidth,background:e.avatar?.background,props:{...e.avatarProps,...e.avatar?.props,motionKey:Xe.motionKey}}),[e.avatar,e.avatarColors,e.avatarFaceColor,e.avatarEyeColor,e.avatarMouthColor,e.avatarShape,e.avatarSize,e.avatarFollowCursor,e.avatarProps,e.enableEmpathyEngine,Xe.emotion,Xe.motion,Xe.motionKey]),be=useMemo(()=>({background:e.launcher?.background??e.launcherBackground??"transparent",icon:e.launcher?.icon??e.launcherIcon,style:{...e.launcherStyle,...e.launcher?.style},closeBackground:e.launcher?.closeBackground??e.closeButtonBackground??N,closeColor:e.launcher?.closeColor??e.closeButtonColor??"#ffffff",size:e.launcher?.size??56}),[e.launcher,e.launcherBackground,e.launcherIcon,e.launcherStyle,e.closeButtonBackground,e.closeButtonColor,N]);if(!u||typeof document>"u")return null;let Qe=e.position==="bottom-left",Ke=e.offset?.x??24,Be=e.offset?.y??24,Ve=e.zIndex??2147483647,T=!p&&be.background&&be.background!=="transparent",d=p?be.closeBackground||N:be.background??"transparent",W=p||T?oe?"0 10px 24px rgba(0, 0, 0, 0.35), 0 4px 8px rgba(0, 0, 0, 0.2)":"0 6px 16px rgba(0, 0, 0, 0.24), 0 3px 6px rgba(0, 0, 0, 0.12)":"none",J=!p&&!T?oe?"drop-shadow(0 8px 18px rgba(0, 0, 0, 0.3))":"drop-shadow(0 3px 8px rgba(0, 0, 0, 0.18))":void 0,O=be.size||56,q=b?e.expandedWidth||"720px":e.width||"380px",P=b?e.expandedHeight||"calc(100vh - 100px)":e.height||"580px",A=jsxs("div",{id:"botzki-react-widget-container",style:{display:m?"block":"none",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'},children:[jsx("style",{children:`
|
|
133
148
|
@keyframes botzki-teaser-in {
|
|
134
149
|
from { opacity: 0; transform: translateY(8px) scale(0.95); }
|
|
135
150
|
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
136
151
|
}
|
|
137
|
-
`}),U&&!
|
|
138
|
-
export{
|
|
152
|
+
`}),U&&!p&&(e.proactiveMessage||me)&&jsxs("div",{onClick:Ee,role:"alert",style:{position:"fixed",bottom:Be+O+12,[Qe?"left":"right"]:Ke,maxWidth:"320px",backgroundColor:H==="dark"?"#1e293b":"#ffffff",color:H==="dark"?"#f8fafc":"#0f172a",padding:"12px 14px",borderRadius:"16px",boxShadow:"0 20px 30px -10px rgba(0, 0, 0, 0.25), 0 8px 12px -4px rgba(0, 0, 0, 0.1)",border:`1px solid ${H==="dark"?"#334155":"#e2e8f0"}`,cursor:"pointer",zIndex:Ve,display:"flex",flexDirection:"column",gap:"6px",animation:"botzki-teaser-in 0.25s cubic-bezier(0.16, 1, 0.3, 1)"},children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[jsx("span",{style:{fontSize:"14px"},children:"\u2728"}),jsx("span",{style:{fontSize:"12.5px",fontWeight:700,color:N},children:me?.headline||"Need help?"})]}),jsx("button",{type:"button",onClick:At,title:"Dismiss teaser","aria-label":"Dismiss greeting",style:{background:"transparent",border:"none",color:H==="dark"?"#94a3b8":"#64748b",cursor:"pointer",padding:"0 2px",fontSize:"14px",lineHeight:1},children:"\u2715"})]}),jsx("div",{style:{fontSize:"12.5px",lineHeight:1.45,opacity:.9},children:me?.message||e.proactiveMessage}),me?.suggestedPrompts&&me.suggestedPrompts.length>0&&jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"4px",paddingTop:"6px",borderTop:`1px solid ${H==="dark"?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}`},children:me.suggestedPrompts.map((l,k)=>jsxs("button",{type:"button",onClick:f=>{f.stopPropagation(),Ee(),v.sendMessage(l);},style:{background:H==="dark"?"#334155":"#f1f5f9",border:`1px solid ${H==="dark"?"#475569":"#cbd5e1"}`,borderRadius:"8px",padding:"4px 8px",fontSize:"11px",fontWeight:500,cursor:"pointer",color:H==="dark"?"#e2e8f0":"#1e293b",transition:"transform 0.1s ease"},children:[l," \u2192"]},k))})]}),!p&&He&&jsxs("div",{onClick:Ee,role:"alert",style:{position:"fixed",bottom:Be+O+12,[Qe?"left":"right"]:Ke,maxWidth:"290px",backgroundColor:H==="dark"?"#1e293b":"#ffffff",color:H==="dark"?"#f8fafc":"#0f172a",padding:"10px 14px",borderRadius:"14px",boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.35), 0 4px 8px rgba(0, 0, 0, 0.15)",border:`1px solid ${H==="dark"?"#334155":"#e2e8f0"}`,cursor:"pointer",zIndex:Ve,display:"flex",alignItems:"flex-start",gap:"8px",animation:"botzki-teaser-in 0.25s cubic-bezier(0.16, 1, 0.3, 1)"},children:[jsxs("div",{style:{flex:1},children:[jsxs("div",{style:{fontSize:"11px",fontWeight:700,color:N,marginBottom:"2px",display:"flex",alignItems:"center",gap:"5px"},children:[jsx("span",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#ef4444"}}),e.widgetTitle||"Botzki AI"]}),jsx("div",{style:{fontSize:"13px",lineHeight:1.4},children:He})]}),jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),Se(null);},title:"Dismiss preview","aria-label":"Dismiss preview",style:{background:"transparent",border:"none",color:H==="dark"?"#94a3b8":"#64748b",cursor:"pointer",padding:"0 2px",fontSize:"14px",lineHeight:1},children:"\u2715"})]}),jsx("div",{role:"dialog","aria-label":"Botzki AI Chat",style:{position:"fixed",bottom:Be+68,[Qe?"left":"right"]:Ke,width:typeof q=="number"?`${q}px`:q,maxWidth:"calc(100vw - 32px)",height:typeof P=="number"?`${P}px`:P,maxHeight:"calc(100vh - 110px)",zIndex:Ve,boxShadow:"0 20px 40px -10px rgba(0, 0, 0, 0.4), 0 0 1px 1px rgba(255, 255, 255, 0.1)",borderRadius:"16px",overflow:"hidden",transition:"width 0.25s ease, height 0.25s ease, opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s",opacity:p?1:0,transform:p?"translateY(0) scale(1)":"translateY(16px) scale(0.95)",visibility:p?"visible":"hidden",pointerEvents:p?"auto":"none"},children:jsx(mn,{chat:v,title:e.widgetTitle,subtitle:e.widgetSubtitle||"Online",avatar:Ae,botAvatar:e.botAvatar,userAvatar:e.userAvatar,showAvatars:e.showAvatars,enableImageUpload:e.enableImageUpload,enableVoiceInput:e.enableVoiceInput,enableVoiceOutput:e.enableVoiceOutput,enableVoiceNotes:e.enableVoiceNotes,enableHumanHandoff:e.enableHumanHandoff,enableActionEngine:e.enableActionEngine,showFeedback:e.showFeedback,showCitations:e.showCitations,showBranding:e.showBranding,showCopyButton:e.showCopyButton,showExportButton:e.showExportButton!==false,greeting:e.greeting,starterQuestions:e.starterPrompts,theme:H,primaryColor:N,showCloseButton:e.showCloseButton!==false,showClearButton:e.showClearButton===true,showNewChatButton:e.showNewChatButton!==false,showHistoryButton:e.showHistoryButton!==false,allowExpand:e.allowExpand!==false,isExpanded:b,onToggleExpand:vt,onNewChat:e.onNewChat,isHistoryOpen:F,onHistoryOpenChange:te,onFeedbackSubmit:e.onFeedbackSubmit,onCitationClick:e.onCitationClick,renderHeader:e.renderHeader,customHeader:e.customHeader,renderMessage:e.renderMessage,renderComposer:e.renderComposer,renderWelcome:e.renderWelcome,unreadFromIndex:Z,placeholder:e.placeholder,inputStyle:e.inputStyle,composerStyle:e.composerStyle,sendButtonStyle:e.sendButtonStyle,userBubbleColor:e.userBubbleColor,userTextColor:e.userTextColor,assistantBubbleColor:e.assistantBubbleColor,assistantTextColor:e.assistantTextColor,fontFamily:e.fontFamily,fontSize:e.fontSize,headerStyle:e.headerStyle,messagesContainerStyle:e.messagesContainerStyle,onClose:We,style:{height:"100%",borderRadius:"16px",...e.chatStyle}})}),e.renderLauncher?jsx("div",{style:{position:"fixed",bottom:Be,[Qe?"left":"right"]:Ke,zIndex:Ve},children:e.renderLauncher({isOpen:p,unreadCount:xe,onClick:Ne,primaryColor:N,isHovered:oe})}):jsxs("button",{type:"button",onClick:Ne,onMouseEnter:()=>j(true),onMouseLeave:()=>j(false),"aria-label":p?"Close AI Support Chat":"Open AI Support Chat","aria-expanded":p,style:{position:"fixed",bottom:Be,[Qe?"left":"right"]:Ke,width:`${O}px`,height:`${O}px`,borderRadius:"50%",backgroundColor:d,color:"#ffffff",border:"none",outline:"none",cursor:"pointer",boxShadow:W,filter:J,zIndex:Ve,display:"flex",alignItems:"center",justifyContent:"center",transform:oe?"scale(1.08)":"scale(1)",transition:"transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease, filter 0.2s ease, background-color 0.2s ease",...be.style},children:[p?jsxs("svg",{viewBox:"0 0 24 24",width:"24",height:"24",fill:"none",stroke:be.closeColor||"#ffffff",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}):be.icon?be.icon:jsx(Bt,{size:Ae.size??50,shape:Ae.shape??"pebble",followCursor:Ae.followCursor??true,colors:Ae.colors??["#66a6ff","#0059d4"],faceColor:Ae.faceColor??"#ffffff",eyeColor:Ae.eyeColor,mouthColor:Ae.mouthColor,motion:Ae.motion,emotion:Ae.emotion,outlineColor:Ae.outlineColor,outlineWidth:Ae.outlineWidth,...Ae.props}),!p&&xe>0?jsx("div",{style:{position:"absolute",top:"-2px",right:"-2px",backgroundColor:"#ef4444",color:"#ffffff",fontSize:"11px",fontWeight:700,width:xe>9?"auto":"22px",minWidth:"22px",height:"22px",borderRadius:xe>9?"9999px":"50%",display:"flex",alignItems:"center",justifyContent:"center",padding:xe>9?"0 6px":"0",boxShadow:"0 2px 6px rgba(0, 0, 0, 0.35)",border:"2px solid #ffffff",pointerEvents:"none",boxSizing:"border-box",lineHeight:1,...e.badgeStyle},children:xe>9?"9+":xe}):null]})]});return createPortal(A,document.body)});function fr(){let{client:o,botId:e,baseUrl:n,sessionId:t}=zt(),[a,s]=useState(false),[c,u]=useState(false),[y,p]=useState(null),R=useCallback(async C=>{s(true),p(null),u(false);try{if(typeof o.submitFeedback=="function")await o.submitFeedback({...C,sessionId:t});else {let b=n?n.replace(/\/+$/,""):"https://api.botzki.com";await fetch(`${b}/api/v1/public/chat/${e}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...C,sessionId:t})});}return u(!0),!0}catch(b){let $=b instanceof Error?b:new Error(String(b));return p($),false}finally{s(false);}},[o,e,n,t]),m=useCallback(()=>{s(false),u(false),p(null);},[]);return {submitFeedback:R,isSubmitting:a,isSuccess:c,error:y,reset:m}}function gr(){let{client:o,botId:e,baseUrl:n,sessionId:t}=zt(),[a,s]=useState(false),[c,u]=useState(false),[y,p]=useState(null),R=useCallback(async C=>{s(true),p(null),u(false);try{if(typeof o.captureLead=="function")await o.captureLead({...C,sessionId:t});else {let b=n?n.replace(/\/+$/,""):"https://api.botzki.com";await fetch(`${b}/api/v1/public/chat/${e}/leads`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...C,sessionId:t})});}return u(!0),!0}catch(b){let $=b instanceof Error?b:new Error(String(b));return p($),false}finally{s(false);}},[o,e,n,t]),m=useCallback(()=>{s(false),u(false),p(null);},[]);return {captureLead:R,isSubmitting:a,isSuccess:c,error:y,reset:m}}function hr(){let{client:o}=zt(),[e,n]=useState(false),[t,a]=useState(null),[s,c]=useState(null),u=useCallback(async p=>{n(true),c(null);try{let m=(await o.transcribeAudio(p)).text||"";return a(m),m}catch(R){let m=R instanceof Error?R:new Error(String(R));return c(m),null}finally{n(false);}},[o]),y=useCallback(()=>{n(false),a(null),c(null);},[]);return {transcribe:u,isTranscribing:e,transcript:t,error:s,reset:y}}
|
|
153
|
+
export{Ji as AiBotAvatar,Bt as BotziAvatar,fn as BotzkiAudioPlayer,mn as BotzkiChat,Wo as BotzkiMarkdown,zi as BotzkiProvider,pr as BotzkiWidget,gn as CoBrowseLaserPointer,Nn as analyzeVisitorSentiment,on as captureDomSnapshot,jt as notifyVisitorIncomingMessage,Ln as playVisitorNotificationChime,Hn as startTabTitleAlert,bo as useBotInfo,zt as useBotzki,mo as useChat,an as useCoBrowse,yo as useEmpathyEngine,fr as useFeedback,gr as useLeadCapture,Dt as useOptionalBotzki,hr as useVoiceTranscription};//# sourceMappingURL=index.mjs.map
|
|
139
154
|
//# sourceMappingURL=index.mjs.map
|