@eduzz-automacoes/webchat-widget 0.0.2 → 0.2.0

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/README.md CHANGED
@@ -31,10 +31,47 @@ export function Example() {
31
31
  }
32
32
  ```
33
33
 
34
+ ## Sessão autenticada com auto-renovação
35
+
36
+ Em vez de injetar `userCredentials` estático, o produto pode fornecer `getSession`: o widget
37
+ busca as credenciais no backend do próprio produto e **renova o `userToken` automaticamente**
38
+ pouco antes de expirar. Os dois modos são **mutuamente exclusivos** — quando `getSession` é
39
+ informado, `userCredentials` é ignorado.
40
+
41
+ ```tsx
42
+ import { Webchat } from "@eduzz-automacoes/webchat";
43
+ import "@eduzz-automacoes/webchat/style.css";
44
+
45
+ export function Example({ authId }: { authId: string }) {
46
+ return (
47
+ <Webchat
48
+ clientId="SEU_CLIENT_ID"
49
+ // chamado pelo widget; renove/recrie a sessão a partir do SEU backend
50
+ getSession={async () => {
51
+ const { userId, userToken, expiresAt } = await fetch(
52
+ "/api/webchat/session",
53
+ {
54
+ method: "POST",
55
+ },
56
+ ).then((res) => res.json());
57
+
58
+ return { userId, userToken, expiresAt }; // expiresAt: epoch em ms
59
+ }}
60
+ // recria a sessão quando este valor muda (ex.: troca de usuário autenticado)
61
+ sessionKey={authId}
62
+ // (opcional) observabilidade da sessão capturada — null quando ausente
63
+ onSessionChange={(session) => console.log("webchat session", session)}
64
+ />
65
+ );
66
+ }
67
+ ```
68
+
69
+ Se `getSession` rejeitar ou resolver sem `userToken`, o widget cai em **modo anônimo**.
70
+
34
71
  ## Publicação manual no npm
35
72
 
36
73
  ```bash
37
- pnpm --filter @eduzz-automacoes/webchat build
38
- cd packages/webchat
74
+ pnpm --filter @eduzz-automacoes/webchat-widget build
75
+ cd packages/webchat-widget
39
76
  pnpm pack
