@eduzz-automacoes/webchat-widget 0.2.1 → 0.2.2
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/eduzz-webchat.cjs +2 -2
- package/dist/eduzz-webchat.js +557 -402
- package/package.json +1 -1
package/dist/eduzz-webchat.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./style.css');const o=require("react/jsx-runtime"),c=require("react"),_=require("@botpress/webchat"),q={botName:"Assistente Virtual",subtitle:"Conectado ao bot real",botAvatar:"",color:"",themeMode:"light",variant:"solid",headerVariant:"glass",radius:4,fontFamily:"Inter",additionalStylesheet:"",additionalStylesheetUrl:"",accentColor:"#2563eb",brandColor:"#18181b",brandTextColor:"#fafafa",placeholder:"Escreva uma mensagem...",fabBackgroundColor:"#2563eb",fabIconColor:"#ffffff",fabChatIconVariant:"messages-square",primaryButtonBackgroundColor:"#18181b",primaryButtonTextColor:"#fafafa",primaryButtonHoverBackgroundColor:"#27272a",panelBackgroundColor:"#ffffff",panelElevatedBackgroundColor:"#ffffff",panelSubtleBackgroundColor:"#fafafa",panelMutedBackgroundColor:"#f4f4f5",panelHoverBackgroundColor:"#f4f4f5",panelSelectedBackgroundColor:"#f5f5f5",panelBorderColor:"#e4e4e7",panelStrongBorderColor:"#d4d4d8",panelTextColor:"#18181b",panelMutedTextColor:"#71717a",panelHeaderBackgroundColor:"rgba(255, 255, 255, 0.96)",welcomeBackground:"linear-gradient(180deg, #f4f4f5 0%, #fafafa 34%, #ffffff 34%, #ffffff 100%)",welcomeHeroBackground:"linear-gradient(180deg, #f5f5f5 0%, #efeff1 100%)",welcomeOnlineStatusColor:"#16a34a",secondaryButtonBackgroundColor:"#ffffff",secondaryButtonTextColor:"#18181b",secondaryButtonBorderColor:"#e4e4e7",secondaryButtonHoverBackgroundColor:"#f4f4f5",iconButtonBackgroundColor:"#ffffff",iconButtonIconColor:"#71717a",iconButtonBorderColor:"#e4e4e7",iconButtonHoverBackgroundColor:"#f4f4f5",outgoingMessageBackgroundColor:"#ebf1fd",outgoingMessageTextColor:"#0f2346",incomingMessageBackgroundColor:"#f0f0f3",incomingMessageTextColor:"#202127",position:"bottom-right",initiallyOpen:!0,showWelcomeScreen:!0,width:"380px",height:"640px",welcomeCoverImage:"",welcomeCardImage:"",welcomeCardTitle:"Suporte",welcomeCardStatus:"Online agora!",welcomeCardDescription:"Estamos disponíveis para esclarecer qualquer dúvida que você possa ter. Sinta-se a vontade para nos contatar a qualquer momento.",welcomeCtaLabel:"Iniciar atendimento",welcomeButtonDescription:"",welcomeCloseLabel:"Fechar painel",openFabBackgroundColor:"#2563eb",openFabIconColor:"#ffffff"},Ie=e=>e==="bottom-left"||e==="top-left"?"bottom-left":"bottom-right",Le=e=>{switch(Ie(e)){case"bottom-left":return{bottom:"24px",left:"24px","--widget-align":"flex-start","--panel-transform-origin":"left bottom"};case"bottom-right":default:return{bottom:"24px",right:"24px","--widget-align":"flex-end","--panel-transform-origin":"right bottom"}}},Me=(e,t,a)=>Math.min(Math.max(e,t),a),xe=e=>{if(typeof e!="string")return null;let t=e.trim();return!t||(t.startsWith("#")&&(t=t.slice(1)),t.length===3&&(t=t.split("").map(a=>`${a}${a}`).join("")),!/^[0-9a-fA-F]{6}$/.test(t))?null:`#${t.toLowerCase()}`},ye=e=>{const t=xe(e);if(!t)return null;const a=t.slice(1);return{r:Number.parseInt(a.slice(0,2),16),g:Number.parseInt(a.slice(2,4),16),b:Number.parseInt(a.slice(4,6),16)}},_e=({r:e,g:t,b:a})=>`#${[e,t,a].map(r=>Me(Math.round(r),0,255).toString(16).padStart(2,"0")).join("")}`,ue=(e,t,a)=>{const r=ye(e),s=ye(t);if(!r||!s)return null;const n=Me(a,0,1);return _e({r:r.r*(1-n)+s.r*n,g:r.g*(1-n)+s.g*n,b:r.b*(1-n)+s.b*n})},ze=(e,t)=>t<0?ue(e,"#000000",Math.abs(t)):ue(e,"#ffffff",t),re=e=>{const t=ye(e);return t&&[t.r,t.g,t.b].map(r=>{const s=r/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4}).reduce((r,s,n)=>r+s*[.2126,.7152,.0722][n],0)>.42?"#18181b":"#ffffff"},D=(e,t)=>e&&Object.prototype.hasOwnProperty.call(e,t)&&e[t]!=null&&e[t]!=="",qe=(e,t)=>{const a=xe(e.brandColor);if(!a)return e;const r=xe(e.brandTextColor)||re(a),s=ue(a,"#ffffff",.82)||q.secondaryButtonBorderColor,n=ue(a,"#ffffff",.92)||q.secondaryButtonHoverBackgroundColor,l=ze(a,-.12)||q.primaryButtonHoverBackgroundColor;return{...e,brandColor:a,brandTextColor:r,primaryButtonBackgroundColor:D(t,"primaryButtonBackgroundColor")?e.primaryButtonBackgroundColor:a,primaryButtonTextColor:D(t,"primaryButtonTextColor")?e.primaryButtonTextColor:r,primaryButtonHoverBackgroundColor:D(t,"primaryButtonHoverBackgroundColor")?e.primaryButtonHoverBackgroundColor:l,secondaryButtonBackgroundColor:D(t,"secondaryButtonBackgroundColor")?e.secondaryButtonBackgroundColor:"#ffffff",secondaryButtonTextColor:D(t,"secondaryButtonTextColor")?e.secondaryButtonTextColor:a,secondaryButtonBorderColor:D(t,"secondaryButtonBorderColor")?e.secondaryButtonBorderColor:s,secondaryButtonHoverBackgroundColor:D(t,"secondaryButtonHoverBackgroundColor")?e.secondaryButtonHoverBackgroundColor:n,iconButtonBackgroundColor:D(t,"iconButtonBackgroundColor")?e.iconButtonBackgroundColor:"#ffffff",iconButtonIconColor:D(t,"iconButtonIconColor")?e.iconButtonIconColor:a,iconButtonBorderColor:D(t,"iconButtonBorderColor")?e.iconButtonBorderColor:s,iconButtonHoverBackgroundColor:D(t,"iconButtonHoverBackgroundColor")?e.iconButtonHoverBackgroundColor:n}},Oe=e=>{const t=e.fabBackgroundColor||e.openFabBackgroundColor||q.fabBackgroundColor,a=e.fabIconColor||e.openFabIconColor||q.fabIconColor;return{...e,fabBackgroundColor:t,fabIconColor:a,openFabBackgroundColor:t,openFabIconColor:a}},Se=(e={})=>Oe(qe({...q,...e,position:Ie(e.position??q.position)},e)),te=e=>({...Le(e.position),"--widget-width":e.width,"--widget-height":e.height,"--bpGray-1":"var(--ui-bg)","--bpGray-50":"var(--ui-bg-subtle)","--bpGray-100":"var(--ui-bg-muted)","--bpGray-200":"var(--ui-border)","--bpGray-300":"var(--ui-border-strong)","--bpGray-400":"var(--ui-text-muted)","--bpGray-500":"var(--ui-text-muted)","--bpGray-600":"var(--ui-text-muted)","--bpGray-700":"var(--ui-text)","--bpGray-800":"var(--ui-text)","--bpGray-900":"var(--ui-text)","--bpGray-950":"var(--ui-text)","--accent-color":e.accentColor,"--accent-text-color":re(e.accentColor),"--header-avatar-bg":e.accentColor,"--header-avatar-text":re(e.accentColor),"--primary-button-background-color":e.primaryButtonBackgroundColor,"--primary-button-text-color":e.primaryButtonTextColor,"--primary-button-hover-background-color":e.primaryButtonHoverBackgroundColor,"--panel-background-color":e.panelBackgroundColor,"--panel-elevated-background-color":e.panelElevatedBackgroundColor,"--panel-subtle-background-color":e.panelSubtleBackgroundColor,"--panel-muted-background-color":e.panelMutedBackgroundColor,"--panel-hover-background-color":e.panelHoverBackgroundColor,"--panel-selected-background-color":e.panelSelectedBackgroundColor,"--panel-border-color":e.panelBorderColor,"--panel-strong-border-color":e.panelStrongBorderColor,"--panel-text-color":e.panelTextColor,"--panel-muted-text-color":e.panelMutedTextColor,"--panel-header-background-color":e.panelHeaderBackgroundColor,"--welcome-background":e.welcomeBackground,"--welcome-hero-background":e.welcomeHeroBackground,"--welcome-online-status-color":e.welcomeOnlineStatusColor,"--secondary-button-background-color":e.secondaryButtonBackgroundColor,"--secondary-button-text-color":e.secondaryButtonTextColor,"--secondary-button-border-color":e.secondaryButtonBorderColor,"--secondary-button-hover-background-color":e.secondaryButtonHoverBackgroundColor,"--icon-button-background-color":e.iconButtonBackgroundColor,"--icon-button-icon-color":e.iconButtonIconColor,"--icon-button-border-color":e.iconButtonBorderColor,"--icon-button-hover-background-color":e.iconButtonHoverBackgroundColor,"--outgoing-message-background-color":e.outgoingMessageBackgroundColor,"--outgoing-message-text-color":e.outgoingMessageTextColor,"--incoming-message-background-color":e.incomingMessageBackgroundColor,"--incoming-message-text-color":e.incomingMessageTextColor,"--message-bg":e.outgoingMessageBackgroundColor,"--message-text":e.outgoingMessageTextColor,"--message-bg-hover":e.outgoingMessageBackgroundColor,"--send-button-bg":e.primaryButtonBackgroundColor,"--send-button-bg-hover":e.primaryButtonHoverBackgroundColor,"--send-button-text":e.primaryButtonTextColor,"--button-bg":e.secondaryButtonBackgroundColor,"--button-bg-hover":e.secondaryButtonHoverBackgroundColor,"--button-text":e.secondaryButtonTextColor,"--fab-background-color":e.fabBackgroundColor,"--fab-icon-color":e.fabIconColor}),We=e=>({color:e.color||e.accentColor,fontFamily:e.fontFamily,radius:e.radius,themeMode:e.themeMode,variant:e.variant,headerVariant:e.headerVariant,additionalStylesheet:e.additionalStylesheet,additionalStylesheetUrl:e.additionalStylesheetUrl});const Ge=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ke=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,a,r)=>r?r.toUpperCase():a.toLowerCase()),Ce=e=>{const t=Ke(e);return t.charAt(0).toUpperCase()+t.slice(1)},Te=(...e)=>e.filter((t,a,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===a).join(" ").trim(),Je=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};var Xe={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const Ze=c.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:a=2,absoluteStrokeWidth:r,className:s="",children:n,iconNode:l,...i},u)=>c.createElement("svg",{ref:u,...Xe,width:t,height:t,stroke:e,strokeWidth:r?Number(a)*24/Number(t):a,className:Te("lucide",s),...!n&&!Je(i)&&{"aria-hidden":"true"},...i},[...l.map(([f,p])=>c.createElement(f,p)),...Array.isArray(n)?n:[n]]));const I=(e,t)=>{const a=c.forwardRef(({className:r,...s},n)=>c.createElement(Ze,{ref:n,iconNode:t,className:Te(`lucide-${Ge(Ce(e))}`,`lucide-${e}`,r),...s}));return a.displayName=Ce(e),a};const Ye=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],Qe=I("arrow-right",Ye);const et=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],tt=I("chevron-down",et);const ot=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],at=I("chevron-right",ot);const nt=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],rt=I("house",nt);const st=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}],["path",{d:"M8 12h.01",key:"czm47f"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}]],ct=I("message-circle-more",st);const lt=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]],it=I("message-circle",lt);const dt=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]],Ae=I("message-square",dt);const ut=[["path",{d:"M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z",key:"1n2ejm"}],["path",{d:"M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1",key:"1qfcsi"}]],Re=I("messages-square",ut);const bt=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],ht=I("rotate-ccw",bt);const mt=[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]],pt=I("square-pen",mt);const ft=[["path",{d:"M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z",key:"m61m77"}],["path",{d:"M17 14V2",key:"8ymqnk"}]],wt=I("thumbs-down",ft);const gt=[["path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z",key:"emmmcr"}],["path",{d:"M7 10v12",key:"1qc93n"}]],xt=I("thumbs-up",gt);const yt=[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],vt=I("user-round",yt);const Ct=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Ue=I("x",Ct),C={"aria-hidden":!0,strokeWidth:1.9},kt=o.jsx(ht,{...C}),be=o.jsx(Ue,{...C}),Bt=o.jsx(Ue,{...C}),ke={"message-circle-more":o.jsx(ct,{...C}),"message-circle":o.jsx(it,{...C}),"message-square":o.jsx(Ae,{...C}),"messages-square":o.jsx(Re,{...C})},jt=(e="messages-square")=>ke[e]||ke["messages-square"],Nt=o.jsx(Qe,{...C}),Ve=o.jsx(rt,{...C}),It=o.jsx(Ae,{...C}),Mt=o.jsx(xt,{...C}),St=o.jsx(wt,{...C}),Tt=o.jsx(Re,{...C}),At=o.jsx(at,{...C}),Rt=o.jsx(tt,{...C}),Ut=o.jsx(pt,{...C}),Vt=o.jsx(vt,{...C}),de=e=>String(e).replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'"),Ft=({name:e,backgroundColor:t})=>{const a=(e||"B").trim().charAt(0).toUpperCase()||"B",r=re(t),s=`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./style.css');const o=require("react/jsx-runtime"),c=require("react"),E=require("@botpress/webchat"),O={botName:"Assistente Virtual",subtitle:"Conectado ao bot real",botAvatar:"",color:"",themeMode:"light",variant:"solid",headerVariant:"glass",radius:4,fontFamily:"Inter",additionalStylesheet:"",additionalStylesheetUrl:"",accentColor:"#2563eb",brandColor:"#18181b",brandTextColor:"#fafafa",placeholder:"Escreva uma mensagem...",fabBackgroundColor:"#2563eb",fabIconColor:"#ffffff",fabChatIconVariant:"messages-square",primaryButtonBackgroundColor:"#18181b",primaryButtonTextColor:"#fafafa",primaryButtonHoverBackgroundColor:"#27272a",panelBackgroundColor:"#ffffff",panelElevatedBackgroundColor:"#ffffff",panelSubtleBackgroundColor:"#fafafa",panelMutedBackgroundColor:"#f4f4f5",panelHoverBackgroundColor:"#f4f4f5",panelSelectedBackgroundColor:"#f5f5f5",panelBorderColor:"#e4e4e7",panelStrongBorderColor:"#d4d4d8",panelTextColor:"#18181b",panelMutedTextColor:"#71717a",panelHeaderBackgroundColor:"rgba(255, 255, 255, 0.96)",welcomeBackground:"linear-gradient(180deg, #f4f4f5 0%, #fafafa 34%, #ffffff 34%, #ffffff 100%)",welcomeHeroBackground:"linear-gradient(180deg, #f5f5f5 0%, #efeff1 100%)",welcomeOnlineStatusColor:"#16a34a",secondaryButtonBackgroundColor:"#ffffff",secondaryButtonTextColor:"#18181b",secondaryButtonBorderColor:"#e4e4e7",secondaryButtonHoverBackgroundColor:"#f4f4f5",iconButtonBackgroundColor:"#ffffff",iconButtonIconColor:"#71717a",iconButtonBorderColor:"#e4e4e7",iconButtonHoverBackgroundColor:"#f4f4f5",outgoingMessageBackgroundColor:"#ebf1fd",outgoingMessageTextColor:"#0f2346",incomingMessageBackgroundColor:"#f0f0f3",incomingMessageTextColor:"#202127",position:"bottom-right",initiallyOpen:!0,showWelcomeScreen:!0,width:"380px",height:"640px",welcomeCoverImage:"",welcomeCardImage:"",welcomeCardTitle:"Suporte",welcomeCardStatus:"Online agora!",welcomeCardDescription:"Estamos disponíveis para esclarecer qualquer dúvida que você possa ter. Sinta-se a vontade para nos contatar a qualquer momento.",welcomeCtaLabel:"Iniciar atendimento",welcomeButtonDescription:"",welcomeCloseLabel:"Fechar painel",openFabBackgroundColor:"#2563eb",openFabIconColor:"#ffffff"},Se=e=>e==="bottom-left"||e==="top-left"?"bottom-left":"bottom-right",Qe=e=>{switch(Se(e)){case"bottom-left":return{bottom:"24px",left:"24px","--widget-align":"flex-start","--panel-transform-origin":"left bottom"};case"bottom-right":default:return{bottom:"24px",right:"24px","--widget-align":"flex-end","--panel-transform-origin":"right bottom"}}},Te=(e,t,a)=>Math.min(Math.max(e,t),a),ve=e=>{if(typeof e!="string")return null;let t=e.trim();return!t||(t.startsWith("#")&&(t=t.slice(1)),t.length===3&&(t=t.split("").map(a=>`${a}${a}`).join("")),!/^[0-9a-fA-F]{6}$/.test(t))?null:`#${t.toLowerCase()}`},Ce=e=>{const t=ve(e);if(!t)return null;const a=t.slice(1);return{r:Number.parseInt(a.slice(0,2),16),g:Number.parseInt(a.slice(2,4),16),b:Number.parseInt(a.slice(4,6),16)}},et=({r:e,g:t,b:a})=>`#${[e,t,a].map(r=>Te(Math.round(r),0,255).toString(16).padStart(2,"0")).join("")}`,ue=(e,t,a)=>{const r=Ce(e),s=Ce(t);if(!r||!s)return null;const n=Te(a,0,1);return et({r:r.r*(1-n)+s.r*n,g:r.g*(1-n)+s.g*n,b:r.b*(1-n)+s.b*n})},tt=(e,t)=>t<0?ue(e,"#000000",Math.abs(t)):ue(e,"#ffffff",t),se=e=>{const t=Ce(e);return t&&[t.r,t.g,t.b].map(r=>{const s=r/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4}).reduce((r,s,n)=>r+s*[.2126,.7152,.0722][n],0)>.42?"#18181b":"#ffffff"},D=(e,t)=>e&&Object.prototype.hasOwnProperty.call(e,t)&&e[t]!=null&&e[t]!=="",ot=(e,t)=>{const a=ve(e.brandColor);if(!a)return e;const r=ve(e.brandTextColor)||se(a),s=ue(a,"#ffffff",.82)||O.secondaryButtonBorderColor,n=ue(a,"#ffffff",.92)||O.secondaryButtonHoverBackgroundColor,l=tt(a,-.12)||O.primaryButtonHoverBackgroundColor;return{...e,brandColor:a,brandTextColor:r,primaryButtonBackgroundColor:D(t,"primaryButtonBackgroundColor")?e.primaryButtonBackgroundColor:a,primaryButtonTextColor:D(t,"primaryButtonTextColor")?e.primaryButtonTextColor:r,primaryButtonHoverBackgroundColor:D(t,"primaryButtonHoverBackgroundColor")?e.primaryButtonHoverBackgroundColor:l,secondaryButtonBackgroundColor:D(t,"secondaryButtonBackgroundColor")?e.secondaryButtonBackgroundColor:"#ffffff",secondaryButtonTextColor:D(t,"secondaryButtonTextColor")?e.secondaryButtonTextColor:a,secondaryButtonBorderColor:D(t,"secondaryButtonBorderColor")?e.secondaryButtonBorderColor:s,secondaryButtonHoverBackgroundColor:D(t,"secondaryButtonHoverBackgroundColor")?e.secondaryButtonHoverBackgroundColor:n,iconButtonBackgroundColor:D(t,"iconButtonBackgroundColor")?e.iconButtonBackgroundColor:"#ffffff",iconButtonIconColor:D(t,"iconButtonIconColor")?e.iconButtonIconColor:a,iconButtonBorderColor:D(t,"iconButtonBorderColor")?e.iconButtonBorderColor:s,iconButtonHoverBackgroundColor:D(t,"iconButtonHoverBackgroundColor")?e.iconButtonHoverBackgroundColor:n}},at=e=>{const t=e.fabBackgroundColor||e.openFabBackgroundColor||O.fabBackgroundColor,a=e.fabIconColor||e.openFabIconColor||O.fabIconColor;return{...e,fabBackgroundColor:t,fabIconColor:a,openFabBackgroundColor:t,openFabIconColor:a}},Ae=(e={})=>at(ot({...O,...e,position:Se(e.position??O.position)},e)),oe=e=>({...Qe(e.position),"--widget-width":e.width,"--widget-height":e.height,"--bpGray-1":"var(--ui-bg)","--bpGray-50":"var(--ui-bg-subtle)","--bpGray-100":"var(--ui-bg-muted)","--bpGray-200":"var(--ui-border)","--bpGray-300":"var(--ui-border-strong)","--bpGray-400":"var(--ui-text-muted)","--bpGray-500":"var(--ui-text-muted)","--bpGray-600":"var(--ui-text-muted)","--bpGray-700":"var(--ui-text)","--bpGray-800":"var(--ui-text)","--bpGray-900":"var(--ui-text)","--bpGray-950":"var(--ui-text)","--accent-color":e.accentColor,"--accent-text-color":se(e.accentColor),"--header-avatar-bg":e.accentColor,"--header-avatar-text":se(e.accentColor),"--primary-button-background-color":e.primaryButtonBackgroundColor,"--primary-button-text-color":e.primaryButtonTextColor,"--primary-button-hover-background-color":e.primaryButtonHoverBackgroundColor,"--panel-background-color":e.panelBackgroundColor,"--panel-elevated-background-color":e.panelElevatedBackgroundColor,"--panel-subtle-background-color":e.panelSubtleBackgroundColor,"--panel-muted-background-color":e.panelMutedBackgroundColor,"--panel-hover-background-color":e.panelHoverBackgroundColor,"--panel-selected-background-color":e.panelSelectedBackgroundColor,"--panel-border-color":e.panelBorderColor,"--panel-strong-border-color":e.panelStrongBorderColor,"--panel-text-color":e.panelTextColor,"--panel-muted-text-color":e.panelMutedTextColor,"--panel-header-background-color":e.panelHeaderBackgroundColor,"--welcome-background":e.welcomeBackground,"--welcome-hero-background":e.welcomeHeroBackground,"--welcome-online-status-color":e.welcomeOnlineStatusColor,"--secondary-button-background-color":e.secondaryButtonBackgroundColor,"--secondary-button-text-color":e.secondaryButtonTextColor,"--secondary-button-border-color":e.secondaryButtonBorderColor,"--secondary-button-hover-background-color":e.secondaryButtonHoverBackgroundColor,"--icon-button-background-color":e.iconButtonBackgroundColor,"--icon-button-icon-color":e.iconButtonIconColor,"--icon-button-border-color":e.iconButtonBorderColor,"--icon-button-hover-background-color":e.iconButtonHoverBackgroundColor,"--outgoing-message-background-color":e.outgoingMessageBackgroundColor,"--outgoing-message-text-color":e.outgoingMessageTextColor,"--incoming-message-background-color":e.incomingMessageBackgroundColor,"--incoming-message-text-color":e.incomingMessageTextColor,"--message-bg":e.outgoingMessageBackgroundColor,"--message-text":e.outgoingMessageTextColor,"--message-bg-hover":e.outgoingMessageBackgroundColor,"--send-button-bg":e.primaryButtonBackgroundColor,"--send-button-bg-hover":e.primaryButtonHoverBackgroundColor,"--send-button-text":e.primaryButtonTextColor,"--button-bg":e.secondaryButtonBackgroundColor,"--button-bg-hover":e.secondaryButtonHoverBackgroundColor,"--button-text":e.secondaryButtonTextColor,"--fab-background-color":e.fabBackgroundColor,"--fab-icon-color":e.fabIconColor}),nt=e=>({color:e.color||e.accentColor,fontFamily:e.fontFamily,radius:e.radius,themeMode:e.themeMode,variant:e.variant,headerVariant:e.headerVariant,additionalStylesheet:e.additionalStylesheet,additionalStylesheetUrl:e.additionalStylesheetUrl});const rt=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),st=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,a,r)=>r?r.toUpperCase():a.toLowerCase()),Be=e=>{const t=st(e);return t.charAt(0).toUpperCase()+t.slice(1)},Re=(...e)=>e.filter((t,a,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===a).join(" ").trim(),ct=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};var lt={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const it=c.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:a=2,absoluteStrokeWidth:r,className:s="",children:n,iconNode:l,...i},u)=>c.createElement("svg",{ref:u,...lt,width:t,height:t,stroke:e,strokeWidth:r?Number(a)*24/Number(t):a,className:Re("lucide",s),...!n&&!ct(i)&&{"aria-hidden":"true"},...i},[...l.map(([f,p])=>c.createElement(f,p)),...Array.isArray(n)?n:[n]]));const I=(e,t)=>{const a=c.forwardRef(({className:r,...s},n)=>c.createElement(it,{ref:n,iconNode:t,className:Re(`lucide-${rt(Be(e))}`,`lucide-${e}`,r),...s}));return a.displayName=Be(e),a};const dt=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],ut=I("arrow-right",dt);const bt=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],ht=I("chevron-down",bt);const mt=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],pt=I("chevron-right",mt);const ft=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],wt=I("house",ft);const gt=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}],["path",{d:"M8 12h.01",key:"czm47f"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}]],xt=I("message-circle-more",gt);const yt=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]],vt=I("message-circle",yt);const Ct=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]],Ue=I("message-square",Ct);const kt=[["path",{d:"M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z",key:"1n2ejm"}],["path",{d:"M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1",key:"1qfcsi"}]],Ve=I("messages-square",kt);const Bt=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],jt=I("rotate-ccw",Bt);const Nt=[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]],It=I("square-pen",Nt);const Mt=[["path",{d:"M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z",key:"m61m77"}],["path",{d:"M17 14V2",key:"8ymqnk"}]],St=I("thumbs-down",Mt);const Tt=[["path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z",key:"emmmcr"}],["path",{d:"M7 10v12",key:"1qc93n"}]],At=I("thumbs-up",Tt);const Rt=[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],Ut=I("user-round",Rt);const Vt=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Fe=I("x",Vt),k={"aria-hidden":!0,strokeWidth:1.9},Ft=o.jsx(jt,{...k}),be=o.jsx(Fe,{...k}),Dt=o.jsx(Fe,{...k}),je={"message-circle-more":o.jsx(xt,{...k}),"message-circle":o.jsx(vt,{...k}),"message-square":o.jsx(Ue,{...k}),"messages-square":o.jsx(Ve,{...k})},Et=(e="messages-square")=>je[e]||je["messages-square"],Pt=o.jsx(ut,{...k}),De=o.jsx(wt,{...k}),Ht=o.jsx(Ue,{...k}),$t=o.jsx(At,{...k}),Lt=o.jsx(St,{...k}),_t=o.jsx(Ve,{...k}),zt=o.jsx(pt,{...k}),qt=o.jsx(ht,{...k}),Ot=o.jsx(It,{...k}),Wt=o.jsx(Ut,{...k}),de=e=>String(e).replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'"),Gt=({name:e,backgroundColor:t})=>{const a=(e||"B").trim().charAt(0).toUpperCase()||"B",r=se(t),s=`
|
|
2
2
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96" role="img" aria-label="${de(e||"Bot")}">
|
|
3
3
|
<rect width="96" height="96" rx="48" fill="${de(t)}" />
|
|
4
4
|
<text x="50%" y="52%" dominant-baseline="middle" text-anchor="middle" font-family="Arial, Helvetica, sans-serif" font-size="42" font-weight="700" fill="${de(r)}">${de(a)}</text>
|
|
5
5
|
</svg>
|
|
6
|
-
`.trim();return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(s)}`},Dt=e=>e?e.payload?.type==="text"?e.payload.text:e.payload?.type==="bloc"&&e.payload.items?.some(t=>t.type==="text")?e.payload.items.find(a=>a.type==="text")?.payload.text??"Conversa sem mensagens":"Anexo enviado":"Conversa sem mensagens",Be=[{unit:"minute",seconds:60},{unit:"hour",seconds:3600},{unit:"day",seconds:3600*24},{unit:"week",seconds:3600*24*7},{unit:"month",seconds:3600*24*30},{unit:"year",seconds:3600*24*365}],Et=new Intl.RelativeTimeFormat("pt-BR",{numeric:"auto"}),Pt=e=>{const t=Math.round((new Date(e).getTime()-Date.now())/1e3);if(Math.abs(t)<45)return"agora";let a=Be[0];for(const r of Be)Math.abs(t)>=r.seconds&&(a=r);return Et.format(Math.round(t/a.seconds),a.unit)},Ht=({messages:e,user:t,botName:a,botAvatar:r})=>e.map(s=>{const n=s.authorId===t?.userId;return{...s,direction:n?"outgoing":"incoming",sender:n?{name:t?.name??"Você",avatar:t?.pictureUrl}:{name:a,avatar:r}}}),$t=({activeView:e,clientState:t,conversationId:a,messagesLength:r})=>{const[s,n]=c.useState(!1),l=e==="chat",i=l&&t==="connecting",u=l&&t==="connected"&&r===0,f=s&&(!l||r>0||t!=="connecting"&&t!=="connected");return c.useEffect(()=>{if(s){if(u){const p=window.setTimeout(()=>n(!1),900);return()=>window.clearTimeout(p)}if(f){const p=window.setTimeout(()=>n(!1),0);return()=>window.clearTimeout(p)}}},[a,s,u,f]),{showInitialLoading:i||s&&l,setShowInitialLoading:n}},Lt=3e4,_t=({getSession:e,sessionKey:t,onSessionChange:a})=>{const[r,s]=c.useState(null),[n,l]=c.useState(!!e),i=c.useRef(e);i.current=e;const u=c.useRef(a);return u.current=a,c.useEffect(()=>{let f=!0,p;const b=w=>{f&&(s(w),u.current?.(w))};if(!i.current){l(!1),b(null);return}const M=async()=>{try{const w=await i.current();if(!w?.userToken)throw new Error("Webchat session not created or empty");if(!f)return;b(w);const v=w.expiresAt-Date.now()-Lt;p=setTimeout(M,Math.max(v,0))}catch(w){console.error("[EduzzWebchat] error creating session: ",w),b(null)}finally{f&&l(!1)}};return l(!0),M(),()=>{f=!1,p&&clearTimeout(p)}},[t,!!e]),{session:r,resolving:n}};function zt({botName:e,botAvatar:t,subtitle:a,onShowHome:r,onOpenHistory:s,onRestartConversation:n,onCloseWidget:l}){return o.jsxs("div",{className:"bp-webchat-header",children:[o.jsxs("div",{className:"bp-webchat-header-meta",children:[o.jsx("div",{className:"bp-webchat-avatar",children:t?o.jsx("img",{src:t,alt:""}):o.jsx("span",{children:(e||"B").slice(0,1).toUpperCase()})}),o.jsxs("div",{className:"bp-webchat-header-text",children:[o.jsx("h2",{className:"bp-webchat-header-title",children:e}),o.jsx("p",{className:"bp-webchat-header-subtitle",children:a})]})]}),o.jsxs("div",{className:"bp-webchat-header-actions",children:[r?o.jsx("button",{className:"bp-webchat-icon-button",type:"button","aria-label":"Abrir início",onClick:r,children:Ve}):null,o.jsx("button",{className:"bp-webchat-icon-button",type:"button","aria-label":"Abrir conversas",onClick:s,children:Tt}),o.jsx("button",{className:"bp-webchat-icon-button",type:"button","aria-label":"Reiniciar conversa",onClick:n,children:kt}),l?o.jsx("button",{className:"bp-webchat-icon-button bp-webchat-mobile-close",type:"button","aria-label":"Fechar webchat",onClick:l,children:be}):null]})]})}function Fe(){return o.jsxs("div",{className:"bp-webchat-loading",children:[o.jsxs("div",{className:"bp-webchat-loading-hero",children:[o.jsx("div",{className:"bp-webchat-loading-circle"}),o.jsx("div",{className:"bp-webchat-loading-line bp-webchat-loading-line--title"}),o.jsx("div",{className:"bp-webchat-loading-line bp-webchat-loading-line--subtitle"})]}),o.jsxs("div",{className:"bp-webchat-loading-bubble",children:[o.jsx("div",{className:"bp-webchat-loading-line",style:{width:"82%",height:"12px"}}),o.jsx("div",{className:"bp-webchat-loading-line",style:{width:"58%",height:"12px"}})]}),o.jsx("div",{className:"bp-webchat-loading-bubble bp-webchat-loading-bubble--right",children:o.jsx("div",{className:"bp-webchat-loading-line",style:{width:"72%",height:"12px"}})}),o.jsxs("div",{className:"bp-webchat-loading-composer",children:[o.jsx("div",{className:"bp-webchat-loading-input"}),o.jsx("div",{className:"bp-webchat-loading-mic"})]})]})}function qt({config:e,allowFileUpload:t,clientState:a,isTyping:r,messages:s,renderers:n,sendMessage:l,uploadFile:i,addMessageFeedback:u,showInitialLoading:f,onShowHome:p,onOpenHistory:b,onRestartConversation:M,onCloseWidget:w}){return o.jsxs("div",{className:"bp-webchat-layout",children:[o.jsx(zt,{botName:e.botName,botAvatar:e.botAvatar,subtitle:e.subtitle,onShowHome:p,onOpenHistory:b,onRestartConversation:M,onCloseWidget:w}),o.jsx(_.Container,{className:"bp-webchat-container",uploadFile:i,allowFileUpload:t,children:f?o.jsx(Fe,{}):o.jsxs(o.Fragment,{children:[o.jsx(_.MessageList,{botName:e.botName,botDescription:e.subtitle,botAvatar:e.botAvatar,isTyping:r,messages:s,sendMessage:l,addMessageFeedback:u,renderers:n,showDateSystemMessage:!1,showMessageStatus:!1,showIncomingMessageAvatar:!0,showOutgoingMessageAvatar:!1}),o.jsx(_.Composer,{connected:a!=="disconnected",sendMessage:l,uploadFile:i,allowFileUpload:t,composerPlaceholder:e.placeholder,disableSendButton:!1})]})})]})}function De({activeView:e,onShowHome:t,onShowConversations:a}){return o.jsxs("div",{className:"bp-webchat-tabs bp-webchat-welcome-bottom",children:[o.jsxs("button",{className:"bp-webchat-tab bp-webchat-welcome-tab","data-active":e==="home",type:"button",onClick:t,children:[o.jsx("span",{className:"bp-webchat-tab-icon bp-webchat-welcome-tab-icon",children:Ve}),o.jsx("span",{children:"Início"})]}),o.jsxs("button",{className:"bp-webchat-tab bp-webchat-welcome-tab","data-active":e==="conversations",type:"button",onClick:a,children:[o.jsx("span",{className:"bp-webchat-tab-icon bp-webchat-welcome-tab-icon",children:It}),o.jsx("span",{children:"Conversas"})]})]})}function Ot({conversations:e,currentConversationId:t,isLoading:a,botAvatar:r,botName:s,onClose:n,onCloseWidget:l,onShowHome:i,onShowConversations:u,onNewConversation:f,onConversationClick:p}){return o.jsxs("div",{className:"bp-webchat-history",children:[o.jsxs("div",{className:"bp-webchat-history-header",children:[o.jsx("h2",{className:"bp-webchat-history-title",children:"Conversas"}),o.jsxs("div",{className:"bp-webchat-header-actions",children:[o.jsx("button",{className:"bp-webchat-icon-button",type:"button",onClick:n,"aria-label":"Fechar conversas",children:be}),l?o.jsx("button",{className:"bp-webchat-icon-button bp-webchat-mobile-close",type:"button",onClick:l,"aria-label":"Fechar webchat",children:be}):null]})]}),o.jsx("div",{className:"bp-webchat-history-list",children:a?o.jsx("div",{className:"bp-webchat-history-loading",children:"Carregando conversas..."}):e.length===0?o.jsx("div",{className:"bp-webchat-history-empty",children:"Nenhuma conversa iniciada ainda."}):e.map(b=>{const M=Dt(b.lastMessage),w=b.lastMessage?.author?.type==="bot";return o.jsxs("button",{className:"bp-webchat-history-item",type:"button",onClick:()=>p(b.id),"data-current":b.id===t||void 0,children:[o.jsx("div",{className:"bp-webchat-history-avatar","data-kind":w?"bot":"user",children:w&&r?o.jsx("img",{src:r,alt:""}):w?o.jsx("span",{children:(s||"B").slice(0,1).toUpperCase()}):Vt}),o.jsxs("div",{className:"bp-webchat-history-content",children:[o.jsx("span",{className:"bp-webchat-history-name",children:M}),o.jsx("span",{className:"bp-webchat-history-time",children:Pt(b.updatedAt)})]}),o.jsx("span",{className:"bp-webchat-history-chevron",children:At})]},b.id)})}),o.jsx("div",{className:"bp-webchat-history-footer",children:o.jsxs("button",{className:"bp-webchat-history-new",type:"button",onClick:f,children:[Ut,o.jsx("span",{children:"Nova conversa"})]})}),o.jsx(De,{activeView:"conversations",onShowHome:i,onShowConversations:u})]})}const je=e=>String(e??"").normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().trim();function Wt(e){const{label:t,options:a=[],sendMessage:r,isReadOnly:s,messageId:n}=e,[l,i]=c.useState(!1),[u,f]=c.useState(""),[p,b]=c.useState(0),[M,w]=c.useState(null),v=c.useRef(null),R=c.useRef([]),E=s||M!==null||a.length===0,S=c.useMemo(()=>{const d=je(u);return d?a.filter(m=>je(m.label).includes(d)):a},[a,u]);c.useEffect(()=>{b(0)},[u]),c.useEffect(()=>{if(!l)return;const d=m=>{v.current&&!v.current.contains(m.target)&&i(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[l]),c.useEffect(()=>{l&&R.current[p]?.scrollIntoView({block:"nearest"})},[p,l]);const z=d=>{d&&(r?.({type:"text",text:d.label,value:d.value}),w(d.label),f(""),i(!1))},O=d=>{if(!E)switch(d.key){case"ArrowDown":if(d.preventDefault(),!l){i(!0);return}b(m=>Math.min(m+1,S.length-1));break;case"ArrowUp":d.preventDefault(),b(m=>Math.max(m-1,0));break;case"Enter":d.preventDefault(),l&&z(S[p]);break;case"Escape":i(!1);break}},k=`bpDropdownList-${n??"x"}`;return o.jsxs("div",{className:"bpDropdown","data-open":l||void 0,"data-disabled":E||void 0,ref:v,children:[t?o.jsx("span",{className:"bpDropdownLabel",children:t}):null,o.jsxs("div",{className:"bpDropdownControl",children:[o.jsx("input",{className:"bpDropdownInput",type:"text",role:"combobox","aria-expanded":l,"aria-controls":k,"aria-autocomplete":"list",autoComplete:"off",placeholder:"Selecione...",value:M??u,disabled:E,onFocus:()=>{E||i(!0)},onChange:d=>{f(d.target.value),i(!0)},onKeyDown:O}),o.jsx("span",{className:"bpDropdownChevron",children:Rt})]}),l&&!E?o.jsx("ul",{className:"bpDropdownMenu",id:k,role:"listbox",children:S.length>0?S.map((d,m)=>o.jsx("li",{ref:T=>{R.current[m]=T},className:"bpDropdownOption",role:"option","aria-selected":m===p,"data-active":m===p||void 0,onMouseEnter:()=>b(m),onMouseDown:T=>{T.preventDefault(),z(d)},children:d.label},d.value)):o.jsx("li",{className:"bpDropdownEmpty",role:"presentation",children:"Nenhuma opção encontrada"})}):null]})}function Gt({open:e,draft:t,setDraft:a,onConfirm:r,onCancel:s}){return e?o.jsx("div",{className:"bp-webchat-modal-backdrop",children:o.jsxs("div",{className:"bp-webchat-modal",children:[o.jsx("h3",{className:"bp-webchat-modal-title",children:"Nos ajude a melhorar"}),o.jsx("p",{className:"bp-webchat-modal-description",children:"Conte o que não ficou bom nesta resposta."}),o.jsx("div",{className:"bp-webchat-modal-field-wrap",children:o.jsx("textarea",{className:"bp-webchat-modal-textarea",value:t,onChange:n=>a(n.target.value),placeholder:"Descreva o problema encontrado..."})}),o.jsxs("div",{className:"bp-webchat-modal-actions",children:[o.jsx("button",{className:"bp-webchat-modal-button bp-webchat-modal-button--primary",type:"button",onClick:r,children:"Enviar feedback"}),o.jsx("button",{className:"bp-webchat-modal-button",type:"button",onClick:s,children:"Cancelar"})]})]})}):null}function Kt({open:e,onConfirm:t,onCancel:a}){return e?o.jsx("div",{className:"bp-webchat-modal-backdrop",children:o.jsxs("div",{className:"bp-webchat-modal",children:[o.jsx("h3",{className:"bp-webchat-modal-title",children:"Criar nova conversa"}),o.jsx("p",{className:"bp-webchat-modal-description",children:"Isso vai limpar a conversa atual e iniciar uma nova sessão com o bot."}),o.jsxs("div",{className:"bp-webchat-modal-actions",children:[o.jsx("button",{className:"bp-webchat-modal-button bp-webchat-modal-button--primary",type:"button",onClick:t,children:"Nova conversa"}),o.jsx("button",{className:"bp-webchat-modal-button",type:"button",onClick:a,children:"Cancelar"})]})]})}):null}function Jt({config:e,activeView:t,onShowHome:a,onShowConversations:r,onStart:s,onClose:n}){const l=e.welcomeCardImage||e.botAvatar;return o.jsxs("div",{className:"bp-webchat-welcome",children:[o.jsxs("div",{className:"bp-webchat-welcome-hero",children:[o.jsx("button",{className:"bp-webchat-icon-button bp-webchat-welcome-close",type:"button",onClick:n,"aria-label":e.welcomeCloseLabel,children:be}),e.welcomeCoverImage?o.jsx("img",{className:"bp-webchat-welcome-cover",src:e.welcomeCoverImage,alt:""}):null]}),o.jsx("div",{className:"bp-webchat-welcome-card-wrap",children:o.jsxs("div",{className:"bp-webchat-welcome-card",children:[o.jsx("div",{className:"bp-webchat-welcome-card-badge",children:l?o.jsx("img",{src:l,alt:""}):o.jsx("span",{children:(e.botName||"B").slice(0,1).toUpperCase()})}),o.jsx("h3",{className:"bp-webchat-welcome-card-title",children:e.welcomeCardTitle}),o.jsx("p",{className:"bp-webchat-welcome-card-status",children:o.jsx("strong",{children:e.welcomeCardStatus})}),o.jsx("p",{className:"bp-webchat-welcome-card-description",children:e.welcomeCardDescription}),o.jsxs("button",{className:"bp-webchat-welcome-cta",type:"button",onClick:s,children:[o.jsx("span",{className:"bp-webchat-welcome-cta-left",children:o.jsxs("span",{className:"bp-webchat-welcome-cta-copy",children:[o.jsx("span",{className:"bp-webchat-welcome-cta-title",children:e.welcomeCtaLabel}),e.welcomeButtonDescription?o.jsx("span",{className:"bp-webchat-welcome-cta-description",children:e.welcomeButtonDescription}):null]})}),o.jsx("span",{className:"bp-webchat-welcome-cta-right",children:Nt})]})]})}),o.jsx(De,{activeView:t,onShowHome:a,onShowConversations:r})]})}const Xt=220,he="eduzz-webchat",ge=Object.freeze({allowFileUpload:!1,allowMessageFeedback:!1}),Zt="anonymous-id",Yt=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Ee=e=>e.replace(/\/+$/,""),ve=({webchatProxyUrl:e})=>{if(typeof e!="string"||!e.trim())return null;const t=Ee(e.trim()),a="/webchat/proxy";return t.endsWith(a)?t.slice(0,-a.length):null},Qt=({webchatProxyUrl:e,clientId:t})=>!e||!t?null:`${e.endsWith("/")?e.slice(0,-1):e}/${encodeURIComponent(t)}/runtime-config`,eo=({webchatProxyUrl:e,clientId:t,presetSlug:a})=>{if(!e||!t)return null;const r=ve({webchatProxyUrl:e});if(!r)return null;const s=new URLSearchParams;typeof a=="string"&&a.trim()&&s.set("slug",a.trim());const n=s.toString();return`${r}/webchat/bootstrap/${encodeURIComponent(t)}${n?`?${n}`:""}`},to=e=>{const t=e&&typeof e=="object"&&e.data&&typeof e.data=="object"?e.data:e;return t&&typeof t=="object"?t:null},oe=e=>Yt(e)?e:null,oo=e=>{if(!e)return"";try{return JSON.stringify(e)}catch{return String(Date.now())}},Pe=e=>{if(typeof window>"u")return null;try{return e==="sessionStorage"?window.sessionStorage:window.localStorage}catch{return null}},He=({storageKey:e,storageLocation:t})=>{const a=Pe(t);if(!a)return null;try{const r=a.getItem(`${e||he}-client`);if(!r)return null;const s=JSON.parse(r),n=typeof s?.state=="string"?JSON.parse(s.state):s?.state??s;return n&&typeof n=="object"?n:null}catch{return}},ao=({storageKey:e,storageLocation:t})=>{const a=He({storageKey:e,storageLocation:t});return typeof a?.conversationId=="string"&&a.conversationId.trim()||void 0},Ne=()=>{try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})},no=e=>`${e||he}-${Zt}`,ro=({storageKey:e,storageLocation:t})=>{const a=Pe(t),r=no(e);try{const s=a?.getItem(r);if(s)return s;const n=`anon_${Ne()}`;return a?.setItem(r,n),n}catch{return`anon_${Ne()}`}},so=async({webchatProxyUrl:e,clientId:t,accountId:a})=>{const r=ve({webchatProxyUrl:e});if(!r)throw new Error("public session request requires a valid webchatProxyUrl");const s=await fetch(`${r}/webchat/session/open/${encodeURIComponent(t)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountId:a})});if(!s.ok)throw new Error(`public session request failed with status ${s.status}`);const n=await s.json(),l=n&&typeof n=="object"&&n.data&&typeof n.data=="object"?n.data:n;if(!l||typeof l!="object")throw new Error("public session response is invalid");if(typeof l.userId!="string"||typeof l.userToken!="string")throw new Error("public session response is missing credentials");return{userId:l.userId,userToken:l.userToken}},co=e=>({...typeof e.name=="string"&&e.name.trim()?{name:e.name.trim()}:{},...typeof e.pictureUrl=="string"&&e.pictureUrl.trim()?{pictureUrl:e.pictureUrl.trim()}:{},userData:e}),lo=({showWelcomeScreen:e,storageKey:t,storageLocation:a,conversationId:r,userToken:s})=>{if(!e)return{activeView:"chat",historyReturnView:"chat",bootstrapView:"chat"};if(r&&s)return{activeView:"chat",historyReturnView:"chat",bootstrapView:"chat"};const n=He({storageKey:t,storageLocation:a});if(n==null)return{activeView:"home",historyReturnView:"home",bootstrapView:"home"};if(n===void 0)return{activeView:"pending",historyReturnView:"home",bootstrapView:"pending"};const l=typeof n.conversationId=="string"?n.conversationId.trim():"",i=typeof n.user?.userToken=="string"?n.user.userToken.trim():"";return l&&i?{activeView:"chat",historyReturnView:"chat",bootstrapView:"chat"}:!l&&!i?{activeView:"home",historyReturnView:"home",bootstrapView:"home"}:{activeView:"pending",historyReturnView:"home",bootstrapView:"pending"}},io=(e,t)=>{switch(t.type){case"show":return{isPanelMounted:!0,isPanelVisible:e.isPanelVisible};case"visible":return{isPanelMounted:!0,isPanelVisible:!0};case"hide":return{isPanelMounted:e.isPanelMounted,isPanelVisible:!1};case"unmount":return{isPanelMounted:!1,isPanelVisible:!1};default:return e}};function uo({clientId:e,webchatProxyUrl:t,userCredentials:a,conversationId:r,config:s,defaultUserData:n,presetSlug:l,storageKey:i=he,storageLocation:u="localStorage",defaultOpen:f,onUserApiChange:p,getSession:b,sessionKey:M,onSessionChange:w}){const{session:v,resolving:R}=_t({getSession:b,sessionKey:M,onSessionChange:w}),J=!!v&&Date.now()<v.expiresAt,E=J?{userId:v.userId,userToken:v.userToken}:void 0,S=b?E:a,z=J?v.conversationId:void 0,O=c.useMemo(()=>typeof l=="string"&&l.trim()?l.trim():void 0,[l]),k=c.useMemo(()=>typeof t=="string"&&t.trim()?Ee(t.trim()):void 0,[t]);c.useMemo(()=>k?ve({webchatProxyUrl:k}):null,[k]);const d=!!(e&&k&&(O||!S)),m=c.useMemo(()=>d?eo({webchatProxyUrl:k,clientId:e,presetSlug:O}):null,[e,O,k,d]),[T,X]=c.useState({error:null,isLoading:!1,payload:null,url:null});c.useEffect(()=>{if(!m){X({error:null,isLoading:!1,payload:null,url:null});return}const B=new AbortController;return X({error:null,isLoading:!0,payload:null,url:m}),fetch(m,{headers:{accept:"application/json"},signal:B.signal}).then(async y=>{if(!y.ok)throw new Error(`bootstrap request failed with status ${y.status}`);return y.json()}).then(y=>{const V=to(y);if(!V)throw new Error("bootstrap response is invalid");X({error:null,isLoading:!1,payload:V,url:m})}).catch(y=>{B.signal.aborted||(console.warn("[EduzzWebchat] failed to load bootstrap",y),X({error:y,isLoading:!1,payload:null,url:m}))}),()=>B.abort()},[m]);const x=m&&T.url===m?T.payload:null,se=m&&T.url===m?T.error:null,N=x?.clientId||e,U=k||x?.webchatProxyUrl||void 0,P=i===he&&x?.storageKey?x.storageKey:i,W=typeof f=="boolean"?f:typeof x?.defaultOpen=="boolean"?x.defaultOpen:f,A=c.useMemo(()=>({...oe(x?.config)||{},...oe(s)||{}}),[x,s]),me=c.useMemo(()=>{const B={...oe(x?.defaultUserData)||{},...oe(n)||{}};return Object.keys(B).length>0?B:null},[n,x]),H=!!(!S&&!R&&x?.sessionMode==="service-hub"&&U&&N),[ae,Z]=c.useState({error:null,isLoading:!1,payload:null,key:null});c.useEffect(()=>{if(!H){Z({error:null,isLoading:!1,payload:null,key:null});return}const B=ro({storageKey:P,storageLocation:u}),y=`${N}:${U}:${B}`;let V=!1;return Z({error:null,isLoading:!0,payload:null,key:y}),so({webchatProxyUrl:U,clientId:N,accountId:B}).then(g=>{V||Z({error:null,isLoading:!1,payload:g,key:y})}).catch(g=>{V||(console.warn("[EduzzWebchat] failed to open public session",g),Z({error:g,isLoading:!1,payload:null,key:y}))}),()=>{V=!0}},[N,P,U,H,u]);const G=H?ae.payload:null,Y=S||G,$=c.useMemo(()=>Se(A),[A]),Q=c.useMemo(()=>z||r||ao({storageKey:P,storageLocation:u}),[z,r,P,u]),F=W??$.initiallyOpen??!0,[pe,K]=c.useState(F),ne=c.useRef(F),[L,ee]=c.useState(ge),fe=c.useCallback(()=>K(B=>!B),[]);c.useEffect(()=>{ne.current!==F&&(ne.current=F,K(F))},[F]);const ce=d&&!x&&!se,we=H&&!G&&!ae.error;return c.useEffect(()=>{const B=Qt({webchatProxyUrl:U,clientId:N});if(ee(ge),!B)return;const y=new AbortController;let V=!1;return fetch(B,{headers:{accept:"application/json"},signal:y.signal}).then(async g=>{if(!g.ok)throw new Error(`runtime config request failed with status ${g.status}`);return g.json()}).then(g=>{if(V)return;const le=g&&typeof g=="object"&&g.data&&typeof g.data=="object"?g.data:{};ee({allowFileUpload:le.allowFileUpload===!0,allowMessageFeedback:le.allowMessageFeedback===!0})}).catch(g=>{y.signal.aborted||V||(console.warn("[EduzzWebchat] failed to load runtime config",g),ee(ge))}),()=>{V=!0,y.abort()}},[N,U]),ce||we||b&&R?null:se&&!x?o.jsx("div",{className:"bp-webchat-shell",style:te($),children:o.jsx("div",{className:"bp-webchat-error",children:"Nao foi possivel carregar a configuracao publica do webchat."})}):ae.error&&!G?o.jsx("div",{className:"bp-webchat-shell",style:te($),children:o.jsx("div",{className:"bp-webchat-error",children:"Nao foi possivel abrir a sessao publica do webchat."})}):U?N?o.jsx(_.WebchatProvider,{clientId:N,apiUrl:U,conversationId:Q,userCredentials:Y,storageKey:P,storageLocation:u,children:o.jsx(bo,{clientId:N,config:$,defaultUserData:me,conversationIdProp:Q,isOpen:pe,onUserApiChange:p,onToggle:fe,runtimeCapabilities:L,storageKey:P,storageLocation:u,userToken:Y?.userToken})}):o.jsx("div",{className:"bp-webchat-shell",style:te($),children:o.jsx("div",{className:"bp-webchat-error",children:"Nenhum clientId foi informado."})}):o.jsx("div",{className:"bp-webchat-shell",style:te($),children:o.jsx("div",{className:"bp-webchat-error",children:"Nenhuma URL publica do proxy do webchat foi informada."})})}function bo({clientId:e,config:t,defaultUserData:a,conversationIdProp:r,isOpen:s,onUserApiChange:n,onToggle:l,runtimeCapabilities:i,storageKey:u,storageLocation:f,userToken:p}){const b=c.useMemo(()=>lo({showWelcomeScreen:t.showWelcomeScreen,storageKey:u,storageLocation:f,conversationId:r,userToken:p}),[t.showWelcomeScreen,r,u,f,p]),[M,w]=c.useState(!1),[v,R]=c.useState({open:!1,messageId:null,draft:""}),[{isPanelMounted:J,isPanelVisible:E},S]=c.useReducer(io,{isPanelMounted:s,isPanelVisible:s}),{conversationId:z,isTyping:O,messages:k,saveMessageFeedback:d,sendMessage:m,status:T,uploadFile:X}=_.useActiveConversation(),{openConversation:x,listConversations:se}=_.useConversations(),{updateUser:N,userCredentials:U}=_.useUser(),P=c.useRef({}),[W,A]=c.useState(()=>b.activeView),[me,H]=c.useState(()=>b.historyReturnView),{conversations:ae,isLoading:Z,refresh:G}=_.useConversationList({userCredentials:U,listConversations:se,clientId:e}),Y=c.useMemo(()=>oo(a),[a]),$=c.useCallback(async(j={})=>{if(!N)return;const h={...oe(a)||{},...P.current,...oe(j)||{}};return P.current=h,N(co(h))},[a,N]),Q=c.useRef($);c.useEffect(()=>{Q.current=$},[$]);const F=!!N;c.useEffect(()=>{P.current={}},[Y]),c.useEffect(()=>{if(n)return n({updateUserData:F?j=>Q.current(j):void 0}),()=>n(null)},[n,F]),c.useEffect(()=>{!F||!Y||Q.current()},[Y,F]),c.useEffect(()=>{i.allowMessageFeedback||R({open:!1,messageId:null,draft:""})},[i.allowMessageFeedback]);const{showInitialLoading:pe,setShowInitialLoading:K}=$t({activeView:W,clientState:T,conversationId:z,messagesLength:k.length}),ne=c.useMemo(()=>t.botAvatar||Ft({name:t.botName,backgroundColor:t.accentColor}),[t.accentColor,t.botAvatar,t.botName]),L=c.useMemo(()=>({...t,botAvatar:ne}),[t,ne]),ee=c.useCallback(async j=>{H(j),A("conversations"),await G()},[G]),fe=c.useCallback(j=>{K(!0),x(j),A("chat")},[x,K]),ce=c.useCallback(()=>{K(!0),x(),A("chat")},[x,K]),we=c.useMemo(()=>Ht({messages:k,user:U,botName:L.botName,botAvatar:L.botAvatar}),[k,L.botAvatar,L.botName,U]),B=te(t),y=c.useMemo(()=>We(t),[t]),V=c.useMemo(()=>jt(t.fabChatIconVariant),[t.fabChatIconVariant]);c.useEffect(()=>{if(s){S({type:"show"});const ie=window.requestAnimationFrame(()=>S({type:"visible"}));return()=>window.cancelAnimationFrame(ie)}S({type:"hide"});const j=window.setTimeout(()=>{w(!1),R({open:!1,messageId:null,draft:""})},0),h=window.setTimeout(()=>S({type:"unmount"}),Xt);return()=>{window.clearTimeout(j),window.clearTimeout(h)}},[s]),c.useEffect(()=>{if(b.bootstrapView==="pending"){if(k.length>0){const j=window.setTimeout(()=>{A("chat"),H("chat")},0);return()=>window.clearTimeout(j)}if(T!=="connecting"){const j=window.setTimeout(()=>{A("home"),H("home")},0);return()=>window.clearTimeout(j)}}},[T,b.bootstrapView,k.length]);const g=c.useMemo(()=>function(h){const ie=i.allowMessageFeedback&&h.direction==="incoming"&&typeof h.addMessageFeedback=="function",$e={...h.block,direction:h.direction,sender:h.sender,timestamp:h.timestamp,messageId:h.messageId,metadata:h.metadata,isReadOnly:h.isReadOnly,status:h.status,feedback:h.feedback,sendMessage:h.sendMessage,addMessageFeedback:h.addMessageFeedback};return o.jsxs("div",{className:"bpMessageBlocksBubble","data-direction":h.direction,"data-feedback":ie||void 0,children:[o.jsx(_.Block,{block:$e}),ie?o.jsxs("div",{className:"bpMessageBlocksBubbleFeedbackContainer",children:[o.jsx("button",{className:"bpMessageBlocksBubbleFeedbackIcon",type:"button","data-selected":h.feedback==="positive","aria-label":"Feedback positivo",onClick:()=>h.addMessageFeedback(h.messageId,{value:"positive"}),children:Mt}),o.jsx("button",{className:"bpMessageBlocksBubbleFeedbackIcon",type:"button","data-selected":h.feedback==="negative","aria-label":"Feedback negativo",onClick:()=>R({open:!0,messageId:h.messageId,draft:""}),children:St})]}):null]})},[i.allowMessageFeedback]),le=c.useMemo(()=>({bubble:g,dropdown:Wt}),[g]);return o.jsxs("div",{className:"bp-webchat-shell","data-panel-mounted":J,"data-panel-open":E,style:B,children:[o.jsx(_.StylesheetProvider,{...y}),J?o.jsx("div",{className:"bp-webchat-panel","data-state":E?"open":"closed",children:W==="home"?o.jsx(Jt,{config:L,activeView:W,onClose:l,onShowHome:()=>A("home"),onShowConversations:()=>ee("home"),onStart:()=>A("chat")}):W==="conversations"?o.jsx(Ot,{conversations:ae,currentConversationId:z,isLoading:Z,botAvatar:L.botAvatar,botName:L.botName,onClose:()=>A(me),onCloseWidget:l,onShowHome:()=>{A("home"),H("home")},onShowConversations:G,onNewConversation:ce,onConversationClick:fe}):W==="pending"?o.jsx("div",{className:"bp-webchat-layout",children:o.jsx(Fe,{})}):o.jsxs(o.Fragment,{children:[o.jsx(qt,{config:L,allowFileUpload:i.allowFileUpload,clientState:T,isTyping:O,messages:we,renderers:le,sendMessage:m,uploadFile:X,addMessageFeedback:i.allowMessageFeedback?d:void 0,showInitialLoading:pe,onShowHome:t.showWelcomeScreen?()=>{A("home"),H("home")}:void 0,onOpenHistory:()=>ee("chat"),onRestartConversation:()=>w(!0),onCloseWidget:l}),o.jsx(Kt,{open:M,onCancel:()=>w(!1),onConfirm:()=>{w(!1),ce()}}),i.allowMessageFeedback?o.jsx(Gt,{open:v.open,draft:v.draft,setDraft:j=>R(h=>({...h,draft:j})),onCancel:()=>R({open:!1,messageId:null,draft:""}),onConfirm:async()=>{v.messageId&&d&&await d(v.messageId,{value:"negative",comment:v.draft}),R({open:!1,messageId:null,draft:""})}}):null]})}):null,o.jsxs("button",{className:"bp-webchat-fab","data-open":s,onClick:l,type:"button","aria-label":s?"Fechar webchat":"Abrir webchat",children:[o.jsx("span",{className:"bp-webchat-fab-icon bp-webchat-fab-icon--chat",children:V}),o.jsx("span",{className:"bp-webchat-fab-icon bp-webchat-fab-icon--close",children:Bt})]})]})}exports.Webchat=uo;exports.defaultConfig=q;exports.getContrastingTextColor=re;exports.getShellStyle=te;exports.normalizeConfig=Se;
|
|
6
|
+
`.trim();return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(s)}`},Kt=e=>e?e.payload?.type==="text"?e.payload.text:e.payload?.type==="bloc"&&e.payload.items?.some(t=>t.type==="text")?e.payload.items.find(a=>a.type==="text")?.payload.text??"Conversa sem mensagens":"Anexo enviado":"Conversa sem mensagens",Ne=[{unit:"minute",seconds:60},{unit:"hour",seconds:3600},{unit:"day",seconds:3600*24},{unit:"week",seconds:3600*24*7},{unit:"month",seconds:3600*24*30},{unit:"year",seconds:3600*24*365}],Jt=new Intl.RelativeTimeFormat("pt-BR",{numeric:"auto"}),Xt=e=>{const t=Math.round((new Date(e).getTime()-Date.now())/1e3);if(Math.abs(t)<45)return"agora";let a=Ne[0];for(const r of Ne)Math.abs(t)>=r.seconds&&(a=r);return Jt.format(Math.round(t/a.seconds),a.unit)},Zt=({messages:e,user:t,botName:a,botAvatar:r})=>e.map(s=>{const n=s.authorId===t?.userId;return{...s,direction:n?"outgoing":"incoming",sender:n?{name:t?.name??"Você",avatar:t?.pictureUrl}:{name:a,avatar:r}}}),Yt=({activeView:e,clientState:t,conversationId:a,messagesLength:r})=>{const[s,n]=c.useState(!1),l=e==="chat",i=l&&t==="connecting",u=l&&t==="connected"&&r===0,f=s&&(!l||r>0||t!=="connecting"&&t!=="connected");return c.useEffect(()=>{if(s){if(u){const p=window.setTimeout(()=>n(!1),900);return()=>window.clearTimeout(p)}if(f){const p=window.setTimeout(()=>n(!1),0);return()=>window.clearTimeout(p)}}},[a,s,u,f]),{showInitialLoading:i||s&&l,setShowInitialLoading:n}},Qt=3e4,eo=({getSession:e,sessionKey:t,onSessionChange:a})=>{const[r,s]=c.useState(null),[n,l]=c.useState(!!e),i=c.useRef(e);i.current=e;const u=c.useRef(a);return u.current=a,c.useEffect(()=>{let f=!0,p;const b=w=>{f&&(s(w),u.current?.(w))};if(!i.current){l(!1),b(null);return}const M=async()=>{try{const w=await i.current();if(!w?.userToken)throw new Error("Webchat session not created or empty");if(!f)return;b(w);const C=w.expiresAt-Date.now()-Qt;p=setTimeout(M,Math.max(C,0))}catch(w){console.error("[EduzzWebchat] error creating session: ",w),b(null)}finally{f&&l(!1)}};return l(!0),M(),()=>{f=!1,p&&clearTimeout(p)}},[t,!!e]),{session:r,resolving:n}};function to({botName:e,botAvatar:t,subtitle:a,onShowHome:r,onOpenHistory:s,onRestartConversation:n,onCloseWidget:l}){return o.jsxs("div",{className:"bp-webchat-header",children:[o.jsxs("div",{className:"bp-webchat-header-meta",children:[o.jsx("div",{className:"bp-webchat-avatar",children:t?o.jsx("img",{src:t,alt:""}):o.jsx("span",{children:(e||"B").slice(0,1).toUpperCase()})}),o.jsxs("div",{className:"bp-webchat-header-text",children:[o.jsx("h2",{className:"bp-webchat-header-title",children:e}),o.jsx("p",{className:"bp-webchat-header-subtitle",children:a})]})]}),o.jsxs("div",{className:"bp-webchat-header-actions",children:[r?o.jsx("button",{className:"bp-webchat-icon-button",type:"button","aria-label":"Abrir início",onClick:r,children:De}):null,o.jsx("button",{className:"bp-webchat-icon-button",type:"button","aria-label":"Abrir conversas",onClick:s,children:_t}),o.jsx("button",{className:"bp-webchat-icon-button",type:"button","aria-label":"Reiniciar conversa",onClick:n,children:Ft}),l?o.jsx("button",{className:"bp-webchat-icon-button bp-webchat-mobile-close",type:"button","aria-label":"Fechar webchat",onClick:l,children:be}):null]})]})}function Ee(){return o.jsxs("div",{className:"bp-webchat-loading",children:[o.jsxs("div",{className:"bp-webchat-loading-hero",children:[o.jsx("div",{className:"bp-webchat-loading-circle"}),o.jsx("div",{className:"bp-webchat-loading-line bp-webchat-loading-line--title"}),o.jsx("div",{className:"bp-webchat-loading-line bp-webchat-loading-line--subtitle"})]}),o.jsxs("div",{className:"bp-webchat-loading-bubble",children:[o.jsx("div",{className:"bp-webchat-loading-line",style:{width:"82%",height:"12px"}}),o.jsx("div",{className:"bp-webchat-loading-line",style:{width:"58%",height:"12px"}})]}),o.jsx("div",{className:"bp-webchat-loading-bubble bp-webchat-loading-bubble--right",children:o.jsx("div",{className:"bp-webchat-loading-line",style:{width:"72%",height:"12px"}})}),o.jsxs("div",{className:"bp-webchat-loading-composer",children:[o.jsx("div",{className:"bp-webchat-loading-input"}),o.jsx("div",{className:"bp-webchat-loading-mic"})]})]})}function oo({config:e,allowFileUpload:t,clientState:a,isTyping:r,messages:s,renderers:n,sendMessage:l,uploadFile:i,addMessageFeedback:u,showInitialLoading:f,onShowHome:p,onOpenHistory:b,onRestartConversation:M,onCloseWidget:w}){return o.jsxs("div",{className:"bp-webchat-layout",children:[o.jsx(to,{botName:e.botName,botAvatar:e.botAvatar,subtitle:e.subtitle,onShowHome:p,onOpenHistory:b,onRestartConversation:M,onCloseWidget:w}),o.jsx(E.Container,{className:"bp-webchat-container",uploadFile:i,allowFileUpload:t,children:f?o.jsx(Ee,{}):o.jsxs(o.Fragment,{children:[o.jsx(E.MessageList,{botName:e.botName,botDescription:e.subtitle,botAvatar:e.botAvatar,isTyping:r,messages:s,sendMessage:l,addMessageFeedback:u,renderers:n,showDateSystemMessage:!1,showMessageStatus:!1,showIncomingMessageAvatar:!0,showOutgoingMessageAvatar:!1}),o.jsx(E.Composer,{connected:a!=="disconnected",sendMessage:l,uploadFile:i,allowFileUpload:t,composerPlaceholder:e.placeholder,disableSendButton:!1})]})})]})}function Pe({activeView:e,onShowHome:t,onShowConversations:a}){return o.jsxs("div",{className:"bp-webchat-tabs bp-webchat-welcome-bottom",children:[o.jsxs("button",{className:"bp-webchat-tab bp-webchat-welcome-tab","data-active":e==="home",type:"button",onClick:t,children:[o.jsx("span",{className:"bp-webchat-tab-icon bp-webchat-welcome-tab-icon",children:De}),o.jsx("span",{children:"Início"})]}),o.jsxs("button",{className:"bp-webchat-tab bp-webchat-welcome-tab","data-active":e==="conversations",type:"button",onClick:a,children:[o.jsx("span",{className:"bp-webchat-tab-icon bp-webchat-welcome-tab-icon",children:Ht}),o.jsx("span",{children:"Conversas"})]})]})}function ao({conversations:e,currentConversationId:t,isLoading:a,botAvatar:r,botName:s,onClose:n,onCloseWidget:l,onShowHome:i,onShowConversations:u,onNewConversation:f,onConversationClick:p}){return o.jsxs("div",{className:"bp-webchat-history",children:[o.jsxs("div",{className:"bp-webchat-history-header",children:[o.jsx("h2",{className:"bp-webchat-history-title",children:"Conversas"}),o.jsxs("div",{className:"bp-webchat-header-actions",children:[o.jsx("button",{className:"bp-webchat-icon-button",type:"button",onClick:n,"aria-label":"Fechar conversas",children:be}),l?o.jsx("button",{className:"bp-webchat-icon-button bp-webchat-mobile-close",type:"button",onClick:l,"aria-label":"Fechar webchat",children:be}):null]})]}),o.jsx("div",{className:"bp-webchat-history-list",children:a?o.jsx("div",{className:"bp-webchat-history-loading",children:"Carregando conversas..."}):e.length===0?o.jsx("div",{className:"bp-webchat-history-empty",children:"Nenhuma conversa iniciada ainda."}):e.map(b=>{const M=Kt(b.lastMessage),w=b.lastMessage?.author?.type==="bot";return o.jsxs("button",{className:"bp-webchat-history-item",type:"button",onClick:()=>p(b.id),"data-current":b.id===t||void 0,children:[o.jsx("div",{className:"bp-webchat-history-avatar","data-kind":w?"bot":"user",children:w&&r?o.jsx("img",{src:r,alt:""}):w?o.jsx("span",{children:(s||"B").slice(0,1).toUpperCase()}):Wt}),o.jsxs("div",{className:"bp-webchat-history-content",children:[o.jsx("span",{className:"bp-webchat-history-name",children:M}),o.jsx("span",{className:"bp-webchat-history-time",children:Xt(b.updatedAt)})]}),o.jsx("span",{className:"bp-webchat-history-chevron",children:zt})]},b.id)})}),o.jsx("div",{className:"bp-webchat-history-footer",children:o.jsxs("button",{className:"bp-webchat-history-new",type:"button",onClick:f,children:[Ot,o.jsx("span",{children:"Nova conversa"})]})}),o.jsx(Pe,{activeView:"conversations",onShowHome:i,onShowConversations:u})]})}const Ie=e=>String(e??"").normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().trim();function no(e){const{label:t,options:a=[],sendMessage:r,isReadOnly:s,messageId:n}=e,[l,i]=c.useState(!1),[u,f]=c.useState(""),[p,b]=c.useState(0),[M,w]=c.useState(null),C=c.useRef(null),R=c.useRef([]),P=s||M!==null||a.length===0,S=c.useMemo(()=>{const d=Ie(u);return d?a.filter(m=>Ie(m.label).includes(d)):a},[a,u]);c.useEffect(()=>{b(0)},[u]),c.useEffect(()=>{if(!l)return;const d=m=>{C.current&&!C.current.contains(m.target)&&i(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[l]),c.useEffect(()=>{l&&R.current[p]?.scrollIntoView({block:"nearest"})},[p,l]);const q=d=>{d&&(r?.({type:"text",text:d.label,value:d.value}),w(d.label),f(""),i(!1))},W=d=>{if(!P)switch(d.key){case"ArrowDown":if(d.preventDefault(),!l){i(!0);return}b(m=>Math.min(m+1,S.length-1));break;case"ArrowUp":d.preventDefault(),b(m=>Math.max(m-1,0));break;case"Enter":d.preventDefault(),l&&q(S[p]);break;case"Escape":i(!1);break}},B=`bpDropdownList-${n??"x"}`;return o.jsxs("div",{className:"bpDropdown","data-open":l||void 0,"data-disabled":P||void 0,ref:C,children:[t?o.jsx("span",{className:"bpDropdownLabel",children:t}):null,o.jsxs("div",{className:"bpDropdownControl",children:[o.jsx("input",{className:"bpDropdownInput",type:"text",role:"combobox","aria-expanded":l,"aria-controls":B,"aria-autocomplete":"list",autoComplete:"off",placeholder:"Selecione...",value:M??u,disabled:P,onFocus:()=>{P||i(!0)},onChange:d=>{f(d.target.value),i(!0)},onKeyDown:W}),o.jsx("span",{className:"bpDropdownChevron",children:qt})]}),l&&!P?o.jsx("ul",{className:"bpDropdownMenu",id:B,role:"listbox",children:S.length>0?S.map((d,m)=>o.jsx("li",{ref:T=>{R.current[m]=T},className:"bpDropdownOption",role:"option","aria-selected":m===p,"data-active":m===p||void 0,onMouseEnter:()=>b(m),onMouseDown:T=>{T.preventDefault(),q(d)},children:d.label},d.value)):o.jsx("li",{className:"bpDropdownEmpty",role:"presentation",children:"Nenhuma opção encontrada"})}):null]})}function ro({open:e,draft:t,setDraft:a,onConfirm:r,onCancel:s}){return e?o.jsx("div",{className:"bp-webchat-modal-backdrop",children:o.jsxs("div",{className:"bp-webchat-modal",children:[o.jsx("h3",{className:"bp-webchat-modal-title",children:"Nos ajude a melhorar"}),o.jsx("p",{className:"bp-webchat-modal-description",children:"Conte o que não ficou bom nesta resposta."}),o.jsx("div",{className:"bp-webchat-modal-field-wrap",children:o.jsx("textarea",{className:"bp-webchat-modal-textarea",value:t,onChange:n=>a(n.target.value),placeholder:"Descreva o problema encontrado..."})}),o.jsxs("div",{className:"bp-webchat-modal-actions",children:[o.jsx("button",{className:"bp-webchat-modal-button bp-webchat-modal-button--primary",type:"button",onClick:r,children:"Enviar feedback"}),o.jsx("button",{className:"bp-webchat-modal-button",type:"button",onClick:s,children:"Cancelar"})]})]})}):null}function so({open:e,onConfirm:t,onCancel:a}){return e?o.jsx("div",{className:"bp-webchat-modal-backdrop",children:o.jsxs("div",{className:"bp-webchat-modal",children:[o.jsx("h3",{className:"bp-webchat-modal-title",children:"Criar nova conversa"}),o.jsx("p",{className:"bp-webchat-modal-description",children:"Isso vai limpar a conversa atual e iniciar uma nova sessão com o bot."}),o.jsxs("div",{className:"bp-webchat-modal-actions",children:[o.jsx("button",{className:"bp-webchat-modal-button bp-webchat-modal-button--primary",type:"button",onClick:t,children:"Nova conversa"}),o.jsx("button",{className:"bp-webchat-modal-button",type:"button",onClick:a,children:"Cancelar"})]})]})}):null}function co({config:e,activeView:t,onShowHome:a,onShowConversations:r,onStart:s,onClose:n}){const l=e.welcomeCardImage||e.botAvatar;return o.jsxs("div",{className:"bp-webchat-welcome",children:[o.jsxs("div",{className:"bp-webchat-welcome-hero",children:[o.jsx("button",{className:"bp-webchat-icon-button bp-webchat-welcome-close",type:"button",onClick:n,"aria-label":e.welcomeCloseLabel,children:be}),e.welcomeCoverImage?o.jsx("img",{className:"bp-webchat-welcome-cover",src:e.welcomeCoverImage,alt:""}):null]}),o.jsx("div",{className:"bp-webchat-welcome-card-wrap",children:o.jsxs("div",{className:"bp-webchat-welcome-card",children:[o.jsx("div",{className:"bp-webchat-welcome-card-badge",children:l?o.jsx("img",{src:l,alt:""}):o.jsx("span",{children:(e.botName||"B").slice(0,1).toUpperCase()})}),o.jsx("h3",{className:"bp-webchat-welcome-card-title",children:e.welcomeCardTitle}),o.jsx("p",{className:"bp-webchat-welcome-card-status",children:o.jsx("strong",{children:e.welcomeCardStatus})}),o.jsx("p",{className:"bp-webchat-welcome-card-description",children:e.welcomeCardDescription}),o.jsxs("button",{className:"bp-webchat-welcome-cta",type:"button",onClick:s,children:[o.jsx("span",{className:"bp-webchat-welcome-cta-left",children:o.jsxs("span",{className:"bp-webchat-welcome-cta-copy",children:[o.jsx("span",{className:"bp-webchat-welcome-cta-title",children:e.welcomeCtaLabel}),e.welcomeButtonDescription?o.jsx("span",{className:"bp-webchat-welcome-cta-description",children:e.welcomeButtonDescription}):null]})}),o.jsx("span",{className:"bp-webchat-welcome-cta-right",children:Pt})]})]})}),o.jsx(Pe,{activeView:t,onShowHome:a,onShowConversations:r})]})}const lo=220,he="eduzz-webchat",ye=Object.freeze({allowFileUpload:!1,allowMessageFeedback:!1}),io="anonymous-id",uo=e=>!!e&&typeof e=="object"&&!Array.isArray(e),He=e=>e.replace(/\/+$/,""),ke=({webchatProxyUrl:e})=>{if(typeof e!="string"||!e.trim())return null;const t=He(e.trim()),a="/webchat/proxy";return t.endsWith(a)?t.slice(0,-a.length):null},bo=({webchatProxyUrl:e,clientId:t})=>!e||!t?null:`${e.endsWith("/")?e.slice(0,-1):e}/${encodeURIComponent(t)}/runtime-config`,ho=({webchatProxyUrl:e,clientId:t,presetSlug:a})=>{if(!e||!t)return null;const r=ke({webchatProxyUrl:e});if(!r)return null;const s=new URLSearchParams;typeof a=="string"&&a.trim()&&s.set("slug",a.trim());const n=s.toString();return`${r}/webchat/bootstrap/${encodeURIComponent(t)}${n?`?${n}`:""}`},mo=e=>{const t=e&&typeof e=="object"&&e.data&&typeof e.data=="object"?e.data:e;return t&&typeof t=="object"?t:null},ae=e=>uo(e)?e:null,po=e=>{if(!e)return"";try{return JSON.stringify(e)}catch{return String(Date.now())}},$e=e=>{if(typeof window>"u")return null;try{return e==="sessionStorage"?window.sessionStorage:window.localStorage}catch{return null}},Le=({storageKey:e,storageLocation:t})=>{const a=$e(t);if(!a)return null;try{const r=a.getItem(`${e||he}-client`);if(!r)return null;const s=JSON.parse(r),n=typeof s?.state=="string"?JSON.parse(s.state):s?.state??s;return n&&typeof n=="object"?n:null}catch{return}},fo=({storageKey:e,storageLocation:t})=>{const a=Le({storageKey:e,storageLocation:t});return typeof a?.conversationId=="string"&&a.conversationId.trim()||void 0},Me=()=>{try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})},wo=e=>`${e||he}-${io}`,go=({storageKey:e,storageLocation:t})=>{const a=$e(t),r=wo(e);try{const s=a?.getItem(r);if(s)return s;const n=`anon_${Me()}`;return a?.setItem(r,n),n}catch{return`anon_${Me()}`}},xo=async({webchatProxyUrl:e,clientId:t,accountId:a})=>{const r=ke({webchatProxyUrl:e});if(!r)throw new Error("public session request requires a valid webchatProxyUrl");const s=await fetch(`${r}/webchat/session/open/${encodeURIComponent(t)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountId:a})});if(!s.ok)throw new Error(`public session request failed with status ${s.status}`);const n=await s.json(),l=n&&typeof n=="object"&&n.data&&typeof n.data=="object"?n.data:n;if(!l||typeof l!="object")throw new Error("public session response is invalid");if(typeof l.userId!="string"||typeof l.userToken!="string")throw new Error("public session response is missing credentials");return{userId:l.userId,userToken:l.userToken}},yo=e=>({...typeof e.name=="string"&&e.name.trim()?{name:e.name.trim()}:{},...typeof e.pictureUrl=="string"&&e.pictureUrl.trim()?{pictureUrl:e.pictureUrl.trim()}:{},userData:e}),vo=({showWelcomeScreen:e,storageKey:t,storageLocation:a,conversationId:r,userToken:s})=>{if(!e)return{activeView:"chat",historyReturnView:"chat",bootstrapView:"chat"};if(r&&s)return{activeView:"chat",historyReturnView:"chat",bootstrapView:"chat"};const n=Le({storageKey:t,storageLocation:a});if(n==null)return{activeView:"home",historyReturnView:"home",bootstrapView:"home"};if(n===void 0)return{activeView:"pending",historyReturnView:"home",bootstrapView:"pending"};const l=typeof n.conversationId=="string"?n.conversationId.trim():"",i=typeof n.user?.userToken=="string"?n.user.userToken.trim():"";return l&&i?{activeView:"chat",historyReturnView:"chat",bootstrapView:"chat"}:!l&&!i?{activeView:"home",historyReturnView:"home",bootstrapView:"home"}:{activeView:"pending",historyReturnView:"home",bootstrapView:"pending"}},Co=(e,t)=>{switch(t.type){case"show":return{isPanelMounted:!0,isPanelVisible:e.isPanelVisible};case"visible":return{isPanelMounted:!0,isPanelVisible:!0};case"hide":return{isPanelMounted:e.isPanelMounted,isPanelVisible:!1};case"unmount":return{isPanelMounted:!1,isPanelVisible:!1};default:return e}};function ko({clientId:e,webchatProxyUrl:t,userCredentials:a,conversationId:r,config:s,defaultUserData:n,presetSlug:l,storageKey:i=he,storageLocation:u="localStorage",defaultOpen:f,onUserApiChange:p,getSession:b,sessionKey:M,onSessionChange:w}){const{session:C,resolving:R}=eo({getSession:b,sessionKey:M,onSessionChange:w}),X=!!C&&Date.now()<C.expiresAt,P=X?{userId:C.userId,userToken:C.userToken}:void 0,S=b?P:a,q=X?C.conversationId:void 0,W=c.useMemo(()=>typeof l=="string"&&l.trim()?l.trim():void 0,[l]),B=c.useMemo(()=>typeof t=="string"&&t.trim()?He(t.trim()):void 0,[t]);c.useMemo(()=>B?ke({webchatProxyUrl:B}):null,[B]);const d=!!(e&&B&&(W||!S)),m=c.useMemo(()=>d?ho({webchatProxyUrl:B,clientId:e,presetSlug:W}):null,[e,W,B,d]),[T,Z]=c.useState({error:null,isLoading:!1,payload:null,url:null});c.useEffect(()=>{if(!m){Z({error:null,isLoading:!1,payload:null,url:null});return}const j=new AbortController;return Z({error:null,isLoading:!0,payload:null,url:m}),fetch(m,{headers:{accept:"application/json"},signal:j.signal}).then(async y=>{if(!y.ok)throw new Error(`bootstrap request failed with status ${y.status}`);return y.json()}).then(y=>{const V=mo(y);if(!V)throw new Error("bootstrap response is invalid");Z({error:null,isLoading:!1,payload:V,url:m})}).catch(y=>{j.signal.aborted||(console.warn("[EduzzWebchat] failed to load bootstrap",y),Z({error:y,isLoading:!1,payload:null,url:m}))}),()=>j.abort()},[m]);const x=m&&T.url===m?T.payload:null,ce=m&&T.url===m?T.error:null,N=x?.clientId||e,U=B||x?.webchatProxyUrl||void 0,H=i===he&&x?.storageKey?x.storageKey:i,G=typeof f=="boolean"?f:typeof x?.defaultOpen=="boolean"?x.defaultOpen:f,A=c.useMemo(()=>({...ae(x?.config)||{},...ae(s)||{}}),[x,s]),me=c.useMemo(()=>{const j={...ae(x?.defaultUserData)||{},...ae(n)||{}};return Object.keys(j).length>0?j:null},[n,x]),$=!!(!S&&!R&&x?.sessionMode==="service-hub"&&U&&N),[ne,Y]=c.useState({error:null,isLoading:!1,payload:null,key:null});c.useEffect(()=>{if(!$){Y({error:null,isLoading:!1,payload:null,key:null});return}const j=go({storageKey:H,storageLocation:u}),y=`${N}:${U}:${j}`;let V=!1;return Y({error:null,isLoading:!0,payload:null,key:y}),xo({webchatProxyUrl:U,clientId:N,accountId:j}).then(v=>{V||Y({error:null,isLoading:!1,payload:v,key:y})}).catch(v=>{V||(console.warn("[EduzzWebchat] failed to open public session",v),Y({error:v,isLoading:!1,payload:null,key:y}))}),()=>{V=!0}},[N,H,U,$,u]);const K=$?ne.payload:null,Q=S||K,L=c.useMemo(()=>Ae(A),[A]),ee=c.useMemo(()=>q||r||fo({storageKey:H,storageLocation:u}),[q,r,H,u]),F=G??L.initiallyOpen??!0,[pe,J]=c.useState(F),re=c.useRef(F),[_,te]=c.useState(ye),fe=c.useCallback(()=>J(j=>!j),[]);c.useEffect(()=>{re.current!==F&&(re.current=F,J(F))},[F]);const le=d&&!x&&!ce,we=$&&!K&&!ne.error;return c.useEffect(()=>{const j=bo({webchatProxyUrl:U,clientId:N});if(te(ye),!j)return;const y=new AbortController;let V=!1;return fetch(j,{headers:{accept:"application/json"},signal:y.signal}).then(async v=>{if(!v.ok)throw new Error(`runtime config request failed with status ${v.status}`);return v.json()}).then(v=>{if(V)return;const h=v&&typeof v=="object"&&v.data&&typeof v.data=="object"?v.data:{};te({allowFileUpload:h.allowFileUpload===!0,allowMessageFeedback:h.allowMessageFeedback===!0})}).catch(v=>{y.signal.aborted||V||(console.warn("[EduzzWebchat] failed to load runtime config",v),te(ye))}),()=>{V=!0,y.abort()}},[N,U]),le||we||b&&R?null:ce&&!x?o.jsx("div",{className:"bp-webchat-shell",style:oe(L),children:o.jsx("div",{className:"bp-webchat-error",children:"Nao foi possivel carregar a configuracao publica do webchat."})}):ne.error&&!K?o.jsx("div",{className:"bp-webchat-shell",style:oe(L),children:o.jsx("div",{className:"bp-webchat-error",children:"Nao foi possivel abrir a sessao publica do webchat."})}):U?N?o.jsx(E.WebchatProvider,{clientId:N,apiUrl:U,conversationId:ee,userCredentials:Q,storageKey:H,storageLocation:u,children:o.jsx(Bo,{clientId:N,config:L,defaultUserData:me,conversationIdProp:ee,isOpen:pe,onUserApiChange:p,onToggle:fe,runtimeCapabilities:_,storageKey:H,storageLocation:u,userToken:Q?.userToken})}):o.jsx("div",{className:"bp-webchat-shell",style:oe(L),children:o.jsx("div",{className:"bp-webchat-error",children:"Nenhum clientId foi informado."})}):o.jsx("div",{className:"bp-webchat-shell",style:oe(L),children:o.jsx("div",{className:"bp-webchat-error",children:"Nenhuma URL publica do proxy do webchat foi informada."})})}function Bo({clientId:e,config:t,defaultUserData:a,conversationIdProp:r,isOpen:s,onUserApiChange:n,onToggle:l,runtimeCapabilities:i,storageKey:u,storageLocation:f,userToken:p}){const b=c.useMemo(()=>vo({showWelcomeScreen:t.showWelcomeScreen,storageKey:u,storageLocation:f,conversationId:r,userToken:p}),[t.showWelcomeScreen,r,u,f,p]),[M,w]=c.useState(!1),[C,R]=c.useState({open:!1,messageId:null,draft:""}),[{isPanelMounted:X,isPanelVisible:P},S]=c.useReducer(Co,{isPanelMounted:s,isPanelVisible:s}),{conversationId:q,isTyping:W,messages:B,saveMessageFeedback:d,sendMessage:m,status:T,uploadFile:Z}=E.useActiveConversation(),{openConversation:x,listConversations:ce}=E.useConversations(),{updateUser:N,userCredentials:U}=E.useUser(),H=c.useRef({}),[G,A]=c.useState(()=>b.activeView),[me,$]=c.useState(()=>b.historyReturnView),{conversations:ne,isLoading:Y,refresh:K}=E.useConversationList({userCredentials:U,listConversations:ce,clientId:e}),Q=c.useMemo(()=>po(a),[a]),L=c.useCallback(async(h={})=>{if(!N)return;const z={...ae(a)||{},...H.current,...ae(h)||{}};return H.current=z,N(yo(z))},[a,N]),ee=c.useRef(L);c.useEffect(()=>{ee.current=L},[L]);const F=!!N;c.useEffect(()=>{H.current={}},[Q]),c.useEffect(()=>{if(n)return n({updateUserData:F?h=>ee.current(h):void 0}),()=>n(null)},[n,F]),c.useEffect(()=>{!F||!Q||ee.current()},[Q,F]),c.useEffect(()=>{i.allowMessageFeedback||R({open:!1,messageId:null,draft:""})},[i.allowMessageFeedback]);const{showInitialLoading:pe,setShowInitialLoading:J}=Yt({activeView:G,clientState:T,conversationId:q,messagesLength:B.length}),re=c.useMemo(()=>t.botAvatar||Gt({name:t.botName,backgroundColor:t.accentColor}),[t.accentColor,t.botAvatar,t.botName]),_=c.useMemo(()=>({...t,botAvatar:re}),[t,re]),te=c.useCallback(async h=>{$(h),A("conversations"),await K()},[K]),fe=c.useCallback(h=>{J(!0),x(h),A("chat")},[x,J]),le=c.useCallback(()=>{J(!0),x(),A("chat")},[x,J]),we=c.useMemo(()=>Zt({messages:B,user:U,botName:_.botName,botAvatar:_.botAvatar}),[B,_.botAvatar,_.botName,U]),j=oe(t),y=c.useMemo(()=>nt(t),[t]),V=c.useMemo(()=>Et(t.fabChatIconVariant),[t.fabChatIconVariant]);c.useEffect(()=>{if(s){S({type:"show"});const ie=window.requestAnimationFrame(()=>S({type:"visible"}));return()=>window.cancelAnimationFrame(ie)}S({type:"hide"});const h=window.setTimeout(()=>{w(!1),R({open:!1,messageId:null,draft:""})},0),z=window.setTimeout(()=>S({type:"unmount"}),lo);return()=>{window.clearTimeout(h),window.clearTimeout(z)}},[s]),c.useEffect(()=>{if(b.bootstrapView==="pending"){if(B.length>0){const h=window.setTimeout(()=>{A("chat"),$("chat")},0);return()=>window.clearTimeout(h)}if(T!=="connecting"){const h=window.setTimeout(()=>{A("home"),$("home")},0);return()=>window.clearTimeout(h)}}},[T,b.bootstrapView,B.length]);const v=c.useMemo(()=>{const h={};h.dropdown=no;const z=(ie,g)=>function({blocks:xe,horizontalAlignment:_e,verticalAlignment:ze,direction:qe,sender:Oe,timestamp:We,metadata:Ge,messageId:Ke,isReadOnly:Je,sendMessage:Xe}){return o.jsx("div",{className:ie,"data-horizontal":_e,"data-vertical":ze,children:xe.map((Ze,Ye)=>o.jsx(E.Block,{block:{...Ze,direction:qe,timestamp:We,sender:Oe,messageId:Ke,isReadOnly:Je,sendMessage:Xe,...g?{metadata:Ge}:{}},renderers:h},Ye))})};return h.column=z("bpMessageBlocksColumn",!1),h.row=z("bpMessageBlocksRow",!0),h.bubble=function(g){const ge=i.allowMessageFeedback&&g.direction==="incoming"&&typeof g.addMessageFeedback=="function",xe={...g.block,direction:g.direction,sender:g.sender,timestamp:g.timestamp,messageId:g.messageId,metadata:g.metadata,isReadOnly:g.isReadOnly,status:g.status,feedback:g.feedback,sendMessage:g.sendMessage,addMessageFeedback:g.addMessageFeedback};return o.jsxs("div",{className:"bpMessageBlocksBubble","data-direction":g.direction,"data-feedback":ge||void 0,children:[o.jsx(E.Block,{block:xe,renderers:h}),ge?o.jsxs("div",{className:"bpMessageBlocksBubbleFeedbackContainer",children:[o.jsx("button",{className:"bpMessageBlocksBubbleFeedbackIcon",type:"button","data-selected":g.feedback==="positive","aria-label":"Feedback positivo",onClick:()=>g.addMessageFeedback(g.messageId,{value:"positive"}),children:$t}),o.jsx("button",{className:"bpMessageBlocksBubbleFeedbackIcon",type:"button","data-selected":g.feedback==="negative","aria-label":"Feedback negativo",onClick:()=>R({open:!0,messageId:g.messageId,draft:""}),children:Lt})]}):null]})},h},[i.allowMessageFeedback]);return o.jsxs("div",{className:"bp-webchat-shell","data-panel-mounted":X,"data-panel-open":P,style:j,children:[o.jsx(E.StylesheetProvider,{...y}),X?o.jsx("div",{className:"bp-webchat-panel","data-state":P?"open":"closed",children:G==="home"?o.jsx(co,{config:_,activeView:G,onClose:l,onShowHome:()=>A("home"),onShowConversations:()=>te("home"),onStart:()=>A("chat")}):G==="conversations"?o.jsx(ao,{conversations:ne,currentConversationId:q,isLoading:Y,botAvatar:_.botAvatar,botName:_.botName,onClose:()=>A(me),onCloseWidget:l,onShowHome:()=>{A("home"),$("home")},onShowConversations:K,onNewConversation:le,onConversationClick:fe}):G==="pending"?o.jsx("div",{className:"bp-webchat-layout",children:o.jsx(Ee,{})}):o.jsxs(o.Fragment,{children:[o.jsx(oo,{config:_,allowFileUpload:i.allowFileUpload,clientState:T,isTyping:W,messages:we,renderers:v,sendMessage:m,uploadFile:Z,addMessageFeedback:i.allowMessageFeedback?d:void 0,showInitialLoading:pe,onShowHome:t.showWelcomeScreen?()=>{A("home"),$("home")}:void 0,onOpenHistory:()=>te("chat"),onRestartConversation:()=>w(!0),onCloseWidget:l}),o.jsx(so,{open:M,onCancel:()=>w(!1),onConfirm:()=>{w(!1),le()}}),i.allowMessageFeedback?o.jsx(ro,{open:C.open,draft:C.draft,setDraft:h=>R(z=>({...z,draft:h})),onCancel:()=>R({open:!1,messageId:null,draft:""}),onConfirm:async()=>{C.messageId&&d&&await d(C.messageId,{value:"negative",comment:C.draft}),R({open:!1,messageId:null,draft:""})}}):null]})}):null,o.jsxs("button",{className:"bp-webchat-fab","data-open":s,onClick:l,type:"button","aria-label":s?"Fechar webchat":"Abrir webchat",children:[o.jsx("span",{className:"bp-webchat-fab-icon bp-webchat-fab-icon--chat",children:V}),o.jsx("span",{className:"bp-webchat-fab-icon bp-webchat-fab-icon--close",children:Dt})]})]})}exports.Webchat=ko;exports.defaultConfig=O;exports.getContrastingTextColor=se;exports.getShellStyle=oe;exports.normalizeConfig=Ae;
|