40
77
  ```
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),c=require("react"),F=require("@botpress/webchat"),E={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"},ye=e=>e==="bottom-left"||e==="top-left"?"bottom-left":"bottom-right",_e=e=>{switch(ye(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"}}},Ce=(e,t,a)=>Math.min(Math.max(e,t),a),de=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()}`},ue=e=>{const t=de(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)}},Le=({r:e,g:t,b:a})=>`#${[e,t,a].map(r=>Ce(Math.round(r),0,255).toString(16).padStart(2,"0")).join("")}`,ne=(e,t,a)=>{const r=ue(e),s=ue(t);if(!r||!s)return null;const n=Ce(a,0,1);return Le({r:r.r*(1-n)+s.r*n,g:r.g*(1-n)+s.g*n,b:r.b*(1-n)+s.b*n})},qe=(e,t)=>t<0?ne(e,"#000000",Math.abs(t)):ne(e,"#ffffff",t),Q=e=>{const t=ue(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"},A=(e,t)=>e&&Object.prototype.hasOwnProperty.call(e,t)&&e[t]!=null&&e[t]!=="",ze=(e,t)=>{const a=de(e.brandColor);if(!a)return e;const r=de(e.brandTextColor)||Q(a),s=ne(a,"#ffffff",.82)||E.secondaryButtonBorderColor,n=ne(a,"#ffffff",.92)||E.secondaryButtonHoverBackgroundColor,l=qe(a,-.12)||E.primaryButtonHoverBackgroundColor;return{...e,brandColor:a,brandTextColor:r,primaryButtonBackgroundColor:A(t,"primaryButtonBackgroundColor")?e.primaryButtonBackgroundColor:a,primaryButtonTextColor:A(t,"primaryButtonTextColor")?e.primaryButtonTextColor:r,primaryButtonHoverBackgroundColor:A(t,"primaryButtonHoverBackgroundColor")?e.primaryButtonHoverBackgroundColor:l,secondaryButtonBackgroundColor:A(t,"secondaryButtonBackgroundColor")?e.secondaryButtonBackgroundColor:"#ffffff",secondaryButtonTextColor:A(t,"secondaryButtonTextColor")?e.secondaryButtonTextColor:a,secondaryButtonBorderColor:A(t,"secondaryButtonBorderColor")?e.secondaryButtonBorderColor:s,secondaryButtonHoverBackgroundColor:A(t,"secondaryButtonHoverBackgroundColor")?e.secondaryButtonHoverBackgroundColor:n,iconButtonBackgroundColor:A(t,"iconButtonBackgroundColor")?e.iconButtonBackgroundColor:"#ffffff",iconButtonIconColor:A(t,"iconButtonIconColor")?e.iconButtonIconColor:a,iconButtonBorderColor:A(t,"iconButtonBorderColor")?e.iconButtonBorderColor:s,iconButtonHoverBackgroundColor:A(t,"iconButtonHoverBackgroundColor")?e.iconButtonHoverBackgroundColor:n}},De=e=>{const t=e.fabBackgroundColor||e.openFabBackgroundColor||E.fabBackgroundColor,a=e.fabIconColor||e.openFabIconColor||E.fabIconColor;return{...e,fabBackgroundColor:t,fabIconColor:a,openFabBackgroundColor:t,openFabIconColor:a}},ve=(e={})=>De(ze({...E,...e,position:ye(e.position??E.position)},e)),G=e=>({..._e(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":Q(e.accentColor),"--header-avatar-bg":e.accentColor,"--header-avatar-text":Q(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}),Oe=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 We=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ge=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,a,r)=>r?r.toUpperCase():a.toLowerCase()),we=e=>{const t=Ge(e);return t.charAt(0).toUpperCase()+t.slice(1)},Be=(...e)=>e.filter((t,a,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===a).join(" ").trim(),Ke=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};var Je={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,...d},h)=>c.createElement("svg",{ref:h,...Je,width:t,height:t,stroke:e,strokeWidth:r?Number(a)*24/Number(t):a,className:Be("lucide",s),...!n&&!Ke(d)&&{"aria-hidden":"true"},...d},[...l.map(([C,B])=>c.createElement(C,B)),...Array.isArray(n)?n:[n]]));const N=(e,t)=>{const a=c.forwardRef(({className:r,...s},n)=>c.createElement(Ze,{ref:n,iconNode:t,className:Be(`lucide-${We(we(e))}`,`lucide-${e}`,r),...s}));return a.displayName=we(e),a};const Xe=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],Ye=N("arrow-right",Xe);const Qe=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],et=N("chevron-right",Qe);const tt=[["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"}]],ot=N("house",tt);const at=[["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"}]],nt=N("message-circle-more",at);const rt=[["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"}]],st=N("message-circle",rt);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"}]],ke=N("message-square",ct);const lt=[["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"}]],je=N("messages-square",lt);const it=[["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"}]],dt=N("rotate-ccw",it);const ut=[["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"}]],bt=N("square-pen",ut);const ht=[["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"}]],mt=N("thumbs-down",ht);const pt=[["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"}]],wt=N("thumbs-up",pt);const ft=[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],gt=N("user-round",ft);const xt=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Ne=N("x",xt),y={"aria-hidden":!0,strokeWidth:1.9},yt=o.jsx(dt,{...y}),re=o.jsx(Ne,{...y}),Ct=o.jsx(Ne,{...y}),fe={"message-circle-more":o.jsx(nt,{...y}),"message-circle":o.jsx(st,{...y}),"message-square":o.jsx(ke,{...y}),"messages-square":o.jsx(je,{...y})},vt=(e="messages-square")=>fe[e]||fe["messages-square"],Bt=o.jsx(Ye,{...y}),Ie=o.jsx(ot,{...y}),kt=o.jsx(ke,{...y}),jt=o.jsx(wt,{...y}),Nt=o.jsx(mt,{...y}),It=o.jsx(je,{...y}),Mt=o.jsx(et,{...y}),St=o.jsx(bt,{...y}),Tt=o.jsx(gt,{...y}),ae=e=>String(e).replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&apos;"),At=({name:e,backgroundColor:t})=>{const a=(e||"B").trim().charAt(0).toUpperCase()||"B",r=Q(t),s=`
2
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96" role="img" aria-label="${ae(e||"Bot")}">
3
- <rect width="96" height="96" rx="48" fill="${ae(t)}" />
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="${ae(r)}">${ae(a)}</text>
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./style.css');const o=require("react/jsx-runtime"),c=require("react"),H=require("@botpress/webchat"),z={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"},Ne=e=>e==="bottom-left"||e==="top-left"?"bottom-left":"bottom-right",_e=e=>{switch(Ne(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"}}},Ie=(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)}},ze=({r:e,g:t,b:a})=>`#${[e,t,a].map(r=>Ie(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=Ie(a,0,1);return ze({r:r.r*(1-n)+s.r*n,g:r.g*(1-n)+s.g*n,b:r.b*(1-n)+s.b*n})},Le=(e,t)=>t<0?ue(e,"#000000",Math.abs(t)):ue(e,"#ffffff",t),ne=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"},A=(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)||ne(a),s=ue(a,"#ffffff",.82)||z.secondaryButtonBorderColor,n=ue(a,"#ffffff",.92)||z.secondaryButtonHoverBackgroundColor,l=Le(a,-.12)||z.primaryButtonHoverBackgroundColor;return{...e,brandColor:a,brandTextColor:r,primaryButtonBackgroundColor:A(t,"primaryButtonBackgroundColor")?e.primaryButtonBackgroundColor:a,primaryButtonTextColor:A(t,"primaryButtonTextColor")?e.primaryButtonTextColor:r,primaryButtonHoverBackgroundColor:A(t,"primaryButtonHoverBackgroundColor")?e.primaryButtonHoverBackgroundColor:l,secondaryButtonBackgroundColor:A(t,"secondaryButtonBackgroundColor")?e.secondaryButtonBackgroundColor:"#ffffff",secondaryButtonTextColor:A(t,"secondaryButtonTextColor")?e.secondaryButtonTextColor:a,secondaryButtonBorderColor:A(t,"secondaryButtonBorderColor")?e.secondaryButtonBorderColor:s,secondaryButtonHoverBackgroundColor:A(t,"secondaryButtonHoverBackgroundColor")?e.secondaryButtonHoverBackgroundColor:n,iconButtonBackgroundColor:A(t,"iconButtonBackgroundColor")?e.iconButtonBackgroundColor:"#ffffff",iconButtonIconColor:A(t,"iconButtonIconColor")?e.iconButtonIconColor:a,iconButtonBorderColor:A(t,"iconButtonBorderColor")?e.iconButtonBorderColor:s,iconButtonHoverBackgroundColor:A(t,"iconButtonHoverBackgroundColor")?e.iconButtonHoverBackgroundColor:n}},De=e=>{const t=e.fabBackgroundColor||e.openFabBackgroundColor||z.fabBackgroundColor,a=e.fabIconColor||e.openFabIconColor||z.fabIconColor;return{...e,fabBackgroundColor:t,fabIconColor:a,openFabBackgroundColor:t,openFabIconColor:a}},Me=(e={})=>De(qe({...z,...e,position:Ne(e.position??z.position)},e)),Z=e=>({..._e(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":ne(e.accentColor),"--header-avatar-bg":e.accentColor,"--header-avatar-text":ne(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}),Oe=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 We=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ge=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,a,r)=>r?r.toUpperCase():a.toLowerCase()),ve=e=>{const t=Ge(e);return t.charAt(0).toUpperCase()+t.slice(1)},Se=(...e)=>e.filter((t,a,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===a).join(" ").trim(),Ke=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};var Je={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 Xe=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,...Je,width:t,height:t,stroke:e,strokeWidth:r?Number(a)*24/Number(t):a,className:Se("lucide",s),...!n&&!Ke(i)&&{"aria-hidden":"true"},...i},[...l.map(([m,f])=>c.createElement(m,f)),...Array.isArray(n)?n:[n]]));const N=(e,t)=>{const a=c.forwardRef(({className:r,...s},n)=>c.createElement(Xe,{ref:n,iconNode:t,className:Se(`lucide-${We(ve(e))}`,`lucide-${e}`,r),...s}));return a.displayName=ve(e),a};const Ze=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],Ye=N("arrow-right",Ze);const Qe=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],et=N("chevron-right",Qe);const tt=[["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"}]],ot=N("house",tt);const at=[["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"}]],nt=N("message-circle-more",at);const rt=[["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"}]],st=N("message-circle",rt);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"}]],Te=N("message-square",ct);const lt=[["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"}]],Ae=N("messages-square",lt);const it=[["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"}]],dt=N("rotate-ccw",it);const ut=[["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"}]],bt=N("square-pen",ut);const ht=[["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"}]],mt=N("thumbs-down",ht);const pt=[["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"}]],ft=N("thumbs-up",pt);const wt=[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],gt=N("user-round",wt);const xt=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Re=N("x",xt),C={"aria-hidden":!0,strokeWidth:1.9},yt=o.jsx(dt,{...C}),be=o.jsx(Re,{...C}),Ct=o.jsx(Re,{...C}),Be={"message-circle-more":o.jsx(nt,{...C}),"message-circle":o.jsx(st,{...C}),"message-square":o.jsx(Te,{...C}),"messages-square":o.jsx(Ae,{...C})},vt=(e="messages-square")=>Be[e]||Be["messages-square"],Bt=o.jsx(Ye,{...C}),Ue=o.jsx(ot,{...C}),kt=o.jsx(Te,{...C}),jt=o.jsx(ft,{...C}),Nt=o.jsx(mt,{...C}),It=o.jsx(Ae,{...C}),Mt=o.jsx(et,{...C}),St=o.jsx(bt,{...C}),Tt=o.jsx(gt,{...C}),de=e=>String(e).replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&apos;"),At=({name:e,backgroundColor:t})=>{const a=(e||"B").trim().charAt(0).toUpperCase()||"B",r=ne(t),s=`
2
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96" role="img" aria-label="${de(e||"Bot")}">
3
+ <rect width="96" height="96" rx="48" fill="${de(t)}" />
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)}`},Vt=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",ge=[{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}],Ut=new Intl.RelativeTimeFormat("pt-BR",{numeric:"auto"}),Ft=e=>{const t=Math.round((new Date(e).getTime()-Date.now())/1e3);if(Math.abs(t)<45)return"agora";let a=ge[0];for(const r of ge)Math.abs(t)>=r.seconds&&(a=r);return Ut.format(Math.round(t/a.seconds),a.unit)},Rt=({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}}}),Pt=({activeView:e,clientState:t,conversationId:a,messagesLength:r})=>{const[s,n]=c.useState(!1),l=e==="chat",d=l&&t==="connecting",h=l&&t==="connected"&&r===0,C=s&&(!l||r>0||t!=="connecting"&&t!=="connected");return c.useEffect(()=>{if(s){if(h){const B=window.setTimeout(()=>n(!1),900);return()=>window.clearTimeout(B)}if(C){const B=window.setTimeout(()=>n(!1),0);return()=>window.clearTimeout(B)}}},[a,s,h,C]),{showInitialLoading:d||s&&l,setShowInitialLoading:n}};function Ht({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:Ie}):null,o.jsx("button",{className:"bp-webchat-icon-button",type:"button","aria-label":"Abrir conversas",onClick:s,children:It}),o.jsx("button",{className:"bp-webchat-icon-button",type:"button","aria-label":"Reiniciar conversa",onClick:n,children:yt}),l?o.jsx("button",{className:"bp-webchat-icon-button bp-webchat-mobile-close",type:"button","aria-label":"Fechar webchat",onClick:l,children:re}):null]})]})}function Me(){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 $t({config:e,allowFileUpload:t,clientState:a,isTyping:r,messages:s,renderers:n,sendMessage:l,uploadFile:d,addMessageFeedback:h,showInitialLoading:C,onShowHome:B,onOpenHistory:p,onRestartConversation:j,onCloseWidget:k}){return o.jsxs("div",{className:"bp-webchat-layout",children:[o.jsx(Ht,{botName:e.botName,botAvatar:e.botAvatar,subtitle:e.subtitle,onShowHome:B,onOpenHistory:p,onRestartConversation:j,onCloseWidget:k}),o.jsx(F.Container,{className:"bp-webchat-container",uploadFile:d,allowFileUpload:t,children:C?o.jsx(Me,{}):o.jsxs(o.Fragment,{children:[o.jsx(F.MessageList,{botName:e.botName,botDescription:e.subtitle,botAvatar:e.botAvatar,isTyping:r,messages:s,sendMessage:l,addMessageFeedback:h,renderers:n,showDateSystemMessage:!1,showMessageStatus:!1,showIncomingMessageAvatar:!0,showOutgoingMessageAvatar:!1}),o.jsx(F.Composer,{connected:a!=="disconnected",sendMessage:l,uploadFile:d,allowFileUpload:t,composerPlaceholder:e.placeholder,disableSendButton:!1})]})})]})}function Se({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:Ie}),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:kt}),o.jsx("span",{children:"Conversas"})]})]})}function Et({conversations:e,currentConversationId:t,isLoading:a,botAvatar:r,botName:s,onClose:n,onCloseWidget:l,onShowHome:d,onShowConversations:h,onNewConversation:C,onConversationClick:B}){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:re}),l?o.jsx("button",{className:"bp-webchat-icon-button bp-webchat-mobile-close",type:"button",onClick:l,"aria-label":"Fechar webchat",children:re}):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(p=>{const j=Vt(p.lastMessage),k=p.lastMessage?.author?.type==="bot";return o.jsxs("button",{className:"bp-webchat-history-item",type:"button",onClick:()=>B(p.id),"data-current":p.id===t||void 0,children:[o.jsx("div",{className:"bp-webchat-history-avatar","data-kind":k?"bot":"user",children:k&&r?o.jsx("img",{src:r,alt:""}):k?o.jsx("span",{children:(s||"B").slice(0,1).toUpperCase()}):Tt}),o.jsxs("div",{className:"bp-webchat-history-content",children:[o.jsx("span",{className:"bp-webchat-history-name",children:j}),o.jsx("span",{className:"bp-webchat-history-time",children:Ft(p.updatedAt)})]}),o.jsx("span",{className:"bp-webchat-history-chevron",children:Mt})]},p.id)})}),o.jsx("div",{className:"bp-webchat-history-footer",children:o.jsxs("button",{className:"bp-webchat-history-new",type:"button",onClick:C,children:[St,o.jsx("span",{children:"Nova conversa"})]})}),o.jsx(Se,{activeView:"conversations",onShowHome:d,onShowConversations:h})]})}function _t({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 Lt({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 qt({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:re}),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:Bt})]})]})}),o.jsx(Se,{activeView:t,onShowHome:a,onShowConversations:r})]})}const zt=220,se="eduzz-webchat",ie=Object.freeze({allowFileUpload:!1,allowMessageFeedback:!1}),Dt="anonymous-id",Ot=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Te=e=>e.replace(/\/+$/,""),be=({webchatProxyUrl:e})=>{if(typeof e!="string"||!e.trim())return null;const t=Te(e.trim()),a="/webchat/proxy";return t.endsWith(a)?t.slice(0,-a.length):null},Wt=({webchatProxyUrl:e,clientId:t})=>!e||!t?null:`${e.endsWith("/")?e.slice(0,-1):e}/${encodeURIComponent(t)}/runtime-config`,Gt=({webchatProxyUrl:e,clientId:t,presetSlug:a})=>{if(!e||!t)return null;const r=be({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}`:""}`},Kt=e=>{const t=e&&typeof e=="object"&&e.data&&typeof e.data=="object"?e.data:e;return t&&typeof t=="object"?t:null},K=e=>Ot(e)?e:null,Jt=e=>{if(!e)return"";try{return JSON.stringify(e)}catch{return String(Date.now())}},Ae=e=>{if(typeof window>"u")return null;try{return e==="sessionStorage"?window.sessionStorage:window.localStorage}catch{return null}},Ve=({storageKey:e,storageLocation:t})=>{const a=Ae(t);if(!a)return null;try{const r=a.getItem(`${e||se}-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}},Zt=({storageKey:e,storageLocation:t})=>{const a=Ve({storageKey:e,storageLocation:t});return typeof a?.conversationId=="string"&&a.conversationId.trim()||void 0},xe=()=>{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)})},Xt=e=>`${e||se}-${Dt}`,Yt=({storageKey:e,storageLocation:t})=>{const a=Ae(t),r=Xt(e);try{const s=a?.getItem(r);if(s)return s;const n=`anon_${xe()}`;return a?.setItem(r,n),n}catch{return`anon_${xe()}`}},Qt=async({webchatProxyUrl:e,clientId:t,accountId:a})=>{const r=be({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}},eo=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}),to=({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=Ve({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():"",d=typeof n.user?.userToken=="string"?n.user.userToken.trim():"";return l&&d?{activeView:"chat",historyReturnView:"chat",bootstrapView:"chat"}:!l&&!d?{activeView:"home",historyReturnView:"home",bootstrapView:"home"}:{activeView:"pending",historyReturnView:"home",bootstrapView:"pending"}},oo=(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 ao({clientId:e,webchatProxyUrl:t,userCredentials:a,conversationId:r,config:s,defaultUserData:n,presetSlug:l,storageKey:d=se,storageLocation:h="localStorage",defaultOpen:C,onUserApiChange:B}){const p=c.useMemo(()=>typeof l=="string"&&l.trim()?l.trim():void 0,[l]),j=c.useMemo(()=>typeof t=="string"&&t.trim()?Te(t.trim()):void 0,[t]);c.useMemo(()=>j?be({webchatProxyUrl:j}):null,[j]);const k=!!(e&&j&&(p||!a)),f=c.useMemo(()=>k?Gt({webchatProxyUrl:j,clientId:e,presetSlug:p}):null,[e,p,j,k]),[S,_]=c.useState({error:null,isLoading:!1,payload:null,url:null});c.useEffect(()=>{if(!f){_({error:null,isLoading:!1,payload:null,url:null});return}const u=new AbortController;return _({error:null,isLoading:!0,payload:null,url:f}),fetch(f,{headers:{accept:"application/json"},signal:u.signal}).then(async m=>{if(!m.ok)throw new Error(`bootstrap request failed with status ${m.status}`);return m.json()}).then(m=>{const v=Kt(m);if(!v)throw new Error("bootstrap response is invalid");_({error:null,isLoading:!1,payload:v,url:f})}).catch(m=>{u.signal.aborted||(console.warn("[EduzzWebchat] failed to load bootstrap",m),_({error:m,isLoading:!1,payload:null,url:f}))}),()=>u.abort()},[f]);const g=f&&S.url===f?S.payload:null,L=f&&S.url===f?S.error:null,I=g?.clientId||e,V=j||g?.webchatProxyUrl||void 0,M=d===se&&g?.storageKey?g.storageKey:d,J=typeof C=="boolean"?C:typeof g?.defaultOpen=="boolean"?g.defaultOpen:C,ee=c.useMemo(()=>({...K(g?.config)||{},...K(s)||{}}),[g,s]),z=c.useMemo(()=>{const u={...K(g?.defaultUserData)||{},...K(n)||{}};return Object.keys(u).length>0?u:null},[n,g]),D=!!(!a&&g?.sessionMode==="service-hub"&&V&&I),[R,O]=c.useState({error:null,isLoading:!1,payload:null,key:null});c.useEffect(()=>{if(!D){O({error:null,isLoading:!1,payload:null,key:null});return}const u=Yt({storageKey:M,storageLocation:h}),m=`${I}:${V}:${u}`;let v=!1;return O({error:null,isLoading:!0,payload:null,key:m}),Qt({webchatProxyUrl:V,clientId:I,accountId:u}).then(b=>{v||O({error:null,isLoading:!1,payload:b,key:m})}).catch(b=>{v||(console.warn("[EduzzWebchat] failed to open public session",b),O({error:b,isLoading:!1,payload:null,key:m}))}),()=>{v=!0}},[I,M,V,D,h]);const P=D?R.payload:null,W=a||P,U=c.useMemo(()=>ve(ee),[ee]),H=c.useMemo(()=>r||Zt({storageKey:M,storageLocation:h}),[r,M,h]),w=J??U.initiallyOpen??!0,[ce,$]=c.useState(w),te=c.useRef(w),[le,q]=c.useState(ie),Z=c.useCallback(()=>$(u=>!u),[]);c.useEffect(()=>{te.current!==w&&(te.current=w,$(w))},[w]);const X=k&&!g&&!L,Y=D&&!P&&!R.error;return c.useEffect(()=>{const u=Wt({webchatProxyUrl:V,clientId:I});if(q(ie),!u)return;const m=new AbortController;let v=!1;return fetch(u,{headers:{accept:"application/json"},signal:m.signal}).then(async b=>{if(!b.ok)throw new Error(`runtime config request failed with status ${b.status}`);return b.json()}).then(b=>{if(v)return;const T=b&&typeof b=="object"&&b.data&&typeof b.data=="object"?b.data:{};q({allowFileUpload:T.allowFileUpload===!0,allowMessageFeedback:T.allowMessageFeedback===!0})}).catch(b=>{m.signal.aborted||v||(console.warn("[EduzzWebchat] failed to load runtime config",b),q(ie))}),()=>{v=!0,m.abort()}},[I,V]),X||Y?null:L&&!g?o.jsx("div",{className:"bp-webchat-shell",style:G(U),children:o.jsx("div",{className:"bp-webchat-error",children:"Nao foi possivel carregar a configuracao publica do webchat."})}):R.error&&!P?o.jsx("div",{className:"bp-webchat-shell",style:G(U),children:o.jsx("div",{className:"bp-webchat-error",children:"Nao foi possivel abrir a sessao publica do webchat."})}):V?I?o.jsx(F.WebchatProvider,{clientId:I,apiUrl:V,conversationId:H,userCredentials:W,storageKey:M,storageLocation:h,children:o.jsx(no,{clientId:I,config:U,defaultUserData:z,conversationIdProp:H,isOpen:ce,onUserApiChange:B,onToggle:Z,runtimeCapabilities:le,storageKey:M,storageLocation:h,userToken:W?.userToken})}):o.jsx("div",{className:"bp-webchat-shell",style:G(U),children:o.jsx("div",{className:"bp-webchat-error",children:"Nenhum clientId foi informado."})}):o.jsx("div",{className:"bp-webchat-shell",style:G(U),children:o.jsx("div",{className:"bp-webchat-error",children:"Nenhuma URL publica do proxy do webchat foi informada."})})}function no({clientId:e,config:t,defaultUserData:a,conversationIdProp:r,isOpen:s,onUserApiChange:n,onToggle:l,runtimeCapabilities:d,storageKey:h,storageLocation:C,userToken:B}){const p=c.useMemo(()=>to({showWelcomeScreen:t.showWelcomeScreen,storageKey:h,storageLocation:C,conversationId:r,userToken:B}),[t.showWelcomeScreen,r,h,C,B]),[j,k]=c.useState(!1),[f,S]=c.useState({open:!1,messageId:null,draft:""}),[{isPanelMounted:_,isPanelVisible:g},L]=c.useReducer(oo,{isPanelMounted:s,isPanelVisible:s}),{conversationId:I,isTyping:V,messages:M,saveMessageFeedback:J,sendMessage:ee,status:z,uploadFile:D}=F.useActiveConversation(),{openConversation:R,listConversations:O}=F.useConversations(),{updateUser:P,userCredentials:W}=F.useUser(),U=c.useRef({}),[H,w]=c.useState(()=>p.activeView),[ce,$]=c.useState(()=>p.historyReturnView),{conversations:te,isLoading:le,refresh:q}=F.useConversationList({userCredentials:W,listConversations:O,clientId:e}),Z=c.useMemo(()=>Jt(a),[a]),X=c.useCallback(async(x={})=>{if(!P)return;const i={...K(a)||{},...U.current,...K(x)||{}};return U.current=i,P(eo(i))},[a,P]),Y=c.useRef(X);c.useEffect(()=>{Y.current=X},[X]);const u=!!P;c.useEffect(()=>{U.current={}},[Z]),c.useEffect(()=>{if(n)return n({updateUserData:u?x=>Y.current(x):void 0}),()=>n(null)},[n,u]),c.useEffect(()=>{!u||!Z||Y.current()},[Z,u]),c.useEffect(()=>{d.allowMessageFeedback||S({open:!1,messageId:null,draft:""})},[d.allowMessageFeedback]);const{showInitialLoading:m,setShowInitialLoading:v}=Pt({activeView:H,clientState:z,conversationId:I,messagesLength:M.length}),b=c.useMemo(()=>t.botAvatar||At({name:t.botName,backgroundColor:t.accentColor}),[t.accentColor,t.botAvatar,t.botName]),T=c.useMemo(()=>({...t,botAvatar:b}),[t,b]),he=c.useCallback(async x=>{$(x),w("conversations"),await q()},[q]),Ue=c.useCallback(x=>{v(!0),R(x),w("chat")},[R,v]),me=c.useCallback(()=>{v(!0),R(),w("chat")},[R,v]),Fe=c.useMemo(()=>Rt({messages:M,user:W,botName:T.botName,botAvatar:T.botAvatar}),[M,T.botAvatar,T.botName,W]),Re=G(t),Pe=c.useMemo(()=>Oe(t),[t]),He=c.useMemo(()=>vt(t.fabChatIconVariant),[t.fabChatIconVariant]);c.useEffect(()=>{if(s){L({type:"show"});const oe=window.requestAnimationFrame(()=>L({type:"visible"}));return()=>window.cancelAnimationFrame(oe)}L({type:"hide"});const x=window.setTimeout(()=>{k(!1),S({open:!1,messageId:null,draft:""})},0),i=window.setTimeout(()=>L({type:"unmount"}),zt);return()=>{window.clearTimeout(x),window.clearTimeout(i)}},[s]),c.useEffect(()=>{if(p.bootstrapView==="pending"){if(M.length>0){const x=window.setTimeout(()=>{w("chat"),$("chat")},0);return()=>window.clearTimeout(x)}if(z!=="connecting"){const x=window.setTimeout(()=>{w("home"),$("home")},0);return()=>window.clearTimeout(x)}}},[z,p.bootstrapView,M.length]);const pe=c.useMemo(()=>function(i){const oe=d.allowMessageFeedback&&i.direction==="incoming"&&typeof i.addMessageFeedback=="function",Ee={...i.block,direction:i.direction,sender:i.sender,timestamp:i.timestamp,messageId:i.messageId,metadata:i.metadata,isReadOnly:i.isReadOnly,status:i.status,feedback:i.feedback,sendMessage:i.sendMessage,addMessageFeedback:i.addMessageFeedback};return o.jsxs("div",{className:"bpMessageBlocksBubble","data-direction":i.direction,"data-feedback":oe||void 0,children:[o.jsx(F.Block,{block:Ee}),oe?o.jsxs("div",{className:"bpMessageBlocksBubbleFeedbackContainer",children:[o.jsx("button",{className:"bpMessageBlocksBubbleFeedbackIcon",type:"button","data-selected":i.feedback==="positive","aria-label":"Feedback positivo",onClick:()=>i.addMessageFeedback(i.messageId,{value:"positive"}),children:jt}),o.jsx("button",{className:"bpMessageBlocksBubbleFeedbackIcon",type:"button","data-selected":i.feedback==="negative","aria-label":"Feedback negativo",onClick:()=>S({open:!0,messageId:i.messageId,draft:""}),children:Nt})]}):null]})},[d.allowMessageFeedback]),$e=c.useMemo(()=>({bubble:pe}),[pe]);return o.jsxs("div",{className:"bp-webchat-shell","data-panel-mounted":_,"data-panel-open":g,style:Re,children:[o.jsx(F.StylesheetProvider,{...Pe}),_?o.jsx("div",{className:"bp-webchat-panel","data-state":g?"open":"closed",children:H==="home"?o.jsx(qt,{config:T,activeView:H,onClose:l,onShowHome:()=>w("home"),onShowConversations:()=>he("home"),onStart:()=>w("chat")}):H==="conversations"?o.jsx(Et,{conversations:te,currentConversationId:I,isLoading:le,botAvatar:T.botAvatar,botName:T.botName,onClose:()=>w(ce),onCloseWidget:l,onShowHome:()=>{w("home"),$("home")},onShowConversations:q,onNewConversation:me,onConversationClick:Ue}):H==="pending"?o.jsx("div",{className:"bp-webchat-layout",children:o.jsx(Me,{})}):o.jsxs(o.Fragment,{children:[o.jsx($t,{config:T,allowFileUpload:d.allowFileUpload,clientState:z,isTyping:V,messages:Fe,renderers:$e,sendMessage:ee,uploadFile:D,addMessageFeedback:d.allowMessageFeedback?J:void 0,showInitialLoading:m,onShowHome:t.showWelcomeScreen?()=>{w("home"),$("home")}:void 0,onOpenHistory:()=>he("chat"),onRestartConversation:()=>k(!0),onCloseWidget:l}),o.jsx(Lt,{open:j,onCancel:()=>k(!1),onConfirm:()=>{k(!1),me()}}),d.allowMessageFeedback?o.jsx(_t,{open:f.open,draft:f.draft,setDraft:x=>S(i=>({...i,draft:x})),onCancel:()=>S({open:!1,messageId:null,draft:""}),onConfirm:async()=>{f.messageId&&J&&await J(f.messageId,{value:"negative",comment:f.draft}),S({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:He}),o.jsx("span",{className:"bp-webchat-fab-icon bp-webchat-fab-icon--close",children:Ct})]})]})}exports.Webchat=ao;exports.defaultConfig=E;exports.getContrastingTextColor=Q;exports.getShellStyle=G;exports.normalizeConfig=ve;
6
+ `.trim();return`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(s)}`},Rt=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",ke=[{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}],Ut=new Intl.RelativeTimeFormat("pt-BR",{numeric:"auto"}),Vt=e=>{const t=Math.round((new Date(e).getTime()-Date.now())/1e3);if(Math.abs(t)<45)return"agora";let a=ke[0];for(const r of ke)Math.abs(t)>=r.seconds&&(a=r);return Ut.format(Math.round(t/a.seconds),a.unit)},Ft=({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}}}),Pt=({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,m=s&&(!l||r>0||t!=="connecting"&&t!=="connected");return c.useEffect(()=>{if(s){if(u){const f=window.setTimeout(()=>n(!1),900);return()=>window.clearTimeout(f)}if(m){const f=window.setTimeout(()=>n(!1),0);return()=>window.clearTimeout(f)}}},[a,s,u,m]),{showInitialLoading:i||s&&l,setShowInitialLoading:n}},Ht=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 m=!0,f;const b=h=>{m&&(s(h),u.current?.(h))};if(!i.current){l(!1),b(null);return}const R=async()=>{try{const h=await i.current();if(!h?.userToken)throw new Error("Webchat session not created or empty");if(!m)return;b(h);const B=h.expiresAt-Date.now()-Ht;f=setTimeout(R,Math.max(B,0))}catch(h){console.error("[EduzzWebchat] error creating session: ",h),b(null)}finally{m&&l(!1)}};return l(!0),R(),()=>{m=!1,f&&clearTimeout(f)}},[t,!!e]),{session:r,resolving:n}};function Et({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:Ue}):null,o.jsx("button",{className:"bp-webchat-icon-button",type:"button","aria-label":"Abrir conversas",onClick:s,children:It}),o.jsx("button",{className:"bp-webchat-icon-button",type:"button","aria-label":"Reiniciar conversa",onClick:n,children:yt}),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 Ve(){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 _t({config:e,allowFileUpload:t,clientState:a,isTyping:r,messages:s,renderers:n,sendMessage:l,uploadFile:i,addMessageFeedback:u,showInitialLoading:m,onShowHome:f,onOpenHistory:b,onRestartConversation:R,onCloseWidget:h}){return o.jsxs("div",{className:"bp-webchat-layout",children:[o.jsx(Et,{botName:e.botName,botAvatar:e.botAvatar,subtitle:e.subtitle,onShowHome:f,onOpenHistory:b,onRestartConversation:R,onCloseWidget:h}),o.jsx(H.Container,{className:"bp-webchat-container",uploadFile:i,allowFileUpload:t,children:m?o.jsx(Ve,{}):o.jsxs(o.Fragment,{children:[o.jsx(H.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(H.Composer,{connected:a!=="disconnected",sendMessage:l,uploadFile:i,allowFileUpload:t,composerPlaceholder:e.placeholder,disableSendButton:!1})]})})]})}function Fe({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:Ue}),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:kt}),o.jsx("span",{children:"Conversas"})]})]})}function zt({conversations:e,currentConversationId:t,isLoading:a,botAvatar:r,botName:s,onClose:n,onCloseWidget:l,onShowHome:i,onShowConversations:u,onNewConversation:m,onConversationClick:f}){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 R=Rt(b.lastMessage),h=b.lastMessage?.author?.type==="bot";return o.jsxs("button",{className:"bp-webchat-history-item",type:"button",onClick:()=>f(b.id),"data-current":b.id===t||void 0,children:[o.jsx("div",{className:"bp-webchat-history-avatar","data-kind":h?"bot":"user",children:h&&r?o.jsx("img",{src:r,alt:""}):h?o.jsx("span",{children:(s||"B").slice(0,1).toUpperCase()}):Tt}),o.jsxs("div",{className:"bp-webchat-history-content",children:[o.jsx("span",{className:"bp-webchat-history-name",children:R}),o.jsx("span",{className:"bp-webchat-history-time",children:Vt(b.updatedAt)})]}),o.jsx("span",{className:"bp-webchat-history-chevron",children:Mt})]},b.id)})}),o.jsx("div",{className:"bp-webchat-history-footer",children:o.jsxs("button",{className:"bp-webchat-history-new",type:"button",onClick:m,children:[St,o.jsx("span",{children:"Nova conversa"})]})}),o.jsx(Fe,{activeView:"conversations",onShowHome:i,onShowConversations:u})]})}function Lt({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 qt({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 Dt({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:Bt})]})]})}),o.jsx(Fe,{activeView:t,onShowHome:a,onShowConversations:r})]})}const Ot=220,he="eduzz-webchat",ge=Object.freeze({allowFileUpload:!1,allowMessageFeedback:!1}),Wt="anonymous-id",Gt=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Pe=e=>e.replace(/\/+$/,""),Ce=({webchatProxyUrl:e})=>{if(typeof e!="string"||!e.trim())return null;const t=Pe(e.trim()),a="/webchat/proxy";return t.endsWith(a)?t.slice(0,-a.length):null},Kt=({webchatProxyUrl:e,clientId:t})=>!e||!t?null:`${e.endsWith("/")?e.slice(0,-1):e}/${encodeURIComponent(t)}/runtime-config`,Jt=({webchatProxyUrl:e,clientId:t,presetSlug:a})=>{if(!e||!t)return null;const r=Ce({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}`:""}`},Xt=e=>{const t=e&&typeof e=="object"&&e.data&&typeof e.data=="object"?e.data:e;return t&&typeof t=="object"?t:null},Y=e=>Gt(e)?e:null,Zt=e=>{if(!e)return"";try{return JSON.stringify(e)}catch{return String(Date.now())}},He=e=>{if(typeof window>"u")return null;try{return e==="sessionStorage"?window.sessionStorage:window.localStorage}catch{return null}},$e=({storageKey:e,storageLocation:t})=>{const a=He(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}},Yt=({storageKey:e,storageLocation:t})=>{const a=$e({storageKey:e,storageLocation:t});return typeof a?.conversationId=="string"&&a.conversationId.trim()||void 0},je=()=>{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)})},Qt=e=>`${e||he}-${Wt}`,eo=({storageKey:e,storageLocation:t})=>{const a=He(t),r=Qt(e);try{const s=a?.getItem(r);if(s)return s;const n=`anon_${je()}`;return a?.setItem(r,n),n}catch{return`anon_${je()}`}},to=async({webchatProxyUrl:e,clientId:t,accountId:a})=>{const r=Ce({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}},oo=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}),ao=({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=$e({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"}},no=(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 ro({clientId:e,webchatProxyUrl:t,userCredentials:a,conversationId:r,config:s,defaultUserData:n,presetSlug:l,storageKey:i=he,storageLocation:u="localStorage",defaultOpen:m,onUserApiChange:f,getSession:b,sessionKey:R,onSessionChange:h}){const{session:B,resolving:$}=$t({getSession:b,sessionKey:R,onSessionChange:h}),Q=!!B&&Date.now()<B.expiresAt,re=Q?{userId:B.userId,userToken:B.userToken}:void 0,_=b?re:a,ee=Q?B.conversationId:void 0,te=c.useMemo(()=>typeof l=="string"&&l.trim()?l.trim():void 0,[l]),k=c.useMemo(()=>typeof t=="string"&&t.trim()?Pe(t.trim()):void 0,[t]);c.useMemo(()=>k?Ce({webchatProxyUrl:k}):null,[k]);const L=!!(e&&k&&(te||!_)),I=c.useMemo(()=>L?Jt({webchatProxyUrl:k,clientId:e,presetSlug:te}):null,[e,te,k,L]),[E,W]=c.useState({error:null,isLoading:!1,payload:null,url:null});c.useEffect(()=>{if(!I){W({error:null,isLoading:!1,payload:null,url:null});return}const x=new AbortController;return W({error:null,isLoading:!0,payload:null,url:I}),fetch(I,{headers:{accept:"application/json"},signal:x.signal}).then(async g=>{if(!g.ok)throw new Error(`bootstrap request failed with status ${g.status}`);return g.json()}).then(g=>{const S=Xt(g);if(!S)throw new Error("bootstrap response is invalid");W({error:null,isLoading:!1,payload:S,url:I})}).catch(g=>{x.signal.aborted||(console.warn("[EduzzWebchat] failed to load bootstrap",g),W({error:g,isLoading:!1,payload:null,url:I}))}),()=>x.abort()},[I]);const w=I&&E.url===I?E.payload:null,se=I&&E.url===I?E.error:null,v=w?.clientId||e,M=k||w?.webchatProxyUrl||void 0,U=i===he&&w?.storageKey?w.storageKey:i,q=typeof m=="boolean"?m:typeof w?.defaultOpen=="boolean"?w.defaultOpen:m,j=c.useMemo(()=>({...Y(w?.config)||{},...Y(s)||{}}),[w,s]),me=c.useMemo(()=>{const x={...Y(w?.defaultUserData)||{},...Y(n)||{}};return Object.keys(x).length>0?x:null},[n,w]),V=!!(!_&&!$&&w?.sessionMode==="service-hub"&&M&&v),[oe,G]=c.useState({error:null,isLoading:!1,payload:null,key:null});c.useEffect(()=>{if(!V){G({error:null,isLoading:!1,payload:null,key:null});return}const x=eo({storageKey:U,storageLocation:u}),g=`${v}:${M}:${x}`;let S=!1;return G({error:null,isLoading:!0,payload:null,key:g}),to({webchatProxyUrl:M,clientId:v,accountId:x}).then(p=>{S||G({error:null,isLoading:!1,payload:p,key:g})}).catch(p=>{S||(console.warn("[EduzzWebchat] failed to open public session",p),G({error:p,isLoading:!1,payload:null,key:g}))}),()=>{S=!0}},[v,U,M,V,u]);const D=V?oe.payload:null,K=_||D,F=c.useMemo(()=>Me(j),[j]),J=c.useMemo(()=>ee||r||Yt({storageKey:U,storageLocation:u}),[ee,r,U,u]),T=q??F.initiallyOpen??!0,[pe,O]=c.useState(T),ae=c.useRef(T),[P,X]=c.useState(ge),fe=c.useCallback(()=>O(x=>!x),[]);c.useEffect(()=>{ae.current!==T&&(ae.current=T,O(T))},[T]);const ce=L&&!w&&!se,we=V&&!D&&!oe.error;return c.useEffect(()=>{const x=Kt({webchatProxyUrl:M,clientId:v});if(X(ge),!x)return;const g=new AbortController;let S=!1;return fetch(x,{headers:{accept:"application/json"},signal:g.signal}).then(async p=>{if(!p.ok)throw new Error(`runtime config request failed with status ${p.status}`);return p.json()}).then(p=>{if(S)return;const le=p&&typeof p=="object"&&p.data&&typeof p.data=="object"?p.data:{};X({allowFileUpload:le.allowFileUpload===!0,allowMessageFeedback:le.allowMessageFeedback===!0})}).catch(p=>{g.signal.aborted||S||(console.warn("[EduzzWebchat] failed to load runtime config",p),X(ge))}),()=>{S=!0,g.abort()}},[v,M]),ce||we||b&&$?null:se&&!w?o.jsx("div",{className:"bp-webchat-shell",style:Z(F),children:o.jsx("div",{className:"bp-webchat-error",children:"Nao foi possivel carregar a configuracao publica do webchat."})}):oe.error&&!D?o.jsx("div",{className:"bp-webchat-shell",style:Z(F),children:o.jsx("div",{className:"bp-webchat-error",children:"Nao foi possivel abrir a sessao publica do webchat."})}):M?v?o.jsx(H.WebchatProvider,{clientId:v,apiUrl:M,conversationId:J,userCredentials:K,storageKey:U,storageLocation:u,children:o.jsx(so,{clientId:v,config:F,defaultUserData:me,conversationIdProp:J,isOpen:pe,onUserApiChange:f,onToggle:fe,runtimeCapabilities:P,storageKey:U,storageLocation:u,userToken:K?.userToken})}):o.jsx("div",{className:"bp-webchat-shell",style:Z(F),children:o.jsx("div",{className:"bp-webchat-error",children:"Nenhum clientId foi informado."})}):o.jsx("div",{className:"bp-webchat-shell",style:Z(F),children:o.jsx("div",{className:"bp-webchat-error",children:"Nenhuma URL publica do proxy do webchat foi informada."})})}function so({clientId:e,config:t,defaultUserData:a,conversationIdProp:r,isOpen:s,onUserApiChange:n,onToggle:l,runtimeCapabilities:i,storageKey:u,storageLocation:m,userToken:f}){const b=c.useMemo(()=>ao({showWelcomeScreen:t.showWelcomeScreen,storageKey:u,storageLocation:m,conversationId:r,userToken:f}),[t.showWelcomeScreen,r,u,m,f]),[R,h]=c.useState(!1),[B,$]=c.useState({open:!1,messageId:null,draft:""}),[{isPanelMounted:Q,isPanelVisible:re},_]=c.useReducer(no,{isPanelMounted:s,isPanelVisible:s}),{conversationId:ee,isTyping:te,messages:k,saveMessageFeedback:L,sendMessage:I,status:E,uploadFile:W}=H.useActiveConversation(),{openConversation:w,listConversations:se}=H.useConversations(),{updateUser:v,userCredentials:M}=H.useUser(),U=c.useRef({}),[q,j]=c.useState(()=>b.activeView),[me,V]=c.useState(()=>b.historyReturnView),{conversations:oe,isLoading:G,refresh:D}=H.useConversationList({userCredentials:M,listConversations:se,clientId:e}),K=c.useMemo(()=>Zt(a),[a]),F=c.useCallback(async(y={})=>{if(!v)return;const d={...Y(a)||{},...U.current,...Y(y)||{}};return U.current=d,v(oo(d))},[a,v]),J=c.useRef(F);c.useEffect(()=>{J.current=F},[F]);const T=!!v;c.useEffect(()=>{U.current={}},[K]),c.useEffect(()=>{if(n)return n({updateUserData:T?y=>J.current(y):void 0}),()=>n(null)},[n,T]),c.useEffect(()=>{!T||!K||J.current()},[K,T]),c.useEffect(()=>{i.allowMessageFeedback||$({open:!1,messageId:null,draft:""})},[i.allowMessageFeedback]);const{showInitialLoading:pe,setShowInitialLoading:O}=Pt({activeView:q,clientState:E,conversationId:ee,messagesLength:k.length}),ae=c.useMemo(()=>t.botAvatar||At({name:t.botName,backgroundColor:t.accentColor}),[t.accentColor,t.botAvatar,t.botName]),P=c.useMemo(()=>({...t,botAvatar:ae}),[t,ae]),X=c.useCallback(async y=>{V(y),j("conversations"),await D()},[D]),fe=c.useCallback(y=>{O(!0),w(y),j("chat")},[w,O]),ce=c.useCallback(()=>{O(!0),w(),j("chat")},[w,O]),we=c.useMemo(()=>Ft({messages:k,user:M,botName:P.botName,botAvatar:P.botAvatar}),[k,P.botAvatar,P.botName,M]),x=Z(t),g=c.useMemo(()=>Oe(t),[t]),S=c.useMemo(()=>vt(t.fabChatIconVariant),[t.fabChatIconVariant]);c.useEffect(()=>{if(s){_({type:"show"});const ie=window.requestAnimationFrame(()=>_({type:"visible"}));return()=>window.cancelAnimationFrame(ie)}_({type:"hide"});const y=window.setTimeout(()=>{h(!1),$({open:!1,messageId:null,draft:""})},0),d=window.setTimeout(()=>_({type:"unmount"}),Ot);return()=>{window.clearTimeout(y),window.clearTimeout(d)}},[s]),c.useEffect(()=>{if(b.bootstrapView==="pending"){if(k.length>0){const y=window.setTimeout(()=>{j("chat"),V("chat")},0);return()=>window.clearTimeout(y)}if(E!=="connecting"){const y=window.setTimeout(()=>{j("home"),V("home")},0);return()=>window.clearTimeout(y)}}},[E,b.bootstrapView,k.length]);const p=c.useMemo(()=>function(d){const ie=i.allowMessageFeedback&&d.direction==="incoming"&&typeof d.addMessageFeedback=="function",Ee={...d.block,direction:d.direction,sender:d.sender,timestamp:d.timestamp,messageId:d.messageId,metadata:d.metadata,isReadOnly:d.isReadOnly,status:d.status,feedback:d.feedback,sendMessage:d.sendMessage,addMessageFeedback:d.addMessageFeedback};return o.jsxs("div",{className:"bpMessageBlocksBubble","data-direction":d.direction,"data-feedback":ie||void 0,children:[o.jsx(H.Block,{block:Ee}),ie?o.jsxs("div",{className:"bpMessageBlocksBubbleFeedbackContainer",children:[o.jsx("button",{className:"bpMessageBlocksBubbleFeedbackIcon",type:"button","data-selected":d.feedback==="positive","aria-label":"Feedback positivo",onClick:()=>d.addMessageFeedback(d.messageId,{value:"positive"}),children:jt}),o.jsx("button",{className:"bpMessageBlocksBubbleFeedbackIcon",type:"button","data-selected":d.feedback==="negative","aria-label":"Feedback negativo",onClick:()=>$({open:!0,messageId:d.messageId,draft:""}),children:Nt})]}):null]})},[i.allowMessageFeedback]),le=c.useMemo(()=>({bubble:p}),[p]);return o.jsxs("div",{className:"bp-webchat-shell","data-panel-mounted":Q,"data-panel-open":re,style:x,children:[o.jsx(H.StylesheetProvider,{...g}),Q?o.jsx("div",{className:"bp-webchat-panel","data-state":re?"open":"closed",children:q==="home"?o.jsx(Dt,{config:P,activeView:q,onClose:l,onShowHome:()=>j("home"),onShowConversations:()=>X("home"),onStart:()=>j("chat")}):q==="conversations"?o.jsx(zt,{conversations:oe,currentConversationId:ee,isLoading:G,botAvatar:P.botAvatar,botName:P.botName,onClose:()=>j(me),onCloseWidget:l,onShowHome:()=>{j("home"),V("home")},onShowConversations:D,onNewConversation:ce,onConversationClick:fe}):q==="pending"?o.jsx("div",{className:"bp-webchat-layout",children:o.jsx(Ve,{})}):o.jsxs(o.Fragment,{children:[o.jsx(_t,{config:P,allowFileUpload:i.allowFileUpload,clientState:E,isTyping:te,messages:we,renderers:le,sendMessage:I,uploadFile:W,addMessageFeedback:i.allowMessageFeedback?L:void 0,showInitialLoading:pe,onShowHome:t.showWelcomeScreen?()=>{j("home"),V("home")}:void 0,onOpenHistory:()=>X("chat"),onRestartConversation:()=>h(!0),onCloseWidget:l}),o.jsx(qt,{open:R,onCancel:()=>h(!1),onConfirm:()=>{h(!1),ce()}}),i.allowMessageFeedback?o.jsx(Lt,{open:B.open,draft:B.draft,setDraft:y=>$(d=>({...d,draft:y})),onCancel:()=>$({open:!1,messageId:null,draft:""}),onConfirm:async()=>{B.messageId&&L&&await L(B.messageId,{value:"negative",comment:B.draft}),$({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:S}),o.jsx("span",{className:"bp-webchat-fab-icon bp-webchat-fab-icon--close",children:Ct})]})]})}exports.Webchat=ro;exports.defaultConfig=z;exports.getContrastingTextColor=ne;exports.getShellStyle=Z;exports.normalizeConfig=Me;