@flowengage/react-chatbot 8.0.117 → 8.0.119
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.
|
@@ -156,78 +156,82 @@ Error generating stack: `+e.message+`
|
|
|
156
156
|
#${Q}-panel {
|
|
157
157
|
position: fixed;
|
|
158
158
|
bottom: 1.5rem;
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
right: 1.5rem;
|
|
160
|
+
width: 320px;
|
|
161
|
+
min-height: 300px;
|
|
162
|
+
height: min(72vh, 640px);
|
|
163
|
+
max-height: calc(100vh - 120px);
|
|
161
164
|
display: flex;
|
|
162
165
|
flex-direction: column;
|
|
163
|
-
background:
|
|
164
|
-
|
|
165
|
-
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
color: #f1f5f9;
|
|
166
|
+
background: #ffffff;
|
|
167
|
+
border: 1px solid rgba(16, 24, 40, 0.08);
|
|
168
|
+
border-radius: 16px;
|
|
169
|
+
box-shadow: 0 12px 40px rgba(16, 24, 40, 0.18), 0 2px 6px rgba(16, 24, 40, 0.06);
|
|
170
|
+
color: #101828;
|
|
169
171
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
170
172
|
z-index: 999998;
|
|
171
173
|
opacity: 0;
|
|
172
|
-
transform: translateY(
|
|
173
|
-
transition: opacity 0.
|
|
174
|
+
transform: translateY(10px);
|
|
175
|
+
transition: opacity 0.18s ease, transform 0.18s ease;
|
|
174
176
|
pointer-events: none;
|
|
175
177
|
overflow: hidden;
|
|
176
178
|
}
|
|
177
179
|
#${Q}-panel.${Q}-show { opacity: 1; transform: translateY(0); pointer-events: auto; }
|
|
178
|
-
#${Q}-panel[data-side="right"] { right: calc(1.5rem + 350px + 14px); }
|
|
179
|
-
#${Q}-panel[data-side="left"] { left: calc(1.5rem + 350px + 14px); }
|
|
180
180
|
@media (max-width: 900px) {
|
|
181
|
-
#${Q}-panel
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
left: 12px; right: 12px; width: auto;
|
|
185
|
-
bottom: 12px; max-height: 45vh;
|
|
181
|
+
#${Q}-panel {
|
|
182
|
+
left: 12px !important; right: 12px !important; width: auto !important;
|
|
183
|
+
bottom: 12px !important; height: 50vh; min-height: 0;
|
|
186
184
|
}
|
|
187
185
|
}
|
|
188
186
|
#${Q}-panel-head {
|
|
189
187
|
display: flex; align-items: center; gap: 8px;
|
|
190
|
-
padding:
|
|
191
|
-
border-bottom: 1px solid rgba(
|
|
188
|
+
padding: 14px 14px 12px;
|
|
189
|
+
border-bottom: 1px solid rgba(16, 24, 40, 0.07);
|
|
192
190
|
flex-shrink: 0;
|
|
193
191
|
}
|
|
194
|
-
#${Q}-panel-title { font-size:
|
|
195
|
-
#${Q}-panel-count {
|
|
192
|
+
#${Q}-panel-title { font-size: 14px; font-weight: 600; color: #101828; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
193
|
+
#${Q}-panel-count {
|
|
194
|
+
font-size: 11px; font-weight: 600; color: #475467; flex-shrink: 0;
|
|
195
|
+
background: #f2f4f7; border-radius: 999px; padding: 2px 8px;
|
|
196
|
+
}
|
|
196
197
|
#${Q}-panel-close {
|
|
197
|
-
flex-shrink: 0; width:
|
|
198
|
-
border-radius: 50%; background:
|
|
199
|
-
font-size:
|
|
200
|
-
transition: background 0.15s ease;
|
|
198
|
+
flex-shrink: 0; width: 26px; height: 26px; border: none; cursor: pointer;
|
|
199
|
+
border-radius: 50%; background: #f2f4f7; color: #475467;
|
|
200
|
+
font-size: 16px; line-height: 1; display: flex; align-items: center; justify-content: center;
|
|
201
|
+
transition: background 0.15s ease, color 0.15s ease;
|
|
201
202
|
}
|
|
202
|
-
#${Q}-panel-close:hover { background:
|
|
203
|
+
#${Q}-panel-close:hover { background: #e4e7ec; color: #101828; }
|
|
203
204
|
#${Q}-panel-list { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
|
|
204
205
|
.${Q}-card {
|
|
205
|
-
display: flex; gap:
|
|
206
|
-
padding:
|
|
207
|
-
background: rgba(
|
|
206
|
+
display: flex; gap: 11px; align-items: center;
|
|
207
|
+
padding: 9px; border-radius: 11px;
|
|
208
|
+
background: #ffffff; border: 1px solid rgba(16, 24, 40, 0.07);
|
|
208
209
|
text-decoration: none; color: inherit;
|
|
209
|
-
transition: background 0.15s ease,
|
|
210
|
+
transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
|
|
211
|
+
}
|
|
212
|
+
.${Q}-card:hover {
|
|
213
|
+
background: #fafbfc; border-color: rgba(16, 24, 40, 0.14);
|
|
214
|
+
box-shadow: 0 2px 8px rgba(16, 24, 40, 0.07);
|
|
210
215
|
}
|
|
211
|
-
.${Q}-card:hover { background: rgba(255,255,255,0.10); transform: translateY(-1px); }
|
|
212
216
|
.${Q}-card-thumb {
|
|
213
|
-
width:
|
|
214
|
-
object-fit: cover; background:
|
|
217
|
+
width: 52px; height: 52px; flex-shrink: 0; border-radius: 9px;
|
|
218
|
+
object-fit: cover; background: #f2f4f7;
|
|
215
219
|
}
|
|
216
220
|
.${Q}-card-thumb-ph {
|
|
217
|
-
width:
|
|
218
|
-
background:
|
|
219
|
-
justify-content: center; font-size:
|
|
221
|
+
width: 52px; height: 52px; flex-shrink: 0; border-radius: 9px;
|
|
222
|
+
background: #f2f4f7; display: flex; align-items: center;
|
|
223
|
+
justify-content: center; font-size: 18px; opacity: 0.6;
|
|
220
224
|
}
|
|
221
225
|
.${Q}-card-body { min-width: 0; flex: 1; }
|
|
222
226
|
.${Q}-card-title {
|
|
223
|
-
font-size:
|
|
227
|
+
font-size: 13px; font-weight: 600; line-height: 1.35; color: #101828;
|
|
224
228
|
display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
|
|
225
229
|
}
|
|
226
|
-
.${Q}-card-meta { font-size:
|
|
227
|
-
.${Q}-card-price { font-size:
|
|
230
|
+
.${Q}-card-meta { font-size: 11px; color: #667085; margin-top: 3px; }
|
|
231
|
+
.${Q}-card-price { font-size: 12.5px; font-weight: 600; color: #101828; margin-top: 3px; }
|
|
228
232
|
.${Q}-chip {
|
|
229
|
-
display: inline-block; font-size:
|
|
230
|
-
background:
|
|
233
|
+
display: inline-block; font-size: 10px; font-weight: 600; padding: 1px 7px;
|
|
234
|
+
border-radius: 999px; background: #eef2ff; color: #4338ca; margin-right: 6px;
|
|
231
235
|
}
|
|
232
236
|
|
|
233
237
|
/* ── Keyframes ───────────────────────────────────────────────────────────────── */
|
|
@@ -251,25 +255,25 @@ Error generating stack: `+e.message+`
|
|
|
251
255
|
50% { transform: translate(-4px,-4px) scale(0.82); }
|
|
252
256
|
100% { transform: translate(-4px,-4px) scale(1); }
|
|
253
257
|
}
|
|
254
|
-
`,t=document.createElement(`style`);t.id=`${Q}-styles`,t.textContent=e,(document.head||document.documentElement).appendChild(t)}var Ch=null,wh=null;function Th(){return(!Ch||!Ch.isConnected)&&(Ch=document.createElement(`div`),Ch.id=`${Q}-toast`,document.body.appendChild(Ch)),Ch}function Eh(e,{spinner:t=!0,icon:n=null,duration:r=0}={}){if(typeof document>`u`)return;Sh(),wh&&=(clearTimeout(wh),null);let i=Th();if(i.innerHTML=``,n){let e=document.createElement(`span`);e.className=`${Q}-icon`,e.textContent=n,i.appendChild(e)}else if(t){let e=document.createElement(`span`);e.className=`${Q}-spin`,i.appendChild(e)}let a=document.createElement(`span`);a.textContent=e,i.appendChild(a),i.classList.remove(`${Q}-show`),i.offsetHeight,i.classList.add(`${Q}-show`),r>0&&(wh=setTimeout(()=>Dh(),r))}function Dh(e=0){Ch&&(e>0?wh=setTimeout(()=>{Ch&&Ch.classList.remove(`${Q}-show`)},e):Ch&&Ch.classList.remove(`${Q}-show`))}var Oh=null;function kh(){return(!Oh||!Oh.isConnected)&&(Oh=document.createElement(`div`),Oh.id=`${Q}-panel`,document.body.appendChild(Oh)),Oh}function Ah(e,t){let n=Number(e);if(!Number.isFinite(n))return null;let r=n.toLocaleString(void 0,{minimumFractionDigits:n%1==0?0:2,maximumFractionDigits:2});return t?`${t} ${r}`:r}function
|
|
258
|
+
`,t=document.createElement(`style`);t.id=`${Q}-styles`,t.textContent=e,(document.head||document.documentElement).appendChild(t)}var Ch=null,wh=null;function Th(){return(!Ch||!Ch.isConnected)&&(Ch=document.createElement(`div`),Ch.id=`${Q}-toast`,document.body.appendChild(Ch)),Ch}function Eh(e,{spinner:t=!0,icon:n=null,duration:r=0}={}){if(typeof document>`u`)return;Sh(),wh&&=(clearTimeout(wh),null);let i=Th();if(i.innerHTML=``,n){let e=document.createElement(`span`);e.className=`${Q}-icon`,e.textContent=n,i.appendChild(e)}else if(t){let e=document.createElement(`span`);e.className=`${Q}-spin`,i.appendChild(e)}let a=document.createElement(`span`);a.textContent=e,i.appendChild(a),i.classList.remove(`${Q}-show`),i.offsetHeight,i.classList.add(`${Q}-show`),r>0&&(wh=setTimeout(()=>Dh(),r))}function Dh(e=0){Ch&&(e>0?wh=setTimeout(()=>{Ch&&Ch.classList.remove(`${Q}-show`)},e):Ch&&Ch.classList.remove(`${Q}-show`))}var Oh=null;function kh(){return(!Oh||!Oh.isConnected)&&(Oh=document.createElement(`div`),Oh.id=`${Q}-panel`,document.body.appendChild(Oh)),Oh}var Ah=12,jh=`right`,Mh=!1;function Nh(e,t){if(e.style.left=``,e.style.right=``,e.style.bottom=``,window.innerWidth<=900)return;let n=document.getElementById(`flowengage-root`),r=(n?.shadowRoot?.querySelector(`.flowengage-widget-root`)||document.querySelector(`.flowengage-widget-root`)||n)?.getBoundingClientRect();if(!r||!r.width){t===`left`?e.style.left=`calc(1.5rem + 120px)`:e.style.right=`calc(1.5rem + 120px)`;return}t===`left`?e.style.left=`${Math.round(r.right+Ah)}px`:e.style.right=`${Math.round(window.innerWidth-r.left+Ah)}px`,e.style.bottom=`${Math.max(12,Math.round(window.innerHeight-r.bottom))}px`}function Ph(e,t){let n=Number(e);if(!Number.isFinite(n))return null;let r=n.toLocaleString(void 0,{minimumFractionDigits:n%1==0?0:2,maximumFractionDigits:2});return t?`${t} ${r}`:r}function Fh(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`})}function Ih(e,{title:t=`Products`,side:n=`right`,productUrl:r=null}={}){if(typeof document>`u`)return;let i=Array.isArray(e)?e.filter(Boolean):[];if(!i.length)return Lh();Sh();let a=kh();jh=n===`left`?`left`:`right`,Nh(a,jh),Mh||(Mh=!0,window.addEventListener(`resize`,()=>{Oh?.classList.contains(`${Q}-show`)&&Nh(Oh,jh)})),a.innerHTML=``;let o=document.createElement(`div`);o.id=`${Q}-panel-head`;let s=document.createElement(`div`);s.id=`${Q}-panel-title`,s.textContent=t;let c=document.createElement(`span`);c.id=`${Q}-panel-count`,c.textContent=String(i.length);let l=document.createElement(`button`);l.id=`${Q}-panel-close`,l.type=`button`,l.setAttribute(`aria-label`,`Close product panel`),l.textContent=`×`,l.addEventListener(`click`,()=>Lh()),o.append(s,c,l);let u=document.createElement(`div`);u.id=`${Q}-panel-list`;for(let e of i){let t=typeof r==`function`?r(e):null,n=document.createElement(t?`a`:`div`);if(n.className=`${Q}-card`,t&&(n.href=t,n.rel=`noopener`),e.image){let t=document.createElement(`img`);t.className=`${Q}-card-thumb`,t.src=e.image,t.alt=``,t.loading=`lazy`,t.addEventListener(`error`,()=>{let e=document.createElement(`div`);e.className=`${Q}-card-thumb-ph`,e.textContent=`🛍`,t.replaceWith(e)}),n.appendChild(t)}else{let e=document.createElement(`div`);e.className=`${Q}-card-thumb-ph`,e.textContent=`🛍`,n.appendChild(e)}let i=document.createElement(`div`);i.className=`${Q}-card-body`;let a=document.createElement(`div`);a.className=`${Q}-card-title`,a.textContent=e.title||`Item`,i.appendChild(a);let o=[];e.quantity>1&&o.push(`Qty ${e.quantity}`);let s=Fh(e.orderedAt);if(s&&o.push(s),e.fulfillmentStatus&&o.push(e.fulfillmentStatus),o.length||e.productType){let t=document.createElement(`div`);if(t.className=`${Q}-card-meta`,e.productType){let n=document.createElement(`span`);n.className=`${Q}-chip`,n.textContent=e.productType,t.appendChild(n)}t.appendChild(document.createTextNode(o.join(` · `))),i.appendChild(t)}let c=Ph(e.price,e.currency);if(c){let e=document.createElement(`div`);e.className=`${Q}-card-price`,e.textContent=c,i.appendChild(e)}n.appendChild(i),u.appendChild(n)}a.append(o,u),a.classList.remove(`${Q}-show`),a.offsetHeight,a.classList.add(`${Q}-show`)}function Lh(){Oh&&Oh.classList.remove(`${Q}-show`)}var Rh=null,zh=[];function Bh(){return(!Rh||!Rh.isConnected)&&(Rh=document.createElement(`div`),Rh.id=`${Q}-bar`,document.body.appendChild(Rh)),Rh}function Vh(){if(typeof document>`u`)return;Sh(),zh.forEach(clearTimeout),zh=[];let e=Bh();e.style.transition=`none`,e.style.width=`0%`,e.classList.add(`${Q}-bar-active`),e.offsetHeight,e.style.transition=`width 0.35s ease, opacity 0.25s ease`;let t=[[80,`width 0.6s ease`],[92,`width 1.2s ease`]],n=50;for(let[e,r]of t){let t=n,i=e,a=r;zh.push(setTimeout(()=>{Rh&&(Rh.style.transition=a,Rh.style.width=`${i}%`)},t)),n+=800}}function Hh(){Rh&&(zh.forEach(clearTimeout),zh=[],Rh.style.transition=`width 0.2s ease`,Rh.style.width=`100%`,zh.push(setTimeout(()=>{Rh&&(Rh.style.transition=`opacity 0.35s ease`,Rh.style.opacity=`0`,zh.push(setTimeout(()=>{Rh&&(Rh.style.width=`0%`,Rh.classList.remove(`${Q}-bar-active`))},380)))},220)))}var Uh=`<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22" fill="none">
|
|
255
259
|
<filter id="${Q}-csh">
|
|
256
260
|
<feDropShadow dx="1" dy="2" stdDeviation="1.5" flood-color="#00000060"/>
|
|
257
261
|
</filter>
|
|
258
262
|
<path d="M4 2L19 10.5L11 12.8L8 20L4 2Z"
|
|
259
263
|
fill="white" stroke="#1e1b4b" stroke-width="1.6" stroke-linejoin="round"
|
|
260
264
|
filter="url(#${Q}-csh)"/>
|
|
261
|
-
</svg>`,
|
|
265
|
+
</svg>`,Wh=null,Gh=!1;function Kh(){return(!Wh||!Wh.isConnected)&&(Wh=document.createElement(`div`),Wh.id=`${Q}-cursor`,Wh.innerHTML=Uh,document.body.appendChild(Wh),Gh=!1),Wh}async function qh(e){if(typeof document>`u`||!e)return;Sh();let t;try{t=e.getBoundingClientRect()}catch{return}let n=t.left+Math.min(16,t.width*.2),r=t.top+Math.min(12,t.height*.25),i=Kh();Gh||=(i.style.transition=`none`,i.style.left=`${window.innerWidth/2}px`,i.style.top=`${window.innerHeight*.4}px`,i.classList.add(`${Q}-cursor-visible`),i.offsetHeight,i.style.transition=`left 0.32s cubic-bezier(0.25,0.46,0.45,0.94), top 0.32s cubic-bezier(0.25,0.46,0.45,0.94), opacity 0.2s ease`,!0),i.style.left=`${n}px`,i.style.top=`${r}px`,await Zh(360)}function Jh(e=!1){Wh&&(e?(Wh.classList.remove(`${Q}-cursor-visible`),Gh=!1):(Wh.classList.remove(`${Q}-cursor-visible`),setTimeout(()=>{Gh=!1},250)))}async function Yh(e){Wh&&(Wh.classList.add(`${Q}-cursor-click`),await Zh(280),Wh.classList.remove(`${Q}-cursor-click`))}function Xh(e){if(!e||typeof document>`u`)return;Sh();let t;try{t=e.getBoundingClientRect()}catch{return}let n=e.style.position,r=e.style.overflow,i=window.getComputedStyle(e).position;[`relative`,`absolute`,`fixed`,`sticky`].includes(i)||(e.style.position=`relative`),e.style.overflow=`hidden`;let a=document.createElement(`span`);a.className=`${Q}-ripple`;let o=Math.max(t.width,t.height)*1.2;Object.assign(a.style,{width:`${o}px`,height:`${o}px`,left:`${t.width/2-o/2}px`,top:`${t.height/2-o/2}px`}),e.appendChild(a),setTimeout(()=>{a.remove(),e.style.position=n,e.style.overflow=r},650)}function Zh(e){return new Promise(t=>setTimeout(t,e))}var Qh=({size:e=18,color:t=`currentColor`})=>(0,V.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,V.jsx)(`path`,{d:`M12 1a4 4 0 014 4v6a4 4 0 01-8 0V5a4 4 0 014-4z`,fill:t}),(0,V.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]}),$h=({size:e=20})=>(0,V.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`path`,{d:`M10.68 13.31a16 16 0 003.41 2.6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7 2 2 0 011.72 2v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.42 19.42 0 013.07 8.62 19.79 19.79 0 01.1 2 2 2 0 012.11 0h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L6.18 7.84`}),(0,V.jsx)(`line`,{x1:`23`,y1:`1`,x2:`1`,y2:`23`})]}),eg=({size:e=18})=>(0,V.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`5`}),(0,V.jsx)(`polyline`,{points:`5 12 12 5 19 12`})]}),tg=()=>(0,V.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`polyline`,{points:`9 17 4 12 9 7`}),(0,V.jsx)(`path`,{d:`M20 18v-2a4 4 0 00-4-4H4`})]}),ng=()=>(0,V.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`path`,{d:`M22 16.92v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07 19.42 19.42 0 01-6.12-6.11A19.79 19.79 0 012 4.11 2 2 0 014.11 2h3a2 2 0 012 1.72c.13.96.37 1.91.71 2.81a2 2 0 01-.45 2.11L8.09 9.91a16 16 0 006 6l1.27-1.27a2 2 0 012.11-.45c.9.34 1.85.58 2.81.71A2 2 0 0122 16.92z`})}),rg=({className:e=``})=>(0,V.jsxs)(`svg`,{className:e,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,V.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,V.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]}),ig=({size:e=14})=>(0,V.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`path`,{d:`M12 8V4H8`}),(0,V.jsx)(`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`}),(0,V.jsx)(`path`,{d:`M2 14h2`}),(0,V.jsx)(`path`,{d:`M20 14h2`}),(0,V.jsx)(`path`,{d:`M15 13v2`}),(0,V.jsx)(`path`,{d:`M9 13v2`})]}),ag=({size:e=20,strokeWidth:t=2,color:n=`currentColor`})=>(0,V.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:n,strokeWidth:t,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`line`,{x1:`12`,y1:`5`,x2:`12`,y2:`19`}),(0,V.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`})]}),og=({size:e=20,color:t=`currentColor`})=>(0,V.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.5`,fill:t}),(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.5`,fill:t}),(0,V.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.5`,fill:t})]}),sg=({size:e=20,color:t=`currentColor`})=>(0,V.jsxs)(`svg`,{width:`24`,height:`24`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,V.jsx)(`path`,{d:`M22 11.5667C22 16.8499 17.5222 21.1334 12 21.1334C11.3507 21.1343 10.7032 21.0742 10.0654 20.9545C9.60633 20.8682 9.37678 20.8251 9.21653 20.8496C9.05627 20.8741 8.82918 20.9948 8.37499 21.2364C7.09014 21.9197 5.59195 22.161 4.15111 21.893C4.69874 21.2194 5.07275 20.4112 5.23778 19.5448C5.33778 19.0148 5.09 18.5 4.71889 18.1231C3.03333 16.4115 2 14.1051 2 11.5667C2 6.28357 6.47778 2 12 2C17.5222 2 22 6.28357 22 11.5667Z`,stroke:`white`,"stroke-width":`1.5`,"stroke-linejoin":`round`}),(0,V.jsx)(`path`,{d:`M11.9955 12H12.0045M15.991 12H16M8 12H8.00897`,stroke:`white`,"stroke-width":`2`,"stroke-linecap":`round`,"stroke-linejoin":`round`})]}),cg=()=>(0,V.jsx)(`svg`,{width:`24`,height:`24`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,V.jsx)(`path`,{d:`M16.7133 8.59374C18.1939 8.98463 19.2229 9.47922 20.1589 10.0848C21.5432 10.9804 22.1367 12.5944 21.9737 14.1517C21.9049 14.8099 21.3744 15.1246 20.7592 14.9544L19.3705 14.57C18.2697 14.2653 17.7193 14.1129 17.3837 13.71C17.0481 13.307 17.0086 12.751 16.9296 11.6391L16.7133 8.59374ZM16.7133 8.59374C13.7164 7.80255 10.2871 7.80163 7.28669 8.59374M7.28669 8.59374C5.80606 8.98463 4.77711 9.47923 3.84113 10.0848C2.45683 10.9804 1.86334 12.5944 2.02628 14.1517C2.09514 14.8099 2.62563 15.1246 3.24078 14.9544L4.62954 14.57C5.73032 14.2653 6.28071 14.1129 6.61631 13.71C6.95191 13.307 6.9914 12.751 7.07038 11.6391L7.28669 8.59374Z`,stroke:`#E30C12`,"stroke-width":`1.5`,"stroke-linejoin":`round`})}),lg=({size:e=24})=>(0,V.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`path`,{d:`M12 19v3`}),(0,V.jsx)(`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`}),(0,V.jsx)(`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`}),(0,V.jsx)(`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`}),(0,V.jsx)(`path`,{d:`m2 2 20 20`}),(0,V.jsx)(`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`})]}),ug=(e=``)=>String(e).replace(/<[^>]+>/g,``).replace(/\s+/g,` `).trim(),dg=(e=``)=>String(e).replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),fg=new Set([`p`,`br`,`ul`,`ol`,`li`,`strong`,`em`,`b`,`i`,`a`]),pg=/^https?:\/\//i;function mg(e){let t=Array.from(e.childNodes);for(let n of t)if(n.nodeType===Node.ELEMENT_NODE){let t=n.tagName.toLowerCase();if(!fg.has(t)){e.replaceChild(document.createTextNode(n.textContent),n);continue}let r={};if(t===`a`){let e=n.getAttribute(`href`)||``;pg.test(e)&&(r.href=e),r.target=`_blank`,r.rel=`noopener noreferrer`}for(;n.attributes.length>0;)n.removeAttribute(n.attributes[0].name);for(let[e,t]of Object.entries(r))n.setAttribute(e,t);mg(n)}else n.nodeType!==Node.TEXT_NODE&&e.removeChild(n)}function hg(e){let t=document.createElement(`div`);return t.innerHTML=e,mg(t),t.innerHTML}function gg(e){let t=String(e||``).trim();if(!t)return t;let n=/^<p>\s*<strong>([\s\S]*?)<\/strong>\s*<\/p>$/i.exec(t);if(n&&!/<\/?strong\b/i.test(n[1]))return`<p>${n[1]}</p>`;let r=/^<strong>([\s\S]*?)<\/strong>$/i.exec(t);if(r&&!/<\/?strong\b/i.test(r[1])){let e=r[1].trim();return/^<(?:p|ul|ol)\b/i.test(e)?e:`<p>${e}</p>`}return e}var _g=(e=``)=>{let t=String(e||``).trim();if(!t)return``;if(/<(p|br|ul|ol|li|strong|em|a)\b/i.test(t))return gg(hg(t));let n=t.replace(/\r\n/g,`
|
|
262
266
|
`).replace(/\n{3,}/g,`
|
|
263
267
|
|
|
264
|
-
`).split(/\n\s*\n/).map(e=>e.trim()).filter(Boolean),r=e=>
|
|
265
|
-
`).map(e=>e.trim()).filter(Boolean),n=t.filter(e=>/^[-*]\s+/.test(e));if(n.length>=2&&n.length===t.length)return`<ul>${n.map(e=>`<li>${r(e.replace(/^[-*]\s+/,``))}</li>`).join(``)}</ul>`;let i=e.split(/\s+(?=[-*]\s+\*\*?)/).map(e=>e.trim()).filter(Boolean);return i.length>=2&&i.every(e=>/^[-*]\s+/.test(e))?`<ul>${i.map(e=>`<li>${r(e.replace(/^[-*]\s+/,``))}</li>`).join(``)}</ul>`:`<p>${r(e).replace(/\n/g,`<br />`)}</p>`}).join(``))},mg=new Set([`application/pdf`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`]),hg=new Set([`.pdf`,`.docx`,`.png`,`.jpg`,`.jpeg`]),gg=`image/png,image/jpeg,.pdf,.docx`;function _g(e){if(!e)return!1;let t=typeof e.name==`string`?e.name.toLowerCase():``,n=t.includes(`.`)?`.${t.split(`.`).pop()}`:``,r=typeof e.type==`string`?e.type.toLowerCase():``;return r===`image/png`||r===`image/jpeg`||mg.has(r)||hg.has(n)}function vg(e){return e?_g(e)?e.size>2097152?`File must be 2 MB or smaller.`:``:`Only PNG, JPEG, PDF, and DOCX files are allowed.`:`No file selected.`}function yg(e=0){if(!Number.isFinite(e)||e<=0)return``;let t=[`B`,`KB`,`MB`,`GB`],n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;let i=n>=10||r===0?0:1;return`${n.toFixed(i)} ${t[r]}`}function bg(e){return e?e.name||`Attachment`:``}function xg(e){if(!e||typeof e!=`string`)return`?`;let t=e.trim();if(!t)return`?`;let n=t.split(/\s+/).filter(Boolean);return n.length>=2?`${n[0][0]}${n[n.length-1][0]}`.toUpperCase():t.slice(0,2).toUpperCase()}function Sg({src:e,name:t,imgStyle:n,initialsSpanStyle:r}){let[i,a]=(0,b.useState)(null),o=typeof e==`string`?e.trim():``;return(0,b.useEffect)(()=>{if(!o){a(null);return}a(null);let e=!1,t=new window.Image;return t.onload=()=>{e||a(o)},t.onerror=()=>{e||a(null)},t.src=o,()=>{e=!0}},[o]),i?(0,V.jsx)(`img`,{src:i,alt:``,style:n,onError:()=>a(null)}):(0,V.jsx)(`span`,{style:r,children:xg(t)})}function Cg({siteId:e,onChoose:t}){let[n,r]=(0,b.useState)(null),i=n=>{ue(e,n),r(n),t?.(n)};return(0,V.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,margin:`4px 0 10px`},children:(0,V.jsxs)(`div`,{style:{maxWidth:`88%`,borderRadius:`14px`,border:`1px solid #e5e7eb`,background:`#f9fafb`,padding:`12px 14px`},children:[(0,V.jsx)(`p`,{style:{margin:`0 0 10px`,fontSize:`12.5px`,color:`#4b5563`,lineHeight:1.45},children:`When I offer to take you to a page, should I ask first each time, or just take you there?`}),n?(0,V.jsx)(`p`,{style:{margin:0,fontSize:`12.5px`,fontWeight:600,color:`#111827`},children:n===`auto`?`Got it — I'll navigate automatically.`:`Got it — I'll ask each time.`}):(0,V.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`},children:[(0,V.jsx)(`button`,{type:`button`,onClick:()=>i(`auto`),style:{padding:`7px 14px`,borderRadius:`999px`,border:`1px solid #d1d5db`,background:`white`,color:`#111827`,fontSize:`12.5px`,fontWeight:600,cursor:`pointer`},children:`Just take me there`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>i(`ask`),style:{padding:`7px 14px`,borderRadius:`999px`,border:`1px solid #d1d5db`,background:`white`,color:`#111827`,fontSize:`12.5px`,fontWeight:600,cursor:`pointer`},children:`Ask me each time`})]})]})})}function wg({chatHistory:e,isAiTyping:t,isLoading:n,isAgentTyping:r,setReplyContext:i,primaryColor:a=`#3B82F6`,agentHeadshot:o=null,agentDisplayName:s=`Agent`,botAvatarNode:c=null}){let{resolvedConfig:l}=jn(),u=(0,b.useRef)(null),[d,f]=(0,b.useState)(null),[p,m]=(0,b.useState)(null),h=(0,b.useRef)(e.length),g=(0,b.useRef)(!0),_=(0,b.useRef)(null),v=(0,b.useCallback)(e=>{let t=e.target.closest(`a[href]`);if(!t)return;let n=t.getAttribute(`href`)||``;if(!(!n||n.startsWith(`mailto:`)||n.startsWith(`tel:`)||n.startsWith(`javascript:`)))try{let t=new URL(n,window.location.href);if(t.origin!==window.location.origin){e.preventDefault(),window.open(t.href,`_blank`,`noopener,noreferrer`);return}e.preventDefault(),Sr(t.href,{siteId:l?.siteId,apiBaseUrl:l?.apiBaseUrl}).then(({allowed:e,correctedUrl:n})=>{e&&Nr(n||t.href)})}catch{}},[l]),y=e=>{if(!e)return`just now`;let t=new Date,n=new Date(e),r=Math.max(0,Math.floor((t-n)/1e3));if(r<60)return`just now`;let i=Math.floor(r/60);if(i<60)return`${i} min${i>1?`s`:``} ago`;let a=Math.floor(i/60);if(a<24)return`${a} hr${a>1?`s`:``} ago`;let o=Math.floor(a/24);return`${o} day${o>1?`s`:``} ago`};return(0,b.useEffect)(()=>{if(g.current){g.current=!1,h.current=e.length,_.current&&(_.current.scrollTop=_.current.scrollHeight);return}let n=e.length>h.current;h.current=e.length,(n||t||r)&&u.current?.scrollIntoView({behavior:`smooth`})},[e.length,t,n,r]),(0,V.jsxs)(`div`,{ref:_,style:{flex:1,overflowY:`auto`,overscrollBehavior:`contain`,padding:`10px 16px 20px`,display:`flex`,flexDirection:`column`,background:`transparent`},children:[e.map(e=>{if(e.type===`call_recording`||typeof e.message==`string`&&e.message.includes(`AI chat recording`))return null;if(e.type===`nav_pref_choice`)return(0,V.jsx)(Cg,{siteId:l?.siteId},e.id||e.messageId);let t=e.sender===`system`,n=e.sender===`user`,r=e.sender===`ai`||e.sender===`bot`,u=e.sender===`agent`,d=e.isPending,h=e.type===`file`&&e.metadata?.fileUrl,g=e.agent_name||e.agentName||e.metadata?.agentName||s,_=typeof e.sender_headshot==`string`&&e.sender_headshot.trim()||typeof o==`string`&&o.trim()||null,b=og(e.replyToContent||e.replyContext?.message||``),x=e.replyToSender===`user`?`You`:e.replyToSender===`agent`?`Agent`:e.replyToSender===`ai`||e.replyToSender===`bot`?`AI Assistant`:`Message`;return t?(0,V.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,margin:`8px 0`},children:(0,V.jsx)(`div`,{style:{padding:`6px 12px`,borderRadius:`9999px`,background:`#f3f4f6`,color:`#6b7280`,fontSize:`12px`,fontWeight:500},children:e.message})},e.id):(0,V.jsxs)(`div`,{style:{display:`flex`,justifyContent:n?`flex-end`:`flex-start`,alignItems:`flex-start`,marginBottom:`16px`,gap:`8px`,flexDirection:`row`},children:[!n&&(r||u)&&(0,V.jsx)(`div`,{style:{width:`32px`,height:`32px`,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,background:u?`#f3f4f6`:c&&r?`transparent`:`var(--flowengage-primary)`,color:u?a:`#fff`,boxShadow:u?`0 2px 8px rgba(0,0,0,0.06)`:c&&r?`none`:`0 8px 20px rgba(59,130,246,0.24)`,overflow:`hidden`,border:u?`1px solid ${a}22`:`none`,fontSize:`12px`,fontWeight:800,marginTop:!d&&(r||u)?`22px`:`0px`},children:r?c||(0,V.jsx)(eg,{size:16}):(0,V.jsx)(Sg,{src:_||``,name:g,imgStyle:{width:`100%`,height:`100%`,objectFit:`cover`},initialsSpanStyle:{lineHeight:1}})}),(0,V.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:n?`flex-end`:`flex-start`,maxWidth:`75%`,minWidth:0},children:[!d&&u&&(0,V.jsxs)(`button`,{type:`button`,onClick:()=>i(e),style:{opacity:1,marginBottom:`4px`,display:`flex`,alignItems:`center`,gap:`4px`,fontSize:`11px`,color:`#9ca3af`,background:`transparent`,border:0,cursor:`pointer`,padding:0,marginLeft:`2px`},onMouseEnter:e=>{e.currentTarget.style.color=`#4b5563`},onMouseLeave:e=>{e.currentTarget.style.color=`#9ca3af`},children:[(0,V.jsx)(Zh,{}),`Reply`]}),(0,V.jsxs)(`div`,{style:{padding:`8px 16px`,borderRadius:n?`20px 6px 20px 20px`:`6px 20px 20px 20px`,lineHeight:1.8,letterSpacing:0,boxShadow:`0 2px 8px rgba(0,0,0,0.06)`,background:n?`var(--flowengage-primary)`:`rgba(255,255,255,0.92)`,color:n?`#fff`:`#111827`,fontSize:`14px`,fontWeight:400,opacity:d?.55:1,transition:`opacity 0.3s ease`,wordBreak:`break-word`,width:`fit-content`},children:[b&&(0,V.jsxs)(`div`,{style:{marginBottom:`8px`,borderRadius:`14px`,borderLeft:n?`2px solid rgba(255,255,255,0.8)`:`2px solid var(--flowengage-primary)`,padding:`8px 12px`,fontSize:`12px`,background:n?`rgba(255,255,255,0.15)`:`#f9fafb`,color:n?`rgba(255,255,255,0.9)`:`#6b7280`},children:[(0,V.jsx)(`div`,{style:{marginBottom:`2px`,fontWeight:600},children:x}),(0,V.jsx)(`div`,{style:{display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`,overflow:`hidden`},children:b})]}),h?(()=>{let t=e.metadata.fileType||``,r=e.metadata.fileName||e.message||`File`,i=yg(e.metadata.fileSize),a=t.startsWith(`image/`),o=`shared file: ${r}`.toLowerCase(),s=(e.message||``).trim(),c=s&&s.toLowerCase()!==o&&!s.toLowerCase().startsWith(`shared file:`),l=t===`application/pdf`?{color:`#ef4444`,label:`PDF`}:t.includes(`word`)||t.includes(`docx`)?{color:`#3b82f6`,label:`DOCX`}:t.includes(`excel`)||t.includes(`sheet`)||t===`text/csv`?{color:`#10b981`,label:`XLSX`}:{color:`#6b7280`,label:`FILE`};return(0,V.jsxs)(`div`,{style:{minWidth:`200px`,maxWidth:`240px`},children:[c&&(0,V.jsx)(`div`,{style:{marginBottom:`6px`,fontSize:`14px`,color:n?`#fff`:`#111827`,whiteSpace:`normal`,wordBreak:`break-word`},children:s}),a?(0,V.jsx)(`button`,{type:`button`,onClick:()=>f({url:e.metadata.fileUrl,name:r}),onMouseEnter:()=>m(e.id),onMouseLeave:()=>m(null),style:{display:`block`,width:`100%`,background:`transparent`,border:0,padding:0,margin:0,textAlign:`left`,cursor:`pointer`},children:(0,V.jsxs)(`div`,{style:{position:`relative`},children:[(0,V.jsx)(`img`,{src:e.metadata.fileUrl,alt:r,style:{width:`100%`,borderRadius:`10px`,display:`block`,maxHeight:`180px`,objectFit:`cover`}}),(0,V.jsx)(`div`,{style:{position:`absolute`,inset:0,borderRadius:`10px`,background:p===e.id?`rgba(17,24,39,0.32)`:`rgba(17,24,39,0)`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#fff`,fontSize:`13px`,fontWeight:700,letterSpacing:`0.02em`,opacity:p===e.id?1:0,transition:`background 0.18s ease, opacity 0.18s ease`,pointerEvents:`none`},children:`Preview`})]})}):(0,V.jsx)(`a`,{href:e.metadata.fileUrl,target:`_blank`,rel:`noopener noreferrer`,style:{textDecoration:`none`,display:`block`},children:(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`10px`,background:n?`rgba(255,255,255,0.15)`:`#f3f4f6`,borderRadius:`12px`,padding:`10px 12px`},children:[(0,V.jsxs)(`div`,{style:{width:`38px`,height:`46px`,borderRadius:`8px`,background:n?`rgba(255,255,255,0.22)`:`#fff`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,flexShrink:0,boxShadow:`0 1px 4px rgba(0,0,0,0.1)`,gap:`3px`},children:[(0,V.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:n?`#fff`:l.color,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`path`,{d:`M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z`}),(0,V.jsx)(`polyline`,{points:`14 2 14 8 20 8`})]}),(0,V.jsx)(`span`,{style:{fontSize:`7px`,fontWeight:800,letterSpacing:`0.04em`,color:n?`#fff`:l.color,lineHeight:1},children:l.label})]}),(0,V.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,V.jsx)(`div`,{style:{fontSize:`13px`,fontWeight:600,color:n?`#fff`:`#111827`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:r}),i&&(0,V.jsx)(`div`,{style:{fontSize:`11px`,marginTop:`3px`,color:n?`rgba(255,255,255,0.6)`:`#9ca3af`},children:i})]}),(0,V.jsxs)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:n?`rgba(255,255,255,0.65)`:`#9ca3af`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:[(0,V.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,V.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,V.jsx)(`line`,{x1:`12`,y1:`15`,x2:`12`,y2:`3`})]})]})})]})})():r?(0,V.jsx)(`div`,{className:`flowengage-message-content fe-bot-message`,dangerouslySetInnerHTML:{__html:pg(e.message)},onClick:v}):(0,V.jsx)(`div`,{style:{whiteSpace:`pre-wrap`},children:e.message})]}),(0,V.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`4px`,marginTop:`4px`,padding:`0 4px`,alignSelf:n?`flex-end`:`flex-start`},children:d?(0,V.jsx)(`span`,{style:{fontSize:`10px`,color:`#9ca3af`,fontWeight:500,fontStyle:`italic`},children:`sending…`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{style:{fontSize:`10px`,color:`#9ca3af`,fontWeight:500},children:y(e.timestamp||e.createdAt)}),(0,V.jsx)(`span`,{style:{fontSize:`10px`,fontWeight:700,color:n?`var(--flowengage-primary)`:`#9ca3af`},children:`✓`})]})})]})]},e.id)}),(t||n)&&(0,V.jsxs)(`div`,{style:{marginBottom:`16px`,display:`flex`,alignItems:`center`,gap:`8px`},children:[(0,V.jsx)(`div`,{style:{width:`32px`,height:`32px`,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,background:c?`transparent`:`var(--flowengage-primary)`,color:`#fff`,boxShadow:c?`none`:`0 8px 20px rgba(59,130,246,0.24)`,overflow:`hidden`},children:c||(0,V.jsx)(eg,{size:16})}),(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`2px`,color:`#374151`,fontSize:`13px`,fontWeight:500,fontStyle:`italic`},children:[`Analysing`,[0,1,2].map(e=>(0,V.jsx)(`span`,{style:{animation:`fe-dot-bounce 1.2s ease-in-out ${e*.2}s infinite`,display:`inline-block`},children:`.`},e))]})]}),r&&(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`flex-start`,gap:`8px`,marginBottom:`12px`},children:[(0,V.jsx)(`div`,{style:{width:`32px`,height:`32px`,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,overflow:`hidden`},children:(0,V.jsx)(Sg,{src:o||``,name:s,imgStyle:{width:`100%`,height:`100%`,objectFit:`cover`},initialsSpanStyle:{lineHeight:1}})}),(0,V.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`12px 16px`,borderRadius:`18px`,background:`#fff`,boxShadow:`0 2px 6px rgba(0,0,0,0.04)`},children:[0,1,2].map(e=>(0,V.jsx)(`span`,{style:{width:`7px`,height:`7px`,borderRadius:`50%`,background:`#9ca3af`,animation:`fe-dot-bounce 1.2s ease-in-out ${e*.2}s infinite`,display:`inline-block`}},e))})]}),(0,V.jsx)(`div`,{ref:u}),d&&(0,V.jsx)(`button`,{type:`button`,onClick:()=>f(null),style:{position:`fixed`,inset:0,zIndex:1e4,border:0,padding:`16px`,margin:0,background:`rgba(2,6,23,0.88)`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`default`},children:(0,V.jsxs)(`div`,{style:{position:`relative`,maxWidth:`min(96vw, 1100px)`,maxHeight:`96vh`,width:`100%`,display:`flex`,flexDirection:`column`,gap:`10px`,alignItems:`center`},children:[(0,V.jsx)(`img`,{src:d.url,alt:d.name,style:{width:`100%`,maxHeight:`calc(96vh - 72px)`,objectFit:`contain`,borderRadius:`16px`,boxShadow:`0 30px 80px rgba(0,0,0,0.42)`}}),(0,V.jsx)(`div`,{style:{maxWidth:`100%`,padding:`8px 14px`,borderRadius:`9999px`,background:`rgba(255,255,255,0.92)`,color:`#0f172a`,fontSize:`12px`,fontWeight:600,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:d.name})]})})]})}var Tg=typeof window<`u`&&(window.matchMedia?.(`(pointer: coarse)`).matches||navigator.maxTouchPoints>0);function Eg({input:e,setInput:t,onSubmit:n,isConversationEnded:r,callUiActive:i,handleToggleVoice:a,activeScreen:o,inputDisabled:s,replyContext:c,clearReplyContext:l,requiresEmail:u,emailInput:d,setEmailInput:f,emailError:p,showVoiceToggle:m=!1,voiceEnabled:h=!0,onFileSelect:g,selectedFile:_=null,onRemoveSelectedFile:v,attachmentError:y=``,isUploadingAttachment:x=!1,inputPlaceholder:S=`Type your message`}){let C=(0,b.useRef)(null),w=(0,b.useRef)(null),T=e=>{e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,120)}px`)};(0,b.useEffect)(()=>{u||T(w.current)},[e,u]),(0,b.useEffect)(()=>{u||Tg||e||s||w.current?.focus()},[e,u,s]);let E=e=>{e.key===`Enter`&&(Tg||e.shiftKey||e.altKey||e.ctrlKey||e.metaKey||(e.preventDefault(),e.currentTarget.form?.requestSubmit()))},ee=c?.sender===`user`?`You`:c?.sender===`agent`?`Agent`:`AI Assistant`,D=u?!!d?.trim():!!e?.trim()||!!_,te=s||x||!D,O=!u&&h&&m;return(0,V.jsxs)(`div`,{style:{padding:`0 16px`,background:`transparent`},children:[c&&(0,V.jsxs)(`div`,{style:{marginBottom:`8px`,display:`flex`,alignItems:`flex-start`,justifyContent:`space-between`,gap:`12px`,borderRadius:`16px`,border:`1px solid rgba(0,0,0,0.05)`,background:`#fff`,padding:`12px 16px`,boxShadow:`0 8px 24px rgba(0,0,0,0.05)`},children:[(0,V.jsxs)(`div`,{style:{minWidth:0,flex:1,borderLeft:`2px solid var(--flowengage-primary)`,paddingLeft:`12px`},children:[(0,V.jsxs)(`div`,{style:{fontSize:`12px`,fontWeight:600,color:`var(--flowengage-primary)`},children:[`Replying to `,ee]}),(0,V.jsx)(`div`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,fontSize:`12px`,color:`#6b7280`},children:c.replyToContent||c.message})]}),(0,V.jsx)(`button`,{type:`button`,style:{width:`28px`,height:`28px`,borderRadius:`9999px`,border:0,background:`#f3f4f6`,color:`#6b7280`,transition:`color 0.2s ease, background 0.2s ease`,cursor:`pointer`},onClick:l,"aria-label":`Cancel reply`,onMouseEnter:e=>{e.currentTarget.style.background=`#e5e7eb`,e.currentTarget.style.color=`#374151`},onMouseLeave:e=>{e.currentTarget.style.background=`#f3f4f6`,e.currentTarget.style.color=`#6b7280`},children:`×`})]}),u&&(0,V.jsx)(`div`,{style:{marginBottom:`8px`,padding:`0 8px`},children:(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`8px`,color:`#111827`,fontSize:`14px`,fontWeight:500,textAlign:`center`},children:[(0,V.jsx)(`span`,{style:{display:`inline-flex`,width:`22px`,height:`22px`,borderRadius:`9999px`,alignItems:`center`,justifyContent:`center`,background:`rgba(59,130,246,0.08)`,color:`var(--flowengage-primary)`},children:(0,V.jsx)(eg,{size:13})}),(0,V.jsx)(`span`,{children:`Please provide your email address so we can help you.`})]})}),_&&!u&&(0,V.jsxs)(`div`,{style:{marginBottom:`10px`,display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`12px`,borderRadius:`16px`,border:`1px solid rgba(0,0,0,0.06)`,background:`#fff`,padding:`12px 14px`,boxShadow:`0 8px 24px rgba(0,0,0,0.05)`},children:[(0,V.jsxs)(`div`,{style:{minWidth:0,flex:1},children:[(0,V.jsx)(`div`,{style:{fontSize:`12px`,fontWeight:600,color:`var(--flowengage-primary)`,marginBottom:`2px`},children:`Attachment ready`}),(0,V.jsx)(`div`,{style:{fontSize:`13px`,color:`#111827`,whiteSpace:`nowrap`,overflow:`hidden`,textOverflow:`ellipsis`},children:bg(_)}),(0,V.jsx)(`div`,{style:{fontSize:`12px`,color:`#6b7280`,marginTop:`2px`},children:yg(_.size)})]}),(0,V.jsx)(`button`,{type:`button`,style:{width:`28px`,height:`28px`,borderRadius:`9999px`,border:0,background:`#f3f4f6`,color:`#6b7280`,transition:`color 0.2s ease, background 0.2s ease`,cursor:`pointer`,flexShrink:0},onClick:v,"aria-label":`Remove attachment`,onMouseEnter:e=>{e.currentTarget.style.background=`#e5e7eb`,e.currentTarget.style.color=`#374151`},onMouseLeave:e=>{e.currentTarget.style.background=`#f3f4f6`,e.currentTarget.style.color=`#6b7280`},children:`×`})]}),(0,V.jsxs)(`form`,{style:{display:`flex`,alignItems:`flex-end`,gap:`8px`,minHeight:`40px`,padding:`4px`,border:`1px solid rgba(0,0,0,0.06)`,borderRadius:`20px`,background:`#fff`,boxShadow:`0 4px 14px rgba(0,0,0,0.04)`,opacity:1},onSubmit:n,children:[O?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`input`,{ref:C,type:`file`,accept:gg,style:{display:`none`},onChange:e=>{let t=e.target.files?.[0];t&&g?.(t),e.target.value=``}}),(0,V.jsx)(`button`,{type:`button`,style:{width:`32px`,height:`32px`,borderRadius:`9999px`,background:`#f3f4f8`,color:`var(--flowengage-primary)`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`background 0.2s ease, opacity 0.2s ease`,border:0,cursor:`pointer`,flexShrink:0},onClick:()=>C.current?.click(),title:`Attach file`,"aria-label":`Attach file`,disabled:x,onMouseEnter:e=>{e.currentTarget.style.opacity=`0.8`},onMouseLeave:e=>{e.currentTarget.style.opacity=`1`},children:(0,V.jsx)(tg,{size:16,color:`currentColor`})})]}):null,u?(0,V.jsx)(`input`,{className:`flowengage-chat-text-input`,style:{flex:1,minWidth:0,border:`none`,fontFamily:`inherit`,fontSize:`14px`,outline:`none`,padding:0,paddingLeft:O?`0`:`8px`,color:`#111827`,background:`transparent`,cursor:`text`,alignSelf:`center`},value:d,onChange:e=>f(e.target.value),placeholder:`Enter your Email`,disabled:s,type:`email`,autoComplete:`email`}):(0,V.jsx)(`textarea`,{ref:w,className:`flowengage-chat-text-input`,rows:1,style:{flex:1,minWidth:0,border:`none`,fontFamily:`inherit`,fontSize:`14px`,lineHeight:`20px`,outline:`none`,padding:`6px 0`,paddingLeft:O?`0`:`8px`,color:`#111827`,background:`transparent`,cursor:`text`,resize:`none`,maxHeight:`120px`,overflowY:`auto`},value:e,onChange:e=>{t(e.target.value),T(e.target)},onKeyDown:E,placeholder:o===`agent`?`Message the agent…`:S,disabled:s,autoComplete:`off`}),(0,V.jsx)(`button`,{type:`submit`,style:{width:`32px`,height:`32px`,borderRadius:`9999px`,background:`var(--flowengage-primary)`,color:`#fff`,border:`none`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`opacity 0.2s ease`,cursor:te?`not-allowed`:`pointer`,opacity:te?.45:1,flexShrink:0},disabled:te,onMouseEnter:e=>{te||(e.currentTarget.style.opacity=`0.85`)},onMouseLeave:e=>{e.currentTarget.style.opacity=`1`},children:(0,V.jsx)(Xh,{size:16})})]}),!u&&y&&(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`7px 4px 0`},children:[(0,V.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`#dc2626`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,V.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,V.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]}),(0,V.jsx)(`span`,{style:{fontSize:`11px`,color:`#dc2626`,fontWeight:500},children:y})]}),u&&p&&(0,V.jsx)(`div`,{style:{padding:`8px 16px 0`,fontSize:`12px`,fontWeight:500,color:`#f43f5e`},children:p})]})}function Dg({webRTCError:e,micError:t,setMicError:n,dismissCallError:r,isRateLimited:i,rateLimitMessage:a}){return(0,V.jsxs)(V.Fragment,{children:[(e||t)&&(0,V.jsxs)(`div`,{style:{margin:`0 20px 10px`,padding:`12px 16px`,borderRadius:`12px`,background:`#fef2f2`,border:`1px solid #fee2e2`,display:`flex`,alignItems:`flex-start`,gap:`10px`},children:[(0,V.jsx)($h,{className:``}),(0,V.jsx)(`span`,{style:{fontSize:`12px`,color:`#b91c1c`,lineHeight:1.5,flex:1},children:e||t}),(0,V.jsx)(`button`,{style:{flexShrink:0,background:`transparent`,border:0,color:`#f87171`,cursor:`pointer`,fontSize:`18px`,lineHeight:1},onClick:()=>{n(null),r()},onMouseEnter:e=>{e.currentTarget.style.color=`#dc2626`},onMouseLeave:e=>{e.currentTarget.style.color=`#f87171`},children:`×`})]}),i&&(0,V.jsx)(`div`,{style:{margin:`0 20px 10px`,padding:`12px 16px`,fontSize:`13px`,borderRadius:`12px`,background:`#fee2e2`,color:`#991b1b`},children:a})]})}var Og=[`#135bd8`,`#ef334b`,`#ffbd2e`];function kg(e){return!Array.isArray(e)||e.length===0?Og:e.length===1?[e[0],e[0],e[0]]:e.length===2?[e[0],e[1],e[0]]:[e[0],e[1],e[2]]}var Ag={idle:3,listening:.75,thinking:1,speaking:1.4,muted:.75,error:.08};function jg(e){if(!e||typeof e!=`string`)return[0,0,0];let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t;return[parseInt(n.slice(0,2),16)/255,parseInt(n.slice(2,4),16)/255,parseInt(n.slice(4,6),16)/255]}function Mg(e,t){if(!e||typeof e!=`string`)return`rgba(0,0,0,${t})`;if(e.startsWith(`rgb`))return e.replace(/[\d.]+\)$/,`${t})`);let n=e.replace(`#`,``),r=n.length===3?n.split(``).map(e=>e+e).join(``):n;return`rgba(${parseInt(r.slice(0,2),16)},${parseInt(r.slice(2,4),16)},${parseInt(r.slice(4,6),16)},${t})`}var Ng=`
|
|
268
|
+
`).split(/\n\s*\n/).map(e=>e.trim()).filter(Boolean),r=e=>dg(e).replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,`<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>`).replace(/\*\*([^*]+)\*\*/g,`<strong>$1</strong>`).replace(/\*([^*\n]+)\*/g,`<em>$1</em>`);return gg(n.map(e=>{let t=e.split(`
|
|
269
|
+
`).map(e=>e.trim()).filter(Boolean),n=t.filter(e=>/^[-*]\s+/.test(e));if(n.length>=2&&n.length===t.length)return`<ul>${n.map(e=>`<li>${r(e.replace(/^[-*]\s+/,``))}</li>`).join(``)}</ul>`;let i=e.split(/\s+(?=[-*]\s+\*\*?)/).map(e=>e.trim()).filter(Boolean);return i.length>=2&&i.every(e=>/^[-*]\s+/.test(e))?`<ul>${i.map(e=>`<li>${r(e.replace(/^[-*]\s+/,``))}</li>`).join(``)}</ul>`:`<p>${r(e).replace(/\n/g,`<br />`)}</p>`}).join(``))},vg=new Set([`application/pdf`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`]),yg=new Set([`.pdf`,`.docx`,`.png`,`.jpg`,`.jpeg`]),bg=`image/png,image/jpeg,.pdf,.docx`;function xg(e){if(!e)return!1;let t=typeof e.name==`string`?e.name.toLowerCase():``,n=t.includes(`.`)?`.${t.split(`.`).pop()}`:``,r=typeof e.type==`string`?e.type.toLowerCase():``;return r===`image/png`||r===`image/jpeg`||vg.has(r)||yg.has(n)}function Sg(e){return e?xg(e)?e.size>2097152?`File must be 2 MB or smaller.`:``:`Only PNG, JPEG, PDF, and DOCX files are allowed.`:`No file selected.`}function Cg(e=0){if(!Number.isFinite(e)||e<=0)return``;let t=[`B`,`KB`,`MB`,`GB`],n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;let i=n>=10||r===0?0:1;return`${n.toFixed(i)} ${t[r]}`}function wg(e){return e?e.name||`Attachment`:``}function Tg(e){if(!e||typeof e!=`string`)return`?`;let t=e.trim();if(!t)return`?`;let n=t.split(/\s+/).filter(Boolean);return n.length>=2?`${n[0][0]}${n[n.length-1][0]}`.toUpperCase():t.slice(0,2).toUpperCase()}function Eg({src:e,name:t,imgStyle:n,initialsSpanStyle:r}){let[i,a]=(0,b.useState)(null),o=typeof e==`string`?e.trim():``;return(0,b.useEffect)(()=>{if(!o){a(null);return}a(null);let e=!1,t=new window.Image;return t.onload=()=>{e||a(o)},t.onerror=()=>{e||a(null)},t.src=o,()=>{e=!0}},[o]),i?(0,V.jsx)(`img`,{src:i,alt:``,style:n,onError:()=>a(null)}):(0,V.jsx)(`span`,{style:r,children:Tg(t)})}function Dg({siteId:e,onChoose:t}){let[n,r]=(0,b.useState)(null),i=n=>{ue(e,n),r(n),t?.(n)};return(0,V.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,margin:`4px 0 10px`},children:(0,V.jsxs)(`div`,{style:{maxWidth:`88%`,borderRadius:`14px`,border:`1px solid #e5e7eb`,background:`#f9fafb`,padding:`12px 14px`},children:[(0,V.jsx)(`p`,{style:{margin:`0 0 10px`,fontSize:`12.5px`,color:`#4b5563`,lineHeight:1.45},children:`When I offer to take you to a page, should I ask first each time, or just take you there?`}),n?(0,V.jsx)(`p`,{style:{margin:0,fontSize:`12.5px`,fontWeight:600,color:`#111827`},children:n===`auto`?`Got it — I'll navigate automatically.`:`Got it — I'll ask each time.`}):(0,V.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`},children:[(0,V.jsx)(`button`,{type:`button`,onClick:()=>i(`auto`),style:{padding:`7px 14px`,borderRadius:`999px`,border:`1px solid #d1d5db`,background:`white`,color:`#111827`,fontSize:`12.5px`,fontWeight:600,cursor:`pointer`},children:`Just take me there`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>i(`ask`),style:{padding:`7px 14px`,borderRadius:`999px`,border:`1px solid #d1d5db`,background:`white`,color:`#111827`,fontSize:`12.5px`,fontWeight:600,cursor:`pointer`},children:`Ask me each time`})]})]})})}function Og({chatHistory:e,isAiTyping:t,isLoading:n,isAgentTyping:r,setReplyContext:i,primaryColor:a=`#3B82F6`,agentHeadshot:o=null,agentDisplayName:s=`Agent`,botAvatarNode:c=null}){let{resolvedConfig:l}=jn(),u=(0,b.useRef)(null),[d,f]=(0,b.useState)(null),[p,m]=(0,b.useState)(null),h=(0,b.useRef)(e.length),g=(0,b.useRef)(!0),_=(0,b.useRef)(null),v=(0,b.useCallback)(e=>{let t=e.target.closest(`a[href]`);if(!t)return;let n=t.getAttribute(`href`)||``;if(!(!n||n.startsWith(`mailto:`)||n.startsWith(`tel:`)||n.startsWith(`javascript:`)))try{let t=new URL(n,window.location.href);if(t.origin!==window.location.origin){e.preventDefault(),window.open(t.href,`_blank`,`noopener,noreferrer`);return}e.preventDefault(),Sr(t.href,{siteId:l?.siteId,apiBaseUrl:l?.apiBaseUrl}).then(({allowed:e,correctedUrl:n})=>{e&&Nr(n||t.href)})}catch{}},[l]),y=e=>{if(!e)return`just now`;let t=new Date,n=new Date(e),r=Math.max(0,Math.floor((t-n)/1e3));if(r<60)return`just now`;let i=Math.floor(r/60);if(i<60)return`${i} min${i>1?`s`:``} ago`;let a=Math.floor(i/60);if(a<24)return`${a} hr${a>1?`s`:``} ago`;let o=Math.floor(a/24);return`${o} day${o>1?`s`:``} ago`};return(0,b.useEffect)(()=>{if(g.current){g.current=!1,h.current=e.length,_.current&&(_.current.scrollTop=_.current.scrollHeight);return}let n=e.length>h.current;h.current=e.length,(n||t||r)&&u.current?.scrollIntoView({behavior:`smooth`})},[e.length,t,n,r]),(0,V.jsxs)(`div`,{ref:_,style:{flex:1,overflowY:`auto`,overscrollBehavior:`contain`,padding:`10px 16px 20px`,display:`flex`,flexDirection:`column`,background:`transparent`},children:[e.map(e=>{if(e.type===`call_recording`||typeof e.message==`string`&&e.message.includes(`AI chat recording`))return null;if(e.type===`nav_pref_choice`)return(0,V.jsx)(Dg,{siteId:l?.siteId},e.id||e.messageId);let t=e.sender===`system`,n=e.sender===`user`,r=e.sender===`ai`||e.sender===`bot`,u=e.sender===`agent`,d=e.isPending,h=e.type===`file`&&e.metadata?.fileUrl,g=e.agent_name||e.agentName||e.metadata?.agentName||s,_=typeof e.sender_headshot==`string`&&e.sender_headshot.trim()||typeof o==`string`&&o.trim()||null,b=ug(e.replyToContent||e.replyContext?.message||``),x=e.replyToSender===`user`?`You`:e.replyToSender===`agent`?`Agent`:e.replyToSender===`ai`||e.replyToSender===`bot`?`AI Assistant`:`Message`;return t?(0,V.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,margin:`8px 0`},children:(0,V.jsx)(`div`,{style:{padding:`6px 12px`,borderRadius:`9999px`,background:`#f3f4f6`,color:`#6b7280`,fontSize:`12px`,fontWeight:500},children:e.message})},e.id):(0,V.jsxs)(`div`,{style:{display:`flex`,justifyContent:n?`flex-end`:`flex-start`,alignItems:`flex-start`,marginBottom:`16px`,gap:`8px`,flexDirection:`row`},children:[!n&&(r||u)&&(0,V.jsx)(`div`,{style:{width:`32px`,height:`32px`,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,background:u?`#f3f4f6`:c&&r?`transparent`:`var(--flowengage-primary)`,color:u?a:`#fff`,boxShadow:u?`0 2px 8px rgba(0,0,0,0.06)`:c&&r?`none`:`0 8px 20px rgba(59,130,246,0.24)`,overflow:`hidden`,border:u?`1px solid ${a}22`:`none`,fontSize:`12px`,fontWeight:800,marginTop:!d&&(r||u)?`22px`:`0px`},children:r?c||(0,V.jsx)(ig,{size:16}):(0,V.jsx)(Eg,{src:_||``,name:g,imgStyle:{width:`100%`,height:`100%`,objectFit:`cover`},initialsSpanStyle:{lineHeight:1}})}),(0,V.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:n?`flex-end`:`flex-start`,maxWidth:`75%`,minWidth:0},children:[!d&&u&&(0,V.jsxs)(`button`,{type:`button`,onClick:()=>i(e),style:{opacity:1,marginBottom:`4px`,display:`flex`,alignItems:`center`,gap:`4px`,fontSize:`11px`,color:`#9ca3af`,background:`transparent`,border:0,cursor:`pointer`,padding:0,marginLeft:`2px`},onMouseEnter:e=>{e.currentTarget.style.color=`#4b5563`},onMouseLeave:e=>{e.currentTarget.style.color=`#9ca3af`},children:[(0,V.jsx)(tg,{}),`Reply`]}),(0,V.jsxs)(`div`,{style:{padding:`8px 16px`,borderRadius:n?`20px 6px 20px 20px`:`6px 20px 20px 20px`,lineHeight:1.8,letterSpacing:0,boxShadow:`0 2px 8px rgba(0,0,0,0.06)`,background:n?`var(--flowengage-primary)`:`rgba(255,255,255,0.92)`,color:n?`#fff`:`#111827`,fontSize:`14px`,fontWeight:400,opacity:d?.55:1,transition:`opacity 0.3s ease`,wordBreak:`break-word`,width:`fit-content`},children:[b&&(0,V.jsxs)(`div`,{style:{marginBottom:`8px`,borderRadius:`14px`,borderLeft:n?`2px solid rgba(255,255,255,0.8)`:`2px solid var(--flowengage-primary)`,padding:`8px 12px`,fontSize:`12px`,background:n?`rgba(255,255,255,0.15)`:`#f9fafb`,color:n?`rgba(255,255,255,0.9)`:`#6b7280`},children:[(0,V.jsx)(`div`,{style:{marginBottom:`2px`,fontWeight:600},children:x}),(0,V.jsx)(`div`,{style:{display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`,overflow:`hidden`},children:b})]}),h?(()=>{let t=e.metadata.fileType||``,r=e.metadata.fileName||e.message||`File`,i=Cg(e.metadata.fileSize),a=t.startsWith(`image/`),o=`shared file: ${r}`.toLowerCase(),s=(e.message||``).trim(),c=s&&s.toLowerCase()!==o&&!s.toLowerCase().startsWith(`shared file:`),l=t===`application/pdf`?{color:`#ef4444`,label:`PDF`}:t.includes(`word`)||t.includes(`docx`)?{color:`#3b82f6`,label:`DOCX`}:t.includes(`excel`)||t.includes(`sheet`)||t===`text/csv`?{color:`#10b981`,label:`XLSX`}:{color:`#6b7280`,label:`FILE`};return(0,V.jsxs)(`div`,{style:{minWidth:`200px`,maxWidth:`240px`},children:[c&&(0,V.jsx)(`div`,{style:{marginBottom:`6px`,fontSize:`14px`,color:n?`#fff`:`#111827`,whiteSpace:`normal`,wordBreak:`break-word`},children:s}),a?(0,V.jsx)(`button`,{type:`button`,onClick:()=>f({url:e.metadata.fileUrl,name:r}),onMouseEnter:()=>m(e.id),onMouseLeave:()=>m(null),style:{display:`block`,width:`100%`,background:`transparent`,border:0,padding:0,margin:0,textAlign:`left`,cursor:`pointer`},children:(0,V.jsxs)(`div`,{style:{position:`relative`},children:[(0,V.jsx)(`img`,{src:e.metadata.fileUrl,alt:r,style:{width:`100%`,borderRadius:`10px`,display:`block`,maxHeight:`180px`,objectFit:`cover`}}),(0,V.jsx)(`div`,{style:{position:`absolute`,inset:0,borderRadius:`10px`,background:p===e.id?`rgba(17,24,39,0.32)`:`rgba(17,24,39,0)`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#fff`,fontSize:`13px`,fontWeight:700,letterSpacing:`0.02em`,opacity:p===e.id?1:0,transition:`background 0.18s ease, opacity 0.18s ease`,pointerEvents:`none`},children:`Preview`})]})}):(0,V.jsx)(`a`,{href:e.metadata.fileUrl,target:`_blank`,rel:`noopener noreferrer`,style:{textDecoration:`none`,display:`block`},children:(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`10px`,background:n?`rgba(255,255,255,0.15)`:`#f3f4f6`,borderRadius:`12px`,padding:`10px 12px`},children:[(0,V.jsxs)(`div`,{style:{width:`38px`,height:`46px`,borderRadius:`8px`,background:n?`rgba(255,255,255,0.22)`:`#fff`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,flexShrink:0,boxShadow:`0 1px 4px rgba(0,0,0,0.1)`,gap:`3px`},children:[(0,V.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:n?`#fff`:l.color,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`path`,{d:`M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z`}),(0,V.jsx)(`polyline`,{points:`14 2 14 8 20 8`})]}),(0,V.jsx)(`span`,{style:{fontSize:`7px`,fontWeight:800,letterSpacing:`0.04em`,color:n?`#fff`:l.color,lineHeight:1},children:l.label})]}),(0,V.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,V.jsx)(`div`,{style:{fontSize:`13px`,fontWeight:600,color:n?`#fff`:`#111827`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:r}),i&&(0,V.jsx)(`div`,{style:{fontSize:`11px`,marginTop:`3px`,color:n?`rgba(255,255,255,0.6)`:`#9ca3af`},children:i})]}),(0,V.jsxs)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:n?`rgba(255,255,255,0.65)`:`#9ca3af`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:[(0,V.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,V.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,V.jsx)(`line`,{x1:`12`,y1:`15`,x2:`12`,y2:`3`})]})]})})]})})():r?(0,V.jsx)(`div`,{className:`flowengage-message-content fe-bot-message`,dangerouslySetInnerHTML:{__html:_g(e.message)},onClick:v}):(0,V.jsx)(`div`,{style:{whiteSpace:`pre-wrap`},children:e.message})]}),(0,V.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`4px`,marginTop:`4px`,padding:`0 4px`,alignSelf:n?`flex-end`:`flex-start`},children:d?(0,V.jsx)(`span`,{style:{fontSize:`10px`,color:`#9ca3af`,fontWeight:500,fontStyle:`italic`},children:`sending…`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{style:{fontSize:`10px`,color:`#9ca3af`,fontWeight:500},children:y(e.timestamp||e.createdAt)}),(0,V.jsx)(`span`,{style:{fontSize:`10px`,fontWeight:700,color:n?`var(--flowengage-primary)`:`#9ca3af`},children:`✓`})]})})]})]},e.id)}),(t||n)&&(0,V.jsxs)(`div`,{style:{marginBottom:`16px`,display:`flex`,alignItems:`center`,gap:`8px`},children:[(0,V.jsx)(`div`,{style:{width:`32px`,height:`32px`,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,background:c?`transparent`:`var(--flowengage-primary)`,color:`#fff`,boxShadow:c?`none`:`0 8px 20px rgba(59,130,246,0.24)`,overflow:`hidden`},children:c||(0,V.jsx)(ig,{size:16})}),(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`2px`,color:`#374151`,fontSize:`13px`,fontWeight:500,fontStyle:`italic`},children:[`Analysing`,[0,1,2].map(e=>(0,V.jsx)(`span`,{style:{animation:`fe-dot-bounce 1.2s ease-in-out ${e*.2}s infinite`,display:`inline-block`},children:`.`},e))]})]}),r&&(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`flex-start`,gap:`8px`,marginBottom:`12px`},children:[(0,V.jsx)(`div`,{style:{width:`32px`,height:`32px`,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,overflow:`hidden`},children:(0,V.jsx)(Eg,{src:o||``,name:s,imgStyle:{width:`100%`,height:`100%`,objectFit:`cover`},initialsSpanStyle:{lineHeight:1}})}),(0,V.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`12px 16px`,borderRadius:`18px`,background:`#fff`,boxShadow:`0 2px 6px rgba(0,0,0,0.04)`},children:[0,1,2].map(e=>(0,V.jsx)(`span`,{style:{width:`7px`,height:`7px`,borderRadius:`50%`,background:`#9ca3af`,animation:`fe-dot-bounce 1.2s ease-in-out ${e*.2}s infinite`,display:`inline-block`}},e))})]}),(0,V.jsx)(`div`,{ref:u}),d&&(0,V.jsx)(`button`,{type:`button`,onClick:()=>f(null),style:{position:`fixed`,inset:0,zIndex:1e4,border:0,padding:`16px`,margin:0,background:`rgba(2,6,23,0.88)`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`default`},children:(0,V.jsxs)(`div`,{style:{position:`relative`,maxWidth:`min(96vw, 1100px)`,maxHeight:`96vh`,width:`100%`,display:`flex`,flexDirection:`column`,gap:`10px`,alignItems:`center`},children:[(0,V.jsx)(`img`,{src:d.url,alt:d.name,style:{width:`100%`,maxHeight:`calc(96vh - 72px)`,objectFit:`contain`,borderRadius:`16px`,boxShadow:`0 30px 80px rgba(0,0,0,0.42)`}}),(0,V.jsx)(`div`,{style:{maxWidth:`100%`,padding:`8px 14px`,borderRadius:`9999px`,background:`rgba(255,255,255,0.92)`,color:`#0f172a`,fontSize:`12px`,fontWeight:600,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:d.name})]})})]})}var kg=typeof window<`u`&&(window.matchMedia?.(`(pointer: coarse)`).matches||navigator.maxTouchPoints>0);function Ag({input:e,setInput:t,onSubmit:n,isConversationEnded:r,callUiActive:i,handleToggleVoice:a,activeScreen:o,inputDisabled:s,replyContext:c,clearReplyContext:l,requiresEmail:u,emailInput:d,setEmailInput:f,emailError:p,showVoiceToggle:m=!1,voiceEnabled:h=!0,onFileSelect:g,selectedFile:_=null,onRemoveSelectedFile:v,attachmentError:y=``,isUploadingAttachment:x=!1,inputPlaceholder:S=`Type your message`}){let C=(0,b.useRef)(null),w=(0,b.useRef)(null),T=e=>{e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,120)}px`)};(0,b.useEffect)(()=>{u||T(w.current)},[e,u]),(0,b.useEffect)(()=>{u||kg||e||s||w.current?.focus()},[e,u,s]);let E=e=>{e.key===`Enter`&&(kg||e.shiftKey||e.altKey||e.ctrlKey||e.metaKey||(e.preventDefault(),e.currentTarget.form?.requestSubmit()))},ee=c?.sender===`user`?`You`:c?.sender===`agent`?`Agent`:`AI Assistant`,D=u?!!d?.trim():!!e?.trim()||!!_,te=s||x||!D,O=!u&&h&&m;return(0,V.jsxs)(`div`,{style:{padding:`0 16px`,background:`transparent`},children:[c&&(0,V.jsxs)(`div`,{style:{marginBottom:`8px`,display:`flex`,alignItems:`flex-start`,justifyContent:`space-between`,gap:`12px`,borderRadius:`16px`,border:`1px solid rgba(0,0,0,0.05)`,background:`#fff`,padding:`12px 16px`,boxShadow:`0 8px 24px rgba(0,0,0,0.05)`},children:[(0,V.jsxs)(`div`,{style:{minWidth:0,flex:1,borderLeft:`2px solid var(--flowengage-primary)`,paddingLeft:`12px`},children:[(0,V.jsxs)(`div`,{style:{fontSize:`12px`,fontWeight:600,color:`var(--flowengage-primary)`},children:[`Replying to `,ee]}),(0,V.jsx)(`div`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,fontSize:`12px`,color:`#6b7280`},children:c.replyToContent||c.message})]}),(0,V.jsx)(`button`,{type:`button`,style:{width:`28px`,height:`28px`,borderRadius:`9999px`,border:0,background:`#f3f4f6`,color:`#6b7280`,transition:`color 0.2s ease, background 0.2s ease`,cursor:`pointer`},onClick:l,"aria-label":`Cancel reply`,onMouseEnter:e=>{e.currentTarget.style.background=`#e5e7eb`,e.currentTarget.style.color=`#374151`},onMouseLeave:e=>{e.currentTarget.style.background=`#f3f4f6`,e.currentTarget.style.color=`#6b7280`},children:`×`})]}),u&&(0,V.jsx)(`div`,{style:{marginBottom:`8px`,padding:`0 8px`},children:(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`8px`,color:`#111827`,fontSize:`14px`,fontWeight:500,textAlign:`center`},children:[(0,V.jsx)(`span`,{style:{display:`inline-flex`,width:`22px`,height:`22px`,borderRadius:`9999px`,alignItems:`center`,justifyContent:`center`,background:`rgba(59,130,246,0.08)`,color:`var(--flowengage-primary)`},children:(0,V.jsx)(ig,{size:13})}),(0,V.jsx)(`span`,{children:`Please provide your email address so we can help you.`})]})}),_&&!u&&(0,V.jsxs)(`div`,{style:{marginBottom:`10px`,display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`12px`,borderRadius:`16px`,border:`1px solid rgba(0,0,0,0.06)`,background:`#fff`,padding:`12px 14px`,boxShadow:`0 8px 24px rgba(0,0,0,0.05)`},children:[(0,V.jsxs)(`div`,{style:{minWidth:0,flex:1},children:[(0,V.jsx)(`div`,{style:{fontSize:`12px`,fontWeight:600,color:`var(--flowengage-primary)`,marginBottom:`2px`},children:`Attachment ready`}),(0,V.jsx)(`div`,{style:{fontSize:`13px`,color:`#111827`,whiteSpace:`nowrap`,overflow:`hidden`,textOverflow:`ellipsis`},children:wg(_)}),(0,V.jsx)(`div`,{style:{fontSize:`12px`,color:`#6b7280`,marginTop:`2px`},children:Cg(_.size)})]}),(0,V.jsx)(`button`,{type:`button`,style:{width:`28px`,height:`28px`,borderRadius:`9999px`,border:0,background:`#f3f4f6`,color:`#6b7280`,transition:`color 0.2s ease, background 0.2s ease`,cursor:`pointer`,flexShrink:0},onClick:v,"aria-label":`Remove attachment`,onMouseEnter:e=>{e.currentTarget.style.background=`#e5e7eb`,e.currentTarget.style.color=`#374151`},onMouseLeave:e=>{e.currentTarget.style.background=`#f3f4f6`,e.currentTarget.style.color=`#6b7280`},children:`×`})]}),(0,V.jsxs)(`form`,{style:{display:`flex`,alignItems:`flex-end`,gap:`8px`,minHeight:`40px`,padding:`4px`,border:`1px solid rgba(0,0,0,0.06)`,borderRadius:`20px`,background:`#fff`,boxShadow:`0 4px 14px rgba(0,0,0,0.04)`,opacity:1},onSubmit:n,children:[O?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`input`,{ref:C,type:`file`,accept:bg,style:{display:`none`},onChange:e=>{let t=e.target.files?.[0];t&&g?.(t),e.target.value=``}}),(0,V.jsx)(`button`,{type:`button`,style:{width:`32px`,height:`32px`,borderRadius:`9999px`,background:`#f3f4f8`,color:`var(--flowengage-primary)`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`background 0.2s ease, opacity 0.2s ease`,border:0,cursor:`pointer`,flexShrink:0},onClick:()=>C.current?.click(),title:`Attach file`,"aria-label":`Attach file`,disabled:x,onMouseEnter:e=>{e.currentTarget.style.opacity=`0.8`},onMouseLeave:e=>{e.currentTarget.style.opacity=`1`},children:(0,V.jsx)(ag,{size:16,color:`currentColor`})})]}):null,u?(0,V.jsx)(`input`,{className:`flowengage-chat-text-input`,style:{flex:1,minWidth:0,border:`none`,fontFamily:`inherit`,fontSize:`14px`,outline:`none`,padding:0,paddingLeft:O?`0`:`8px`,color:`#111827`,background:`transparent`,cursor:`text`,alignSelf:`center`},value:d,onChange:e=>f(e.target.value),placeholder:`Enter your Email`,disabled:s,type:`email`,autoComplete:`email`}):(0,V.jsx)(`textarea`,{ref:w,className:`flowengage-chat-text-input`,rows:1,style:{flex:1,minWidth:0,border:`none`,fontFamily:`inherit`,fontSize:`14px`,lineHeight:`20px`,outline:`none`,padding:`6px 0`,paddingLeft:O?`0`:`8px`,color:`#111827`,background:`transparent`,cursor:`text`,resize:`none`,maxHeight:`120px`,overflowY:`auto`},value:e,onChange:e=>{t(e.target.value),T(e.target)},onKeyDown:E,placeholder:o===`agent`?`Message the agent…`:S,disabled:s,autoComplete:`off`}),(0,V.jsx)(`button`,{type:`submit`,style:{width:`32px`,height:`32px`,borderRadius:`9999px`,background:`var(--flowengage-primary)`,color:`#fff`,border:`none`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`opacity 0.2s ease`,cursor:te?`not-allowed`:`pointer`,opacity:te?.45:1,flexShrink:0},disabled:te,onMouseEnter:e=>{te||(e.currentTarget.style.opacity=`0.85`)},onMouseLeave:e=>{e.currentTarget.style.opacity=`1`},children:(0,V.jsx)(eg,{size:16})})]}),!u&&y&&(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`7px 4px 0`},children:[(0,V.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`#dc2626`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,V.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,V.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]}),(0,V.jsx)(`span`,{style:{fontSize:`11px`,color:`#dc2626`,fontWeight:500},children:y})]}),u&&p&&(0,V.jsx)(`div`,{style:{padding:`8px 16px 0`,fontSize:`12px`,fontWeight:500,color:`#f43f5e`},children:p})]})}function jg({webRTCError:e,micError:t,setMicError:n,dismissCallError:r,isRateLimited:i,rateLimitMessage:a}){return(0,V.jsxs)(V.Fragment,{children:[(e||t)&&(0,V.jsxs)(`div`,{style:{margin:`0 20px 10px`,padding:`12px 16px`,borderRadius:`12px`,background:`#fef2f2`,border:`1px solid #fee2e2`,display:`flex`,alignItems:`flex-start`,gap:`10px`},children:[(0,V.jsx)(rg,{className:``}),(0,V.jsx)(`span`,{style:{fontSize:`12px`,color:`#b91c1c`,lineHeight:1.5,flex:1},children:e||t}),(0,V.jsx)(`button`,{style:{flexShrink:0,background:`transparent`,border:0,color:`#f87171`,cursor:`pointer`,fontSize:`18px`,lineHeight:1},onClick:()=>{n(null),r()},onMouseEnter:e=>{e.currentTarget.style.color=`#dc2626`},onMouseLeave:e=>{e.currentTarget.style.color=`#f87171`},children:`×`})]}),i&&(0,V.jsx)(`div`,{style:{margin:`0 20px 10px`,padding:`12px 16px`,fontSize:`13px`,borderRadius:`12px`,background:`#fee2e2`,color:`#991b1b`},children:a})]})}var Mg=[`#135bd8`,`#ef334b`,`#ffbd2e`];function Ng(e){return!Array.isArray(e)||e.length===0?Mg:e.length===1?[e[0],e[0],e[0]]:e.length===2?[e[0],e[1],e[0]]:[e[0],e[1],e[2]]}var Pg={idle:3,listening:.75,thinking:1,speaking:1.4,muted:.75,error:.08};function Fg(e){if(!e||typeof e!=`string`)return[0,0,0];let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t;return[parseInt(n.slice(0,2),16)/255,parseInt(n.slice(2,4),16)/255,parseInt(n.slice(4,6),16)/255]}function Ig(e,t){if(!e||typeof e!=`string`)return`rgba(0,0,0,${t})`;if(e.startsWith(`rgb`))return e.replace(/[\d.]+\)$/,`${t})`);let n=e.replace(`#`,``),r=n.length===3?n.split(``).map(e=>e+e).join(``):n;return`rgba(${parseInt(r.slice(0,2),16)},${parseInt(r.slice(2,4),16)},${parseInt(r.slice(4,6),16)},${t})`}var Lg=`
|
|
266
270
|
attribute vec2 a_pos;
|
|
267
271
|
varying vec2 v_uv;
|
|
268
272
|
void main() {
|
|
269
273
|
v_uv = a_pos * 0.5 + 0.5;
|
|
270
274
|
gl_Position = vec4(a_pos, 0.0, 1.0);
|
|
271
275
|
}
|
|
272
|
-
`,
|
|
276
|
+
`,Rg=`
|
|
273
277
|
precision highp float;
|
|
274
278
|
|
|
275
279
|
varying vec2 v_uv;
|
|
@@ -384,7 +388,7 @@ Error generating stack: `+e.message+`
|
|
|
384
388
|
|
|
385
389
|
gl_FragColor = vec4(clamp(col, 0.0, 1.0), 1.0);
|
|
386
390
|
}
|
|
387
|
-
`;function
|
|
391
|
+
`;function zg(e,t,n){let r=(t,n)=>{let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.error(`[AnimatedOrb shader]`,e.getShaderInfoLog(r)),null)},i=r(e.VERTEX_SHADER,t),a=r(e.FRAGMENT_SHADER,n);if(!i||!a)return null;let o=e.createProgram();return e.attachShader(o,i),e.attachShader(o,a),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS)?o:(console.error(`[AnimatedOrb link]`,e.getProgramInfoLog(o)),null)}function Bg({size:e=94,voiceState:t=`idle`,isMuted:n=!1,colors:r,onClick:i,style:a,className:o}){let[s,c,l]=Ng(r),u=t===`speaking`,d=e<=50,f=(0,b.useRef)(null),p=(0,b.useRef)(Pg[t]??.35);(0,b.useEffect)(()=>{p.current=Pg[t]??.35},[t]),(0,b.useEffect)(()=>{let t=f.current;if(!t)return;let n=Math.min(window.devicePixelRatio||1,2);t.width=e*n,t.height=e*n;let r=t.getContext(`webgl`,{alpha:!0,antialias:!0})||t.getContext(`experimental-webgl`,{alpha:!0,antialias:!0});if(!r){console.warn(`[AnimatedOrb] WebGL unavailable.`);return}let i=zg(r,Lg,Rg);if(!i){console.error(`[AnimatedOrb] WebGL program failed to compile/link`);return}r.useProgram(i);let a=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,a),r.bufferData(r.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),r.STATIC_DRAW);let o=r.getAttribLocation(i,`a_pos`);r.enableVertexAttribArray(o),r.vertexAttribPointer(o,2,r.FLOAT,!1,0,0);let u={time:r.getUniformLocation(i,`u_time`),speed:r.getUniformLocation(i,`u_speed`),c1:r.getUniformLocation(i,`u_c1`),c2:r.getUniformLocation(i,`u_c2`),c3:r.getUniformLocation(i,`u_c3`)};r.uniform3fv(u.c1,Fg(s)),r.uniform3fv(u.c2,Fg(c)),r.uniform3fv(u.c3,Fg(l)),r.viewport(0,0,t.width,t.height);let d=performance.now(),m,h=e=>{r.uniform1f(u.time,(e-d)/1e3),r.uniform1f(u.speed,p.current),r.drawArrays(r.TRIANGLES,0,6),m=requestAnimationFrame(h)};return m=requestAnimationFrame(h),()=>{cancelAnimationFrame(m),r.deleteProgram(i),r.deleteBuffer(a)}},[s,c,l,e]);let m=n?`saturate(0.3) brightness(1.1)`:t===`error`?`saturate(0.4) hue-rotate(28deg)`:`none`;return(0,V.jsxs)(`div`,{style:{position:`relative`,width:e,height:e,flexShrink:0,cursor:i?`pointer`:`default`,...a},className:o,onClick:i,children:[u&&!d&&(0,V.jsx)(Qm.div,{style:{position:`absolute`,inset:-10,borderRadius:`50%`,background:`radial-gradient(circle, ${Ig(s,.18)} 0%, transparent 70%)`,pointerEvents:`none`},animate:{opacity:[.3,.75]},transition:{duration:1,repeat:1/0,repeatType:`mirror`,ease:`easeInOut`}}),(0,V.jsx)(`div`,{style:{width:e,height:e,borderRadius:`50%`,overflow:`hidden`,WebkitMaskImage:`-webkit-radial-gradient(white, black)`,filter:m,transition:`filter 1.2s ease`},children:(0,V.jsx)(`canvas`,{ref:f,style:{width:`100%`,height:`100%`,display:`block`}})}),u&&(0,V.jsx)(`div`,{style:{position:`absolute`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,pointerEvents:`none`,zIndex:1},children:(0,V.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`3px`},children:[4,8,12,8,4].map((e,t)=>(0,V.jsx)(Qm.div,{style:{width:`3px`,borderRadius:`3px`,background:`rgba(255,255,255,0.85)`},animate:{height:[4,e+8,4]},transition:{duration:.48,delay:t*.08,repeat:1/0,ease:`easeInOut`}},t))})})]})}var Vg=`
|
|
388
392
|
@keyframes fe-call-ring-pulse {
|
|
389
393
|
0% { transform: scale(1); opacity: 0.55; }
|
|
390
394
|
70% { transform: scale(1.85); opacity: 0; }
|
|
@@ -413,22 +417,22 @@ Error generating stack: `+e.message+`
|
|
|
413
417
|
0%, 100% { opacity: 0.5; transform: scale(1); }
|
|
414
418
|
50% { opacity: 0.9; transform: scale(1.12); }
|
|
415
419
|
}
|
|
416
|
-
`;function Rg(e){let t=(e||``).replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t;return`${parseInt(n.slice(0,2),16)},${parseInt(n.slice(2,4),16)},${parseInt(n.slice(4,6),16)}`}function zg(e){if(!e||typeof e!=`string`)return`#1a1a1a`;let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t,r=parseInt(n.slice(0,2),16)/255,i=parseInt(n.slice(2,4),16)/255,a=parseInt(n.slice(4,6),16)/255,o=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4;return .2126*o(r)+.7152*o(i)+.0722*o(a)>.179?`#1a1a1a`:`#ffffff`}function Bg(e,t){let n=Array.isArray(e)&&e.length>0?e:[t||`#3B82F6`],[r,i,a]=n;return n.length===1?[`radial-gradient(ellipse 110% 65% at 50% -5%, ${r}28 0%, transparent 68%)`,`radial-gradient(ellipse 90% 55% at 50% 108%, ${r}1a 0%, transparent 65%)`,`#f7f8fa`].join(`, `):n.length===2?[`radial-gradient(ellipse 80% 100% at -10% 50%, ${r}22 0%, transparent 70%)`,`radial-gradient(ellipse 80% 100% at 110% 50%, ${i}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `):[`radial-gradient(ellipse 80% 70% at -10% 50%, ${r}22 0%, transparent 70%)`,`radial-gradient(ellipse 70% 80% at 110% 30%, ${i}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 60% at 50% 110%, ${a}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `)}function Vg({headshot:e,name:t,size:n=80,primaryColor:r=`#3B82F6`}){let i=(t||`A`)[0].toUpperCase(),a=zg(r),o=n>48?{boxShadow:`0 0 0 3px ${r}44`,border:`3px solid rgba(255,255,255,0.15)`}:{border:`1.5px solid ${r}55`};return e?(0,V.jsx)(`img`,{src:e,alt:t||`Agent`,style:{width:n,height:n,borderRadius:`50%`,objectFit:`cover`,position:`relative`,zIndex:1,flexShrink:0,...o}}):(0,V.jsx)(`div`,{style:{width:n,height:n,borderRadius:`50%`,background:`linear-gradient(135deg, ${r}, ${r}99)`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:Math.round(n*.36)+`px`,fontWeight:700,color:a,position:`relative`,zIndex:1,flexShrink:0,...o},children:i})}function Hg(e){let t=(0,b.useRef)(null),n=(0,b.useCallback)(()=>{if(!t.current)return;let{audioContext:e,oscillator:n,interval:r,toneTimeout:i}=t.current;window.clearInterval(r),window.clearTimeout(i);try{n.stop()}catch{}try{e.close()}catch{}t.current=null},[]),r=(0,b.useCallback)(()=>{if(t.current||typeof window>`u`)return;let e=window.AudioContext||window.webkitAudioContext||null;if(e)try{let n=new e,r=n.createOscillator(),i=n.createGain();r.connect(i),i.connect(n.destination),r.frequency.value=0,r.type=`sine`,i.gain.value=.3;let a=()=>{t.current&&(window.clearTimeout(t.current.toneTimeout),r.frequency.value=440,t.current.toneTimeout=window.setTimeout(()=>{r.frequency.value=0},400))};n.state===`suspended`&&n.resume().catch(e=>{console.warn(`[FlowEngage] ringtone autoplay blocked`,e)}),r.start(),t.current={audioContext:n,oscillator:r,interval:null,toneTimeout:null},a(),t.current.interval=window.setInterval(a,1e3)}catch(e){console.warn(`[FlowEngage] failed to start ringtone`,e)}},[]);return(0,b.useEffect)(()=>{if(e){r();return}n()},[e,r,n]),(0,b.useEffect)(()=>()=>n(),[n]),n}function Ug({incomingCall:e,activeCallId:t,callConnectionState:n,callDurationSeconds:r,isCallMuted:i,agentName:a,agentHeadshot:o,fallbackAgentName:s,acceptCall:c,rejectCall:l,endWebRTCCall:u,toggleCallMute:d,formatCallDuration:f,onMinimize:p,primaryColor:m=`#3B82F6`,orbColors:h,chatHistory:g=[]}){let _=a||s||`Agent`,v=e?`incoming`:n===`connecting`?`connecting`:`ongoing`,y=Hg(!!e),b=async()=>{y(),await c()},x=async()=>{y(),await l()},S=i?`muted`:n===`connecting`?`idle`:`listening`,C=v===`ongoing`,w={position:`absolute`,inset:0,zIndex:10,display:`flex`,flexDirection:`column`,borderRadius:`inherit`,overflow:`hidden`,background:Bg(h,m),animation:C?`fe-call-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)`:`fe-call-fade-in 0.32s ease`};if(v===`incoming`){let e=Array.isArray(h)&&h.length>0?h:[m];return(0,V.jsxs)(`div`,{style:w,children:[(0,V.jsx)(`style`,{children:Lg}),(0,V.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`space-between`,padding:`60px 32px 56px`},children:[(0,V.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`22px`},children:[(0,V.jsxs)(`div`,{style:{position:`relative`,width:`96px`,height:`96px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:[(0,V.jsx)(`div`,{style:{position:`absolute`,width:`96px`,height:`96px`,borderRadius:`50%`,background:`radial-gradient(circle, rgba(${Rg(e[0])},0.2) 0%, transparent 70%)`,filter:`blur(10px)`,zIndex:0}}),[0,.5,1].map((t,n)=>(0,V.jsx)(`div`,{style:{position:`absolute`,width:`96px`,height:`96px`,borderRadius:`50%`,border:`1.5px solid ${e[n%e.length]}`,animation:`fe-call-ring-pulse 2.6s cubic-bezier(0.215,0.61,0.355,1) ${t}s infinite`,zIndex:1}},n)),(0,V.jsx)(Vg,{headshot:o,name:_,size:82,primaryColor:m})]}),(0,V.jsxs)(`div`,{style:{textAlign:`center`},children:[(0,V.jsx)(`div`,{style:{fontSize:`22px`,fontWeight:700,color:`#111827`,letterSpacing:`-0.015em`,lineHeight:1.2},children:_}),(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`6px`,marginTop:`8px`},children:[(0,V.jsx)(`div`,{style:{width:`7px`,height:`7px`,borderRadius:`50%`,background:e[0],boxShadow:`0 0 5px ${e[0]}88`,animation:`fe-call-dot-blink 1.4s ease-in-out infinite`}}),(0,V.jsx)(`span`,{style:{fontSize:`13px`,color:`#6b7280`,letterSpacing:`0.01em`},children:`Incoming call`})]})]})]}),(0,V.jsxs)(`div`,{style:{display:`flex`,gap:`56px`,alignItems:`flex-end`},children:[(0,V.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`10px`},children:[(0,V.jsx)(`button`,{type:`button`,onClick:x,style:{width:`68px`,height:`68px`,borderRadius:`50%`,background:`#ef4444`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`white`,boxShadow:`0 6px 24px rgba(239,68,68,0.5)`,transition:`transform 0.15s ease, box-shadow 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.08)`,e.currentTarget.style.boxShadow=`0 8px 28px rgba(239,68,68,0.65)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`,e.currentTarget.style.boxShadow=`0 6px 24px rgba(239,68,68,0.5)`},"aria-label":`Decline call`,children:(0,V.jsx)(Yh,{size:26})}),(0,V.jsx)(`span`,{style:{fontSize:`12px`,color:`#6b7280`,fontWeight:500,letterSpacing:`0.01em`},children:`Decline`})]}),(0,V.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`10px`},children:[(0,V.jsx)(`button`,{type:`button`,onClick:b,style:{width:`68px`,height:`68px`,borderRadius:`50%`,background:`#22c55e`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`white`,boxShadow:`0 6px 24px rgba(34,197,94,0.5)`,transition:`transform 0.15s ease, box-shadow 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.08)`,e.currentTarget.style.boxShadow=`0 8px 28px rgba(34,197,94,0.65)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`,e.currentTarget.style.boxShadow=`0 6px 24px rgba(34,197,94,0.5)`},"aria-label":`Accept call`,children:(0,V.jsx)(Qh,{})}),(0,V.jsx)(`span`,{style:{fontSize:`12px`,color:`#6b7280`,fontWeight:500,letterSpacing:`0.01em`},children:`Accept`})]})]})]})]})}return v===`connecting`?(0,V.jsxs)(`div`,{style:w,children:[(0,V.jsx)(`style`,{children:Lg}),(0,V.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`24px`},children:[(0,V.jsx)(Vg,{headshot:o,name:_,size:64,primaryColor:m}),(0,V.jsx)(`div`,{style:{width:`48px`,height:`48px`,borderRadius:`50%`,border:`3px solid rgba(255,255,255,0.12)`,borderTopColor:Array.isArray(h)&&h[0]||m,animation:`fe-call-spin 0.9s linear infinite`}}),(0,V.jsx)(`span`,{style:{fontSize:`15px`,color:`#6b7280`,letterSpacing:`0.01em`},children:`Connecting…`})]})]}):(0,V.jsxs)(`div`,{style:w,children:[(0,V.jsx)(`style`,{children:Lg}),(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,padding:`16px 16px 10px`,gap:`10px`,flexShrink:0},children:[(0,V.jsx)(`button`,{type:`button`,onClick:p,style:{width:`40px`,height:`40px`,borderRadius:`50%`,background:`rgba(0,0,0,0.06)`,border:`1px solid rgba(0,0,0,0.1)`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#374151`,transition:`background 0.15s ease`,flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(0,0,0,0.11)`},onMouseLeave:e=>{e.currentTarget.style.background=`rgba(0,0,0,0.06)`},"aria-label":`Minimize call`,children:(0,V.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`polyline`,{points:`15 18 9 12 15 6`})})}),(0,V.jsx)(Ig,{colors:h,size:36,voiceState:S}),(0,V.jsx)(`div`,{style:{flex:1,minWidth:0,fontSize:`15px`,fontWeight:600,color:`#111827`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:_}),(0,V.jsx)(`div`,{style:{flexShrink:0,padding:`3px 10px`,borderRadius:`999px`,background:`${m}18`,border:`1px solid ${m}44`,display:`flex`,alignItems:`center`},children:(0,V.jsx)(`span`,{style:{fontSize:`11px`,fontWeight:600,color:m,letterSpacing:`0.02em`,lineHeight:1},children:`On Call`})})]}),(0,V.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`16px`,padding:`0 24px 16px`},children:[(0,V.jsx)(Vg,{headshot:o,name:_,size:116,primaryColor:m}),(0,V.jsxs)(`div`,{style:{textAlign:`center`},children:[(0,V.jsx)(`div`,{style:{fontSize:`20px`,fontWeight:700,color:`#111827`,letterSpacing:`-0.01em`},children:_}),(0,V.jsx)(`div`,{style:{marginTop:`8px`,fontSize:`24px`,fontWeight:300,color:`#9ca3af`,letterSpacing:`0.06em`,fontVariantNumeric:`tabular-nums`},children:f(r)})]})]}),(0,V.jsxs)(`div`,{style:{flexShrink:0,display:`flex`,gap:`12px`,padding:`16px 24px 40px`},children:[(0,V.jsxs)(`button`,{type:`button`,onClick:d,style:{flex:1,height:`54px`,borderRadius:`14px`,background:i?`rgba(239,68,68,0.1)`:`rgba(0,0,0,0.06)`,border:i?`1.5px solid rgba(239,68,68,0.4)`:`1.5px solid rgba(0,0,0,0.1)`,cursor:`pointer`,color:i?`#ef4444`:`#374151`,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`8px`,fontSize:`14px`,fontWeight:600,transition:`all 0.2s ease`},"aria-label":i?`Unmute`:`Mute`,children:[i?(0,V.jsx)(ag,{size:18}):(0,V.jsx)(Jh,{size:18}),i?`Unmute`:`Mute`]}),(0,V.jsxs)(`button`,{type:`button`,onClick:u,style:{flex:1,height:`54px`,borderRadius:`14px`,background:`rgba(239,68,68,0.9)`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`8px`,color:`white`,fontSize:`14px`,fontWeight:600,boxShadow:`0 4px 20px rgba(239,68,68,0.38)`,transition:`transform 0.15s ease, background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`#ef4444`,e.currentTarget.style.transform=`scale(1.02)`},onMouseLeave:e=>{e.currentTarget.style.background=`rgba(239,68,68,0.9)`,e.currentTarget.style.transform=`scale(1)`},"aria-label":`End call`,children:[(0,V.jsx)(Yh,{size:18}),`End Call`]})]})]})}function Wg({agentName:e,agentHeadshot:t,fallbackAgentName:n,callDurationSeconds:r,isCallMuted:i,formatCallDuration:a,toggleCallMute:o,endWebRTCCall:s,onExpand:c,primaryColor:l=`#3B82F6`}){let u=e||n||`Agent`;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`style`,{children:Lg}),(0,V.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:c,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&c?.()},onMouseEnter:e=>{e.currentTarget.style.boxShadow=`0 8px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.08), inset 0 1px 0 rgba(255,255,255,0.95)`,e.currentTarget.style.transform=`translateY(-2px)`},onMouseLeave:e=>{e.currentTarget.style.boxShadow=`0 4px 20px rgba(0,0,0,0.09), 0 1px 6px rgba(0,0,0,0.06), inset 0 1px 0 rgba(255,255,255,0.9)`,e.currentTarget.style.transform=`translateY(0)`},style:{display:`flex`,alignItems:`center`,gap:`12px`,padding:`10px 12px 10px 10px`,margin:`0 12px 8px`,borderRadius:`18px`,background:`rgba(255,255,255,0.88)`,backdropFilter:`blur(20px)`,WebkitBackdropFilter:`blur(20px)`,border:`1px solid rgba(255,255,255,0.65)`,boxShadow:`0 4px 20px rgba(0,0,0,0.09), 0 1px 6px rgba(0,0,0,0.06), inset 0 1px 0 rgba(255,255,255,0.9)`,cursor:`pointer`,animation:`fe-call-bar-slide-in 0.3s cubic-bezier(0.16,1,0.3,1)`,flexShrink:0,userSelect:`none`,outline:`none`,transition:`box-shadow 0.22s ease, transform 0.18s ease`},children:[(0,V.jsxs)(`div`,{style:{position:`relative`,flexShrink:0,width:`42px`,height:`42px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:[(0,V.jsx)(`div`,{style:{position:`absolute`,inset:`-4px`,borderRadius:`50%`,background:`${l}28`,animation:`fe-call-avatar-breathe 2.8s ease-in-out infinite`}}),(0,V.jsx)(`div`,{style:{position:`absolute`,inset:`-2px`,borderRadius:`50%`,border:`1.5px solid ${l}55`}}),(0,V.jsx)(Vg,{headshot:t,name:u,size:38,primaryColor:l})]}),(0,V.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,V.jsx)(`div`,{style:{fontSize:`13px`,fontWeight:600,color:`#111827`,lineHeight:1.3,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:u}),(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,marginTop:`3px`},children:[(0,V.jsx)(`div`,{style:{width:`6px`,height:`6px`,borderRadius:`50%`,background:`#22c55e`,flexShrink:0,boxShadow:`0 0 4px rgba(34,197,94,0.6)`,animation:`fe-call-dot-blink 1.6s ease-in-out infinite`}}),(0,V.jsxs)(`span`,{style:{fontSize:`12px`,color:`#6b7280`,fontVariantNumeric:`tabular-nums`,letterSpacing:`0.01em`},children:[`On Call\xA0•\xA0`,a(r)]})]})]}),(0,V.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`,flexShrink:0},children:[(0,V.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.12)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},style:{width:`36px`,height:`36px`,borderRadius:`50%`,background:i?`${l}18`:`rgba(0,0,0,0.05)`,border:i?`1.5px solid ${l}55`:`1.5px solid rgba(0,0,0,0.08)`,cursor:`pointer`,color:i?l:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,transition:`all 0.18s ease`,boxShadow:i?`0 0 0 3px ${l}12`:`none`},"aria-label":i?`Unmute`:`Mute`,children:i?(0,V.jsx)(ag,{size:15}):(0,V.jsx)(Jh,{size:15})}),(0,V.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.12)`,e.currentTarget.style.boxShadow=`0 4px 16px rgba(239,68,68,0.55)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`,e.currentTarget.style.boxShadow=`0 2px 10px rgba(239,68,68,0.35)`},style:{width:`36px`,height:`36px`,borderRadius:`50%`,background:`#ef4444`,border:`none`,cursor:`pointer`,color:`white`,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,boxShadow:`0 2px 10px rgba(239,68,68,0.35)`,transition:`all 0.18s ease`},"aria-label":`End call`,children:(0,V.jsx)(Yh,{size:16})})]})]})]})}function Gg(e,t={}){let n=t.maxChars??4500;if(!Array.isArray(e)||e.length===0)return``;let r=[];for(let t of e){if(!t||t.isPending)continue;let e=String(t.sender||``).toLowerCase(),n=null;if(e===`user`?n=`Visitor`:(e===`bot`||e===`ai`||e===`agent`)&&(n=`Assistant`),!n)continue;let i=String(t.message||``).replace(/<[^>]+>/g,` `).replace(/\s+/g,` `).trim().slice(0,1200);i&&r.push(`${n}: ${i}`)}if(r.length===0)return``;let i=r.join(`
|
|
420
|
+
`;function Hg(e){let t=(e||``).replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t;return`${parseInt(n.slice(0,2),16)},${parseInt(n.slice(2,4),16)},${parseInt(n.slice(4,6),16)}`}function Ug(e){if(!e||typeof e!=`string`)return`#1a1a1a`;let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t,r=parseInt(n.slice(0,2),16)/255,i=parseInt(n.slice(2,4),16)/255,a=parseInt(n.slice(4,6),16)/255,o=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4;return .2126*o(r)+.7152*o(i)+.0722*o(a)>.179?`#1a1a1a`:`#ffffff`}function Wg(e,t){let n=Array.isArray(e)&&e.length>0?e:[t||`#3B82F6`],[r,i,a]=n;return n.length===1?[`radial-gradient(ellipse 110% 65% at 50% -5%, ${r}28 0%, transparent 68%)`,`radial-gradient(ellipse 90% 55% at 50% 108%, ${r}1a 0%, transparent 65%)`,`#f7f8fa`].join(`, `):n.length===2?[`radial-gradient(ellipse 80% 100% at -10% 50%, ${r}22 0%, transparent 70%)`,`radial-gradient(ellipse 80% 100% at 110% 50%, ${i}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `):[`radial-gradient(ellipse 80% 70% at -10% 50%, ${r}22 0%, transparent 70%)`,`radial-gradient(ellipse 70% 80% at 110% 30%, ${i}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 60% at 50% 110%, ${a}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `)}function Gg({headshot:e,name:t,size:n=80,primaryColor:r=`#3B82F6`}){let i=(t||`A`)[0].toUpperCase(),a=Ug(r),o=n>48?{boxShadow:`0 0 0 3px ${r}44`,border:`3px solid rgba(255,255,255,0.15)`}:{border:`1.5px solid ${r}55`};return e?(0,V.jsx)(`img`,{src:e,alt:t||`Agent`,style:{width:n,height:n,borderRadius:`50%`,objectFit:`cover`,position:`relative`,zIndex:1,flexShrink:0,...o}}):(0,V.jsx)(`div`,{style:{width:n,height:n,borderRadius:`50%`,background:`linear-gradient(135deg, ${r}, ${r}99)`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:Math.round(n*.36)+`px`,fontWeight:700,color:a,position:`relative`,zIndex:1,flexShrink:0,...o},children:i})}function Kg(e){let t=(0,b.useRef)(null),n=(0,b.useCallback)(()=>{if(!t.current)return;let{audioContext:e,oscillator:n,interval:r,toneTimeout:i}=t.current;window.clearInterval(r),window.clearTimeout(i);try{n.stop()}catch{}try{e.close()}catch{}t.current=null},[]),r=(0,b.useCallback)(()=>{if(t.current||typeof window>`u`)return;let e=window.AudioContext||window.webkitAudioContext||null;if(e)try{let n=new e,r=n.createOscillator(),i=n.createGain();r.connect(i),i.connect(n.destination),r.frequency.value=0,r.type=`sine`,i.gain.value=.3;let a=()=>{t.current&&(window.clearTimeout(t.current.toneTimeout),r.frequency.value=440,t.current.toneTimeout=window.setTimeout(()=>{r.frequency.value=0},400))};n.state===`suspended`&&n.resume().catch(e=>{console.warn(`[FlowEngage] ringtone autoplay blocked`,e)}),r.start(),t.current={audioContext:n,oscillator:r,interval:null,toneTimeout:null},a(),t.current.interval=window.setInterval(a,1e3)}catch(e){console.warn(`[FlowEngage] failed to start ringtone`,e)}},[]);return(0,b.useEffect)(()=>{if(e){r();return}n()},[e,r,n]),(0,b.useEffect)(()=>()=>n(),[n]),n}function qg({incomingCall:e,activeCallId:t,callConnectionState:n,callDurationSeconds:r,isCallMuted:i,agentName:a,agentHeadshot:o,fallbackAgentName:s,acceptCall:c,rejectCall:l,endWebRTCCall:u,toggleCallMute:d,formatCallDuration:f,onMinimize:p,primaryColor:m=`#3B82F6`,orbColors:h,chatHistory:g=[]}){let _=a||s||`Agent`,v=e?`incoming`:n===`connecting`?`connecting`:`ongoing`,y=Kg(!!e),b=async()=>{y(),await c()},x=async()=>{y(),await l()},S=i?`muted`:n===`connecting`?`idle`:`listening`,C=v===`ongoing`,w={position:`absolute`,inset:0,zIndex:10,display:`flex`,flexDirection:`column`,borderRadius:`inherit`,overflow:`hidden`,background:Wg(h,m),animation:C?`fe-call-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)`:`fe-call-fade-in 0.32s ease`};if(v===`incoming`){let e=Array.isArray(h)&&h.length>0?h:[m];return(0,V.jsxs)(`div`,{style:w,children:[(0,V.jsx)(`style`,{children:Vg}),(0,V.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`space-between`,padding:`60px 32px 56px`},children:[(0,V.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`22px`},children:[(0,V.jsxs)(`div`,{style:{position:`relative`,width:`96px`,height:`96px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:[(0,V.jsx)(`div`,{style:{position:`absolute`,width:`96px`,height:`96px`,borderRadius:`50%`,background:`radial-gradient(circle, rgba(${Hg(e[0])},0.2) 0%, transparent 70%)`,filter:`blur(10px)`,zIndex:0}}),[0,.5,1].map((t,n)=>(0,V.jsx)(`div`,{style:{position:`absolute`,width:`96px`,height:`96px`,borderRadius:`50%`,border:`1.5px solid ${e[n%e.length]}`,animation:`fe-call-ring-pulse 2.6s cubic-bezier(0.215,0.61,0.355,1) ${t}s infinite`,zIndex:1}},n)),(0,V.jsx)(Gg,{headshot:o,name:_,size:82,primaryColor:m})]}),(0,V.jsxs)(`div`,{style:{textAlign:`center`},children:[(0,V.jsx)(`div`,{style:{fontSize:`22px`,fontWeight:700,color:`#111827`,letterSpacing:`-0.015em`,lineHeight:1.2},children:_}),(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`6px`,marginTop:`8px`},children:[(0,V.jsx)(`div`,{style:{width:`7px`,height:`7px`,borderRadius:`50%`,background:e[0],boxShadow:`0 0 5px ${e[0]}88`,animation:`fe-call-dot-blink 1.4s ease-in-out infinite`}}),(0,V.jsx)(`span`,{style:{fontSize:`13px`,color:`#6b7280`,letterSpacing:`0.01em`},children:`Incoming call`})]})]})]}),(0,V.jsxs)(`div`,{style:{display:`flex`,gap:`56px`,alignItems:`flex-end`},children:[(0,V.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`10px`},children:[(0,V.jsx)(`button`,{type:`button`,onClick:x,style:{width:`68px`,height:`68px`,borderRadius:`50%`,background:`#ef4444`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`white`,boxShadow:`0 6px 24px rgba(239,68,68,0.5)`,transition:`transform 0.15s ease, box-shadow 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.08)`,e.currentTarget.style.boxShadow=`0 8px 28px rgba(239,68,68,0.65)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`,e.currentTarget.style.boxShadow=`0 6px 24px rgba(239,68,68,0.5)`},"aria-label":`Decline call`,children:(0,V.jsx)($h,{size:26})}),(0,V.jsx)(`span`,{style:{fontSize:`12px`,color:`#6b7280`,fontWeight:500,letterSpacing:`0.01em`},children:`Decline`})]}),(0,V.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`10px`},children:[(0,V.jsx)(`button`,{type:`button`,onClick:b,style:{width:`68px`,height:`68px`,borderRadius:`50%`,background:`#22c55e`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`white`,boxShadow:`0 6px 24px rgba(34,197,94,0.5)`,transition:`transform 0.15s ease, box-shadow 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.08)`,e.currentTarget.style.boxShadow=`0 8px 28px rgba(34,197,94,0.65)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`,e.currentTarget.style.boxShadow=`0 6px 24px rgba(34,197,94,0.5)`},"aria-label":`Accept call`,children:(0,V.jsx)(ng,{})}),(0,V.jsx)(`span`,{style:{fontSize:`12px`,color:`#6b7280`,fontWeight:500,letterSpacing:`0.01em`},children:`Accept`})]})]})]})]})}return v===`connecting`?(0,V.jsxs)(`div`,{style:w,children:[(0,V.jsx)(`style`,{children:Vg}),(0,V.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`24px`},children:[(0,V.jsx)(Gg,{headshot:o,name:_,size:64,primaryColor:m}),(0,V.jsx)(`div`,{style:{width:`48px`,height:`48px`,borderRadius:`50%`,border:`3px solid rgba(255,255,255,0.12)`,borderTopColor:Array.isArray(h)&&h[0]||m,animation:`fe-call-spin 0.9s linear infinite`}}),(0,V.jsx)(`span`,{style:{fontSize:`15px`,color:`#6b7280`,letterSpacing:`0.01em`},children:`Connecting…`})]})]}):(0,V.jsxs)(`div`,{style:w,children:[(0,V.jsx)(`style`,{children:Vg}),(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,padding:`16px 16px 10px`,gap:`10px`,flexShrink:0},children:[(0,V.jsx)(`button`,{type:`button`,onClick:p,style:{width:`40px`,height:`40px`,borderRadius:`50%`,background:`rgba(0,0,0,0.06)`,border:`1px solid rgba(0,0,0,0.1)`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#374151`,transition:`background 0.15s ease`,flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(0,0,0,0.11)`},onMouseLeave:e=>{e.currentTarget.style.background=`rgba(0,0,0,0.06)`},"aria-label":`Minimize call`,children:(0,V.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`polyline`,{points:`15 18 9 12 15 6`})})}),(0,V.jsx)(Bg,{colors:h,size:36,voiceState:S}),(0,V.jsx)(`div`,{style:{flex:1,minWidth:0,fontSize:`15px`,fontWeight:600,color:`#111827`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:_}),(0,V.jsx)(`div`,{style:{flexShrink:0,padding:`3px 10px`,borderRadius:`999px`,background:`${m}18`,border:`1px solid ${m}44`,display:`flex`,alignItems:`center`},children:(0,V.jsx)(`span`,{style:{fontSize:`11px`,fontWeight:600,color:m,letterSpacing:`0.02em`,lineHeight:1},children:`On Call`})})]}),(0,V.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`16px`,padding:`0 24px 16px`},children:[(0,V.jsx)(Gg,{headshot:o,name:_,size:116,primaryColor:m}),(0,V.jsxs)(`div`,{style:{textAlign:`center`},children:[(0,V.jsx)(`div`,{style:{fontSize:`20px`,fontWeight:700,color:`#111827`,letterSpacing:`-0.01em`},children:_}),(0,V.jsx)(`div`,{style:{marginTop:`8px`,fontSize:`24px`,fontWeight:300,color:`#9ca3af`,letterSpacing:`0.06em`,fontVariantNumeric:`tabular-nums`},children:f(r)})]})]}),(0,V.jsxs)(`div`,{style:{flexShrink:0,display:`flex`,gap:`12px`,padding:`16px 24px 40px`},children:[(0,V.jsxs)(`button`,{type:`button`,onClick:d,style:{flex:1,height:`54px`,borderRadius:`14px`,background:i?`rgba(239,68,68,0.1)`:`rgba(0,0,0,0.06)`,border:i?`1.5px solid rgba(239,68,68,0.4)`:`1.5px solid rgba(0,0,0,0.1)`,cursor:`pointer`,color:i?`#ef4444`:`#374151`,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`8px`,fontSize:`14px`,fontWeight:600,transition:`all 0.2s ease`},"aria-label":i?`Unmute`:`Mute`,children:[i?(0,V.jsx)(lg,{size:18}):(0,V.jsx)(Qh,{size:18}),i?`Unmute`:`Mute`]}),(0,V.jsxs)(`button`,{type:`button`,onClick:u,style:{flex:1,height:`54px`,borderRadius:`14px`,background:`rgba(239,68,68,0.9)`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`8px`,color:`white`,fontSize:`14px`,fontWeight:600,boxShadow:`0 4px 20px rgba(239,68,68,0.38)`,transition:`transform 0.15s ease, background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`#ef4444`,e.currentTarget.style.transform=`scale(1.02)`},onMouseLeave:e=>{e.currentTarget.style.background=`rgba(239,68,68,0.9)`,e.currentTarget.style.transform=`scale(1)`},"aria-label":`End call`,children:[(0,V.jsx)($h,{size:18}),`End Call`]})]})]})}function Jg({agentName:e,agentHeadshot:t,fallbackAgentName:n,callDurationSeconds:r,isCallMuted:i,formatCallDuration:a,toggleCallMute:o,endWebRTCCall:s,onExpand:c,primaryColor:l=`#3B82F6`}){let u=e||n||`Agent`;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`style`,{children:Vg}),(0,V.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:c,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&c?.()},onMouseEnter:e=>{e.currentTarget.style.boxShadow=`0 8px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.08), inset 0 1px 0 rgba(255,255,255,0.95)`,e.currentTarget.style.transform=`translateY(-2px)`},onMouseLeave:e=>{e.currentTarget.style.boxShadow=`0 4px 20px rgba(0,0,0,0.09), 0 1px 6px rgba(0,0,0,0.06), inset 0 1px 0 rgba(255,255,255,0.9)`,e.currentTarget.style.transform=`translateY(0)`},style:{display:`flex`,alignItems:`center`,gap:`12px`,padding:`10px 12px 10px 10px`,margin:`0 12px 8px`,borderRadius:`18px`,background:`rgba(255,255,255,0.88)`,backdropFilter:`blur(20px)`,WebkitBackdropFilter:`blur(20px)`,border:`1px solid rgba(255,255,255,0.65)`,boxShadow:`0 4px 20px rgba(0,0,0,0.09), 0 1px 6px rgba(0,0,0,0.06), inset 0 1px 0 rgba(255,255,255,0.9)`,cursor:`pointer`,animation:`fe-call-bar-slide-in 0.3s cubic-bezier(0.16,1,0.3,1)`,flexShrink:0,userSelect:`none`,outline:`none`,transition:`box-shadow 0.22s ease, transform 0.18s ease`},children:[(0,V.jsxs)(`div`,{style:{position:`relative`,flexShrink:0,width:`42px`,height:`42px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:[(0,V.jsx)(`div`,{style:{position:`absolute`,inset:`-4px`,borderRadius:`50%`,background:`${l}28`,animation:`fe-call-avatar-breathe 2.8s ease-in-out infinite`}}),(0,V.jsx)(`div`,{style:{position:`absolute`,inset:`-2px`,borderRadius:`50%`,border:`1.5px solid ${l}55`}}),(0,V.jsx)(Gg,{headshot:t,name:u,size:38,primaryColor:l})]}),(0,V.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,V.jsx)(`div`,{style:{fontSize:`13px`,fontWeight:600,color:`#111827`,lineHeight:1.3,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:u}),(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,marginTop:`3px`},children:[(0,V.jsx)(`div`,{style:{width:`6px`,height:`6px`,borderRadius:`50%`,background:`#22c55e`,flexShrink:0,boxShadow:`0 0 4px rgba(34,197,94,0.6)`,animation:`fe-call-dot-blink 1.6s ease-in-out infinite`}}),(0,V.jsxs)(`span`,{style:{fontSize:`12px`,color:`#6b7280`,fontVariantNumeric:`tabular-nums`,letterSpacing:`0.01em`},children:[`On Call\xA0•\xA0`,a(r)]})]})]}),(0,V.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`,flexShrink:0},children:[(0,V.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.12)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},style:{width:`36px`,height:`36px`,borderRadius:`50%`,background:i?`${l}18`:`rgba(0,0,0,0.05)`,border:i?`1.5px solid ${l}55`:`1.5px solid rgba(0,0,0,0.08)`,cursor:`pointer`,color:i?l:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,transition:`all 0.18s ease`,boxShadow:i?`0 0 0 3px ${l}12`:`none`},"aria-label":i?`Unmute`:`Mute`,children:i?(0,V.jsx)(lg,{size:15}):(0,V.jsx)(Qh,{size:15})}),(0,V.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.12)`,e.currentTarget.style.boxShadow=`0 4px 16px rgba(239,68,68,0.55)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`,e.currentTarget.style.boxShadow=`0 2px 10px rgba(239,68,68,0.35)`},style:{width:`36px`,height:`36px`,borderRadius:`50%`,background:`#ef4444`,border:`none`,cursor:`pointer`,color:`white`,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,boxShadow:`0 2px 10px rgba(239,68,68,0.35)`,transition:`all 0.18s ease`},"aria-label":`End call`,children:(0,V.jsx)($h,{size:16})})]})]})]})}function Yg(e,t={}){let n=t.maxChars??4500;if(!Array.isArray(e)||e.length===0)return``;let r=[];for(let t of e){if(!t||t.isPending)continue;let e=String(t.sender||``).toLowerCase(),n=null;if(e===`user`?n=`Visitor`:(e===`bot`||e===`ai`||e===`agent`)&&(n=`Assistant`),!n)continue;let i=String(t.message||``).replace(/<[^>]+>/g,` `).replace(/\s+/g,` `).trim().slice(0,1200);i&&r.push(`${n}: ${i}`)}if(r.length===0)return``;let i=r.join(`
|
|
417
421
|
`);return i.length>n&&(i=`…(earlier messages omitted)
|
|
418
|
-
`+i.slice(-n)),i}var
|
|
422
|
+
`+i.slice(-n)),i}var Xg=/^\/[a-z]{2}(?:-[a-z]{2})?(?=\/|$)/i;function Zg(e){return String(e||``).replace(Xg,``).replace(/\/+$/,``).toLowerCase()||`/`}function Qg(e,t){return Zg(e)===Zg(t)}function $(...e){Mn()&&console.log(`[FlowEngage:voice-tools]`,...e)}function $g(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function e_(e){let t=new Set;function n(r){if(!r||t.has(r))return;t.add(r),e(r);let i=r.querySelectorAll(`iframe`);for(let e of i)if(!Rn(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function t_(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function n_(e){let t=e.ownerDocument||document,n=e.getAttribute(`aria-labelledby`);if(n){let e=n.trim().split(/\s+/).filter(Boolean),r=[];for(let n of e)try{let e=t.getElementById(n);e?.textContent&&r.push(e.textContent.trim())}catch{}if(r.length)return t_(r.join(` `))}if(e.labels&&e.labels.length)return t_(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return t_(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return t_(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return t_(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=t_(i.textContent);if(e)return e}i=i.previousElementSibling}let a=e.parentElement;for(let e=0;e<5&&a;e+=1){if(a.tagName===`LABEL`)return t_(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return t_(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?t_(o):null}function r_(){let e=[];return e_(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(Rn(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=$g(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e}function i_(){return r_().map((e,t)=>{let n={formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:n_(e),placeholder:e.placeholder||null};return e.tagName===`SELECT`&&(n.options=Array.from(e.options).filter(e=>e.value!==``&&!e.disabled).map(e=>({value:e.value,text:e.text.trim()})),n.currentValue=e.value||null),n})}function a_(){let e=[];return e_(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(Rn(e)||e.disabled)return!1;try{let t=$g(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e.slice(0,60).map((e,t)=>({index:t,text:(e.textContent||e.value||``).replace(/\s+/g,` `).trim().slice(0,120)||null,ariaLabel:e.getAttribute(`aria-label`),type:e.type||e.tagName}))}function o_(e,t){try{if(!e?.getBoundingClientRect||!t?.getBoundingClientRect)return 1/0;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i={x:n.left+n.width/2,y:n.top+n.height/2},a={x:r.left+r.width/2,y:r.top+r.height/2};return Math.hypot(i.x-a.x,i.y-a.y)}catch{return 1/0}}function s_(e,t){let n=String(t||``).toLowerCase().trim();if(!n)return 0;let r=(e.innerText||e.textContent||``).replace(/\s+/g,` `).trim(),i=[r,e.value,e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-text`),e.getAttribute(`data-label`)].filter(Boolean).join(` `).toLowerCase().replace(/\s+/g,` `);if(i.includes(n)||r.toLowerCase()===n)return 100;let a=n.split(/\s+/).filter(e=>e.length>1);if(!a.length)return 0;let o=0;for(let e of a)i.includes(e)&&(o+=1);return o/a.length*92}function c_(e,t,n=6){let r=String(t||``).toLowerCase().trim();if(!r)return!1;let i=e;for(let e=0;e<n&&i&&(i=i.parentElement,i);e++)if((i.innerText||i.textContent||``).toLowerCase().includes(r))return!0;return!1}function l_(e,t,n){let r=[];e_(e=>{let t=Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"], a[href]`));r.push(...t.filter(e=>{if(Rn(e)||e.disabled)return!1;try{let t=$g(e);if(t.display===`none`||t.visibility===`hidden`||t.opacity===`0`)return!1}catch{}return!0}))});let i=0,a=r.map(t=>({el:t,s:s_(t,e)}));for(let{s:e}of a)e>i&&(i=e);if(i<28)return null;let o=a.filter(({s:e})=>e===i).map(({el:e})=>e);if(o.length===1)return o[0];if(n){let e=o.filter(e=>c_(e,n));if(e.length===1)return e[0];e.length>1&&(o=e)}let s=Array.isArray(t)?t.filter(e=>e&&e.isConnected):[];if(s.length){let e=o[0],t=1/0;for(let n of o)for(let r of s){let i=o_(n,r);i<t&&(t=i,e=n)}return e}return o[0]}function u_(e){if(e==null)return{};if(typeof e==`string`){let t=e.trim();if(!t)return{};try{return JSON.parse(t)}catch{return{url:t}}}return e}function d_(e){if(!e||typeof e!=`object`)return null;let t=e.url??e.target_url??e.page_url??e.pageUrl??e.link??e.href??e.path;return t==null?null:String(t).trim()||null}function f_(){let e={};document.querySelectorAll(`h1, h2, h3, h4, h5, h6`).forEach(t=>{if(t.id)return;let n=t.textContent.trim();if(!n)return;let r=n.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``).substring(0,60);if(e[r]){let t=2;for(;e[r+`-`+t];)t++;r=r+`-`+t}e[r]=!0,t.id=r})}function p_(){let e=e=>{let t=Array.from(e).filter(e=>!e.closest(`#flowengage-root, .flowengage-shell, .flowengage-widget-root`)&&!e.closest(`nav, footer, header, aside, .nav, .footer, .header, .sidebar`)),n=[],r=0;for(;r<t.length;){let e=t[r],i=zn(e);if(!i||i.length<2){r++;continue}let a=i;if(i.length<40&&!/[.!?:;]$/.test(i)&&r+1<t.length){let n=t[r+1],o=zn(n);o&&n.tagName===e.tagName&&o.length<60&&(e.nextElementSibling===n||e.parentElement===n.parentElement)&&(a=`${i} ${o}`,r++)}a.length>2&&a.length<200&&n.push({text:a,level:Number(e.tagName.slice(1))||6}),r++}return n},t=document.querySelector(`main, [role='main']`)||document.body,n=e(t.querySelectorAll(`h1, h2, h3, h4, h5`));n.length||(n=e(document.body.querySelectorAll(`h1, h2, h3, h4, h5`)));let r=new Set,i=[];for(let e of n)if(!(!e||r.has(e.text))&&(r.add(e.text),i.push(e),i.length>=30))break;let a=i.map(e=>e.text),o=[];for(let e=0;e<i.length;e++){let t=0;for(let n=e+1;n<i.length&&!(i[n].level<=i[e].level);n++)t+=1;t>=3&&o.push(i[e].text)}let s=Array.from(t.querySelectorAll(`h1`)).filter(e=>!e.closest(`#flowengage-root, .flowengage-shell, .flowengage-widget-root`)&&!e.closest(`nav, footer, header, aside, .nav, .footer, .header, .sidebar`)),c=null;if(s.length===1){let e=zn(s[0]);e&&a[0]&&a[0].toLowerCase().trim()===e.toLowerCase().trim()&&(c=a[0])}let l=``;try{let e=t.querySelector(`h1, h2, h3, h4, h5`);if(e){let n=document.createRange();n.setStart(t,0),n.setEndBefore(e);let r=n.cloneContents(),i=[];r.querySelectorAll(`p, li`).forEach(e=>{let t=e.textContent.replace(/\s+/g,` `).trim();t.length>20&&i.push(t)}),l=i.join(` `).slice(0,600)}}catch{}return{headings:a,pageTitleHeading:c,introText:l,containerHeadings:o}}function m_(e){if(!e||typeof document>`u`)return``;let t=new Set([`script`,`style`,`noscript`,`svg`,`iframe`,`nav`,`footer`,`header`,`aside`]),n=parseInt(e.tagName[1],10),r=Array.from({length:n},(e,t)=>`h${t+1}`).join(`, `),i=Array.from(document.querySelectorAll(r)).filter(e=>!e.closest(Ln)),a=i.indexOf(e),o=a===-1?null:i[a+1],s=document.createRange();try{if(s.setStartAfter(e),o)s.setEndBefore(o);else{let e=document.querySelector(`main, [role='main'], article`)||document.body;s.setEnd(e,e.childNodes.length)}}catch{return e.textContent.replace(/\s+/g,` `).trim()}let c;try{c=s.cloneContents()}catch{return e.textContent.replace(/\s+/g,` `).trim()}let l=[];function u(e){if(e.nodeType===Node.TEXT_NODE){let t=e.textContent.replace(/\s+/g,` `).trim();t&&l.push(t);return}if(e.nodeType!==Node.ELEMENT_NODE)return;let n=e.tagName.toLowerCase();if(!t.has(n)){if(n===`ul`||n===`ol`){let t=Array.from(e.querySelectorAll(`:scope > li`)).map(e=>{let t=e.textContent.replace(/\s+/g,` `).trim();return t?`• ${t}`:null}).filter(Boolean);t.length&&l.push(t.join(`
|
|
419
423
|
`));return}if(n===`table`){let t=Array.from(e.querySelectorAll(`tr`)).map(e=>Array.from(e.querySelectorAll(`td, th`)).map(e=>e.textContent.replace(/\s+/g,` `).trim()).filter(Boolean).join(` | `)).filter(Boolean);t.length&&l.push(t.join(`
|
|
420
424
|
`));return}if(n===`form`){let t=Array.from(e.querySelectorAll(`input, textarea, select`)).map(e=>{let t=(e.getAttribute(`type`)||`text`).toLowerCase();if([`hidden`,`submit`,`button`,`reset`].includes(t))return null;let n=e.getAttribute(`placeholder`)||e.getAttribute(`aria-label`)||e.getAttribute(`name`)||t;return n?String(n).trim().slice(0,40):null}).filter(Boolean),n=e.querySelector(`button[type="submit"], input[type="submit"]`),r=n?(n.textContent||n.value||`Submit`).trim().slice(0,40):`Submit`;t.length&&l.push(`[FORM PRESENT: ${t.length} field(s) — ${t.join(`, `)}. Submit button: "${r}"]`);return}if(n===`p`||n===`blockquote`){let t=e.textContent.replace(/\s+/g,` `).trim();t.length>2&&l.push(t);return}if(/^h[1-6]$/.test(n)){let t=e.textContent.replace(/\s+/g,` `).trim();t.length>2&&l.push(t);return}for(let t of e.childNodes)u(t)}}for(let e of c.childNodes)u(e);let d=new Set;return l.filter(e=>{let t=e.substring(0,80);return d.has(t)?!1:(d.add(t),!0)}).join(`
|
|
421
425
|
`).replace(/\n{3,}/g,`
|
|
422
426
|
|
|
423
|
-
`).trim()}function d_(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=typeof e.beaconSyncFullVoiceHistory==`function`?e.beaconSyncFullVoiceHistory:null,a=[],o={"fwh-navigate-mvp":async n=>{if($(`fwh-navigate-mvp ▶ raw parameters:`,n),e?.isWalkthroughActive?.())return $(`fwh-navigate-mvp ✖ blocked — walkthrough in progress`),`NAVIGATION_BLOCKED_DURING_WALKTHROUGH. A walkthrough of the current page is in progress, so navigation is not allowed. Do NOT tell the visitor you navigated or offer to. Describe the requested section using the CURRENT page's own content (fwh-read-content-mvp), then stop.`;let a=o_(n),o=s_(a),s=a.section_text??a.sectionText??a.section,c=Array.isArray(a.expected_landmarks)?a.expected_landmarks:Array.isArray(a.expectedLandmarks)?a.expectedLandmarks:[];if($(`fwh-navigate-mvp · coerced:`,{url:o,sectionText:s,expectedLandmarks:c}),!o){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`fwh-navigate-mvp ✖`,e),e}if(typeof window<`u`)try{let e=new URL(o,window.location.href);if(e.hostname===window.location.hostname&&e.origin!==window.location.origin)o=e.pathname+e.search+e.hash,$(`fwh-navigate-mvp · cross-protocol same-host URL normalized →`,o);else if(e.origin!==window.location.origin&&/^https?:$/i.test(e.protocol)){let t=e.hostname;return $(`fwh-navigate-mvp ✖ external URL blocked:`,e.href),`EXTERNAL_LINK_BLOCKED: The URL "${o}" points to an external site (${t}) that opens in a new tab. I cannot open new tabs or navigate to external sites. Tell the visitor exactly this: "That link opens an external app — I'm not able to open it for you, but you can click the link directly in the navigation header."`}}catch{}if(typeof window<`u`){try{let e=new URL(o,window.location.href);if(e.pathname===window.location.pathname&&e.search===window.location.search)return $(`fwh-navigate-mvp ✖ already on page, skipping`),`OK_ALREADY_ON_PAGE. The visitor is already on this page. Do not navigate. Proceed directly with highlights, answering the question, or reading page content.`}catch{}let e=window.__fe_user_nav_during_speech;if(e&&Date.now()-e.ts<3e4)try{if(new URL(o,window.location.href).pathname===e.fromPath)return $(`flowengage_navigate ✖ blocked — would navigate back to page visitor just left`,e),`NAV_BLOCKED: The visitor just left "${e.fromPageName}" and is now on "${e.toPageName}". Do NOT navigate them back. If they said "continue", resume verbally from where you left off — no navigation needed. If they want to return, they will navigate themselves.`}catch{}}let{allowed:l,correctedUrl:u}=await Sr(o,{siteId:t,apiBaseUrl:e.apiBaseUrl});if(!l){let e=`PAGE_NOT_IN_SITE: "${o}" is NOT a real page on this site — do NOT guess or invent URL paths. Do NOT tell the visitor you are taking them there. Instead, find the REAL page: look at your Popular Pages / Site Pages list for the closest actual match, or call fwh-list-nav-links-mvp (to read the site's real menu links) or fwh-search-mvp (to find the right page). If a close match exists (e.g. the visitor said "support" and the site has "Technical Support"), tell them the ACTUAL page name and ask "we don't have a page called that, but we do have [real page] — would you like me to take you there?" Then navigate only to that verified URL.`;return $(`fwh-navigate-mvp ✖ blocked`,e),e}u&&u!==o&&($(`fwh-navigate-mvp · corrected url:`,{requested:o,correctedUrl:u}),o=u);try{Eh(`Navigating to ${o}...`,{spinner:!0}),Lh(),In();try{i?.()}catch{}try{let e=r?r():``;if(e&&t){let n=Gg([{sender:`user`,message:e}]);n&&Ee(t,n)}}catch{}Ae();let e=o;try{e=new URL(o,typeof window<`u`?window.location.href:``).href}catch{}let n=`this`;try{let e=new URL(o,window.location.href).pathname.split(`/`).filter(Boolean).pop()||``;n=e?e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()):`Home`}catch{}t&&typeof window<`u`&&Le(t,window.location.href,e,n),Tr(e);try{window.__fe_agent_nav={path:new URL(e,window.location.href).pathname,ts:Date.now()}}catch{}$(`fwh-navigate-mvp → real navigation`,o);let a=typeof window<`u`&&!window.Shopify&&!!nr();if(typeof window<`u`&&window.__fe_triggerVoiceNavHooks&&window.__fe_triggerVoiceNavHooks(),a&&qn(12e3),Nr(o,{voiceActive:!0}).catch(()=>{}),a)try{let e=new URL(o,window.location.origin).pathname,t=window.location.pathname,n=Date.now()+2e3;for(;Date.now()<n&&!(typeof window<`u`&&window.location.pathname===e);)await new Promise(e=>setTimeout(e,80));let r=typeof window<`u`?window.location.pathname:e,i=typeof window<`u`?window.location.href:o;(r.split(`/`).filter(Boolean).pop()||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),$(`fwh-navigate-mvp → SPA nav complete. target:`,e,`actual:`,r);try{typeof window<`u`&&window.scrollTo(0,0)}catch{}let a=[],s=null,c=``,l=Date.now()+12e3;for(;Date.now()<l&&(await new Promise(e=>setTimeout(e,300)),{headings:a,pageTitleHeading:s,introText:c}=l_(),!(a.length>=1)););c_(),$(`fwh-navigate-mvp → page headings collected:`,a,`titleHeading:`,s);let u=a.length?a.join(` | `):`none`,d=a.length?`Use ONLY these exact heading strings for fwh-highlight-mvp — never invent or abbreviate.`:`No headings collected yet — call fwh-get-current-page-mvp immediately (no speech) to get the live headings before speaking or highlighting.`,f=s?` "${s}" is the PAGE TITLE, not a content section — do not fwh-highlight-mvp it separately; if doing a walkthrough, just fold this intro into your opening line: "${c||`(no intro text found)`}"`:c?` No separate page-title heading detected, but this intro text precedes the first section — mention it briefly before covering sections: "${c}"`:``,p=``;try{if(a.length>0){let e=a.slice(0,3),t=[];for(let n of e){let e=_r(null,n);if(e){let r=u_(e).substring(0,800);r&&t.push(`[Section: ${n}] ${r}`)}}t.length>0&&(p=` CONTENT FOR FIRST FEW SECTIONS: ${t.join(` | `)}. Use this content to answer immediately if the visitor asks about one of these sections.`)}}catch{}if(Or())return Er(),$(`fwh-navigate-mvp ✖ landed on a not-found/404 page:`,i),`NAVIGATION_PAGE_NOT_FOUND. The page at ${i} does not exist — it shows a "not found"/404 error, not real content. Do NOT offer a page overview, do NOT describe or highlight any sections, do NOT claim the navigation succeeded. Tell the visitor EXACTLY: "It looks like that page doesn't exist — I couldn't find it. Would you like me to take you somewhere else?" Then STOP and wait for their reply.`;let m=Date.now()+4e3,h=typeof window<`u`?window.location.pathname:r;for(;Date.now()<m&&!Jg(h,e)&&Jg(h,t);)await new Promise(e=>setTimeout(e,120)),h=window.location.pathname;$(`fwh-navigate-mvp route settle:`,{startPath:t,targetPath:e,settledPath:h});let g=typeof window<`u`?window.location.href:i,_=(h.split(`/`).filter(Boolean).pop()||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())||`Home`,v=Jg(h,e),y=!Jg(h,t),b=v||y;return $(`fwh-navigate-mvp settled:`,h,`target:`,e,`match:`,b),b?(Er(),`OK_NAVIGATE_SPA. Visitor is now on: ${g} (page: "${_}") | Section headings: ${u}.${f} ${d}${p} Now confirm the arrival in ONE short sentence phrased for what the visitor actually asked for — mention the page by name and what it lets them do (e.g. for a contact request: "I've taken you to the Contact Us page — filling in this form sends your query straight to our team."). Do NOT use a fixed template. Then, in the same breath, offer either a specific section or a full overview. Then STOP — wait for their reply.`):(Er(),`NAVIGATION_DID_NOT_HAPPEN. The visitor is STILL on ${g} (page: "${_}") — the navigation did not go through. Do NOT say "I have navigated you". Do NOT claim success. Tell the visitor EXACTLY: "Sorry, I couldn't open that page just now. Would you like me to try again, or is there something else I can help with?" Then STOP and wait for their reply.`)}catch{}return`OK_NAVIGATE_RELOADING. The page is reloading now and this session is ending. Say NOTHING further — do not confirm the navigation, do not describe the page. The arrival greeting is spoken automatically on the new page; you resume from the visitor's next reply.`}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`fwh-navigate-mvp ✖`,t),Eh(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{Rh(),Dh(900)}},"fwh-highlight-mvp":async e=>{$(`fwh-highlight-mvp ▶`,e);let t=o_(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText;if(qn(3e3),typeof window<`u`&&window.__fe_user_nav_during_speech){let e=window.__fe_user_nav_during_speech,t=window.location.pathname;if(Date.now()-e.ts>=3e4)window.__fe_user_nav_during_speech=null;else return $(`flowengage_highlight ✖ blocked — user navigated during speech`,e),`NAV_CHANGED: The visitor navigated from "${e.fromPageName}" to "${e.toPageName}" (current path: ${t}) while you were speaking. STOP the current walkthrough immediately. DO NOT call fwh-highlight-mvp again. Say out loud: "I see you've navigated to the ${e.toPageName} page — do you want me to continue what I was explaining, or shall I guide you through this page?" Wait for the visitor's answer before doing anything else.`}c_();let i=(e=>e&&e.replace(/^\d+\.\s*/,``).replace(/^["']|["']$/g,``).trim())(r),a=_r(n||null,i||null);if(!a&&i){let e=Date.now()+600;for(;!a&&Date.now()<e;)await new Promise(e=>setTimeout(e,50)),c_(),a=_r(null,i)}if(!a){$(`fwh-highlight-mvp ✖ no element for:`,i||n);let{headings:e}=l_(),t=e.length?`Page headings: ${e.map(e=>`"${e}"`).join(` | `)}. Use one of these EXACT strings for section_text — no numbers, no quotes around them.`:`No headings found — skip highlight and continue speaking.`;return`HIGHLIGHT_NOT_FOUND: "${i||n}" on the current page. ${t}`}return Fn(a),$(`fwh-highlight-mvp ✓`,i||n),`OK_HIGHLIGHT: "${i||n}". Your NEXT response must be speech only (no tool call) describing THIS section — "${i||n}" — using its own content. Do not ask whether to continue.`},"fwh-read-content-mvp":async e=>{$(`fwh-read-content-mvp ▶`,e);let t=o_(e),n=t?.section_text||t?.sectionText||``;try{let e=``;if(n){let t=_r(null,n);if(!t)return`Could not find section "${n}" on the page.`;e=u_(t)}else{let t=(document.querySelector(`main`)||document.querySelector(`article`)||document.querySelector(`[role="main"]`)||document.querySelector(`#content`)||document.querySelector(`.content`)||document.body).cloneNode(!0);t.querySelectorAll(`nav, footer, header, aside, script, style, noscript, .nav, .footer, .header, .sidebar, #flowengage-root, .flowengage-shell, .flowengage-widget-root`).forEach(e=>e.remove()),e=t.textContent.replace(/\s+/g,` `).trim()}return e.length>8e3&&(e=e.substring(0,8e3)+`... (truncated)`),$(`fwh-read-content-mvp ✓`,`${e.length} chars`),e||`No readable content found on this page.`}catch(e){return $(`fwh-read-content-mvp ✖`,e.message),`Could not read page content: ${e.message}`}},"fwh-page-content-mvp":async e=>{$(`fwh-page-content-mvp ▶`,e);let r=o_(e),i=r?.url||r?.page_url||``;if($(`fwh-page-content-mvp · url:`,i,`siteId:`,t,`apiBase:`,n||`(empty)`),!i)return $(`fwh-page-content-mvp ✖ missing url`),`Missing url parameter.`;if(!t)return $(`fwh-page-content-mvp ✖ no siteId`),`Site is not configured.`;if(!n)return $(`fwh-page-content-mvp ✖ no api base`),`API base URL is missing; cannot fetch page content.`;try{let e=`${n}/api/site-tools/page-content`;$(`fwh-page-content-mvp → POST`,e);let r=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,url:i})}),a=await r.json();if($(`fwh-page-content-mvp · HTTP`,r.status,`success:`,a.success),!a.success){let e=a.error||`Failed to get page content.`;return $(`fwh-page-content-mvp ✖`,e),`${e} FALLBACK REQUIRED: This page is not in the search index. Call fwh-read-content-mvp (no parameters) immediately to read the live page content directly from the visitor's browser — do NOT tell the visitor you cannot access the page.`}return $(`fwh-page-content-mvp ✓`,`title: ${a.title}`,`sections: ${(a.sections||[]).length}`,`content: ${(a.content||``).length} chars`),JSON.stringify({title:a.title,url:a.url,sections:a.sections,content:a.content})}catch(e){let t=`Page content error: ${e.message||`network`}`;return $(`fwh-page-content-mvp ✖`,t),t}},"fwh-search-mvp":async e=>{$(`fwh-search-mvp ▶`,e);let r=o_(e).query;if(!r)return $(`fwh-search-mvp ✖ missing query`),`Missing query parameter.`;if(!t)return $(`fwh-search-mvp ✖ no siteId`),`Search unavailable (no siteId configured).`;if(!n)return $(`fwh-search-mvp ✖ no api base`),`Search unavailable (no API base URL).`;try{let e=`${n}/api/site-tools/search`;$(`fwh-search-mvp → POST`,e);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,query:r,currentUrl:typeof window<`u`?window.location.href:``})}),a=await i.json();if($(`fwh-search-mvp · HTTP`,i.status,`success:`,a.success),!a.success||!a.results?.length)return`No results found for that query. Try rephrasing, or use fwh-read-content-mvp to read the current page.`;let o=a.results.slice(0,5).map((e,t)=>`${t+1}. ${e.title||e.url} (${e.url})${e.snippet?` — ${e.snippet}`:``}`).join(`
|
|
424
|
-
`);return $(`fwh-search-mvp ✓`,`${a.results.length} result(s)`),`SEARCH_RESULTS:\n${o}`}catch(e){return $(`fwh-search-mvp ✖`,e.message),`Search failed. Use fwh-read-content-mvp to read the current page instead.`}},"fwh-list-nav-links-mvp":async()=>{if($(`fwh-list-nav-links-mvp ▶`),typeof window>`u`)return`Cannot read navigation (no browser context).`;let e=new Map,t=[],n=[`nav a`,`[role='navigation'] a`,`header a`,`.navbar a`,`.nav a`,`.menu a`,`.navigation a`,`.header a`,`[class*='nav'] a`,`[class*='menu'] a`,`[class*='header'] a`];if(
|
|
425
|
-
`);return $(`fwh-list-nav-links-mvp ✓`,`${t.length} links`),`NAV_LINKS (${t.length} total, showing up to 50):\n${r}\n\nIMPORTANT: Use the EXACT text shown above when reading link names to the visitor. Do NOT rename, abbreviate, or invent options not listed here. To navigate, call fwh-navigate-mvp with the href value.`},"fwh-end-session-mvp":async()=>($(`fwh-end-session-mvp ▶`),typeof e.requestEndSession==`function`&&e.requestEndSession(),`Voice session is ending.`),"fwh-request-email-mvp":async()=>($(`fwh-request-email-mvp ▶`),typeof e.requestEmailCollection==`function`&&e.requestEmailCollection(),`EMAIL_BOX_SHOWN. An email input text box is now visible to the visitor. Say EXACTLY: "Please enter your email in the text box to continue." Then stop and wait silently — do NOT ask them to say it aloud, do NOT repeat, and do NOT answer any other question until you receive the EMAIL_SAVED message.`),"fwh-get-current-page-mvp":async()=>{if($(`fwh-get-current-page-mvp ▶`),typeof window>`u`)return`Cannot determine current page (no browser context).`;let e=window.location.href,t=window.location.pathname,n=document.title||``;if(Or())return $(`fwh-get-current-page-mvp ✓ 404 detected`,{url:e}),`CURRENT_PAGE_NOT_FOUND. The visitor is currently on a 404 / page-not-found error page (${e}). There is no real content here. Do NOT describe this page, do NOT list sections, do NOT offer a walkthrough, and do NOT describe it from your own knowledge. Tell the visitor plainly that the page they are on doesn't exist, and offer to take them somewhere that does.`;let{headings:r,pageTitleHeading:i,introText:a}=l_();$(`fwh-get-current-page-mvp ✓`,{url:e,path:t,title:n}),$(`fwh-get-current-page-mvp → page headings collected:`,r,`titleHeading:`,i);let o=i?` NOTE: "${i}" is the PAGE TITLE, not a content section — do NOT fwh-highlight-mvp it or list it as a separate section in a walkthrough. Instead, open with a brief 1-2 sentence summary of this intro text before covering the real sections: "${a||`(no intro text captured)`}"`:a?` NOTE: no separate page-title heading was detected, but this intro text appears before the first section — open your walkthrough with a brief 1-2 sentence summary of it before covering sections: "${a}"`:``;if(!r.length)return`CURRENT_PAGE. URL: ${e} | Title: ${n} |${o} No structured section headings found on this page. If there is intro text above, describe it; otherwise describe the page from your knowledge. Do not call this tool again.`;let s=r.map(e=>`"${e}"`).join(` | `);return`CURRENT_PAGE. URL: ${e} | Title: ${n} | Page sections (${r.length} total): ${s}.${o} *** WALKTHROUGH: do NOT drive it yourself. Do not call fwh-highlight-mvp and do not decide the order — highlighting and section order are handled for you. You will be told which section to describe, one at a time. When told, describe ONLY that section in 3-4 sentences and then stop; never announce another section, never ask whether to continue. ***`},"fwh-list-forms-mvp":async()=>{let e=e_(),t=t_();$(`fwh-list-forms-mvp ✓`,`${e.length} field(s)`,`${t.length} button(s)`);let n=e.map(e=>({...e,inputCategory:e.tag===`SELECT`?`dropdown_select`:`text_input`}));return JSON.stringify({fields:n,buttons:t,hint:`field_key: use the label/placeholder/name shown above. CRITICAL: fields with inputCategory='dropdown_select' are SELECT elements — their field_key must match the SELECT's own label (e.g. 'Company Size'), NOT the option text (e.g. 'Small Business') and NOT a nearby text input label. Never fill a SELECT option value into a text input.`})},"fwh-fill-form-mvp":async()=>`FORM_FILLING_DISABLED: Form filling is not available at this time. Tell the visitor what fields are present (use fwh-list-forms-mvp) and ask them to fill the form themselves.`,"fwh-click-button-mvp":async e=>{let t=o_(e),n=(t.button_text??t.buttonText??t.text??``).trim(),r=(t.card_context??t.cardContext??``).trim();if($(`fwh-click-button-mvp ▶`,n,r?`(card_context: ${r})`:``),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;let i=a_(n,a,r);if(!i)return $(`fwh-click-button-mvp ✖ no match`),`Could not find a button matching "${n}". Call fwh-list-forms-mvp to see button texts.`;try{Eh(`Clicking ${n}...`,{spinner:!0});try{i.scrollIntoView({block:`center`,inline:`nearest`})}catch{i.scrollIntoView(!0)}await Uh(i),i.focus?.(),await Gh(i),Kh(i),i.click();let e=(i.textContent||i.value||i.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`,t=`OK_CLICK ${e}`;return $(`fwh-click-button-mvp ✓`,t),Eh(`Clicked ${e}`,{spinner:!1,icon:`✅`,duration:1200}),t}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`fwh-click-button-mvp ✖`,t),Eh(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{Wh(),Dh(700)}},"fwh-cart-get-mvp":async()=>{$(`fwh-cart-get-mvp ▶`);try{let e=await Kr();if(!e)return`CART_UNAVAILABLE: this page is not a Shopify storefront, so there is no cart to read.`;let t=e.items.map((e,t)=>{let n=e.variantTitle&&e.variantTitle!==`Default Title`?` (${e.variantTitle})`:``;return`${t+1}. ${e.title}${n} — qty ${e.quantity} — ${e.linePrice}${e.handle?` — handle: ${e.handle}`:``}`}),n=`CART. Items: ${e.itemCount} | Subtotal: ${e.subtotal}${e.currency?` ${e.currency}`:``}${t.length?` | ${t.join(` | `)}`:` | (cart is empty)`}`;return $(`fwh-cart-get-mvp ✓`,n),n}catch(e){return $(`fwh-cart-get-mvp ✖`,e),`CART_ERROR: ${e?.userMessage||e?.message||`could not read the cart`}`}},"fwh-shop-search-mvp":async e=>{let t=String((e||{}).query||``).trim();if($(`fwh-shop-search-mvp ▶`,t),!t)return`Missing query: pass the product name or keyword to search.`;try{let e=await $r(t);if(!e.length)return`NO_PRODUCTS_FOUND for "${t}". Tell the visitor no matching product was found — do not invent products.`;let n=e.map(e=>`"${e.title}" — handle: ${e.handle}${e.price?` — price: ${e.price}`:``}`).join(` | `);return $(`fwh-shop-search-mvp ✓`,n),`PRODUCTS_FOUND: ${n}. Use the handle with fwh-cart-add-mvp or fwh-view-product-mvp.`}catch(e){return $(`fwh-shop-search-mvp ✖`,e),`SEARCH_ERROR: ${e?.message||`product search failed`}`}},"fwh-cart-add-mvp":async e=>{let t=e||{},n=String(t.product_handle||t.productHandle||``).trim().toLowerCase(),r=String(t.variant||``).trim()||null,i=Math.min(20,Math.max(1,parseInt(t.quantity,10)||1));if($(`fwh-cart-add-mvp ▶`,{handle:n,variantText:r,quantity:i}),!n)return`Missing product_handle: search the product first with fwh-shop-search-mvp.`;try{let{variant:e,product:t}=await qr(n,r);await Jr(e.id,i);let a=await Ur(),o=await s(a),c=e.title&&e.title!==`Default Title`?` (${e.title})`:``,l=`ADDED ${i} × ${t.title}${c}. Cart now has ${a.item_count} item(s), subtotal ${Gr(a.items_subtotal_price)}${a.currency?` ${a.currency}`:``}.${o}`;return $(`fwh-cart-add-mvp ✓`,l),l}catch(e){return $(`fwh-cart-add-mvp ✖`,e),`ADD_FAILED: ${e?.userMessage||e?.message||`could not add the item`}. Relay this reason to the visitor.`}},"fwh-cart-update-mvp":async e=>{let t=e||{},n=parseInt(t.line,10),r=Math.min(20,Math.max(0,parseInt(t.quantity,10)));if($(`fwh-cart-update-mvp ▶`,{line:n,quantity:r}),!Number.isFinite(n)||n<1)return`Missing/invalid line: call fwh-cart-get-mvp first and use the item's 1-based number.`;if(!Number.isFinite(r))return`Missing/invalid quantity.`;try{let e=await Ur(),t=e.items?.[n-1];if(!t)return`NO_SUCH_LINE: the cart has ${e.items?.length||0} item(s). Call fwh-cart-get-mvp for the current list.`;let i=await Yr(n,r),a=await s(i),o=`UPDATED ${t.product_title||t.title} to qty ${r}. Cart now has ${i.item_count} item(s), subtotal ${Gr(i.items_subtotal_price)}${i.currency?` ${i.currency}`:``}.${a}`;return $(`fwh-cart-update-mvp ✓`,o),o}catch(e){return $(`fwh-cart-update-mvp ✖`,e),`UPDATE_FAILED: ${e?.userMessage||e?.message||`could not update the item`}`}},"fwh-cart-remove-mvp":async e=>{let t=parseInt((e||{}).line,10);if($(`fwh-cart-remove-mvp ▶`,{line:t}),!Number.isFinite(t)||t<1)return`Missing/invalid line: call fwh-cart-get-mvp first and use the item's 1-based number.`;try{let e=await Ur(),n=e.items?.[t-1];if(!n)return`NO_SUCH_LINE: the cart has ${e.items?.length||0} item(s). Call fwh-cart-get-mvp for the current list.`;let r=await Yr(t,0),i=await s(r),a=`REMOVED ${n.product_title||n.title}. Cart now has ${r.item_count} item(s), subtotal ${Gr(r.items_subtotal_price)}${r.currency?` ${r.currency}`:``}.${i}`;return $(`fwh-cart-remove-mvp ✓`,a),a}catch(e){return $(`fwh-cart-remove-mvp ✖`,e),`REMOVE_FAILED: ${e?.userMessage||e?.message||`could not remove the item`}`}},"fwh-cart-open-mvp":async()=>($(`fwh-cart-open-mvp ▶`),c(Xr(),`Cart`)),"fwh-checkout-mvp":async()=>{$(`fwh-checkout-mvp ▶`);try{if(!(await Ur()).item_count)return`CART_EMPTY: do not go to checkout. Tell the visitor their cart is empty and offer to help find products.`}catch{}return c(Zr(),`Checkout`)},"fwh-view-product-mvp":async e=>{let t=e||{},n=String(t.product_handle||t.productHandle||``).trim().toLowerCase();return $(`fwh-view-product-mvp ▶`,{handle:n}),n?c(Qr(n),n.replace(/[-_]/g,` `)):`Missing product_handle: search the product first with fwh-shop-search-mvp.`}};async function s(e){try{let{sectionsSwapped:t}=await si(e);if(!t&&ei())return` NOTE: the cart list on this page could not be re-rendered — briefly tell the visitor the page may need a quick refresh to show the change.`}catch{}return``}function c(e,n){if(typeof window>`u`)return`NAV_FAILED: no browser context.`;let r=e;try{r=new URL(e,window.location.href).href}catch{}return t&&Le(t,window.location.href,r,n),Tr(r),Mr().then(()=>{window.location.assign(r)}),`OK_NAVIGATING to ${n}. The page is loading — say one short phrase like "Here you go." and nothing more.`}return{...o,highlightOnPage:o[`fwh-highlight-mvp`],getPageContent:o[`fwh-page-content-mvp`],endVoiceSession:o[`fwh-end-session-mvp`],listPageForms:o[`fwh-list-forms-mvp`],fillFormFields:o[`fwh-fill-form-mvp`],clickPageButton:o[`fwh-click-button-mvp`]}}var f_=/^(get in touch|contact us|let'?s (talk|connect)|subscribe|newsletter|follow us|quick links|company|solutions|what we do|resources|legal|sitemap|share this)/i;function p_(){try{let{headings:e,pageTitleHeading:t,containerHeadings:n}=l_(),r=new Set((n||[]).map(e=>e.trim())),i=(e||[]).map(e=>typeof e==`string`?e:e?.text||``).filter(Boolean).filter(e=>!t||e.trim()!==t.trim()).filter(e=>!f_.test(e.trim())),a=i.filter(e=>!r.has(e.trim()));return a.length?a:i}catch{return[]}}function m_(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=Mn();r?console.log(`[FlowEngage:voice-tool] ▶`,e,n):console.info(`[FlowEngage] voice tool » ${e}`);let i;try{i=await t(n)}catch(t){let n=`Tool error: ${t?.message||String(t)}`;return console.error(`[FlowEngage] voice tool ${e} threw:`,t),n}let a=typeof i==`string`?i.length>220?`${i.slice(0,220)}…`:i:String(i);return r?console.log(`[FlowEngage:voice-tool] ◀`,e,a):console.info(`[FlowEngage] voice tool « ${e}:`,a),i}]))}var h_=`[PAGE_CONTEXT]`;function g_(e,t,n){return`${h_} SESSION_CONTEXT (NOT a tool result — do NOT treat as CURRENT_PAGE): Visitor is on: ${e} | Approx headings for awareness only: ${t||``}. ${n?`Forms: ${n}. `:``}The visitor is ALREADY on this page — do NOT offer to navigate there.`}var __={blue:`#135bd8`,red:`#ef334b`,yellow:`#ffbd2e`,dark:`#0d1b2a`,highlight:`rgba(255,255,255,0.9)`,green:`#10b981`};function v_(e){if(!Array.isArray(e)||e.length<2)return`linear-gradient(145deg, #dce8f022 0%, #e8dff522 45%, #f5e0e022 100%), #f7f8fa`;let[t,n,r]=e;return e.length>=3&&r?[`radial-gradient(ellipse 80% 70% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 70% 80% at 110% 30%, ${n}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 60% at 50% 110%, ${r}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `):[`radial-gradient(ellipse 80% 100% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 100% at 110% 50%, ${n}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `)}function y_(e){if(!e||typeof e!=`string`)return`#1a1a1a`;let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t,r=parseInt(n.slice(0,2),16)/255,i=parseInt(n.slice(2,4),16)/255,a=parseInt(n.slice(4,6),16)/255,o=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4;return .2126*o(r)+.7152*o(i)+.0722*o(a)>.179?`#1a1a1a`:`#ffffff`}function b_(e){let[t,n]=b.useState(null),r=typeof e==`string`?e.trim():``;return b.useEffect(()=>{if(!r){n(null);return}n(null);let e=!1,t=new window.Image;return t.onload=()=>{e||n(r)},t.onerror=()=>{e||n(null)},t.src=r,()=>{e=!0}},[r]),t}function x_({logo:e,style:t}){let n=b_(typeof e==`string`?e:null);if(!e)return null;if(typeof e==`string`)return n?(0,V.jsx)(`img`,{src:n,alt:``,style:{objectFit:`contain`,flexShrink:0,display:`block`,...t}}):null;let r=typeof e==`function`?b.createElement(e):b.isValidElement(e)?e:null;return r?(0,V.jsx)(`span`,{className:`fe-logo-slot`,style:{display:`inline-flex`,alignItems:`center`,flexShrink:0,overflow:`hidden`,...t},children:r}):null}function S_({title:e}){return(0,V.jsx)(`div`,{style:{width:`100%`,height:`100%`,borderRadius:`16px`,background:`linear-gradient(135deg, rgba(59,130,246,0.16) 0%, rgba(59,130,246,0.08) 100%)`,color:`#2563eb`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`18px`,fontWeight:700,letterSpacing:`-0.03em`},children:String(e||`FE`).split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0]?.toUpperCase()||``).join(``)||`FE`})}function C_(e,t){let n=(t||``).trim();return n?!!(/\b(let'?s|let us)\s+(end|stop|finish|wrap up|close)\s+(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\bend\s+(this\s+)?(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\b(hang\s+up|disconnect)\b/i.test(n)||e===`bot`&&(/\b(that'?s all|we'?re done)\b/i.test(n)||/\b(goodbye|bye)\b/i.test(n)||/\b(I'?ll|I will|Let me|I can|I'?m going to)\s+(end|close)\s+(the\s+)?(voice\s+)?(session|call)\b/i.test(n)||/\b(ending|closing)\s+(the\s+)?(voice\s+)?session\b|\bvoice\s+session\s+(is\s+)?(now\s+)?(ended|over|closing)\b/i.test(n)||/\b(session|call)\s+(is\s+)?(now\s+)?(ended|over)\b/i.test(n)||/\bwe\s+can\s+end\s+(the\s+)?(session|call)?\s*(here|now)\b/i.test(n)||/\b(wrapping\s+up|signing\s+off)\b/i.test(n))):!1}function w_({orbColors:e,...t}){return(0,V.jsx)(Ig,{colors:e,...t})}function T_({copy:e,orbColors:t,primaryColor:n,onYes:r,onLater:i,isMobile:a,isClosing:o}){let s=n||__.green,c=y_(s),l=a?72:94,u=(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:a?`flex-end`:`center`,gap:a?`7px`:`9px`},children:[(0,V.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,V.jsx)(Qm.p,{initial:{x:-16,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.36},style:{margin:`0 0 14px`,fontSize:`14px`,fontWeight:700,color:`white`,lineHeight:1.4,textShadow:`0 1px 4px rgba(0,0,0,0.35)`,maxWidth:`210px`,wordBreak:`break-word`,overflow:`hidden`,display:`-webkit-box`,WebkitLineClamp:4,WebkitBoxOrient:`vertical`},children:e.entryPrompt}),(0,V.jsxs)(Qm.div,{initial:{y:10,opacity:0},animate:{y:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.54},style:{display:`flex`,gap:`16px`,flexWrap:`nowrap`},children:[(0,V.jsx)(`button`,{onClick:r,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:s,color:c,fontWeight:400,fontSize:`14px`,border:`none`,cursor:`pointer`,whiteSpace:`nowrap`,boxShadow:`0 4px 16px ${s}66`,transition:`transform 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.04)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.yesLabel}),(0,V.jsx)(`button`,{onClick:i,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:`transparent`,color:`white`,fontWeight:400,fontSize:`14px`,border:`2px solid rgba(255,255,255,0.55)`,cursor:`pointer`,whiteSpace:`nowrap`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.9)`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.55)`},children:e.laterLabel})]})]}),(0,V.jsx)(Qm.div,{initial:{x:120,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:220,damping:22,delay:0},style:{flexShrink:0},children:(0,V.jsx)(w_,{size:l,orbColors:t})})]});return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Qm.div,{initial:{opacity:0},animate:{opacity:o?0:1},transition:{duration:.28},style:{position:`fixed`,inset:0,background:`rgba(0,0,0,0.72)`,zIndex:-1}}),a?(0,V.jsx)(`div`,{style:{position:`absolute`,bottom:0,left:0,right:0,padding:`24px 20px 40px`,overflow:`hidden`,animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u}):(0,V.jsx)(`div`,{style:{animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u})]})}function E_({copy:e,orbColors:t,primaryColor:n,onVoice:r,onText:i,onClose:a,isMobile:o,isClosing:s}){let c=n||__.green,l=y_(c);return(0,V.jsxs)(Qm.div,{initial:{scale:50/350,borderRadius:`50%`},animate:s?{scale:50/350,opacity:0,borderRadius:`50%`}:{scale:1,borderRadius:`16px`,opacity:1},transition:{type:`spring`,stiffness:260,damping:26},style:{transformOrigin:o?`bottom center`:`bottom right`,background:`white`,width:o?`100%`:`350px`,height:`245px`,padding:`24px 40px 32px`,boxSizing:`border-box`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`space-between`,boxShadow:`0 20px 60px rgba(0,0,0,0.2)`,position:`relative`,overflow:`hidden`},children:[(0,V.jsx)(`button`,{onClick:a,style:{position:`absolute`,top:`14px`,right:`14px`,background:`none`,border:`none`,cursor:`pointer`,color:`#9ca3af`,padding:`4px`,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#374151`},onMouseLeave:e=>{e.currentTarget.style.color=`#9ca3af`},children:(0,V.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}),(0,V.jsx)(w_,{size:72,orbColors:t}),(0,V.jsxs)(`div`,{style:{textAlign:`center`},children:[(0,V.jsx)(`p`,{style:{margin:0,fontSize:`16px`,fontWeight:400,color:`#111827`,lineHeight:1.4},children:e.connectionTitle}),e.connectionSubtitle&&(0,V.jsx)(`p`,{style:{margin:`6px 0 0`,fontSize:`13px`,fontWeight:400,color:`#6b7280`,lineHeight:1.4},children:e.connectionSubtitle})]}),(0,V.jsxs)(`div`,{style:{display:`flex`,gap:`16px`,width:`100%`},children:[(0,V.jsx)(`button`,{onClick:r,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:c,color:l,fontWeight:400,fontSize:`16px`,border:`none`,cursor:`pointer`,transition:`transform 0.15s ease`,boxShadow:`0 4px 12px ${c}55`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.03)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.voiceLabel}),(0,V.jsx)(`button`,{onClick:i,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:`transparent`,color:`#111827`,fontWeight:400,fontSize:`16px`,border:`1.5px solid #d1d5db`,cursor:`pointer`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`#6b7280`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`#d1d5db`},children:e.textLabel})]})]})}function D_({orbColors:e,onEnterChat:t,onEndChat:n,agentId:r,siteId:i,apiBaseUrl:a,chatId:o,historyRef:s,onMessageSync:c,beaconSyncVoiceTranscript:l,widgetPosition:u=`bottom-right`,voiceEndCounter:d,websiteName:f,voiceFirstMessage:p,captureVisitorEmail:m,emailRequired:h,emailCaptureEnabled:g=!0,listeningLabel:_=`Listening...`,thinkingLabel:v=`Thinking...`,enterChatModeLabel:y=`Enter Chat Mode`,endConversationLabel:x=`End Conversation`}){(0,b.useEffect)(()=>(console.log(`[FlowEngage:VoiceDebug] 🔵 VoiceMode MOUNTED`),()=>console.log(`[FlowEngage:VoiceDebug] 🔴 VoiceMode UNMOUNTED`)),[]);let[S,C]=(0,b.useState)(`idle`),[w,T]=(0,b.useState)(!1),[E,ee]=(0,b.useState)(!1),[D,te]=(0,b.useState)(()=>le(i)===`auto`),O=()=>{let e=D?`ask`:`auto`;ue(i,e),te(e===`auto`)},[ne,re]=(0,b.useState)(!1),[ie,ae]=(0,b.useState)(``),[oe,k]=(0,b.useState)(``),A=(0,b.useRef)(!1),se=(0,b.useRef)(!1),ce=(0,b.useRef)(null),de=(0,b.useRef)(0),j=(0,b.useRef)(``),fe=(0,b.useRef)(!1),pe=(0,b.useRef)(0),me=(0,b.useRef)(!1),he=(0,b.useRef)(!1),ge=(0,b.useRef)(!1),_e=(0,b.useRef)([]),ve=(0,b.useRef)(null),ye=(0,b.useRef)(``),M=(0,b.useRef)(null),be=e=>{me.current=e,e||(he.current=!1),N.current?.setWalkthroughActive?.(e)};M.current=async()=>{if(he.current)return;let e=typeof window<`u`?window.location.pathname:null;if(e&&ve.current&&e!==ve.current){console.log(`[FlowEngage] walkthrough ended — visitor left `+ve.current),ve.current=null,_e.current=[],be(!1);return}let t=_e.current;xe.current+=1;let n=xe.current,r=t[n];if(!r){if(be(!1),t.length)N.current?.sendUserMessage?.(`That was the last section. Say so in one short sentence and ask if they want to explore any section further.`);else if(n===0){let e=``;try{let t=await Se.current?.[`fwh-read-content-mvp`]?.({});typeof t==`string`&&t&&!/^Could not/i.test(t)&&(e=t.slice(0,2800))}catch{}N.current?.sendUserMessage?.(e?`Give the visitor a complete spoken overview of this page in 4-6 sentences, based ONLY on this page content:\n"""${e}"""\nThen ask which part they'd like to hear more about. Do not call any tool.`:`Give the visitor a complete spoken overview of this page in 4-6 sentences based on what you know about it, then ask which part they'd like to hear more about. Do not call any tool.`,{suppressQuestion:!0})}return}try{await Se.current?.highlightOnPage?.({section_text:r})}catch(e){console.warn(`[FlowEngage] walkthrough highlight failed:`,e?.message||e)}console.debug(`[FlowEngage] walkthrough step ${n+1}/${t.length}: ${r}`);let i=``;try{let e=await Se.current?.[`fwh-read-content-mvp`]?.({section_text:r});typeof e==`string`&&e&&!/^Could not/i.test(e)&&(i=e.slice(0,2500))}catch{}let a=i?`Here is this section's full content — describe it from THIS text only, and do not call any tool:\n"""${i}"""\n`:`read the section's content silently first (fwh-read-content-mvp) if you don't already have it. `;N.current?.sendUserMessage?.(`Describe the section titled "${r}" in 3-4 sentences, starting with ${n===0?`Starting with`:`Next —`} ${r}. Describe ONLY this section. If this section contains named sub-items (steps, checklist entries, cards, plans, FAQs, team members), name EVERY one of them in order with a short phrase each — never skip or collapse them into a summary; `+a+`This section is ON THE PAGE THE VISITOR IS ALREADY ON — do NOT call fwh-navigate-mvp, do not go to a product/detail page, and do not offer to, even if this section's name also matches a page name. Do not mention any other section, do not ask whether to continue, then stop.`,{suppressQuestion:!0})};let xe=(0,b.useRef)(0),N=(0,b.useRef)(null),Se=(0,b.useRef)(null),Ce=(0,b.useRef)(``),we=(0,b.useRef)(async()=>{}),Te=(0,b.useRef)(!1),ke=(0,b.useRef)(!1),je=(0,b.useRef)(!1),Me=(0,b.useRef)(!1),Ne=(0,b.useRef)(`minimized`),Pe=(0,b.useRef)(null),Ie=(0,b.useRef)(null),Le=(0,b.useRef)(null),ze=(0,b.useRef)(0),P=(0,b.useRef)(!1),Be=(0,b.useRef)(`idle`),Ve=(0,b.useRef)(null),He=(0,b.useRef)(!1),Ue=(0,b.useRef)(null),We=(0,b.useCallback)((e=`minimized`)=>{console.warn(`[FlowEngage:VoiceDebug] 🛑 requestSessionShutdown called`,{destination:e,stack:Error().stack?.split(`
|
|
426
|
-
`).slice(1,4).join(` | `)}),Ne.current=e,Me.current=!0,queueMicrotask(()=>{Te.current||(Te.current=!0,we.current?.())})},[s]),Ge=(0,b.useCallback)(()=>{ce.current&&=(clearTimeout(ce.current),null)},[]);(0,b.useEffect)(()=>{if(h){A.current=!1;return}if(A.current=!0,se.current=!1,re(!1),Ge(),fe.current){fe.current=!1,N.current?.setMicMuted?.(!1);let e=j.current;j.current=``,N.current?.injectAgentSpeech?.(`Thanks — I already have your email on file.`,`interrupt`),e&&N.current?.sendUserMessage?.(`The visitor's email is already on file — do not ask for it. Answer their question now: "${e}"`)}N.current?.sendContextualUpdate?.(`EMAIL REQUIREMENT SATISFIED — the visitor's email is already on file. All earlier instructions about requiring or asking for an email are VOID. Never ask for it again.`)},[h,Ge]);let Ke=/(walk\s*(me\s*)?through|walkthrough|take me through|(complete|full|detailed) (overview|understanding|walkthrough|picture|breakdown|explanation)|give me (a|an|the) (overview|tour|walk)|tell me about (each|all)|go through (it|them|each|all)|overview of|one by one|tell me everything|explain (me )?(this|the) (whole |entire |full )?page|everything (about|on) this page|show me (each|all|around))/i,qe=/(that covers everything|that was all|covered everything|that(?:'|’)?s everything)/i,Je=/^((uh+|um+|so|well|okay|ok|yeah)[,.\s]+)*(yes|yeah|yep|yup|sure|ok(ay)?|please|continue|go on|next|keep going|carry on|go ahead|resume|back to the tour)[\s.!,]*$/i,Ye=/(would you like (me )?to take you|shall i take you|want me to take you|would you like to (go|explore|visit|see)|take you there)/i,Xe=/^((uh+|um+|oh|ah|so|well)[,.\s]+)*(cool|nice|great|awesome|wow|lovely|perfect|got it|gotcha|i see|understood|makes sense|interesting|right|alright|sounds good|mm+-?hmm+|hmm+|k)[\s.!,]*$/i,Ze=e=>String(e||``).replace(/[\s.,!?]*((uh+|um+|er+|hmm+|mm+)[\s.,!?]*)+$/i,``).trim(),Qe=(0,b.useCallback)(()=>{Ge(),ce.current=setTimeout(()=>{if(!(!se.current||A.current))if(de.current<3){de.current+=1;try{N.current?.injectAgentSpeech?.(`I still need your email in the box below to continue — could you enter it, please?`,`queue`)}catch{}Qe()}else{try{N.current?.injectAgentSpeech?.(`Since I haven't received your email, I'll close this session for now. Feel free to come back anytime — take care!`,`queue`)}catch{}se.current=!1,re(!1),Ge(),P.current=!0}},1e4)},[Ge]),$e=(0,b.useCallback)(async e=>{Me.current=!0;try{In()}catch{}try{Nh()}catch{}if(i)try{Re(i)}catch{}try{await N.current?.endSession?.()}catch{}let t=Pe.current,n=Ie.current;if(t&&o&&a){let e=n?Math.round((Date.now()-n)/1e3):0;fetch(`${a}/api/voice/save-chat-recording`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({chatId:o,voiceSessionId:t,duration:e,siteId:i})}).catch(e=>console.warn(`[FlowEngage] save-chat-recording failed:`,e.message))}if(Pe.current=null,Ie.current=null,N.current=null,C(`idle`),T(!1),Te.current=!1,Lr(),i)try{Oe(i)}catch{}typeof c==`function`&&await c(s.current),e?.()},[s,c,i,o,a]);we.current=()=>$e(Ne.current===`chat`?t:n),(0,b.useEffect)(()=>{ke.current=w},[w]),(0,b.useEffect)(()=>{d&&We(`chat`)},[d]),(0,b.useEffect)(()=>{let e=!1,d=null,m=null,_=null;return(async()=>{if(!i){C(`error`);return}try{if((await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),e)return;s.current=[],Ce.current=``,Te.current=!1,je.current=!1,Me.current=!1,Ne.current=`minimized`,Ir({onBeforeNavigate:()=>{if(i&&s.current.length>0)try{let e=Gg(s.current);e&&Ee(i,e)}catch{}if(!nr()){let e=Pe.current,t=Ie.current;if(e&&o&&a)try{let n=t?Math.round((Date.now()-t)/1e3):0,r=JSON.stringify({chatId:o,voiceSessionId:e,duration:n,siteId:i}),s=`${a}/api/voice/save-chat-recording`;fetch(s,{method:`POST`,headers:{"Content-Type":`application/json`},body:r,keepalive:!0}).catch(()=>{}),Pe.current=null,Ie.current=null}catch{}}Ae()}});let t=m_(d_({siteId:i||null,apiBaseUrl:a||null,chatId:o||null,getLastUserVoiceText:()=>Ce.current,beaconSyncFullVoiceHistory:()=>l?.(s.current),isWalkthroughActive:()=>me.current&&!he.current,requestEndSession:()=>{P.current=!0},requestEmailCollection:()=>{g&&(A.current||se.current||(se.current=!0,de.current=0,re(!0),Qe()))}})),n=i?De(i):null,r=!!n?.transcript,c=i?Re(i):null,v=!!c,y=typeof window<`u`?window.location.pathname:`/`,b=typeof document<`u`?document.title:``,x=y.replace(/^\/[a-z]{2}(?:-[a-z]{2})?(?=\/|$)/i,``)||`/`,S=x===`/`||x===``,w={apiBaseUrl:a,siteId:i,chatId:o,clientTools:t};Se.current=t;let E=(y.split(`/`).filter(Boolean).pop()||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),ee=``;b&&b.includes(`|`)&&(ee=b.split(`|`).map(e=>e.trim()).filter(Boolean).reduce((e,t)=>e.length<=t.length?e:t));let D=ee||E||``,te=D?`the ${D} page`:`this page`,O=(()=>{if(!c?.targetUrl)return!0;try{return new URL(c.targetUrl,window.location.href).pathname.replace(/\/$/,``)===window.location.pathname.replace(/\/$/,``)}catch{return!0}})(),ne=(()=>{if(!c?.targetUrl)return null;try{return new URL(c.targetUrl,window.location.href).pathname}catch{return null}})();if(v&&!O)w.greeting=`You're on ${te}. What would you like to know?`,console.warn(`[FlowEngage] nav target "${c?.pageName}" not reached — on "${D}" instead; not claiming navigation`);else if(v){let e=c?.pageName?`the ${c.pageName} page`:te;w.greeting=`I have navigated you to ${e}. Do you want to know about any specific section or want a complete overview?`,console.log(`[FlowEngage] 🔄 Agent-nav resume: greeting set for "${e}" (${y})`)}else if(r)w.greeting=`Welcome back! I see you're now on ${te}. Would you like me to continue what I was explaining before, or would you like to know about this page instead?`;else{let e=f||``;w.greeting=p||(S?e?`Hi, welcome to ${e}! How may I help you?`:`Hi, welcome! How may I help you?`:`Welcome to ${te}! How may I help you?`),S||console.log(`[FlowEngage] 🏠 Page-context greeting: "${D}" for ${y}`)}let ie=!1,ae=v?`NAVIGATION COMPLETE — The exact phrase "I have navigated you to the [page] page. Do you want to know about any specific section or want a complete overview?" has already been spoken as your firstMessage. DO NOT repeat it. PRIOR CONVERSATION CONTEXT:\n${n?.transcript?`Prior transcript:\n${n.transcript}\n`:`(no prior transcript)`}\nNow STOP — wait silently for the visitor's reply. Do NOT speak, do NOT call any tool until the visitor responds. When they reply: if they name a specific section → call fwh-get-current-page-mvp then answer immediately; if they say "overview" or anything non-specific → call fwh-get-current-page-mvp (zero speech) then do a full highlighted walkthrough.`:null,oe=!1,k=!v&&!r?`Your greeting has been spoken. Wait for the visitor to ask a question or tell you what they need. Do NOT auto-start a walkthrough or highlight any sections — let the visitor lead.`:null,ce=r&&!v,ue=!1,we=ce?`The question "Would you like me to continue what I was explaining before, or would you like to know about this page instead?" has already been spoken as your firstMessage. DO NOT repeat it. PRIOR CONVERSATION CONTEXT:\n${n?.transcript?`Prior transcript:\n${n.transcript}\n`:`(no prior transcript, or the visitor navigated before saying much)`}\nNow STOP — wait silently for the visitor's reply. Do NOT speak, do NOT call any tool until they respond. When they reply: if they want you to CONTINUE the previous topic → resume verbally from the prior transcript above, do NOT call fwh-get-current-page-mvp or describe the new page unless they ask. If they want to know about THIS page → call fwh-get-current-page-mvp (zero speech) then proceed as a normal fresh-page walkthrough/description. If their reply is ambiguous, ask them to clarify which they'd prefer rather than guessing.`:null,Oe=!1,Le=!1,$e=g&&!!h&&!ge.current,F=await xh.startSession({...w,onConnect:({conversationId:e})=>{Pe.current=e,Ie.current=Date.now(),console.log(`[FlowEngage] 🎙️ AI chat session connected:`,e)},onUnhandledClientToolCall:e=>console.error(`[FlowEngage] Unhandled tool:`,e?.tool_name),onSessionInfo:({emailOnFile:e})=>{ge.current=!!e,e&&(A.current=!0,se.current=!1,re(!1),Ge(),console.log(`[FlowEngage] email already on file per server — gate disabled`))},onAgentTurnEnd:()=>{e||me.current&&(he.current||fe.current||setTimeout(()=>M.current?.(),250))},onSessionEnding:()=>{e||We(`minimized`)},onPanel:({title:t,items:n})=>{e||Mh(n,{title:t||`Products`,side:u===`bottom-left`?`left`:`right`,productUrl:e=>e.handle?`${window.location.origin}/products/${encodeURIComponent(e.handle)}`:null})},onModeChange:({mode:t,tentative:n})=>{if(!e){if(t===`speaking`){Ve.current&&=(clearTimeout(Ve.current),null),Ue.current&&=(clearTimeout(Ue.current),null),C(`speaking`),Be.current=`speaking`,He.current=!1;return}if(t===`user-speaking`){if(se.current&&!A.current&&Qe(),Ue.current&&=(clearTimeout(Ue.current),null),Be.current===`speaking`)return;try{In()}catch{}Ve.current&&=(clearTimeout(Ve.current),null),Be.current!==`listening`&&(C(`listening`),Be.current=`listening`);return}if(t===`thinking`){if(Ve.current&&=(clearTimeout(Ve.current),null),Ue.current&&=(clearTimeout(Ue.current),null),Be.current===`speaking`)return;C(`thinking`),Be.current=`thinking`,n&&(Ue.current=setTimeout(()=>{Ue.current=null,!(e||Be.current!==`thinking`)&&(Be.current=`listening`,C(`listening`))},4e3));return}if(Be.current=`listening`,P.current){P.current=!1,We();return}if($e&&!Le&&!A.current&&!ge.current){Le=!0,ie=!0,oe=!0;try{N.current?.sendContextualUpdate?.(`CRITICAL — EMAIL REQUIRED BEFORE ANYTHING ELSE. The visitor has not provided their email. The app itself speaks the email request out loud — you must NOT say it, and you must NOT answer. Stay completely silent from now until you receive an EMAIL_SAVED message: produce no speech and call no tools, no matter what the visitor says. Remember their question. On EMAIL_SAVED, thank them briefly and answer that remembered question in full.`)}catch{}}if(ae&&!ie){ie=!0;try{N.current?.sendContextualUpdate?.(ae)}catch{}}if(we&&!ue){ue=!0;try{N.current?.sendContextualUpdate?.(we)}catch{}}if(k&&!oe){oe=!0;try{N.current?.sendContextualUpdate?.(k)}catch{}}Ve.current&&clearTimeout(Ve.current),Ve.current=setTimeout(()=>{e||Be.current!==`speaking`&&(He.current||(Ve.current=null,Be.current=`listening`,C(`listening`)))},1200)}},onMessage:t=>{if(e||fe.current&&t.role!==`user`&&!/email/i.test(String(t.message||``)))return;let n=t.role===`user`&&/^(Describe the section titled "|\[SYSTEM:|Give the visitor a complete spoken overview|That was the last section)/.test(String(t.message||``).trim()),r=/\b(?:this|that|the)\s+(?:case\s*stud(?:y|ies)|product|article|blog|post|item|service)\b/i.test(String(t.message||``));if(!n&&!r&&t.role===`user`&&Ke.test(String(t.message||``)))typeof window<`u`&&(window.__fe_user_nav_during_speech=null),be(!0),he.current=!1,pe.current=0,xe.current=-1,_e.current=p_(),ve.current=typeof window<`u`?window.location.pathname:null,setTimeout(()=>M.current?.(),400),console.log(`[FlowEngage] walkthrough armed — ${_e.current.length} sections on this page`);else if(!n&&t.role===`user`&&me.current){let e=String(t.message||``).trim(),n=Ze(e),r=e=>!!e&&(Je.test(e)||Xe.test(e));Ye.test(ye.current||``)?(console.log(`[FlowEngage] walkthrough ended — visitor accepted a navigation offer`),ve.current=null,_e.current=[],be(!1)):!n||r(e)||r(n)?he.current&&(he.current=!1,console.debug(`[FlowEngage] walkthrough resumed by visitor`),setTimeout(()=>M.current?.(),300)):(console.log(`[FlowEngage] walkthrough ended — visitor moved to a new topic`),ve.current=null,_e.current=[],be(!1))}if(t.role!==`user`&&!n&&(ye.current=String(t.message||``)),t.role!==`user`&&qe.test(String(t.message||``))){let e=_e.current.length;!e||xe.current>=e-1?be(!1):console.debug(`[FlowEngage] agent claimed completion at step ${xe.current+1}/${e} — ignoring, tour continues`)}let a=t.role===`user`?`user`:`bot`,o=t.message||t.text||t.content||``;if(o){if(a===`user`&&(Ce.current=o,typeof window<`u`&&(window.__fe_user_nav_during_speech=null),He.current=!0,Ve.current&&=(clearTimeout(Ve.current),null),Be.current!==`speaking`&&(C(`thinking`),Be.current=`thinking`),$e&&!Oe&&!A.current&&!ge.current&&(Oe=!0,j.current=o,fe.current=!0,N.current?.injectAgentSpeech?.(`Before I answer that, could you please enter your email in the text box below?`,`interrupt`),N.current?.setMicMuted?.(!0),se.current||(se.current=!0,de.current=0,re(!0),Qe()))),s.current=[...s.current,{sender:a,message:o,timestamp:new Date().toISOString(),debug:t.debug}],i)try{let e=Gg(s.current);e&&Ee(i,e)}catch{}if(C_(a,o)){P.current=!0;return}if(ke.current&&a===`bot`&&/are you still there|still there\??|hello\?|anyone there|checking in|you there|are you available|is anyone|did you step away/i.test(o))if(ze.current+=1,ze.current===2)try{N.current?.sendContextualUpdate?.(`IMPORTANT: The visitor is muted and has not responded to your last 2 checks. Make exactly ONE more check. If there is still no response, say: 'I feel like you are not active, so I'm ending this session. You can connect with me anytime.' then immediately call the fwh-end-session-mvp tool to end the voice session. Do NOT ask again after that.`)}catch{}else ze.current>=5&&We(`minimized`)}},onError:t=>{if(!e&&!Me.current&&!je.current&&!Fe()){je.current=!0,console.error(`[FlowEngageVoiceCall] session:error`,{message:t?.message,name:t?.name,raw:t});try{N.current?.setMicMuted?.(!0)}catch{}T(!0),C(`error`),We(`chat`)}},onDisconnect:t=>{if(e||Me.current||je.current||Fe())return;let n=s.current?.length||0;console.warn(`[FlowEngageVoiceCall] session:disconnected`,{historyCount:n,reason:t?.reason,closeCode:t?.context?.code,closeReason:t?.context?.reason||t?.message,lastUserText:Ce.current||``,wasMuted:ke.current}),je.current=!0;try{N.current?.setMicMuted?.(!0)}catch{}T(!0),We(`chat`)}});if(e){console.warn(`[FlowEngage:VoiceDebug] ❌ cancelled=true after startSession resolved — killing session immediately`),F.endSession().catch(()=>{});return}d=F,N.current=F,C(`listening`);try{sessionStorage.setItem(`el_conv_${i}`,F.getId())}catch{}parent.postMessage({type:`AGENT_EXPAND`},`*`);try{let e=typeof window<`u`?window.location.href:``,a=`[]`;try{a=await t[`fwh-list-forms-mvp`]()}catch{}let o=`none`;if(typeof window<`u`&&typeof document<`u`)try{let e=`#flowengage-root, .flowengage-shell, .flowengage-widget-root`,t=document.querySelector(`main, [role='main']`)||document.body,n=Array.from(t.querySelectorAll(`h1, h2, h3`)).filter(t=>!t.closest(e)).map(e=>e.textContent.replace(/\s+/g,` `).trim()).filter(e=>e.length>2&&e.length<200);n.length||(n=Array.from(document.body.querySelectorAll(`h1, h2, h3`)).filter(t=>!t.closest(e)).map(e=>e.textContent.replace(/\s+/g,` `).trim()).filter(e=>e.length>2&&e.length<200)),n.length&&(o=[...new Set(n)].slice(0,15).join(` | `))}catch{}let s=r&&!v?`RESUMING PRIOR SESSION — DO NOT GREET. The visitor is continuing the same conversation after a page reload. Do not introduce yourself or re-state your capabilities. Wait silently until the visitor speaks; if you must speak first, briefly acknowledge where you left off in one short sentence.\nPrior transcript:\n${n?.transcript||``}\n\n`:``;F.sendContextualUpdate(`${s}SiteId: ${i||`unknown`}. ${h?``:`Visitor's email is already on file from a prior session — do NOT ask for it again. `}WALKTHROUGH RULE: When the visitor asks for a walkthrough or overview of this page, you MUST IMMEDIATELY call fwh-get-current-page-mvp (zero speech — call it silently with NO words before it) to get the exact highlightable headings. Do NOT skip fwh-get-current-page-mvp. Voice: call end_voice_session or say you are ending the session to stop.`),F.sendContextualUpdate(g_(e,o,a))}catch{}if(typeof window<`u`){let t=window.location.pathname,n=Date.now(),r=e=>{try{return(decodeURIComponent(e||`/`).replace(/\/+$/,``)||`/`).toLowerCase()}catch{return((e||`/`).replace(/\/+$/,``)||`/`).toLowerCase()}},a=()=>{if(e)return;let a=window.location.pathname;if(r(a)===r(t)){t=a;return}if(Date.now()-n<8e3){t=a;return}let o=typeof window<`u`&&window.__fe_agent_nav||null,s=ne&&r(a)===r(ne)||Jn()||o&&Date.now()-o.ts<15e3&&r(o.path)===r(a),c=t;t=a;let l=window.location.href,u=typeof document<`u`?document.title:``,d=typeof document<`u`?Array.from(document.querySelectorAll(`h1, h2, h3, h4`)).filter(e=>!e.closest(`#flowengage-root, .flowengage-shell`)).map(e=>({tag:e.tagName,text:e.textContent.trim()})).filter(e=>e.text.length>0&&e.text.length<200).slice(0,20):[];try{In()}catch{}let f=d.map(e=>e.text).join(` | `),p=e=>(e.split(`/`).filter(Boolean).pop()||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())||`Home`,m=p(c),h=p(a);if(s){if(typeof window<`u`&&(window.__fe_agent_nav=null),console.log(`[FlowEngage] agent-driven navigation settled: "${c}" → "${a}"`),le(i)!==`auto`)try{N.current?.sendUserMessage?.(`[SYSTEM: YOU just navigated the visitor to the "${h}" page (${l}) at their request — this was YOUR action, not theirs. Page title: "${u}". Sections: ${JSON.stringify(d)}. Say: "Here we are on the ${h} page." Then introduce this page in 2-3 sentences, and finish by asking: "Would you like me to walk you through it section by section?" NEVER say "I see you've navigated" — the visitor did not navigate, you did. Do NOT call fwh-navigate-mvp again. Wait for their answer before describing sections.]`,{suppressQuestion:!0})}catch{}else console.log(`[FlowEngage] auto-nav — skipping the arrival acknowledgment turn`);try{N.current?.sendContextualUpdate?.(g_(l,f))}catch{}return}typeof window<`u`&&(window.__fe_user_nav_during_speech={fromPath:c,toPath:a,fromPageName:m,toPageName:h,ts:Date.now()}),console.log(`[FlowEngage] visitor navigation detected: "${c}" → "${a}" (agent target: ${ne||`none`})`);try{N.current?.sendUserMessage?.(`[SYSTEM: I navigated away mid-walkthrough — I am now on the "${h}" page (${l}). Page title: "${u}". Sections: ${JSON.stringify(d)}. STOP everything. Do NOT describe the new page. Say EXACTLY: "I see you've navigated to the ${h} page — would you like me to continue what I was explaining, or shall I walk you through this page?" Then wait for my answer. IF I say continue/yes/carry on: resume speaking verbally from where you left off — do NOT call fwh-navigate-mvp, do NOT call fwh-highlight-mvp, the visitor will navigate themselves if needed. IF I want to hear about this page: call fwh-highlight-mvp for sections of "${h}" only.]`)}catch{}try{N.current?.sendContextualUpdate?.(g_(l,f))}catch{}};m=window.history.pushState.bind(window.history),window.history.pushState=(...e)=>{m(...e),setTimeout(a,50)},_=()=>setTimeout(a,50),window.addEventListener(`popstate`,_)}}catch(r){e||(console.error(`[FlowEngage] startSession failed`,r),r.message&&r.message.includes(`Too many voice sessions`)?(alert(r.message),n&&n(`minimized`)):(C(`error`),Ne.current=`chat`,window.setTimeout(()=>{e||t?.()},0)))}})(),()=>{console.warn(`[FlowEngage:VoiceDebug] ⚠️ useEffect CLEANUP fired — session will be killed`,{agentId:r,siteId:i,apiBaseUrl:a}),e=!0,Me.current=!0;try{In()}catch{}if(i)try{Re(i)}catch{}typeof window<`u`&&(window.__fe_user_nav_during_speech=null),Lr(),Ve.current&&=(clearTimeout(Ve.current),null),Ue.current&&=(clearTimeout(Ue.current),null),ce.current&&=(clearTimeout(ce.current),null),He.current=!1,Be.current=`idle`,m&&typeof window<`u`&&(window.history.pushState=m),_&&typeof window<`u`&&window.removeEventListener(`popstate`,_);let t=d||N.current,n=Pe.current,l=Ie.current;if(t?.endSession?.().catch(()=>{}),n&&o&&a){let e=l?Math.round((Date.now()-l)/1e3):0,t=JSON.stringify({chatId:o,voiceSessionId:n,duration:e,siteId:i}),r=`${a}/api/voice/save-chat-recording`;typeof navigator<`u`&&navigator.sendBeacon&&navigator.sendBeacon(r,new Blob([t],{type:`application/json`}))||fetch(r,{method:`POST`,headers:{"Content-Type":`application/json`},body:t,keepalive:!0}).catch(()=>{}),Pe.current=null,Ie.current=null}typeof c==`function`&&s.current.length>0&&c(s.current).catch?.(()=>{})}},[r,i,a,We]),(0,b.useEffect)(()=>{if(!E)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;Le.current&&!Le.current.contains(t)&&ee(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[E]);let F=async()=>{if(N.current)try{if(w){ze.current=0,await N.current.setMicMuted?.(!1),T(!1);try{N.current.sendContextualUpdate?.(`The visitor has unmuted. Resume normal interaction and wait for them to speak.`)}catch{}}else{ze.current=0,await N.current.setMicMuted?.(!0),T(!0);try{N.current.sendContextualUpdate?.(`The visitor has muted their microphone. Do NOT speak, ask if they are there, or prompt them in any way. Stay completely silent until they unmute.`)}catch{}}}catch{}},I=(0,b.useCallback)(async e=>{e?.preventDefault?.();let t=ie.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)){k(`Please enter a valid email address.`);return}k(``),A.current=!0,se.current=!1,Ge(),re(!1),ae(``),fe.current=!1;try{typeof m==`function`&&await m(t)}catch{}N.current?.setMicMuted?.(!1);let n=j.current;j.current=``;try{N.current?.injectAgentSpeech?.(`Thank you for submitting your email.`),N.current?.sendUserMessage?.(n||`The visitor's email is on file. Carry on helping them and never ask for it again.`)}catch{}},[ie,m,Ge]),L=Array.isArray(e)&&e[0]||`#3B82F6`;return(0,V.jsxs)(`div`,{ref:Le,style:{position:`relative`,display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`14px`,animation:`fe-orb-slide-up 0.42s cubic-bezier(0.16,1,0.3,1)`},children:[ne&&(0,V.jsxs)(`form`,{onSubmit:I,style:{width:`270px`,maxWidth:`calc(100vw - 40px)`,boxSizing:`border-box`,background:`rgba(15,22,36,0.97)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,padding:`16px`,display:`flex`,flexDirection:`column`,gap:`10px`,animation:`fe-orb-fade-in 0.18s ease`},children:[(0,V.jsx)(`span`,{style:{color:`white`,fontSize:`13px`,fontWeight:600,lineHeight:1.4},children:`Please enter your email to continue`}),(0,V.jsx)(`input`,{type:`email`,inputMode:`email`,autoComplete:`email`,autoFocus:!0,value:ie,onChange:e=>{ae(e.target.value),oe&&k(``)},placeholder:`you@example.com`,style:{width:`100%`,boxSizing:`border-box`,padding:`10px 12px`,borderRadius:`10px`,border:oe?`1.5px solid #ef4444`:`1.5px solid #4b5563`,background:`#1f2937`,color:`white`,fontSize:`14px`,outline:`none`}}),oe&&(0,V.jsx)(`span`,{style:{color:`#f87171`,fontSize:`12px`},children:oe}),(0,V.jsx)(`button`,{type:`submit`,disabled:!ie.trim(),style:{width:`100%`,padding:`10px 12px`,borderRadius:`10px`,border:`none`,background:ie.trim()?L:`#374151`,color:`white`,fontSize:`14px`,fontWeight:600,cursor:ie.trim()?`pointer`:`default`,transition:`background 0.2s ease`},children:`Submit`})]}),(0,V.jsxs)(`div`,{style:{position:`relative`},children:[(S===`listening`||S===`thinking`)&&!w&&(0,V.jsx)(`span`,{style:{position:`absolute`,right:`100%`,marginRight:`18px`,top:`50%`,transform:`translateY(-50%)`,color:`white`,fontSize:`18px`,fontWeight:600,letterSpacing:`0.01em`,textShadow:`0 2px 4px rgba(0,0,0,0.4)`,whiteSpace:`nowrap`},children:S===`thinking`?v:_}),w&&(0,V.jsx)(`span`,{style:{position:`absolute`,right:`100%`,marginRight:`18px`,top:`50%`,transform:`translateY(-50%)`,color:`#f87171`,fontSize:`16px`,fontWeight:600,letterSpacing:`0.01em`,textShadow:`0 2px 4px rgba(0,0,0,0.4)`,whiteSpace:`nowrap`},children:`Muted`}),(0,V.jsx)(w_,{size:72,voiceState:S,isMuted:w,orbColors:e})]}),S===`error`&&(0,V.jsx)(`span`,{style:{color:`#f87171`,fontSize:`13px`,fontWeight:500},children:`Could not start voice session.`}),(0,V.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,alignItems:`center`},children:[(0,V.jsx)(`button`,{onClick:F,title:w?`Unmute`:`Mute`,style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:w?`#7f1d1d`:`#1f2937`,border:w?`1.5px solid #ef4444`:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:w?`#f87171`:`white`,transition:`all 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:w?(0,V.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`line`,{x1:`1`,y1:`1`,x2:`23`,y2:`23`}),(0,V.jsx)(`path`,{d:`M9 9v3a3 3 0 005.12 2.12M15 9.34V4a3 3 0 00-5.94-.6`}),(0,V.jsx)(`path`,{d:`M17 16.95A7 7 0 015 12v-2m14 0v2a7 7 0 01-.11 1.23`}),(0,V.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`23`}),(0,V.jsx)(`line`,{x1:`8`,y1:`23`,x2:`16`,y2:`23`})]}):(0,V.jsx)(Jh,{size:16,color:`currentColor`})}),(0,V.jsx)(`button`,{onClick:()=>ee(e=>!e),style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:`#1f2937`,border:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`,transition:`background 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:(0,V.jsx)(ng,{size:16,color:`currentColor`})})]}),E&&(0,V.jsxs)(`div`,{style:{position:`absolute`,bottom:0,right:0,width:`230px`,zIndex:9999,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,animation:`fe-orb-fade-in 0.18s ease`,padding:`12px 12px 40px`},children:[(0,V.jsxs)(`button`,{onClick:()=>{ee(!1),Ne.current=`chat`,$e(t)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsx)(rg,{}),y]}),i&&(0,V.jsxs)(`button`,{onClick:()=>O(),style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`8px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,minWidth:0,overflow:`hidden`},children:[(0,V.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:(0,V.jsx)(`polygon`,{points:`3 11 22 2 13 21 11 13 3 11`})}),(0,V.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:`Auto-navigate`})]}),(0,V.jsx)(`span`,{"aria-hidden":!0,style:{width:`34px`,height:`19px`,borderRadius:`999px`,background:D?`#22c55e`:`rgba(255,255,255,0.2)`,position:`relative`,flexShrink:0,transition:`background 0.15s ease`},children:(0,V.jsx)(`span`,{style:{position:`absolute`,top:`2px`,left:D?`17px`:`2px`,width:`15px`,height:`15px`,borderRadius:`50%`,background:`white`,transition:`left 0.15s ease`}})})]}),(0,V.jsxs)(`button`,{onClick:()=>{ee(!1),Ne.current=`minimized`,$e(n)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`#E30C12`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(227,12,18,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsx)(ig,{}),x]}),(0,V.jsx)(`button`,{onClick:()=>ee(!1),style:{position:`absolute`,bottom:`8px`,right:`8px`,width:`24px`,height:`24px`,borderRadius:`50%`,background:`rgba(255,255,255,0.15)`,border:`none`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.25)`},onMouseLeave:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.15)`},children:(0,V.jsxs)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,V.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]})]})}function O_({orbColors:e}){let t=Array.isArray(e)&&e.length>0?e:[`#135bd8`,`#ef334b`,`#ffbd2e`],n=t[0],r=t[1]||t[0],i=t[2]||t[0];return(0,V.jsx)(`div`,{style:{width:`32px`,height:`32px`,borderRadius:`50%`,flexShrink:0,background:`
|
|
427
|
+
`).trim()}function h_(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=typeof e.beaconSyncFullVoiceHistory==`function`?e.beaconSyncFullVoiceHistory:null,a=[],o={"fwh-navigate-mvp":async n=>{if($(`fwh-navigate-mvp ▶ raw parameters:`,n),e?.isWalkthroughActive?.())return $(`fwh-navigate-mvp ✖ blocked — walkthrough in progress`),`NAVIGATION_BLOCKED_DURING_WALKTHROUGH. A walkthrough of the current page is in progress, so navigation is not allowed. Do NOT tell the visitor you navigated or offer to. Describe the requested section using the CURRENT page's own content (fwh-read-content-mvp), then stop.`;let a=u_(n),o=d_(a),s=a.section_text??a.sectionText??a.section,c=Array.isArray(a.expected_landmarks)?a.expected_landmarks:Array.isArray(a.expectedLandmarks)?a.expectedLandmarks:[];if($(`fwh-navigate-mvp · coerced:`,{url:o,sectionText:s,expectedLandmarks:c}),!o){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`fwh-navigate-mvp ✖`,e),e}if(typeof window<`u`)try{let e=new URL(o,window.location.href);if(e.hostname===window.location.hostname&&e.origin!==window.location.origin)o=e.pathname+e.search+e.hash,$(`fwh-navigate-mvp · cross-protocol same-host URL normalized →`,o);else if(e.origin!==window.location.origin&&/^https?:$/i.test(e.protocol)){let t=e.hostname;return $(`fwh-navigate-mvp ✖ external URL blocked:`,e.href),`EXTERNAL_LINK_BLOCKED: The URL "${o}" points to an external site (${t}) that opens in a new tab. I cannot open new tabs or navigate to external sites. Tell the visitor exactly this: "That link opens an external app — I'm not able to open it for you, but you can click the link directly in the navigation header."`}}catch{}if(typeof window<`u`){try{let e=new URL(o,window.location.href);if(e.pathname===window.location.pathname&&e.search===window.location.search)return $(`fwh-navigate-mvp ✖ already on page, skipping`),`OK_ALREADY_ON_PAGE. The visitor is already on this page. Do not navigate. Proceed directly with highlights, answering the question, or reading page content.`}catch{}let e=window.__fe_user_nav_during_speech;if(e&&Date.now()-e.ts<3e4)try{if(new URL(o,window.location.href).pathname===e.fromPath)return $(`flowengage_navigate ✖ blocked — would navigate back to page visitor just left`,e),`NAV_BLOCKED: The visitor just left "${e.fromPageName}" and is now on "${e.toPageName}". Do NOT navigate them back. If they said "continue", resume verbally from where you left off — no navigation needed. If they want to return, they will navigate themselves.`}catch{}}let{allowed:l,correctedUrl:u}=await Sr(o,{siteId:t,apiBaseUrl:e.apiBaseUrl});if(!l){let e=`PAGE_NOT_IN_SITE: "${o}" is NOT a real page on this site — do NOT guess or invent URL paths. Do NOT tell the visitor you are taking them there. Instead, find the REAL page: look at your Popular Pages / Site Pages list for the closest actual match, or call fwh-list-nav-links-mvp (to read the site's real menu links) or fwh-search-mvp (to find the right page). If a close match exists (e.g. the visitor said "support" and the site has "Technical Support"), tell them the ACTUAL page name and ask "we don't have a page called that, but we do have [real page] — would you like me to take you there?" Then navigate only to that verified URL.`;return $(`fwh-navigate-mvp ✖ blocked`,e),e}u&&u!==o&&($(`fwh-navigate-mvp · corrected url:`,{requested:o,correctedUrl:u}),o=u);try{Eh(`Navigating to ${o}...`,{spinner:!0}),Vh(),In();try{i?.()}catch{}try{let e=r?r():``;if(e&&t){let n=Yg([{sender:`user`,message:e}]);n&&Ee(t,n)}}catch{}Ae();let e=o;try{e=new URL(o,typeof window<`u`?window.location.href:``).href}catch{}let n=`this`;try{let e=new URL(o,window.location.href).pathname.split(`/`).filter(Boolean).pop()||``;n=e?e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()):`Home`}catch{}t&&typeof window<`u`&&Le(t,window.location.href,e,n),Tr(e);try{window.__fe_agent_nav={path:new URL(e,window.location.href).pathname,ts:Date.now()}}catch{}$(`fwh-navigate-mvp → real navigation`,o);let a=typeof window<`u`&&!window.Shopify&&!!nr();if(typeof window<`u`&&window.__fe_triggerVoiceNavHooks&&window.__fe_triggerVoiceNavHooks(),a&&qn(12e3),Nr(o,{voiceActive:!0}).catch(()=>{}),a)try{let e=new URL(o,window.location.origin).pathname,t=window.location.pathname,n=Date.now()+2e3;for(;Date.now()<n&&!(typeof window<`u`&&window.location.pathname===e);)await new Promise(e=>setTimeout(e,80));let r=typeof window<`u`?window.location.pathname:e,i=typeof window<`u`?window.location.href:o;(r.split(`/`).filter(Boolean).pop()||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),$(`fwh-navigate-mvp → SPA nav complete. target:`,e,`actual:`,r);try{typeof window<`u`&&window.scrollTo(0,0)}catch{}let a=[],s=null,c=``,l=Date.now()+12e3;for(;Date.now()<l&&(await new Promise(e=>setTimeout(e,300)),{headings:a,pageTitleHeading:s,introText:c}=p_(),!(a.length>=1)););f_(),$(`fwh-navigate-mvp → page headings collected:`,a,`titleHeading:`,s);let u=a.length?a.join(` | `):`none`,d=a.length?`Use ONLY these exact heading strings for fwh-highlight-mvp — never invent or abbreviate.`:`No headings collected yet — call fwh-get-current-page-mvp immediately (no speech) to get the live headings before speaking or highlighting.`,f=s?` "${s}" is the PAGE TITLE, not a content section — do not fwh-highlight-mvp it separately; if doing a walkthrough, just fold this intro into your opening line: "${c||`(no intro text found)`}"`:c?` No separate page-title heading detected, but this intro text precedes the first section — mention it briefly before covering sections: "${c}"`:``,p=``;try{if(a.length>0){let e=a.slice(0,3),t=[];for(let n of e){let e=_r(null,n);if(e){let r=m_(e).substring(0,800);r&&t.push(`[Section: ${n}] ${r}`)}}t.length>0&&(p=` CONTENT FOR FIRST FEW SECTIONS: ${t.join(` | `)}. Use this content to answer immediately if the visitor asks about one of these sections.`)}}catch{}if(Or())return Er(),$(`fwh-navigate-mvp ✖ landed on a not-found/404 page:`,i),`NAVIGATION_PAGE_NOT_FOUND. The page at ${i} does not exist — it shows a "not found"/404 error, not real content. Do NOT offer a page overview, do NOT describe or highlight any sections, do NOT claim the navigation succeeded. Tell the visitor EXACTLY: "It looks like that page doesn't exist — I couldn't find it. Would you like me to take you somewhere else?" Then STOP and wait for their reply.`;let m=Date.now()+4e3,h=typeof window<`u`?window.location.pathname:r;for(;Date.now()<m&&!Qg(h,e)&&Qg(h,t);)await new Promise(e=>setTimeout(e,120)),h=window.location.pathname;$(`fwh-navigate-mvp route settle:`,{startPath:t,targetPath:e,settledPath:h});let g=typeof window<`u`?window.location.href:i,_=(h.split(`/`).filter(Boolean).pop()||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())||`Home`,v=Qg(h,e),y=!Qg(h,t),b=v||y;return $(`fwh-navigate-mvp settled:`,h,`target:`,e,`match:`,b),b?(Er(),`OK_NAVIGATE_SPA. Visitor is now on: ${g} (page: "${_}") | Section headings: ${u}.${f} ${d}${p} Now confirm the arrival in ONE short sentence phrased for what the visitor actually asked for — mention the page by name and what it lets them do (e.g. for a contact request: "I've taken you to the Contact Us page — filling in this form sends your query straight to our team."). Do NOT use a fixed template. Then, in the same breath, offer either a specific section or a full overview. Then STOP — wait for their reply.`):(Er(),`NAVIGATION_DID_NOT_HAPPEN. The visitor is STILL on ${g} (page: "${_}") — the navigation did not go through. Do NOT say "I have navigated you". Do NOT claim success. Tell the visitor EXACTLY: "Sorry, I couldn't open that page just now. Would you like me to try again, or is there something else I can help with?" Then STOP and wait for their reply.`)}catch{}return`OK_NAVIGATE_RELOADING. The page is reloading now and this session is ending. Say NOTHING further — do not confirm the navigation, do not describe the page. The arrival greeting is spoken automatically on the new page; you resume from the visitor's next reply.`}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`fwh-navigate-mvp ✖`,t),Eh(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{Hh(),Dh(900)}},"fwh-highlight-mvp":async e=>{$(`fwh-highlight-mvp ▶`,e);let t=u_(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText;if(qn(3e3),typeof window<`u`&&window.__fe_user_nav_during_speech){let e=window.__fe_user_nav_during_speech,t=window.location.pathname;if(Date.now()-e.ts>=3e4)window.__fe_user_nav_during_speech=null;else return $(`flowengage_highlight ✖ blocked — user navigated during speech`,e),`NAV_CHANGED: The visitor navigated from "${e.fromPageName}" to "${e.toPageName}" (current path: ${t}) while you were speaking. STOP the current walkthrough immediately. DO NOT call fwh-highlight-mvp again. Say out loud: "I see you've navigated to the ${e.toPageName} page — do you want me to continue what I was explaining, or shall I guide you through this page?" Wait for the visitor's answer before doing anything else.`}f_();let i=(e=>e&&e.replace(/^\d+\.\s*/,``).replace(/^["']|["']$/g,``).trim())(r),a=_r(n||null,i||null);if(!a&&i){let e=Date.now()+600;for(;!a&&Date.now()<e;)await new Promise(e=>setTimeout(e,50)),f_(),a=_r(null,i)}if(!a){$(`fwh-highlight-mvp ✖ no element for:`,i||n);let{headings:e}=p_(),t=e.length?`Page headings: ${e.map(e=>`"${e}"`).join(` | `)}. Use one of these EXACT strings for section_text — no numbers, no quotes around them.`:`No headings found — skip highlight and continue speaking.`;return`HIGHLIGHT_NOT_FOUND: "${i||n}" on the current page. ${t}`}return Fn(a),$(`fwh-highlight-mvp ✓`,i||n),`OK_HIGHLIGHT: "${i||n}". Your NEXT response must be speech only (no tool call) describing THIS section — "${i||n}" — using its own content. Do not ask whether to continue.`},"fwh-read-content-mvp":async e=>{$(`fwh-read-content-mvp ▶`,e);let t=u_(e),n=t?.section_text||t?.sectionText||``;try{let e=``;if(n){let t=_r(null,n);if(!t)return`Could not find section "${n}" on the page.`;e=m_(t)}else{let t=(document.querySelector(`main`)||document.querySelector(`article`)||document.querySelector(`[role="main"]`)||document.querySelector(`#content`)||document.querySelector(`.content`)||document.body).cloneNode(!0);t.querySelectorAll(`nav, footer, header, aside, script, style, noscript, .nav, .footer, .header, .sidebar, #flowengage-root, .flowengage-shell, .flowengage-widget-root`).forEach(e=>e.remove()),e=t.textContent.replace(/\s+/g,` `).trim()}return e.length>8e3&&(e=e.substring(0,8e3)+`... (truncated)`),$(`fwh-read-content-mvp ✓`,`${e.length} chars`),e||`No readable content found on this page.`}catch(e){return $(`fwh-read-content-mvp ✖`,e.message),`Could not read page content: ${e.message}`}},"fwh-page-content-mvp":async e=>{$(`fwh-page-content-mvp ▶`,e);let r=u_(e),i=r?.url||r?.page_url||``;if($(`fwh-page-content-mvp · url:`,i,`siteId:`,t,`apiBase:`,n||`(empty)`),!i)return $(`fwh-page-content-mvp ✖ missing url`),`Missing url parameter.`;if(!t)return $(`fwh-page-content-mvp ✖ no siteId`),`Site is not configured.`;if(!n)return $(`fwh-page-content-mvp ✖ no api base`),`API base URL is missing; cannot fetch page content.`;try{let e=`${n}/api/site-tools/page-content`;$(`fwh-page-content-mvp → POST`,e);let r=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,url:i})}),a=await r.json();if($(`fwh-page-content-mvp · HTTP`,r.status,`success:`,a.success),!a.success){let e=a.error||`Failed to get page content.`;return $(`fwh-page-content-mvp ✖`,e),`${e} FALLBACK REQUIRED: This page is not in the search index. Call fwh-read-content-mvp (no parameters) immediately to read the live page content directly from the visitor's browser — do NOT tell the visitor you cannot access the page.`}return $(`fwh-page-content-mvp ✓`,`title: ${a.title}`,`sections: ${(a.sections||[]).length}`,`content: ${(a.content||``).length} chars`),JSON.stringify({title:a.title,url:a.url,sections:a.sections,content:a.content})}catch(e){let t=`Page content error: ${e.message||`network`}`;return $(`fwh-page-content-mvp ✖`,t),t}},"fwh-search-mvp":async e=>{$(`fwh-search-mvp ▶`,e);let r=u_(e).query;if(!r)return $(`fwh-search-mvp ✖ missing query`),`Missing query parameter.`;if(!t)return $(`fwh-search-mvp ✖ no siteId`),`Search unavailable (no siteId configured).`;if(!n)return $(`fwh-search-mvp ✖ no api base`),`Search unavailable (no API base URL).`;try{let e=`${n}/api/site-tools/search`;$(`fwh-search-mvp → POST`,e);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,query:r,currentUrl:typeof window<`u`?window.location.href:``})}),a=await i.json();if($(`fwh-search-mvp · HTTP`,i.status,`success:`,a.success),!a.success||!a.results?.length)return`No results found for that query. Try rephrasing, or use fwh-read-content-mvp to read the current page.`;let o=a.results.slice(0,5).map((e,t)=>`${t+1}. ${e.title||e.url} (${e.url})${e.snippet?` — ${e.snippet}`:``}`).join(`
|
|
428
|
+
`);return $(`fwh-search-mvp ✓`,`${a.results.length} result(s)`),`SEARCH_RESULTS:\n${o}`}catch(e){return $(`fwh-search-mvp ✖`,e.message),`Search failed. Use fwh-read-content-mvp to read the current page instead.`}},"fwh-list-nav-links-mvp":async()=>{if($(`fwh-list-nav-links-mvp ▶`),typeof window>`u`)return`Cannot read navigation (no browser context).`;let e=new Map,t=[],n=[`nav a`,`[role='navigation'] a`,`header a`,`.navbar a`,`.nav a`,`.menu a`,`.navigation a`,`.header a`,`[class*='nav'] a`,`[class*='menu'] a`,`[class*='header'] a`];if(e_(t=>{for(let r of n)try{t.querySelectorAll(r).forEach(t=>{if(Rn(t))return;let n=t.getAttribute(`href`),r=(t.textContent||``).replace(/\s+/g,` `).trim();if(!r||!n||n===`#`||n.startsWith(`javascript:`))return;try{let e=t.parentElement;if(e&&$g(e).display===`none`&&!e.closest(`nav, [role='navigation'], header, [class*='nav'], [class*='menu']`))return}catch{}let i=r.toLowerCase()+`|`+n;e.has(i)||e.set(i,{text:r,href:n})})}catch{}t.querySelectorAll(`select`).forEach(t=>{if(Rn(t))return;let n=n_(t);/nav|menu|page|section|go to/i.test(n||t.name||t.id||``)&&Array.from(t.options).forEach(r=>{if(!r.value||r.disabled)return;let i=r.text.trim();if(!i)return;let a=i.toLowerCase()+`|`+r.value;e.has(a)||e.set(a,{text:i,href:r.value,isSelectOption:!0,selectLabel:n||t.name||`dropdown`})})})}),e.forEach(e=>t.push(e)),!t.length)return`NAV_LINKS: No navigation links found on this page. Use fwh-read-content-mvp to read page content or fwh-search-mvp to search the site.`;let r=t.slice(0,50).map((e,t)=>`${t+1}. "${e.text}"${e.isSelectOption?` (dropdown option in "${e.selectLabel}")`:``} → ${e.href}`).join(`
|
|
429
|
+
`);return $(`fwh-list-nav-links-mvp ✓`,`${t.length} links`),`NAV_LINKS (${t.length} total, showing up to 50):\n${r}\n\nIMPORTANT: Use the EXACT text shown above when reading link names to the visitor. Do NOT rename, abbreviate, or invent options not listed here. To navigate, call fwh-navigate-mvp with the href value.`},"fwh-end-session-mvp":async()=>($(`fwh-end-session-mvp ▶`),typeof e.requestEndSession==`function`&&e.requestEndSession(),`Voice session is ending.`),"fwh-request-email-mvp":async()=>($(`fwh-request-email-mvp ▶`),typeof e.requestEmailCollection==`function`&&e.requestEmailCollection(),`EMAIL_BOX_SHOWN. An email input text box is now visible to the visitor. Say EXACTLY: "Please enter your email in the text box to continue." Then stop and wait silently — do NOT ask them to say it aloud, do NOT repeat, and do NOT answer any other question until you receive the EMAIL_SAVED message.`),"fwh-get-current-page-mvp":async()=>{if($(`fwh-get-current-page-mvp ▶`),typeof window>`u`)return`Cannot determine current page (no browser context).`;let e=window.location.href,t=window.location.pathname,n=document.title||``;if(Or())return $(`fwh-get-current-page-mvp ✓ 404 detected`,{url:e}),`CURRENT_PAGE_NOT_FOUND. The visitor is currently on a 404 / page-not-found error page (${e}). There is no real content here. Do NOT describe this page, do NOT list sections, do NOT offer a walkthrough, and do NOT describe it from your own knowledge. Tell the visitor plainly that the page they are on doesn't exist, and offer to take them somewhere that does.`;let{headings:r,pageTitleHeading:i,introText:a}=p_();$(`fwh-get-current-page-mvp ✓`,{url:e,path:t,title:n}),$(`fwh-get-current-page-mvp → page headings collected:`,r,`titleHeading:`,i);let o=i?` NOTE: "${i}" is the PAGE TITLE, not a content section — do NOT fwh-highlight-mvp it or list it as a separate section in a walkthrough. Instead, open with a brief 1-2 sentence summary of this intro text before covering the real sections: "${a||`(no intro text captured)`}"`:a?` NOTE: no separate page-title heading was detected, but this intro text appears before the first section — open your walkthrough with a brief 1-2 sentence summary of it before covering sections: "${a}"`:``;if(!r.length)return`CURRENT_PAGE. URL: ${e} | Title: ${n} |${o} No structured section headings found on this page. If there is intro text above, describe it; otherwise describe the page from your knowledge. Do not call this tool again.`;let s=r.map(e=>`"${e}"`).join(` | `);return`CURRENT_PAGE. URL: ${e} | Title: ${n} | Page sections (${r.length} total): ${s}.${o} *** WALKTHROUGH: do NOT drive it yourself. Do not call fwh-highlight-mvp and do not decide the order — highlighting and section order are handled for you. You will be told which section to describe, one at a time. When told, describe ONLY that section in 3-4 sentences and then stop; never announce another section, never ask whether to continue. ***`},"fwh-list-forms-mvp":async()=>{let e=i_(),t=a_();$(`fwh-list-forms-mvp ✓`,`${e.length} field(s)`,`${t.length} button(s)`);let n=e.map(e=>({...e,inputCategory:e.tag===`SELECT`?`dropdown_select`:`text_input`}));return JSON.stringify({fields:n,buttons:t,hint:`field_key: use the label/placeholder/name shown above. CRITICAL: fields with inputCategory='dropdown_select' are SELECT elements — their field_key must match the SELECT's own label (e.g. 'Company Size'), NOT the option text (e.g. 'Small Business') and NOT a nearby text input label. Never fill a SELECT option value into a text input.`})},"fwh-fill-form-mvp":async()=>`FORM_FILLING_DISABLED: Form filling is not available at this time. Tell the visitor what fields are present (use fwh-list-forms-mvp) and ask them to fill the form themselves.`,"fwh-click-button-mvp":async e=>{let t=u_(e),n=(t.button_text??t.buttonText??t.text??``).trim(),r=(t.card_context??t.cardContext??``).trim();if($(`fwh-click-button-mvp ▶`,n,r?`(card_context: ${r})`:``),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;let i=l_(n,a,r);if(!i)return $(`fwh-click-button-mvp ✖ no match`),`Could not find a button matching "${n}". Call fwh-list-forms-mvp to see button texts.`;try{Eh(`Clicking ${n}...`,{spinner:!0});try{i.scrollIntoView({block:`center`,inline:`nearest`})}catch{i.scrollIntoView(!0)}await qh(i),i.focus?.(),await Yh(i),Xh(i),i.click();let e=(i.textContent||i.value||i.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`,t=`OK_CLICK ${e}`;return $(`fwh-click-button-mvp ✓`,t),Eh(`Clicked ${e}`,{spinner:!1,icon:`✅`,duration:1200}),t}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`fwh-click-button-mvp ✖`,t),Eh(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{Jh(),Dh(700)}},"fwh-cart-get-mvp":async()=>{$(`fwh-cart-get-mvp ▶`);try{let e=await Kr();if(!e)return`CART_UNAVAILABLE: this page is not a Shopify storefront, so there is no cart to read.`;let t=e.items.map((e,t)=>{let n=e.variantTitle&&e.variantTitle!==`Default Title`?` (${e.variantTitle})`:``;return`${t+1}. ${e.title}${n} — qty ${e.quantity} — ${e.linePrice}${e.handle?` — handle: ${e.handle}`:``}`}),n=`CART. Items: ${e.itemCount} | Subtotal: ${e.subtotal}${e.currency?` ${e.currency}`:``}${t.length?` | ${t.join(` | `)}`:` | (cart is empty)`}`;return $(`fwh-cart-get-mvp ✓`,n),n}catch(e){return $(`fwh-cart-get-mvp ✖`,e),`CART_ERROR: ${e?.userMessage||e?.message||`could not read the cart`}`}},"fwh-shop-search-mvp":async e=>{let t=String((e||{}).query||``).trim();if($(`fwh-shop-search-mvp ▶`,t),!t)return`Missing query: pass the product name or keyword to search.`;try{let e=await $r(t);if(!e.length)return`NO_PRODUCTS_FOUND for "${t}". Tell the visitor no matching product was found — do not invent products.`;let n=e.map(e=>`"${e.title}" — handle: ${e.handle}${e.price?` — price: ${e.price}`:``}`).join(` | `);return $(`fwh-shop-search-mvp ✓`,n),`PRODUCTS_FOUND: ${n}. Use the handle with fwh-cart-add-mvp or fwh-view-product-mvp.`}catch(e){return $(`fwh-shop-search-mvp ✖`,e),`SEARCH_ERROR: ${e?.message||`product search failed`}`}},"fwh-cart-add-mvp":async e=>{let t=e||{},n=String(t.product_handle||t.productHandle||``).trim().toLowerCase(),r=String(t.variant||``).trim()||null,i=Math.min(20,Math.max(1,parseInt(t.quantity,10)||1));if($(`fwh-cart-add-mvp ▶`,{handle:n,variantText:r,quantity:i}),!n)return`Missing product_handle: search the product first with fwh-shop-search-mvp.`;try{let{variant:e,product:t}=await qr(n,r);await Jr(e.id,i);let a=await Ur(),o=await s(a),c=e.title&&e.title!==`Default Title`?` (${e.title})`:``,l=`ADDED ${i} × ${t.title}${c}. Cart now has ${a.item_count} item(s), subtotal ${Gr(a.items_subtotal_price)}${a.currency?` ${a.currency}`:``}.${o}`;return $(`fwh-cart-add-mvp ✓`,l),l}catch(e){return $(`fwh-cart-add-mvp ✖`,e),`ADD_FAILED: ${e?.userMessage||e?.message||`could not add the item`}. Relay this reason to the visitor.`}},"fwh-cart-update-mvp":async e=>{let t=e||{},n=parseInt(t.line,10),r=Math.min(20,Math.max(0,parseInt(t.quantity,10)));if($(`fwh-cart-update-mvp ▶`,{line:n,quantity:r}),!Number.isFinite(n)||n<1)return`Missing/invalid line: call fwh-cart-get-mvp first and use the item's 1-based number.`;if(!Number.isFinite(r))return`Missing/invalid quantity.`;try{let e=await Ur(),t=e.items?.[n-1];if(!t)return`NO_SUCH_LINE: the cart has ${e.items?.length||0} item(s). Call fwh-cart-get-mvp for the current list.`;let i=await Yr(n,r),a=await s(i),o=`UPDATED ${t.product_title||t.title} to qty ${r}. Cart now has ${i.item_count} item(s), subtotal ${Gr(i.items_subtotal_price)}${i.currency?` ${i.currency}`:``}.${a}`;return $(`fwh-cart-update-mvp ✓`,o),o}catch(e){return $(`fwh-cart-update-mvp ✖`,e),`UPDATE_FAILED: ${e?.userMessage||e?.message||`could not update the item`}`}},"fwh-cart-remove-mvp":async e=>{let t=parseInt((e||{}).line,10);if($(`fwh-cart-remove-mvp ▶`,{line:t}),!Number.isFinite(t)||t<1)return`Missing/invalid line: call fwh-cart-get-mvp first and use the item's 1-based number.`;try{let e=await Ur(),n=e.items?.[t-1];if(!n)return`NO_SUCH_LINE: the cart has ${e.items?.length||0} item(s). Call fwh-cart-get-mvp for the current list.`;let r=await Yr(t,0),i=await s(r),a=`REMOVED ${n.product_title||n.title}. Cart now has ${r.item_count} item(s), subtotal ${Gr(r.items_subtotal_price)}${r.currency?` ${r.currency}`:``}.${i}`;return $(`fwh-cart-remove-mvp ✓`,a),a}catch(e){return $(`fwh-cart-remove-mvp ✖`,e),`REMOVE_FAILED: ${e?.userMessage||e?.message||`could not remove the item`}`}},"fwh-cart-open-mvp":async()=>($(`fwh-cart-open-mvp ▶`),c(Xr(),`Cart`)),"fwh-checkout-mvp":async()=>{$(`fwh-checkout-mvp ▶`);try{if(!(await Ur()).item_count)return`CART_EMPTY: do not go to checkout. Tell the visitor their cart is empty and offer to help find products.`}catch{}return c(Zr(),`Checkout`)},"fwh-view-product-mvp":async e=>{let t=e||{},n=String(t.product_handle||t.productHandle||``).trim().toLowerCase();return $(`fwh-view-product-mvp ▶`,{handle:n}),n?c(Qr(n),n.replace(/[-_]/g,` `)):`Missing product_handle: search the product first with fwh-shop-search-mvp.`}};async function s(e){try{let{sectionsSwapped:t}=await si(e);if(!t&&ei())return` NOTE: the cart list on this page could not be re-rendered — briefly tell the visitor the page may need a quick refresh to show the change.`}catch{}return``}function c(e,n){if(typeof window>`u`)return`NAV_FAILED: no browser context.`;let r=e;try{r=new URL(e,window.location.href).href}catch{}return t&&Le(t,window.location.href,r,n),Tr(r),Mr().then(()=>{window.location.assign(r)}),`OK_NAVIGATING to ${n}. The page is loading — say one short phrase like "Here you go." and nothing more.`}return{...o,highlightOnPage:o[`fwh-highlight-mvp`],getPageContent:o[`fwh-page-content-mvp`],endVoiceSession:o[`fwh-end-session-mvp`],listPageForms:o[`fwh-list-forms-mvp`],fillFormFields:o[`fwh-fill-form-mvp`],clickPageButton:o[`fwh-click-button-mvp`]}}var g_=/^(get in touch|contact us|let'?s (talk|connect)|subscribe|newsletter|follow us|quick links|company|solutions|what we do|resources|legal|sitemap|share this)/i;function __(){try{let{headings:e,pageTitleHeading:t,containerHeadings:n}=p_(),r=new Set((n||[]).map(e=>e.trim())),i=(e||[]).map(e=>typeof e==`string`?e:e?.text||``).filter(Boolean).filter(e=>!t||e.trim()!==t.trim()).filter(e=>!g_.test(e.trim())),a=i.filter(e=>!r.has(e.trim()));return a.length?a:i}catch{return[]}}function v_(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=Mn();r?console.log(`[FlowEngage:voice-tool] ▶`,e,n):console.info(`[FlowEngage] voice tool » ${e}`);let i;try{i=await t(n)}catch(t){let n=`Tool error: ${t?.message||String(t)}`;return console.error(`[FlowEngage] voice tool ${e} threw:`,t),n}let a=typeof i==`string`?i.length>220?`${i.slice(0,220)}…`:i:String(i);return r?console.log(`[FlowEngage:voice-tool] ◀`,e,a):console.info(`[FlowEngage] voice tool « ${e}:`,a),i}]))}var y_=`[PAGE_CONTEXT]`;function b_(e,t,n){return`${y_} SESSION_CONTEXT (NOT a tool result — do NOT treat as CURRENT_PAGE): Visitor is on: ${e} | Approx headings for awareness only: ${t||``}. ${n?`Forms: ${n}. `:``}The visitor is ALREADY on this page — do NOT offer to navigate there.`}var x_={blue:`#135bd8`,red:`#ef334b`,yellow:`#ffbd2e`,dark:`#0d1b2a`,highlight:`rgba(255,255,255,0.9)`,green:`#10b981`};function S_(e){if(!Array.isArray(e)||e.length<2)return`linear-gradient(145deg, #dce8f022 0%, #e8dff522 45%, #f5e0e022 100%), #f7f8fa`;let[t,n,r]=e;return e.length>=3&&r?[`radial-gradient(ellipse 80% 70% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 70% 80% at 110% 30%, ${n}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 60% at 50% 110%, ${r}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `):[`radial-gradient(ellipse 80% 100% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 100% at 110% 50%, ${n}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `)}function C_(e){if(!e||typeof e!=`string`)return`#1a1a1a`;let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t,r=parseInt(n.slice(0,2),16)/255,i=parseInt(n.slice(2,4),16)/255,a=parseInt(n.slice(4,6),16)/255,o=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4;return .2126*o(r)+.7152*o(i)+.0722*o(a)>.179?`#1a1a1a`:`#ffffff`}function w_(e){let[t,n]=b.useState(null),r=typeof e==`string`?e.trim():``;return b.useEffect(()=>{if(!r){n(null);return}n(null);let e=!1,t=new window.Image;return t.onload=()=>{e||n(r)},t.onerror=()=>{e||n(null)},t.src=r,()=>{e=!0}},[r]),t}function T_({logo:e,style:t}){let n=w_(typeof e==`string`?e:null);if(!e)return null;if(typeof e==`string`)return n?(0,V.jsx)(`img`,{src:n,alt:``,style:{objectFit:`contain`,flexShrink:0,display:`block`,...t}}):null;let r=typeof e==`function`?b.createElement(e):b.isValidElement(e)?e:null;return r?(0,V.jsx)(`span`,{className:`fe-logo-slot`,style:{display:`inline-flex`,alignItems:`center`,flexShrink:0,overflow:`hidden`,...t},children:r}):null}function E_({title:e}){return(0,V.jsx)(`div`,{style:{width:`100%`,height:`100%`,borderRadius:`16px`,background:`linear-gradient(135deg, rgba(59,130,246,0.16) 0%, rgba(59,130,246,0.08) 100%)`,color:`#2563eb`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`18px`,fontWeight:700,letterSpacing:`-0.03em`},children:String(e||`FE`).split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0]?.toUpperCase()||``).join(``)||`FE`})}function D_(e,t){let n=(t||``).trim();return n?!!(/\b(let'?s|let us)\s+(end|stop|finish|wrap up|close)\s+(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\bend\s+(this\s+)?(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\b(hang\s+up|disconnect)\b/i.test(n)||e===`bot`&&(/\b(that'?s all|we'?re done)\b/i.test(n)||/\b(goodbye|bye)\b/i.test(n)||/\b(I'?ll|I will|Let me|I can|I'?m going to)\s+(end|close)\s+(the\s+)?(voice\s+)?(session|call)\b/i.test(n)||/\b(ending|closing)\s+(the\s+)?(voice\s+)?session\b|\bvoice\s+session\s+(is\s+)?(now\s+)?(ended|over|closing)\b/i.test(n)||/\b(session|call)\s+(is\s+)?(now\s+)?(ended|over)\b/i.test(n)||/\bwe\s+can\s+end\s+(the\s+)?(session|call)?\s*(here|now)\b/i.test(n)||/\b(wrapping\s+up|signing\s+off)\b/i.test(n))):!1}function O_({orbColors:e,...t}){return(0,V.jsx)(Bg,{colors:e,...t})}function k_({copy:e,orbColors:t,primaryColor:n,onYes:r,onLater:i,isMobile:a,isClosing:o}){let s=n||x_.green,c=C_(s),l=a?72:94,u=(0,V.jsxs)(`div`,{style:{display:`flex`,alignItems:a?`flex-end`:`center`,gap:a?`7px`:`9px`},children:[(0,V.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,V.jsx)(Qm.p,{initial:{x:-16,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.36},style:{margin:`0 0 14px`,fontSize:`14px`,fontWeight:700,color:`white`,lineHeight:1.4,textShadow:`0 1px 4px rgba(0,0,0,0.35)`,maxWidth:`210px`,wordBreak:`break-word`,overflow:`hidden`,display:`-webkit-box`,WebkitLineClamp:4,WebkitBoxOrient:`vertical`},children:e.entryPrompt}),(0,V.jsxs)(Qm.div,{initial:{y:10,opacity:0},animate:{y:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.54},style:{display:`flex`,gap:`16px`,flexWrap:`nowrap`},children:[(0,V.jsx)(`button`,{onClick:r,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:s,color:c,fontWeight:400,fontSize:`14px`,border:`none`,cursor:`pointer`,whiteSpace:`nowrap`,boxShadow:`0 4px 16px ${s}66`,transition:`transform 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.04)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.yesLabel}),(0,V.jsx)(`button`,{onClick:i,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:`transparent`,color:`white`,fontWeight:400,fontSize:`14px`,border:`2px solid rgba(255,255,255,0.55)`,cursor:`pointer`,whiteSpace:`nowrap`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.9)`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.55)`},children:e.laterLabel})]})]}),(0,V.jsx)(Qm.div,{initial:{x:120,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:220,damping:22,delay:0},style:{flexShrink:0},children:(0,V.jsx)(O_,{size:l,orbColors:t})})]});return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Qm.div,{initial:{opacity:0},animate:{opacity:o?0:1},transition:{duration:.28},style:{position:`fixed`,inset:0,background:`rgba(0,0,0,0.72)`,zIndex:-1}}),a?(0,V.jsx)(`div`,{style:{position:`absolute`,bottom:0,left:0,right:0,padding:`24px 20px 40px`,overflow:`hidden`,animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u}):(0,V.jsx)(`div`,{style:{animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u})]})}function A_({copy:e,orbColors:t,primaryColor:n,onVoice:r,onText:i,onClose:a,isMobile:o,isClosing:s}){let c=n||x_.green,l=C_(c);return(0,V.jsxs)(Qm.div,{initial:{scale:50/350,borderRadius:`50%`},animate:s?{scale:50/350,opacity:0,borderRadius:`50%`}:{scale:1,borderRadius:`16px`,opacity:1},transition:{type:`spring`,stiffness:260,damping:26},style:{transformOrigin:o?`bottom center`:`bottom right`,background:`white`,width:o?`100%`:`350px`,height:`245px`,padding:`24px 40px 32px`,boxSizing:`border-box`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`space-between`,boxShadow:`0 20px 60px rgba(0,0,0,0.2)`,position:`relative`,overflow:`hidden`},children:[(0,V.jsx)(`button`,{onClick:a,style:{position:`absolute`,top:`14px`,right:`14px`,background:`none`,border:`none`,cursor:`pointer`,color:`#9ca3af`,padding:`4px`,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#374151`},onMouseLeave:e=>{e.currentTarget.style.color=`#9ca3af`},children:(0,V.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}),(0,V.jsx)(O_,{size:72,orbColors:t}),(0,V.jsxs)(`div`,{style:{textAlign:`center`},children:[(0,V.jsx)(`p`,{style:{margin:0,fontSize:`16px`,fontWeight:400,color:`#111827`,lineHeight:1.4},children:e.connectionTitle}),e.connectionSubtitle&&(0,V.jsx)(`p`,{style:{margin:`6px 0 0`,fontSize:`13px`,fontWeight:400,color:`#6b7280`,lineHeight:1.4},children:e.connectionSubtitle})]}),(0,V.jsxs)(`div`,{style:{display:`flex`,gap:`16px`,width:`100%`},children:[(0,V.jsx)(`button`,{onClick:r,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:c,color:l,fontWeight:400,fontSize:`16px`,border:`none`,cursor:`pointer`,transition:`transform 0.15s ease`,boxShadow:`0 4px 12px ${c}55`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.03)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.voiceLabel}),(0,V.jsx)(`button`,{onClick:i,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:`transparent`,color:`#111827`,fontWeight:400,fontSize:`16px`,border:`1.5px solid #d1d5db`,cursor:`pointer`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`#6b7280`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`#d1d5db`},children:e.textLabel})]})]})}function j_({orbColors:e,onEnterChat:t,onEndChat:n,agentId:r,siteId:i,apiBaseUrl:a,chatId:o,historyRef:s,onMessageSync:c,beaconSyncVoiceTranscript:l,widgetPosition:u=`bottom-right`,voiceEndCounter:d,websiteName:f,voiceFirstMessage:p,captureVisitorEmail:m,emailRequired:h,emailCaptureEnabled:g=!0,listeningLabel:_=`Listening...`,thinkingLabel:v=`Thinking...`,enterChatModeLabel:y=`Enter Chat Mode`,endConversationLabel:x=`End Conversation`}){(0,b.useEffect)(()=>(console.log(`[FlowEngage:VoiceDebug] 🔵 VoiceMode MOUNTED`),()=>console.log(`[FlowEngage:VoiceDebug] 🔴 VoiceMode UNMOUNTED`)),[]);let[S,C]=(0,b.useState)(`idle`),[w,T]=(0,b.useState)(!1),[E,ee]=(0,b.useState)(!1),[D,te]=(0,b.useState)(()=>le(i)===`auto`),O=()=>{let e=D?`ask`:`auto`;ue(i,e),te(e===`auto`)},[ne,re]=(0,b.useState)(!1),[ie,ae]=(0,b.useState)(``),[oe,k]=(0,b.useState)(``),A=(0,b.useRef)(!1),se=(0,b.useRef)(!1),ce=(0,b.useRef)(null),de=(0,b.useRef)(0),j=(0,b.useRef)(``),fe=(0,b.useRef)(!1),pe=(0,b.useRef)(0),me=(0,b.useRef)(!1),he=(0,b.useRef)(!1),ge=(0,b.useRef)(!1),_e=(0,b.useRef)([]),ve=(0,b.useRef)(null),ye=(0,b.useRef)(``),M=(0,b.useRef)(null),be=e=>{me.current=e,e||(he.current=!1),N.current?.setWalkthroughActive?.(e)};M.current=async()=>{if(he.current)return;let e=typeof window<`u`?window.location.pathname:null;if(e&&ve.current&&e!==ve.current){console.log(`[FlowEngage] walkthrough ended — visitor left `+ve.current),ve.current=null,_e.current=[],be(!1);return}let t=_e.current;xe.current+=1;let n=xe.current,r=t[n];if(!r){if(be(!1),t.length)N.current?.sendUserMessage?.(`That was the last section. Say so in one short sentence and ask if they want to explore any section further.`);else if(n===0){let e=``;try{let t=await Se.current?.[`fwh-read-content-mvp`]?.({});typeof t==`string`&&t&&!/^Could not/i.test(t)&&(e=t.slice(0,2800))}catch{}N.current?.sendUserMessage?.(e?`Give the visitor a complete spoken overview of this page in 4-6 sentences, based ONLY on this page content:\n"""${e}"""\nThen ask which part they'd like to hear more about. Do not call any tool.`:`Give the visitor a complete spoken overview of this page in 4-6 sentences based on what you know about it, then ask which part they'd like to hear more about. Do not call any tool.`,{suppressQuestion:!0})}return}try{await Se.current?.highlightOnPage?.({section_text:r})}catch(e){console.warn(`[FlowEngage] walkthrough highlight failed:`,e?.message||e)}console.debug(`[FlowEngage] walkthrough step ${n+1}/${t.length}: ${r}`);let i=``;try{let e=await Se.current?.[`fwh-read-content-mvp`]?.({section_text:r});typeof e==`string`&&e&&!/^Could not/i.test(e)&&(i=e.slice(0,2500))}catch{}let a=i?`Here is this section's full content — describe it from THIS text only, and do not call any tool:\n"""${i}"""\n`:`read the section's content silently first (fwh-read-content-mvp) if you don't already have it. `;N.current?.sendUserMessage?.(`Describe the section titled "${r}" in 3-4 sentences, starting with ${n===0?`Starting with`:`Next —`} ${r}. Describe ONLY this section. If this section contains named sub-items (steps, checklist entries, cards, plans, FAQs, team members), name EVERY one of them in order with a short phrase each — never skip or collapse them into a summary; `+a+`This section is ON THE PAGE THE VISITOR IS ALREADY ON — do NOT call fwh-navigate-mvp, do not go to a product/detail page, and do not offer to, even if this section's name also matches a page name. Do not mention any other section, do not ask whether to continue, then stop.`,{suppressQuestion:!0})};let xe=(0,b.useRef)(0),N=(0,b.useRef)(null),Se=(0,b.useRef)(null),Ce=(0,b.useRef)(``),we=(0,b.useRef)(async()=>{}),Te=(0,b.useRef)(!1),ke=(0,b.useRef)(!1),je=(0,b.useRef)(!1),Me=(0,b.useRef)(!1),Ne=(0,b.useRef)(`minimized`),Pe=(0,b.useRef)(null),Ie=(0,b.useRef)(null),Le=(0,b.useRef)(null),ze=(0,b.useRef)(0),P=(0,b.useRef)(!1),Be=(0,b.useRef)(`idle`),Ve=(0,b.useRef)(null),He=(0,b.useRef)(!1),Ue=(0,b.useRef)(null),We=(0,b.useCallback)((e=`minimized`)=>{console.warn(`[FlowEngage:VoiceDebug] 🛑 requestSessionShutdown called`,{destination:e,stack:Error().stack?.split(`
|
|
430
|
+
`).slice(1,4).join(` | `)}),Ne.current=e,Me.current=!0,queueMicrotask(()=>{Te.current||(Te.current=!0,we.current?.())})},[s]),Ge=(0,b.useCallback)(()=>{ce.current&&=(clearTimeout(ce.current),null)},[]);(0,b.useEffect)(()=>{if(h){A.current=!1;return}if(A.current=!0,se.current=!1,re(!1),Ge(),fe.current){fe.current=!1,N.current?.setMicMuted?.(!1);let e=j.current;j.current=``,N.current?.injectAgentSpeech?.(`Thanks — I already have your email on file.`,`interrupt`),e&&N.current?.sendUserMessage?.(`The visitor's email is already on file — do not ask for it. Answer their question now: "${e}"`)}N.current?.sendContextualUpdate?.(`EMAIL REQUIREMENT SATISFIED — the visitor's email is already on file. All earlier instructions about requiring or asking for an email are VOID. Never ask for it again.`)},[h,Ge]);let Ke=/(walk\s*(me\s*)?through|walkthrough|take me through|(complete|full|detailed) (overview|understanding|walkthrough|picture|breakdown|explanation)|give me (a|an|the) (overview|tour|walk)|tell me about (each|all)|go through (it|them|each|all)|overview of|one by one|tell me everything|explain (me )?(this|the) (whole |entire |full )?page|everything (about|on) this page|show me (each|all|around))/i,qe=/(that covers everything|that was all|covered everything|that(?:'|’)?s everything)/i,Je=/^((uh+|um+|so|well|okay|ok|yeah)[,.\s]+)*(yes|yeah|yep|yup|sure|ok(ay)?|please|continue|go on|next|keep going|carry on|go ahead|resume|back to the tour)[\s.!,]*$/i,Ye=/(would you like (me )?to take you|shall i take you|want me to take you|would you like to (go|explore|visit|see)|take you there)/i,Xe=/^((uh+|um+|oh|ah|so|well)[,.\s]+)*(cool|nice|great|awesome|wow|lovely|perfect|got it|gotcha|i see|understood|makes sense|interesting|right|alright|sounds good|mm+-?hmm+|hmm+|k)[\s.!,]*$/i,Ze=e=>String(e||``).replace(/[\s.,!?]*((uh+|um+|er+|hmm+|mm+)[\s.,!?]*)+$/i,``).trim(),Qe=(0,b.useCallback)(()=>{Ge(),ce.current=setTimeout(()=>{if(!(!se.current||A.current))if(de.current<3){de.current+=1;try{N.current?.injectAgentSpeech?.(`I still need your email in the box below to continue — could you enter it, please?`,`queue`)}catch{}Qe()}else{try{N.current?.injectAgentSpeech?.(`Since I haven't received your email, I'll close this session for now. Feel free to come back anytime — take care!`,`queue`)}catch{}se.current=!1,re(!1),Ge(),P.current=!0}},1e4)},[Ge]),$e=(0,b.useCallback)(async e=>{Me.current=!0;try{In()}catch{}try{Lh()}catch{}if(i)try{Re(i)}catch{}try{await N.current?.endSession?.()}catch{}let t=Pe.current,n=Ie.current;if(t&&o&&a){let e=n?Math.round((Date.now()-n)/1e3):0;fetch(`${a}/api/voice/save-chat-recording`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({chatId:o,voiceSessionId:t,duration:e,siteId:i})}).catch(e=>console.warn(`[FlowEngage] save-chat-recording failed:`,e.message))}if(Pe.current=null,Ie.current=null,N.current=null,C(`idle`),T(!1),Te.current=!1,Lr(),i)try{Oe(i)}catch{}typeof c==`function`&&await c(s.current),e?.()},[s,c,i,o,a]);we.current=()=>$e(Ne.current===`chat`?t:n),(0,b.useEffect)(()=>{ke.current=w},[w]),(0,b.useEffect)(()=>{d&&We(`chat`)},[d]),(0,b.useEffect)(()=>{let e=!1,d=null,m=null,_=null;return(async()=>{if(!i){C(`error`);return}try{if((await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),e)return;s.current=[],Ce.current=``,Te.current=!1,je.current=!1,Me.current=!1,Ne.current=`minimized`,Ir({onBeforeNavigate:()=>{if(i&&s.current.length>0)try{let e=Yg(s.current);e&&Ee(i,e)}catch{}if(!nr()){let e=Pe.current,t=Ie.current;if(e&&o&&a)try{let n=t?Math.round((Date.now()-t)/1e3):0,r=JSON.stringify({chatId:o,voiceSessionId:e,duration:n,siteId:i}),s=`${a}/api/voice/save-chat-recording`;fetch(s,{method:`POST`,headers:{"Content-Type":`application/json`},body:r,keepalive:!0}).catch(()=>{}),Pe.current=null,Ie.current=null}catch{}}Ae()}});let t=v_(h_({siteId:i||null,apiBaseUrl:a||null,chatId:o||null,getLastUserVoiceText:()=>Ce.current,beaconSyncFullVoiceHistory:()=>l?.(s.current),isWalkthroughActive:()=>me.current&&!he.current,requestEndSession:()=>{P.current=!0},requestEmailCollection:()=>{g&&(A.current||se.current||(se.current=!0,de.current=0,re(!0),Qe()))}})),n=i?De(i):null,r=!!n?.transcript,c=i?Re(i):null,v=!!c,y=typeof window<`u`?window.location.pathname:`/`,b=typeof document<`u`?document.title:``,x=y.replace(/^\/[a-z]{2}(?:-[a-z]{2})?(?=\/|$)/i,``)||`/`,S=x===`/`||x===``,w={apiBaseUrl:a,siteId:i,chatId:o,clientTools:t};Se.current=t;let E=(y.split(`/`).filter(Boolean).pop()||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),ee=``;b&&b.includes(`|`)&&(ee=b.split(`|`).map(e=>e.trim()).filter(Boolean).reduce((e,t)=>e.length<=t.length?e:t));let D=ee||E||``,te=D?`the ${D} page`:`this page`,O=(()=>{if(!c?.targetUrl)return!0;try{return new URL(c.targetUrl,window.location.href).pathname.replace(/\/$/,``)===window.location.pathname.replace(/\/$/,``)}catch{return!0}})(),ne=(()=>{if(!c?.targetUrl)return null;try{return new URL(c.targetUrl,window.location.href).pathname}catch{return null}})();if(v&&!O)w.greeting=`You're on ${te}. What would you like to know?`,console.warn(`[FlowEngage] nav target "${c?.pageName}" not reached — on "${D}" instead; not claiming navigation`);else if(v){let e=c?.pageName?`the ${c.pageName} page`:te;w.greeting=`I have navigated you to ${e}. Do you want to know about any specific section or want a complete overview?`,console.log(`[FlowEngage] 🔄 Agent-nav resume: greeting set for "${e}" (${y})`)}else if(r)w.greeting=`Welcome back! I see you're now on ${te}. Would you like me to continue what I was explaining before, or would you like to know about this page instead?`;else{let e=f||``;w.greeting=p||(S?e?`Hi, welcome to ${e}! How may I help you?`:`Hi, welcome! How may I help you?`:`Welcome to ${te}! How may I help you?`),S||console.log(`[FlowEngage] 🏠 Page-context greeting: "${D}" for ${y}`)}let ie=!1,ae=v?`NAVIGATION COMPLETE — The exact phrase "I have navigated you to the [page] page. Do you want to know about any specific section or want a complete overview?" has already been spoken as your firstMessage. DO NOT repeat it. PRIOR CONVERSATION CONTEXT:\n${n?.transcript?`Prior transcript:\n${n.transcript}\n`:`(no prior transcript)`}\nNow STOP — wait silently for the visitor's reply. Do NOT speak, do NOT call any tool until the visitor responds. When they reply: if they name a specific section → call fwh-get-current-page-mvp then answer immediately; if they say "overview" or anything non-specific → call fwh-get-current-page-mvp (zero speech) then do a full highlighted walkthrough.`:null,oe=!1,k=!v&&!r?`Your greeting has been spoken. Wait for the visitor to ask a question or tell you what they need. Do NOT auto-start a walkthrough or highlight any sections — let the visitor lead.`:null,ce=r&&!v,ue=!1,we=ce?`The question "Would you like me to continue what I was explaining before, or would you like to know about this page instead?" has already been spoken as your firstMessage. DO NOT repeat it. PRIOR CONVERSATION CONTEXT:\n${n?.transcript?`Prior transcript:\n${n.transcript}\n`:`(no prior transcript, or the visitor navigated before saying much)`}\nNow STOP — wait silently for the visitor's reply. Do NOT speak, do NOT call any tool until they respond. When they reply: if they want you to CONTINUE the previous topic → resume verbally from the prior transcript above, do NOT call fwh-get-current-page-mvp or describe the new page unless they ask. If they want to know about THIS page → call fwh-get-current-page-mvp (zero speech) then proceed as a normal fresh-page walkthrough/description. If their reply is ambiguous, ask them to clarify which they'd prefer rather than guessing.`:null,Oe=!1,Le=!1,$e=g&&!!h&&!ge.current,F=await xh.startSession({...w,onConnect:({conversationId:e})=>{Pe.current=e,Ie.current=Date.now(),console.log(`[FlowEngage] 🎙️ AI chat session connected:`,e)},onUnhandledClientToolCall:e=>console.error(`[FlowEngage] Unhandled tool:`,e?.tool_name),onSessionInfo:({emailOnFile:e})=>{ge.current=!!e,e&&(A.current=!0,se.current=!1,re(!1),Ge(),console.log(`[FlowEngage] email already on file per server — gate disabled`))},onAgentTurnEnd:()=>{e||me.current&&(he.current||fe.current||setTimeout(()=>M.current?.(),250))},onSessionEnding:()=>{e||We(`minimized`)},onPanel:({title:t,items:n})=>{e||Ih(n,{title:t||`Products`,side:u===`bottom-left`?`left`:`right`,productUrl:e=>e.handle?`${window.location.origin}/products/${encodeURIComponent(e.handle)}`:null})},onModeChange:({mode:t,tentative:n})=>{if(!e){if(t===`speaking`){Ve.current&&=(clearTimeout(Ve.current),null),Ue.current&&=(clearTimeout(Ue.current),null),C(`speaking`),Be.current=`speaking`,He.current=!1;return}if(t===`user-speaking`){if(se.current&&!A.current&&Qe(),Ue.current&&=(clearTimeout(Ue.current),null),Be.current===`speaking`)return;try{In()}catch{}Ve.current&&=(clearTimeout(Ve.current),null),Be.current!==`listening`&&(C(`listening`),Be.current=`listening`);return}if(t===`thinking`){if(Ve.current&&=(clearTimeout(Ve.current),null),Ue.current&&=(clearTimeout(Ue.current),null),Be.current===`speaking`)return;C(`thinking`),Be.current=`thinking`,n&&(Ue.current=setTimeout(()=>{Ue.current=null,!(e||Be.current!==`thinking`)&&(Be.current=`listening`,C(`listening`))},4e3));return}if(Be.current=`listening`,P.current){P.current=!1,We();return}if($e&&!Le&&!A.current&&!ge.current){Le=!0,ie=!0,oe=!0;try{N.current?.sendContextualUpdate?.(`CRITICAL — EMAIL REQUIRED BEFORE ANYTHING ELSE. The visitor has not provided their email. The app itself speaks the email request out loud — you must NOT say it, and you must NOT answer. Stay completely silent from now until you receive an EMAIL_SAVED message: produce no speech and call no tools, no matter what the visitor says. Remember their question. On EMAIL_SAVED, thank them briefly and answer that remembered question in full.`)}catch{}}if(ae&&!ie){ie=!0;try{N.current?.sendContextualUpdate?.(ae)}catch{}}if(we&&!ue){ue=!0;try{N.current?.sendContextualUpdate?.(we)}catch{}}if(k&&!oe){oe=!0;try{N.current?.sendContextualUpdate?.(k)}catch{}}Ve.current&&clearTimeout(Ve.current),Ve.current=setTimeout(()=>{e||Be.current!==`speaking`&&(He.current||(Ve.current=null,Be.current=`listening`,C(`listening`)))},1200)}},onMessage:t=>{if(e||fe.current&&t.role!==`user`&&!/email/i.test(String(t.message||``)))return;let n=t.role===`user`&&/^(Describe the section titled "|\[SYSTEM:|Give the visitor a complete spoken overview|That was the last section)/.test(String(t.message||``).trim()),r=/\b(?:this|that|the)\s+(?:case\s*stud(?:y|ies)|product|article|blog|post|item|service)\b/i.test(String(t.message||``));if(!n&&!r&&t.role===`user`&&Ke.test(String(t.message||``)))typeof window<`u`&&(window.__fe_user_nav_during_speech=null),be(!0),he.current=!1,pe.current=0,xe.current=-1,_e.current=__(),ve.current=typeof window<`u`?window.location.pathname:null,setTimeout(()=>M.current?.(),400),console.log(`[FlowEngage] walkthrough armed — ${_e.current.length} sections on this page`);else if(!n&&t.role===`user`&&me.current){let e=String(t.message||``).trim(),n=Ze(e),r=e=>!!e&&(Je.test(e)||Xe.test(e));Ye.test(ye.current||``)?(console.log(`[FlowEngage] walkthrough ended — visitor accepted a navigation offer`),ve.current=null,_e.current=[],be(!1)):!n||r(e)||r(n)?he.current&&(he.current=!1,console.debug(`[FlowEngage] walkthrough resumed by visitor`),setTimeout(()=>M.current?.(),300)):(console.log(`[FlowEngage] walkthrough ended — visitor moved to a new topic`),ve.current=null,_e.current=[],be(!1))}if(t.role!==`user`&&!n&&(ye.current=String(t.message||``)),t.role!==`user`&&qe.test(String(t.message||``))){let e=_e.current.length;!e||xe.current>=e-1?be(!1):console.debug(`[FlowEngage] agent claimed completion at step ${xe.current+1}/${e} — ignoring, tour continues`)}let a=t.role===`user`?`user`:`bot`,o=t.message||t.text||t.content||``;if(o){if(a===`user`&&(Ce.current=o,typeof window<`u`&&(window.__fe_user_nav_during_speech=null),He.current=!0,Ve.current&&=(clearTimeout(Ve.current),null),Be.current!==`speaking`&&(C(`thinking`),Be.current=`thinking`),$e&&!Oe&&!A.current&&!ge.current&&(Oe=!0,j.current=o,fe.current=!0,N.current?.injectAgentSpeech?.(`Before I answer that, could you please enter your email in the text box below?`,`interrupt`),N.current?.setMicMuted?.(!0),se.current||(se.current=!0,de.current=0,re(!0),Qe()))),s.current=[...s.current,{sender:a,message:o,timestamp:new Date().toISOString(),debug:t.debug}],i)try{let e=Yg(s.current);e&&Ee(i,e)}catch{}if(D_(a,o)){P.current=!0;return}if(ke.current&&a===`bot`&&/are you still there|still there\??|hello\?|anyone there|checking in|you there|are you available|is anyone|did you step away/i.test(o))if(ze.current+=1,ze.current===2)try{N.current?.sendContextualUpdate?.(`IMPORTANT: The visitor is muted and has not responded to your last 2 checks. Make exactly ONE more check. If there is still no response, say: 'I feel like you are not active, so I'm ending this session. You can connect with me anytime.' then immediately call the fwh-end-session-mvp tool to end the voice session. Do NOT ask again after that.`)}catch{}else ze.current>=5&&We(`minimized`)}},onError:t=>{if(!e&&!Me.current&&!je.current&&!Fe()){je.current=!0,console.error(`[FlowEngageVoiceCall] session:error`,{message:t?.message,name:t?.name,raw:t});try{N.current?.setMicMuted?.(!0)}catch{}T(!0),C(`error`),We(`chat`)}},onDisconnect:t=>{if(e||Me.current||je.current||Fe())return;let n=s.current?.length||0;console.warn(`[FlowEngageVoiceCall] session:disconnected`,{historyCount:n,reason:t?.reason,closeCode:t?.context?.code,closeReason:t?.context?.reason||t?.message,lastUserText:Ce.current||``,wasMuted:ke.current}),je.current=!0;try{N.current?.setMicMuted?.(!0)}catch{}T(!0),We(`chat`)}});if(e){console.warn(`[FlowEngage:VoiceDebug] ❌ cancelled=true after startSession resolved — killing session immediately`),F.endSession().catch(()=>{});return}d=F,N.current=F,C(`listening`);try{sessionStorage.setItem(`el_conv_${i}`,F.getId())}catch{}parent.postMessage({type:`AGENT_EXPAND`},`*`);try{let e=typeof window<`u`?window.location.href:``,a=`[]`;try{a=await t[`fwh-list-forms-mvp`]()}catch{}let o=`none`;if(typeof window<`u`&&typeof document<`u`)try{let e=`#flowengage-root, .flowengage-shell, .flowengage-widget-root`,t=document.querySelector(`main, [role='main']`)||document.body,n=Array.from(t.querySelectorAll(`h1, h2, h3`)).filter(t=>!t.closest(e)).map(e=>e.textContent.replace(/\s+/g,` `).trim()).filter(e=>e.length>2&&e.length<200);n.length||(n=Array.from(document.body.querySelectorAll(`h1, h2, h3`)).filter(t=>!t.closest(e)).map(e=>e.textContent.replace(/\s+/g,` `).trim()).filter(e=>e.length>2&&e.length<200)),n.length&&(o=[...new Set(n)].slice(0,15).join(` | `))}catch{}let s=r&&!v?`RESUMING PRIOR SESSION — DO NOT GREET. The visitor is continuing the same conversation after a page reload. Do not introduce yourself or re-state your capabilities. Wait silently until the visitor speaks; if you must speak first, briefly acknowledge where you left off in one short sentence.\nPrior transcript:\n${n?.transcript||``}\n\n`:``;F.sendContextualUpdate(`${s}SiteId: ${i||`unknown`}. ${h?``:`Visitor's email is already on file from a prior session — do NOT ask for it again. `}WALKTHROUGH RULE: When the visitor asks for a walkthrough or overview of this page, you MUST IMMEDIATELY call fwh-get-current-page-mvp (zero speech — call it silently with NO words before it) to get the exact highlightable headings. Do NOT skip fwh-get-current-page-mvp. Voice: call end_voice_session or say you are ending the session to stop.`),F.sendContextualUpdate(b_(e,o,a))}catch{}if(typeof window<`u`){let t=window.location.pathname,n=Date.now(),r=e=>{try{return(decodeURIComponent(e||`/`).replace(/\/+$/,``)||`/`).toLowerCase()}catch{return((e||`/`).replace(/\/+$/,``)||`/`).toLowerCase()}},a=()=>{if(e)return;let a=window.location.pathname;if(r(a)===r(t)){t=a;return}if(Date.now()-n<8e3){t=a;return}let o=typeof window<`u`&&window.__fe_agent_nav||null,s=ne&&r(a)===r(ne)||Jn()||o&&Date.now()-o.ts<15e3&&r(o.path)===r(a),c=t;t=a;let l=window.location.href,u=typeof document<`u`?document.title:``,d=typeof document<`u`?Array.from(document.querySelectorAll(`h1, h2, h3, h4`)).filter(e=>!e.closest(`#flowengage-root, .flowengage-shell`)).map(e=>({tag:e.tagName,text:e.textContent.trim()})).filter(e=>e.text.length>0&&e.text.length<200).slice(0,20):[];try{In()}catch{}let f=d.map(e=>e.text).join(` | `),p=e=>(e.split(`/`).filter(Boolean).pop()||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())||`Home`,m=p(c),h=p(a);if(s){if(typeof window<`u`&&(window.__fe_agent_nav=null),console.log(`[FlowEngage] agent-driven navigation settled: "${c}" → "${a}"`),le(i)!==`auto`)try{N.current?.sendUserMessage?.(`[SYSTEM: YOU just navigated the visitor to the "${h}" page (${l}) at their request — this was YOUR action, not theirs. Page title: "${u}". Sections: ${JSON.stringify(d)}. Say: "Here we are on the ${h} page." Then introduce this page in 2-3 sentences, and finish by asking: "Would you like me to walk you through it section by section?" NEVER say "I see you've navigated" — the visitor did not navigate, you did. Do NOT call fwh-navigate-mvp again. Wait for their answer before describing sections.]`,{suppressQuestion:!0})}catch{}else console.log(`[FlowEngage] auto-nav — skipping the arrival acknowledgment turn`);try{N.current?.sendContextualUpdate?.(b_(l,f))}catch{}return}typeof window<`u`&&(window.__fe_user_nav_during_speech={fromPath:c,toPath:a,fromPageName:m,toPageName:h,ts:Date.now()}),console.log(`[FlowEngage] visitor navigation detected: "${c}" → "${a}" (agent target: ${ne||`none`})`);try{N.current?.sendUserMessage?.(`[SYSTEM: I navigated away mid-walkthrough — I am now on the "${h}" page (${l}). Page title: "${u}". Sections: ${JSON.stringify(d)}. STOP everything. Do NOT describe the new page. Say EXACTLY: "I see you've navigated to the ${h} page — would you like me to continue what I was explaining, or shall I walk you through this page?" Then wait for my answer. IF I say continue/yes/carry on: resume speaking verbally from where you left off — do NOT call fwh-navigate-mvp, do NOT call fwh-highlight-mvp, the visitor will navigate themselves if needed. IF I want to hear about this page: call fwh-highlight-mvp for sections of "${h}" only.]`)}catch{}try{N.current?.sendContextualUpdate?.(b_(l,f))}catch{}};m=window.history.pushState.bind(window.history),window.history.pushState=(...e)=>{m(...e),setTimeout(a,50)},_=()=>setTimeout(a,50),window.addEventListener(`popstate`,_)}}catch(r){e||(console.error(`[FlowEngage] startSession failed`,r),r.message&&r.message.includes(`Too many voice sessions`)?(alert(r.message),n&&n(`minimized`)):(C(`error`),Ne.current=`chat`,window.setTimeout(()=>{e||t?.()},0)))}})(),()=>{console.warn(`[FlowEngage:VoiceDebug] ⚠️ useEffect CLEANUP fired — session will be killed`,{agentId:r,siteId:i,apiBaseUrl:a}),e=!0,Me.current=!0;try{In()}catch{}if(i)try{Re(i)}catch{}typeof window<`u`&&(window.__fe_user_nav_during_speech=null),Lr(),Ve.current&&=(clearTimeout(Ve.current),null),Ue.current&&=(clearTimeout(Ue.current),null),ce.current&&=(clearTimeout(ce.current),null),He.current=!1,Be.current=`idle`,m&&typeof window<`u`&&(window.history.pushState=m),_&&typeof window<`u`&&window.removeEventListener(`popstate`,_);let t=d||N.current,n=Pe.current,l=Ie.current;if(t?.endSession?.().catch(()=>{}),n&&o&&a){let e=l?Math.round((Date.now()-l)/1e3):0,t=JSON.stringify({chatId:o,voiceSessionId:n,duration:e,siteId:i}),r=`${a}/api/voice/save-chat-recording`;typeof navigator<`u`&&navigator.sendBeacon&&navigator.sendBeacon(r,new Blob([t],{type:`application/json`}))||fetch(r,{method:`POST`,headers:{"Content-Type":`application/json`},body:t,keepalive:!0}).catch(()=>{}),Pe.current=null,Ie.current=null}typeof c==`function`&&s.current.length>0&&c(s.current).catch?.(()=>{})}},[r,i,a,We]),(0,b.useEffect)(()=>{if(!E)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;Le.current&&!Le.current.contains(t)&&ee(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[E]);let F=async()=>{if(N.current)try{if(w){ze.current=0,await N.current.setMicMuted?.(!1),T(!1);try{N.current.sendContextualUpdate?.(`The visitor has unmuted. Resume normal interaction and wait for them to speak.`)}catch{}}else{ze.current=0,await N.current.setMicMuted?.(!0),T(!0);try{N.current.sendContextualUpdate?.(`The visitor has muted their microphone. Do NOT speak, ask if they are there, or prompt them in any way. Stay completely silent until they unmute.`)}catch{}}}catch{}},I=(0,b.useCallback)(async e=>{e?.preventDefault?.();let t=ie.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)){k(`Please enter a valid email address.`);return}k(``),A.current=!0,se.current=!1,Ge(),re(!1),ae(``),fe.current=!1;try{typeof m==`function`&&await m(t)}catch{}N.current?.setMicMuted?.(!1);let n=j.current;j.current=``;try{N.current?.injectAgentSpeech?.(`Thank you for submitting your email.`),N.current?.sendUserMessage?.(n||`The visitor's email is on file. Carry on helping them and never ask for it again.`)}catch{}},[ie,m,Ge]),L=Array.isArray(e)&&e[0]||`#3B82F6`;return(0,V.jsxs)(`div`,{ref:Le,style:{position:`relative`,display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`14px`,animation:`fe-orb-slide-up 0.42s cubic-bezier(0.16,1,0.3,1)`},children:[ne&&(0,V.jsxs)(`form`,{onSubmit:I,style:{width:`270px`,maxWidth:`calc(100vw - 40px)`,boxSizing:`border-box`,background:`rgba(15,22,36,0.97)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,padding:`16px`,display:`flex`,flexDirection:`column`,gap:`10px`,animation:`fe-orb-fade-in 0.18s ease`},children:[(0,V.jsx)(`span`,{style:{color:`white`,fontSize:`13px`,fontWeight:600,lineHeight:1.4},children:`Please enter your email to continue`}),(0,V.jsx)(`input`,{type:`email`,inputMode:`email`,autoComplete:`email`,autoFocus:!0,value:ie,onChange:e=>{ae(e.target.value),oe&&k(``)},placeholder:`you@example.com`,style:{width:`100%`,boxSizing:`border-box`,padding:`10px 12px`,borderRadius:`10px`,border:oe?`1.5px solid #ef4444`:`1.5px solid #4b5563`,background:`#1f2937`,color:`white`,fontSize:`14px`,outline:`none`}}),oe&&(0,V.jsx)(`span`,{style:{color:`#f87171`,fontSize:`12px`},children:oe}),(0,V.jsx)(`button`,{type:`submit`,disabled:!ie.trim(),style:{width:`100%`,padding:`10px 12px`,borderRadius:`10px`,border:`none`,background:ie.trim()?L:`#374151`,color:`white`,fontSize:`14px`,fontWeight:600,cursor:ie.trim()?`pointer`:`default`,transition:`background 0.2s ease`},children:`Submit`})]}),(0,V.jsxs)(`div`,{style:{position:`relative`},children:[(S===`listening`||S===`thinking`)&&!w&&(0,V.jsx)(`span`,{style:{position:`absolute`,right:`100%`,marginRight:`18px`,top:`50%`,transform:`translateY(-50%)`,color:`white`,fontSize:`18px`,fontWeight:600,letterSpacing:`0.01em`,textShadow:`0 2px 4px rgba(0,0,0,0.4)`,whiteSpace:`nowrap`},children:S===`thinking`?v:_}),w&&(0,V.jsx)(`span`,{style:{position:`absolute`,right:`100%`,marginRight:`18px`,top:`50%`,transform:`translateY(-50%)`,color:`#f87171`,fontSize:`16px`,fontWeight:600,letterSpacing:`0.01em`,textShadow:`0 2px 4px rgba(0,0,0,0.4)`,whiteSpace:`nowrap`},children:`Muted`}),(0,V.jsx)(O_,{size:72,voiceState:S,isMuted:w,orbColors:e})]}),S===`error`&&(0,V.jsx)(`span`,{style:{color:`#f87171`,fontSize:`13px`,fontWeight:500},children:`Could not start voice session.`}),(0,V.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,alignItems:`center`},children:[(0,V.jsx)(`button`,{onClick:F,title:w?`Unmute`:`Mute`,style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:w?`#7f1d1d`:`#1f2937`,border:w?`1.5px solid #ef4444`:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:w?`#f87171`:`white`,transition:`all 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:w?(0,V.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`line`,{x1:`1`,y1:`1`,x2:`23`,y2:`23`}),(0,V.jsx)(`path`,{d:`M9 9v3a3 3 0 005.12 2.12M15 9.34V4a3 3 0 00-5.94-.6`}),(0,V.jsx)(`path`,{d:`M17 16.95A7 7 0 015 12v-2m14 0v2a7 7 0 01-.11 1.23`}),(0,V.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`23`}),(0,V.jsx)(`line`,{x1:`8`,y1:`23`,x2:`16`,y2:`23`})]}):(0,V.jsx)(Qh,{size:16,color:`currentColor`})}),(0,V.jsx)(`button`,{onClick:()=>ee(e=>!e),style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:`#1f2937`,border:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`,transition:`background 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:(0,V.jsx)(og,{size:16,color:`currentColor`})})]}),E&&(0,V.jsxs)(`div`,{style:{position:`absolute`,bottom:0,right:0,width:`230px`,zIndex:9999,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,animation:`fe-orb-fade-in 0.18s ease`,padding:`12px 12px 40px`},children:[(0,V.jsxs)(`button`,{onClick:()=>{ee(!1),Ne.current=`chat`,$e(t)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsx)(sg,{}),y]}),i&&(0,V.jsxs)(`button`,{onClick:()=>O(),style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`8px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,minWidth:0,overflow:`hidden`},children:[(0,V.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:(0,V.jsx)(`polygon`,{points:`3 11 22 2 13 21 11 13 3 11`})}),(0,V.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:`Auto-navigate`})]}),(0,V.jsx)(`span`,{"aria-hidden":!0,style:{width:`34px`,height:`19px`,borderRadius:`999px`,background:D?`#22c55e`:`rgba(255,255,255,0.2)`,position:`relative`,flexShrink:0,transition:`background 0.15s ease`},children:(0,V.jsx)(`span`,{style:{position:`absolute`,top:`2px`,left:D?`17px`:`2px`,width:`15px`,height:`15px`,borderRadius:`50%`,background:`white`,transition:`left 0.15s ease`}})})]}),(0,V.jsxs)(`button`,{onClick:()=>{ee(!1),Ne.current=`minimized`,$e(n)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`#E30C12`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(227,12,18,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsx)(cg,{}),x]}),(0,V.jsx)(`button`,{onClick:()=>ee(!1),style:{position:`absolute`,bottom:`8px`,right:`8px`,width:`24px`,height:`24px`,borderRadius:`50%`,background:`rgba(255,255,255,0.15)`,border:`none`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.25)`},onMouseLeave:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.15)`},children:(0,V.jsxs)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,V.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]})]})}function M_({orbColors:e}){let t=Array.isArray(e)&&e.length>0?e:[`#135bd8`,`#ef334b`,`#ffbd2e`],n=t[0],r=t[1]||t[0],i=t[2]||t[0];return(0,V.jsx)(`div`,{style:{width:`32px`,height:`32px`,borderRadius:`50%`,flexShrink:0,background:`
|
|
427
431
|
radial-gradient(circle at 18% 50%, ${n} 0%, ${n}99 35%, transparent 65%),
|
|
428
432
|
radial-gradient(circle at 82% 50%, ${r} 0%, ${r}99 35%, transparent 65%),
|
|
429
433
|
radial-gradient(circle at 50% 82%, ${i} 0%, ${i}99 30%, transparent 58%),
|
|
430
434
|
white
|
|
431
|
-
`.replace(/\s+/g,` `).trim()}})}var k_=()=>(0,V.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,V.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`12px 16px`,borderRadius:`18px`,background:`#fff`,boxShadow:`0 2px 6px rgba(0,0,0,0.04)`},children:[0,1,2].map(e=>(0,V.jsx)(`span`,{style:{width:`7px`,height:`7px`,borderRadius:`50%`,background:`#9ca3af`,animation:`fe-dot-bounce 1.2s ease-in-out ${e*.2}s infinite`,display:`inline-block`}},e))})});function A_({copy:e,orbColors:t,primaryColor:n,chatBgGradient:r,logo:i,quickChatOptions:a,onQuickChatSelect:o,isMobile:s,chatHistory:c,isAiTyping:l,isAgentTyping:u,activeScreen:d,agentName:f,agentHeadshot:p,fallbackAgentName:m,input:h,setInput:g,onSubmit:_,isConversationEnded:v,isLoading:y,isRateLimited:x,rateLimitMessage:S,selectedFile:C,onFileSelect:w,onRemoveSelectedFile:T,attachmentError:E,isUploadingAttachment:ee,requiresEmail:D,emailInput:te,setEmailInput:O,emailError:ne,emailCaptureSuccess:re,replyContext:ie,setReplyContext:ae,webRTCError:oe,micError:k,setMicError:A,dismissCallError:se,activeCallId:ce,isCallMuted:de,toggleCallMute:j,endWebRTCCall:fe,formatCallDuration:pe,callDurationSeconds:me,isCallMinimized:he,onExpand:ge,onCollapse:_e,onStartVoice:ve,voiceEnabled:ye,headerBgColor:M,onNewChat:be,showPoweredBy:xe,privacyPolicyUrl:N,getVisitorChatHistory:Se,resumeChat:Ce,isSessionRestoring:we,isClosing:Te}){let Ee=c.length>0,De=y||x||v,Oe=!!ce,[ke,Ae]=(0,b.useState)(!1),{resolvedConfig:je}=jn(),Me=je?.siteId||null,[Ne,Pe]=(0,b.useState)(()=>le(Me)===`auto`),Fe=()=>{let e=Ne?`ask`:`auto`;ue(Me,e),Pe(e===`auto`)},[Ie,Le]=(0,b.useState)(!1),[Re,ze]=(0,b.useState)([]),[P,Be]=(0,b.useState)(!1),Ve=(0,b.useRef)(null),[He,Ue]=(0,b.useState)(()=>typeof window<`u`?window.visualViewport?.height??window.innerHeight:600),[We,Ge]=(0,b.useState)(0);(0,b.useEffect)(()=>{if(!s)return;let e=window.visualViewport;if(!e)return;let t=()=>{Ue(e.height),Ge(Math.max(0,window.innerHeight-e.offsetTop-e.height))};return e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),t(),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[s]);let Ke=s&&window.innerHeight-He>150,qe=async()=>{Ae(!1),Le(!0),Be(!0);try{let e=await Se();e?.data&&ze(e.data)}catch(e){console.error(e)}finally{Be(!1)}},Je=async e=>{Le(!1),Ce?.(e.chatId)};return(0,b.useEffect)(()=>{if(!ke)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;Ve.current&&!Ve.current.contains(t)&&Ae(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[ke]),(0,V.jsxs)(`div`,{style:s?{"--flowengage-primary":n,"--flowengage-accent":n,position:`fixed`,left:`0`,right:`0`,bottom:`${We}px`,height:He>0?`${Math.round(He*(Ke?1:.92))}px`:`90dvh`,background:r,borderRadius:`16px 16px 0 0`,display:`flex`,flexDirection:`column`,overflow:`hidden`,animation:Te?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)`}:{"--flowengage-primary":n,"--flowengage-accent":n,width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,background:r,borderRadius:`22px`,boxShadow:`0 24px 64px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08)`,display:`flex`,flexDirection:`column`,overflow:`hidden`,position:`relative`,animation:Te?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)`},children:[(0,V.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`40px minmax(0, 1fr) 40px`,alignItems:`center`,columnGap:`14px`,padding:`16px 10px 14px`,background:M||`transparent`,flexShrink:0,position:`relative`,zIndex:30},children:[(0,V.jsx)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:(0,V.jsx)(`button`,{onClick:_e,style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`,flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},children:(0,V.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})}),(()=>{let t=!!i,n=!!e.hasCustomTitle,r=t||n,a=t||!r,o=n||!r,c=a&&o;return(0,V.jsxs)(`div`,{style:{minWidth:0,maxWidth:s?`100%`:`250px`,width:`100%`,justifySelf:`center`,display:`grid`,gridTemplateColumns:c?`minmax(72px, 40%) minmax(0, 60%)`:`1fr`,columnGap:c?`12px`:0,alignItems:`center`,justifyItems:c?`stretch`:`center`},children:[a&&(0,V.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`,justifyContent:`center`,height:`40px`},children:i?(0,V.jsx)(x_,{logo:i,style:{height:`34px`,width:`100%`,maxWidth:`96px`}}):(0,V.jsx)(`div`,{style:{width:`40px`,height:`40px`,flexShrink:0},children:(0,V.jsx)(S_,{title:e.chatTitle})})}),o&&(0,V.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`,justifyContent:c?`flex-start`:`center`},children:(0,V.jsx)(`span`,{style:{fontSize:`15px`,fontWeight:600,color:`#111827`,letterSpacing:`-0.01em`,lineHeight:1.2,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:e.chatTitle,children:e.chatTitle})})]})})(),(0,V.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:Ve,children:[(0,V.jsx)(`button`,{type:`button`,onClick:()=>Ae(e=>!e),style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},"aria-label":`Chat options`,children:(0,V.jsxs)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.5`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.5`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.5`})]})}),ke&&(0,V.jsxs)(`div`,{style:{position:`absolute`,top:`34px`,right:0,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,overflow:`hidden`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,minWidth:`210px`,border:`1px solid rgba(255,255,255,0.07)`,animation:`fe-orb-fade-in 0.18s ease`},children:[ye&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(!1),ve?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`path`,{d:`M12 1a4 4 0 014 4v6a4 4 0 01-8 0V5a4 4 0 014-4z`}),(0,V.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]}),`Enter Voice Mode`]}),(0,V.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}})]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(!1),be?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`path`,{d:`M12 5H5a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-7`}),(0,V.jsx)(`path`,{d:`M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z`})]}),`Start new chat`]}),Se&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,V.jsxs)(`button`,{type:`button`,onClick:qe,style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`path`,{d:`M12 8v4l3 3M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z`})}),`Chat history`]})]}),Me&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{Fe(),Ae(!1)},style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`8px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,minWidth:0,overflow:`hidden`},children:[(0,V.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:(0,V.jsx)(`polygon`,{points:`3 11 22 2 13 21 11 13 3 11`})}),(0,V.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:`Auto-navigate`})]}),(0,V.jsx)(`span`,{"aria-hidden":!0,style:{width:`34px`,height:`19px`,borderRadius:`999px`,background:Ne?`#22c55e`:`rgba(255,255,255,0.2)`,position:`relative`,flexShrink:0,transition:`background 0.15s ease`},children:(0,V.jsx)(`span`,{style:{position:`absolute`,top:`2px`,left:Ne?`17px`:`2px`,width:`15px`,height:`15px`,borderRadius:`50%`,background:`white`,transition:`left 0.15s ease`}})})]})]}),(0,V.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(!1),_e?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`#f87171`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(248,113,113,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,V.jsx)(`line`,{x1:`15`,y1:`9`,x2:`9`,y2:`15`}),(0,V.jsx)(`line`,{x1:`9`,y1:`9`,x2:`15`,y2:`15`})]}),`Close conversation`]})]})]})]}),(0,V.jsx)(Dg,{webRTCError:oe,micError:k,setMicError:A,dismissCallError:se,isRateLimited:x,rateLimitMessage:S}),he&&(0,V.jsx)(Wg,{agentName:f,agentHeadshot:p,fallbackAgentName:m,callDurationSeconds:me,isCallMuted:de,formatCallDuration:pe,toggleCallMute:j,endWebRTCCall:fe,onExpand:ge,primaryColor:n}),(0,V.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,background:`transparent`,position:`relative`},children:[Ie?(0,V.jsxs)(`div`,{style:{position:`absolute`,inset:0,background:`white`,zIndex:20,display:`flex`,flexDirection:`column`,animation:`fe-orb-fade-in 0.2s ease`},children:[(0,V.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,padding:`16px`,borderBottom:`1px solid #f3f4f6`,flexShrink:0},children:(0,V.jsxs)(`button`,{onClick:()=>Le(!1),style:{background:`none`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,color:`#6b7280`},children:[(0,V.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),(0,V.jsx)(`span`,{style:{marginLeft:`8px`,fontWeight:500,fontSize:`15px`},children:`Return to Chat`})]})}),(0,V.jsx)(`div`,{style:{flex:1,overflowY:`auto`,position:`relative`},children:P?(0,V.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#6b7280`,fontSize:`14px`},children:`Loading past conversations...`}):Re.length>0?(0,V.jsx)(`div`,{children:Re.map(e=>(0,V.jsxs)(`div`,{onClick:()=>Je(e),style:{padding:`16px 20px`,borderBottom:`1px solid #f3f4f6`,cursor:`pointer`,transition:`background 0.15s ease`},onMouseEnter:e=>e.currentTarget.style.background=`#f9fafb`,onMouseLeave:e=>e.currentTarget.style.background=`white`,children:[(0,V.jsxs)(`div`,{style:{fontSize:`12px`,color:`#6b7280`,marginBottom:`6px`,fontWeight:500},children:[new Date(e.createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),` at `,new Date(e.createdAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})]}),(0,V.jsx)(`div`,{style:{fontSize:`14.5px`,color:`#111827`,opacity:.9,overflow:`hidden`,textOverflow:`ellipsis`,display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`,lineHeight:1.4},children:e.message||`Conversation`})]},e.chatId))}):(0,V.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#9ca3af`,fontSize:`14px`},children:`No previous chats found.`})})]}):null,Ee?(0,V.jsx)(wg,{chatHistory:c,isAiTyping:l,isLoading:y,isAgentTyping:u,setReplyContext:ae,TypingDots:k_,primaryColor:n,agentHeadshot:p,agentDisplayName:f||m,botAvatarNode:(0,V.jsx)(O_,{orbColors:t})}):we?(0,V.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`16px`},children:[(0,V.jsx)(`div`,{style:{width:`28px`,height:`28px`,border:`3px solid #f3f4f6`,borderTop:`3px solid ${n}`,borderRadius:`50%`,animation:`spin 1s linear infinite`},children:(0,V.jsx)(`style`,{children:`@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }`})}),(0,V.jsx)(`div`,{style:{color:`#6b7280`,fontSize:`14px`,fontWeight:500,animation:`fe-orb-fade-in 1s infinite alternate`},children:`Loading chat...`})]}):(0,V.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`22px`,padding:`28px 24px`},children:[(0,V.jsx)(w_,{size:94,orbColors:t}),(0,V.jsx)(`p`,{style:{margin:0,textAlign:`center`,fontSize:`16px`,color:`#374151`,lineHeight:1.55,maxWidth:`270px`},children:e.introGreeting}),a.length>0&&(0,V.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`8px`,justifyContent:`center`,width:`100%`,padding:`0 8px`},children:a.map(e=>(0,V.jsx)(`button`,{onClick:()=>o?.(e),style:{padding:`8px 16px`,borderRadius:`999px`,background:`white`,border:`1.5px solid ${n}33`,color:n||`#374151`,fontSize:`13px`,fontWeight:500,cursor:`pointer`,transition:`all 0.15s ease`,boxShadow:`0 1px 4px rgba(0,0,0,0.06)`},onMouseEnter:e=>{e.currentTarget.style.background=`${n}12`,e.currentTarget.style.borderColor=n},onMouseLeave:e=>{e.currentTarget.style.background=`white`,e.currentTarget.style.borderColor=`${n}33`},children:e.label||e.text},e.id))})]})]}),re&&(0,V.jsxs)(`div`,{style:{margin:`0 16px 8px`,padding:`9px 14px`,borderRadius:`12px`,background:`#ecfdf5`,border:`1px solid #6ee7b7`,display:`flex`,alignItems:`center`,gap:`8px`,animation:`fe-orb-fade-in 0.2s ease`,flexShrink:0},children:[(0,V.jsx)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`#10b981`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:(0,V.jsx)(`polyline`,{points:`20 6 9 17 4 12`})}),(0,V.jsx)(`span`,{style:{fontSize:`13px`,fontWeight:500,color:`#065f46`},children:`Email saved — we'll be in touch!`})]}),(0,V.jsx)(`div`,{style:{background:`transparent`,flexShrink:0,position:`relative`,zIndex:1,padding:D?`6px 0 0`:`12px 0 0`},children:(0,V.jsx)(Eg,{input:h,setInput:g,onSubmit:_,isConversationEnded:v,callUiActive:Oe,handleToggleVoice:ve,showVoiceToggle:d===`agent`,activeScreen:d,inputDisabled:De,replyContext:ie,clearReplyContext:()=>ae(null),onFileSelect:w,selectedFile:C,onRemoveSelectedFile:T,attachmentError:E,isUploadingAttachment:ee,requiresEmail:D,emailInput:te,setEmailInput:O,emailError:ne,inputPlaceholder:e.inputPlaceholder})}),!Ke&&(0,V.jsxs)(`div`,{style:{flexShrink:0,textAlign:`center`,padding:`8px 20px`,paddingBottom:`max(12px, env(safe-area-inset-bottom, 12px))`,pointerEvents:`none`},children:[N&&(0,V.jsxs)(`p`,{style:{margin:`0 0 4px`,fontSize:`10px`,color:`#9ca3af`,lineHeight:1.4,userSelect:`none`,pointerEvents:`auto`},children:[`This conversation is recorded for quality assurance purposes.`,` `,(0,V.jsx)(`a`,{href:N,target:`_blank`,rel:`noopener noreferrer`,style:{color:`#6b7280`,textDecoration:`underline`},children:`See our privacy policy`})]}),xe&&(0,V.jsxs)(`span`,{style:{fontSize:`11px`,color:`#9ca3af`,letterSpacing:`0.01em`,userSelect:`none`},children:[`Powered by `,(0,V.jsx)(`strong`,{style:{fontWeight:600,color:`#6b7280`},children:`FlowEngage`})]})]})]})}function j_(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatHistory:r,isOpen:i,activeScreen:a,isHumanHandled:o,agentName:s,agentHeadshot:c,visitorEmail:l,isAgentTyping:u,isAiTyping:d,isLoading:f,isRateLimited:p,rateLimitMessage:m,isConversationEnded:h,incomingCall:g,activeCallId:_,callConnectionState:v,callConnectedAt:y,isCallMuted:x,webRTCError:S,language:C,chatId:w,historyRef:T,onMessageSync:E,beaconSyncVoiceTranscript:ee,sendMessage:D,uploadChatFile:te,openWidget:O,captureVisitorEmail:ne,setVoiceMode:re,endConversation:ie,startNewChat:ae,acceptCall:oe,rejectCall:se,endWebRTCCall:ce,toggleCallMute:le,dismissCallError:ue,startTyping:de,stopTyping:j,updateTypingDraft:fe,getVisitorChatHistory:pe,resumeChat:me,isSessionRestoring:he,openToChatCounter:ge,voiceEndCounter:_e}=jn();(0,b.useEffect)(()=>{try{hr()}catch{}},[]),(0,b.useEffect)(()=>{ge&&L!==`voice_mode`&&L!==`text_chat`&&L!==`call_screen`&&(re?.(!1),et(`text_chat`))},[ge]);let ve=t?.widgetSettings||{},ye=n?.widgetSettings||{},M={...ve.branding||{},...ye.branding||{}},be={...ve.theme||{},...ye.theme||{}},xe={...ve.features||{},...ye.features||{}},N=xe.voice!==!1,Se=Array.isArray(be.orbColors)&&be.orbColors.length>0?be.orbColors:null,Ce=be.buttonColor||be.primaryColor||Se?.[0]||`#3B82F6`,we={small:50,medium:64,large:80},Te=we[be.orbSize]||we.small,Ee=be.position||`bottom-right`,ke=M.fallbackAgentName||`Agent`,Ae=v_(Se??be.chatBgColors),Me=M.logo||M.logoUrl||null,Ne=C||`en`,Fe=ve.recommendations?.[Ne]||[],Ie=(ye.recommendations?.[Ne]??Fe).filter(e=>String(e?.label??``).trim()).map((e,t)=>({id:e.key||`qr-${t}`,label:e.label,message:e.label,text:e.label})),Le=Array.isArray(M.quickChatOptions)&&M.quickChatOptions.length>0?M.quickChatOptions:Ie,Re=M.hideWatermark===!0?!1:M.showPoweredBy!==!1,ze=M.headerBgColor||null,P=be.bottomPosition==null?`1.5rem`:`${be.bottomPosition}px`,Be=M.privacyPolicyUrl||null,Ve=M.chatbotEnabled!==!1&&be.chatbotEnabled!==!1,[He,Ue]=(0,b.useState)(()=>typeof window<`u`?window.location.pathname:`/`);(0,b.useEffect)(()=>{if(typeof window>`u`)return;let e=()=>Ue(window.location.pathname),t=window.history.pushState.bind(window.history);return window.history.pushState=(...n)=>{t(...n),setTimeout(e,50)},window.addEventListener(`popstate`,e),()=>{window.history.pushState=t,window.removeEventListener(`popstate`,e)}},[]);let We=(()=>{let e={...ve.pageVisibility||{},...ye.pageVisibility||{}};return Array.isArray(e.allowedPaths)?e.allowedPaths.filter(Boolean):[]})(),Ge=We.length===0||We.some(e=>e===`*`||e===`/*`?!0:e.endsWith(`/*`)?He.startsWith(e.slice(0,-1)):He.replace(/\/$/,``)===e.replace(/\/$/,``)),Ke=ve.greetings?.[C]||ye.greetings?.[C]||M.introGreeting||`Hello, I'm here to help you know more about OpenSense Labs.`,qe={entryPrompt:M.entryPrompt||`Do you want to explore in a new way?`,yesLabel:M.yesLabel||`Yes`,laterLabel:M.laterLabel||`Later`,connectionTitle:M.connectionTitle||`How would you like to connect?`,connectionSubtitle:M.connectionSubtitle||``,voiceLabel:M.voiceLabel||`Voice`,textLabel:M.textLabel||`Text`,chatTitle:M.headerName||`Chat with FlowEngage`,hasCustomTitle:!!(M.headerName&&String(M.headerName).trim()),introGreeting:Ke,inputPlaceholder:M.inputPlaceholder||`Type your message`,analysingLabel:M.analysingLabel||`analysing...`},Je=ye.elevenLabsAgentId||t?.elevenLabsAgentId||null,Ye=t?.siteId||n?.siteId||null,Xe=t?.apiBaseUrl||``;(0,b.useEffect)(()=>{tr(t?.siteType||null)},[t?.siteType]);let Ze=(0,b.useMemo)(()=>s&&String(s).trim()||t?.ownerName&&String(t.ownerName).trim()||t?.websiteName&&String(t.websiteName).trim()||`Agent`,[s,t?.ownerName,t?.websiteName]),Qe=c&&String(c).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,$e=r.some(e=>e.sender===`user`),F=(0,b.useMemo)(()=>{let e=r.findIndex(e=>e.sender===`user`);return e===-1?!1:r.slice(e+1).some(e=>e.sender===`bot`||e.sender===`ai`||e.sender===`agent`)},[r]),I=!!(ye._dashboardLivePreview||ve._dashboardLivePreview),[L,et]=(0,b.useState)(()=>I?`text_chat`:`entry_prompt`),[tt,nt]=(0,b.useState)(``),[rt,it]=(0,b.useState)(null),[at,ot]=(0,b.useState)(l||``),[st,ct]=(0,b.useState)(``),[lt,ut]=(0,b.useState)(!1),[dt,R]=(0,b.useState)(0),[ft,pt]=(0,b.useState)(null),[z,mt]=(0,b.useState)(null),[ht,gt]=(0,b.useState)(``),[_t,vt]=(0,b.useState)(!1),[yt,bt]=(0,b.useState)(!1),[xt,St]=(0,b.useState)(!1),Ct=(0,b.useRef)(null),wt=(0,b.useRef)(!1),Tt=!l&&$e&&F&&L!==`voice_mode`;(0,b.useLayoutEffect)(()=>{if(e!==`ready`||wt.current)return;if(wt.current=!0,!N){et(`minimized_orb`);return}let t=!1;try{t=Dr().shouldResumeVoice}catch{}let n=je(),r=Ye?De(Ye):null,i=n||!!r?.transcript;if(t){O?.({notifyChatInitiated:!0}),re?.(!0),et(`voice_mode`);return}if(Pe()){O?.({notifyChatInitiated:!1}),et(`text_chat`);return}if(i){if((typeof performance<`u`?performance.getEntriesByType?.(`navigation`)?.[0]?.type??`navigate`:`navigate`)===`reload`){et(`minimized_orb`);return}O?.({notifyChatInitiated:!0}),re?.(!0),et(`voice_mode`);return}if(Ye)try{Oe(Ye)}catch{}if(k(Ye)){et(`minimized_orb`);return}},[e,r]);let[Et,Dt]=(0,b.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: 640px)`).matches);(0,b.useEffect)(()=>{let e=window.matchMedia(`(max-width: 640px)`),t=e=>Dt(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,b.useEffect)(()=>{ot(l||``),l&&ct(``)},[l]);let Ot=(0,b.useCallback)(()=>{mt(null),gt(``)},[]),kt=(0,b.useCallback)(e=>{let t=vg(e);if(t){mt(null),gt(t);return}mt(e),gt(``)},[]);(0,b.useEffect)(()=>{if(!y||v!==`connected`){R(0);return}let e=()=>{let e=new Date(y).getTime();isNaN(e)||R(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[y,v]);let At=(0,b.useCallback)(()=>{et(`call_screen`),bt(!1)},[]),jt=(0,b.useCallback)(()=>{et(`text_chat`),bt(!0)},[]);(0,b.useEffect)(()=>{let e=g?.callId||_||null;if(!e){Ct.current=null;return}if(g?.callId||v===`connecting`||v===`connected`){if(L===`minimized_orb`&&yt&&_&&!g?.callId){Ct.current=e;return}!(!i||L===`minimized_orb`||L===`voice_mode`)&&Ct.current===e||(console.log(`[FlowEngageWidget] forcing call UI to front`,{forcedKey:e,isOpen:i,surface:L,hasIncomingCall:!!g?.callId,activeCallId:_,callConnectionState:v}),Ct.current=e,L===`voice_mode`&&re?.(!1),O?.(),At())}},[_,v,At,g?.callId,i,O,re,L]),(0,b.useEffect)(()=>{!g&&!_&&L===`call_screen`&&et(`text_chat`)},[g,_,L]),(0,b.useEffect)(()=>{!_&&yt&&bt(!1)},[_,yt]),(0,b.useEffect)(()=>{if(!o||h){fe?.(``),j?.();return}if(!tt.trim()||z){fe?.(``);let e=window.setTimeout(()=>j?.(),100);return()=>window.clearTimeout(e)}de?.();let e=window.setTimeout(()=>fe?.(tt),120),t=window.setTimeout(()=>j?.(),1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[tt,z,o,h,de,j,fe]);let Mt=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,Nt=async e=>{if(e.preventDefault(),h)return;if(Tt){let e=at.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){ct(`Please enter a valid email so we can continue helping you.`);return}await ne(e),ct(``),ut(!0),setTimeout(()=>ut(!1),3e3);return}let t=Mt(rt);if(!tt.trim()&&!z)return;if(z){try{vt(!0),gt(``);let e=await te(z),n=e?.data||e,r=tt.trim()||`Shared file: ${bg(z)}`;nt(``),it(null),Ot(),await D(r,``,t,{type:`file`,metadata:{fileUrl:n?.fileUrl,fileName:n?.fileName||z.name,fileType:n?.fileType||z.type,fileSize:n?.fileSize||z.size}})}catch(e){gt(e?.message||`Failed to upload the selected file.`)}finally{vt(!1)}return}let n=tt.trim();nt(``),it(null),await D(n,``,t)},Pt=(0,b.useCallback)(()=>{r.length!==0&&ae?.()},[r.length,ae]),Ft=e=>{let t=Math.floor(e/60);return`${String(t).padStart(2,`0`)}:${String(e%60).padStart(2,`0`)}`},It=(0,b.useCallback)(async e=>{if(h||f)return;let t=e.message||e.label||e.text||``;t.trim()&&await D(t.trim(),``)},[h,f,D]),Lt=Et&&L===`entry_prompt`?{inset:0}:Et&&L===`text_chat`?{left:0,right:0,bottom:0}:Et&&L===`call_screen`?{left:0,right:0,bottom:0,height:`90dvh`,overflow:`hidden`,borderRadius:`16px 16px 0 0`}:Et&&L===`connection_modal`?{left:`12px`,right:`12px`,bottom:`12px`}:L===`call_screen`?{width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,borderRadius:`22px`,overflow:`hidden`,...Ee===`bottom-left`?{left:`1.5rem`,bottom:P}:{right:`1.5rem`,bottom:P}}:Ee===`bottom-left`?{left:`1.5rem`,bottom:P}:{right:`1.5rem`,bottom:P},Rt=(0,b.useCallback)(()=>{L!==`minimized_orb`&&(St(!0),setTimeout(()=>{et(`minimized_orb`),St(!1),_&&bt(!0)},280))},[_,L]),zt=()=>et(`connection_modal`),Bt=()=>{try{let e=window.AudioContext||window.webkitAudioContext;if(e){let t=new e;t.resume().catch(()=>{}),setTimeout(()=>t.close().catch(()=>{}),3e3)}}catch{}O({notifyChatInitiated:!0}),re?.(!0),et(`voice_mode`)},Vt=()=>{O({notifyChatInitiated:!0}),re?.(!1),et(`text_chat`)},Ht=()=>{re?.(!1),Rt()};return e!==`ready`||!Ve||xe.chat===!1||!Ge?null:(0,V.jsxs)(`div`,{className:`flowengage-widget-root`,style:{position:`fixed`,zIndex:999999,...Lt},onWheel:e=>e.stopPropagation(),onTouchMove:e=>e.stopPropagation(),children:[L===`entry_prompt`&&(0,V.jsx)(T_,{copy:qe,orbColors:Se,primaryColor:Ce,onYes:()=>{A(Ye),Bt()},onLater:()=>{A(Ye),Rt()},isMobile:Et,isClosing:xt}),L===`minimized_orb`&&(0,V.jsxs)(Qm.div,{layoutId:`fe-main-orb`,initial:{scale:.4,opacity:0},animate:{scale:1,opacity:1},transition:{type:`spring`,stiffness:280,damping:18},style:{transformOrigin:`bottom right`,display:`inline-flex`,flexDirection:`column`,alignItems:Ee===`bottom-left`?`flex-start`:`flex-end`,gap:`10px`},children:[_&&(0,V.jsxs)(`button`,{type:`button`,onClick:At,style:{maxWidth:Et?`220px`:`240px`,padding:`10px 14px`,borderRadius:`18px`,border:`1px solid rgba(255,255,255,0.7)`,background:`rgba(255,255,255,0.94)`,backdropFilter:`blur(18px)`,WebkitBackdropFilter:`blur(18px)`,boxShadow:`0 10px 26px rgba(15,23,42,0.14)`,display:`flex`,alignItems:`center`,gap:`10px`,cursor:`pointer`,textAlign:`left`},children:[(0,V.jsx)(`span`,{style:{width:`9px`,height:`9px`,borderRadius:`50%`,background:`#22c55e`,boxShadow:`0 0 0 4px rgba(34,197,94,0.16)`,flexShrink:0}}),(0,V.jsxs)(`span`,{style:{minWidth:0},children:[(0,V.jsx)(`span`,{style:{display:`block`,fontSize:`12px`,fontWeight:700,color:`#111827`,lineHeight:1.2},children:v===`connected`?`Call in progress`:`Call is active`}),(0,V.jsx)(`span`,{style:{display:`block`,fontSize:`11px`,color:`#6b7280`,lineHeight:1.3,marginTop:`2px`,whiteSpace:`nowrap`},children:v===`connected`?`${Ft(dt)} with ${Ze}`:`Tap to return to ${Ze}`})]})]}),(0,V.jsx)(w_,{size:Te,orbColors:Se,onClick:_?At:N?zt:Vt})]}),L===`connection_modal`&&(0,V.jsx)(E_,{copy:qe,orbColors:Se,primaryColor:Ce,onVoice:Bt,onText:Vt,onClose:Rt,isMobile:Et,isClosing:xt}),L===`voice_mode`&&(0,V.jsx)(D_,{orbColors:Se,onEnterChat:Vt,onEndChat:Ht,agentId:Je,siteId:Ye,apiBaseUrl:Xe,chatId:w,historyRef:T,onMessageSync:E,beaconSyncVoiceTranscript:ee,widgetPosition:Ee,voiceEndCounter:_e,websiteName:t?.websiteName,voiceFirstMessage:ve.voiceFirstMessage||null,captureVisitorEmail:ne,emailRequired:!l,emailCaptureEnabled:xe.emailCapture!==!1&&M.disableEmailCapture!==!0,listeningLabel:M.voiceListeningLabel||`Listening...`,thinkingLabel:M.voiceThinkingLabel||`Thinking...`,enterChatModeLabel:M.voiceEnterChatLabel||`Enter Chat Mode`,endConversationLabel:M.voiceEndConversationLabel||`End Conversation`},`voice`),L===`call_screen`&&(0,V.jsx)(Ug,{incomingCall:g,activeCallId:_,callConnectionState:v,callDurationSeconds:dt,isCallMuted:x,agentName:Ze,agentHeadshot:Qe,fallbackAgentName:ke,acceptCall:oe,rejectCall:se,endWebRTCCall:ce,toggleCallMute:le,formatCallDuration:Ft,onMinimize:jt,primaryColor:Ce,orbColors:Se,chatHistory:r}),L===`text_chat`&&(0,V.jsx)(A_,{isClosing:xt,copy:qe,orbColors:Se,primaryColor:Ce,chatBgGradient:Ae,logo:Me,quickChatOptions:Le,onQuickChatSelect:It,isMobile:Et,chatHistory:r,isAiTyping:d,isAgentTyping:u,activeScreen:a,agentName:Ze,agentHeadshot:Qe,fallbackAgentName:ke,input:tt,setInput:nt,onSubmit:Nt,isConversationEnded:h,isLoading:f,isRateLimited:p,rateLimitMessage:m,selectedFile:z,onFileSelect:kt,onRemoveSelectedFile:Ot,attachmentError:ht,isUploadingAttachment:_t,requiresEmail:Tt,emailInput:at,setEmailInput:ot,emailError:st,emailCaptureSuccess:lt,replyContext:rt,setReplyContext:it,webRTCError:S,micError:ft,setMicError:pt,dismissCallError:ue,activeCallId:_,isCallMuted:x,toggleCallMute:le,endWebRTCCall:ce,formatCallDuration:Ft,callDurationSeconds:dt,onCollapse:Rt,onStartVoice:Bt,voiceEnabled:N,onNewChat:Pt,onMinimize:jt,onExpand:At,isCallMinimized:!!_,showPoweredBy:Re,privacyPolicyUrl:Be,headerBgColor:ze,getVisitorChatHistory:pe,resumeChat:me,isSessionRestoring:he}),(0,V.jsx)(`style`,{children:`
|
|
435
|
+
`.replace(/\s+/g,` `).trim()}})}var N_=()=>(0,V.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,V.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`12px 16px`,borderRadius:`18px`,background:`#fff`,boxShadow:`0 2px 6px rgba(0,0,0,0.04)`},children:[0,1,2].map(e=>(0,V.jsx)(`span`,{style:{width:`7px`,height:`7px`,borderRadius:`50%`,background:`#9ca3af`,animation:`fe-dot-bounce 1.2s ease-in-out ${e*.2}s infinite`,display:`inline-block`}},e))})});function P_({copy:e,orbColors:t,primaryColor:n,chatBgGradient:r,logo:i,quickChatOptions:a,onQuickChatSelect:o,isMobile:s,chatHistory:c,isAiTyping:l,isAgentTyping:u,activeScreen:d,agentName:f,agentHeadshot:p,fallbackAgentName:m,input:h,setInput:g,onSubmit:_,isConversationEnded:v,isLoading:y,isRateLimited:x,rateLimitMessage:S,selectedFile:C,onFileSelect:w,onRemoveSelectedFile:T,attachmentError:E,isUploadingAttachment:ee,requiresEmail:D,emailInput:te,setEmailInput:O,emailError:ne,emailCaptureSuccess:re,replyContext:ie,setReplyContext:ae,webRTCError:oe,micError:k,setMicError:A,dismissCallError:se,activeCallId:ce,isCallMuted:de,toggleCallMute:j,endWebRTCCall:fe,formatCallDuration:pe,callDurationSeconds:me,isCallMinimized:he,onExpand:ge,onCollapse:_e,onStartVoice:ve,voiceEnabled:ye,headerBgColor:M,onNewChat:be,showPoweredBy:xe,privacyPolicyUrl:N,getVisitorChatHistory:Se,resumeChat:Ce,isSessionRestoring:we,isClosing:Te}){let Ee=c.length>0,De=y||x||v,Oe=!!ce,[ke,Ae]=(0,b.useState)(!1),{resolvedConfig:je}=jn(),Me=je?.siteId||null,[Ne,Pe]=(0,b.useState)(()=>le(Me)===`auto`),Fe=()=>{let e=Ne?`ask`:`auto`;ue(Me,e),Pe(e===`auto`)},[Ie,Le]=(0,b.useState)(!1),[Re,ze]=(0,b.useState)([]),[P,Be]=(0,b.useState)(!1),Ve=(0,b.useRef)(null),[He,Ue]=(0,b.useState)(()=>typeof window<`u`?window.visualViewport?.height??window.innerHeight:600),[We,Ge]=(0,b.useState)(0);(0,b.useEffect)(()=>{if(!s)return;let e=window.visualViewport;if(!e)return;let t=()=>{Ue(e.height),Ge(Math.max(0,window.innerHeight-e.offsetTop-e.height))};return e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),t(),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[s]);let Ke=s&&window.innerHeight-He>150,qe=async()=>{Ae(!1),Le(!0),Be(!0);try{let e=await Se();e?.data&&ze(e.data)}catch(e){console.error(e)}finally{Be(!1)}},Je=async e=>{Le(!1),Ce?.(e.chatId)};return(0,b.useEffect)(()=>{if(!ke)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;Ve.current&&!Ve.current.contains(t)&&Ae(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[ke]),(0,V.jsxs)(`div`,{style:s?{"--flowengage-primary":n,"--flowengage-accent":n,position:`fixed`,left:`0`,right:`0`,bottom:`${We}px`,height:He>0?`${Math.round(He*(Ke?1:.92))}px`:`90dvh`,background:r,borderRadius:`16px 16px 0 0`,display:`flex`,flexDirection:`column`,overflow:`hidden`,animation:Te?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)`}:{"--flowengage-primary":n,"--flowengage-accent":n,width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,background:r,borderRadius:`22px`,boxShadow:`0 24px 64px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08)`,display:`flex`,flexDirection:`column`,overflow:`hidden`,position:`relative`,animation:Te?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)`},children:[(0,V.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`40px minmax(0, 1fr) 40px`,alignItems:`center`,columnGap:`14px`,padding:`16px 10px 14px`,background:M||`transparent`,flexShrink:0,position:`relative`,zIndex:30},children:[(0,V.jsx)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:(0,V.jsx)(`button`,{onClick:_e,style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`,flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},children:(0,V.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})}),(()=>{let t=!!i,n=!!e.hasCustomTitle,r=t||n,a=t||!r,o=n||!r,c=a&&o;return(0,V.jsxs)(`div`,{style:{minWidth:0,maxWidth:s?`100%`:`250px`,width:`100%`,justifySelf:`center`,display:`grid`,gridTemplateColumns:c?`minmax(72px, 40%) minmax(0, 60%)`:`1fr`,columnGap:c?`12px`:0,alignItems:`center`,justifyItems:c?`stretch`:`center`},children:[a&&(0,V.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`,justifyContent:`center`,height:`40px`},children:i?(0,V.jsx)(T_,{logo:i,style:{height:`34px`,width:`100%`,maxWidth:`96px`}}):(0,V.jsx)(`div`,{style:{width:`40px`,height:`40px`,flexShrink:0},children:(0,V.jsx)(E_,{title:e.chatTitle})})}),o&&(0,V.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`,justifyContent:c?`flex-start`:`center`},children:(0,V.jsx)(`span`,{style:{fontSize:`15px`,fontWeight:600,color:`#111827`,letterSpacing:`-0.01em`,lineHeight:1.2,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:e.chatTitle,children:e.chatTitle})})]})})(),(0,V.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:Ve,children:[(0,V.jsx)(`button`,{type:`button`,onClick:()=>Ae(e=>!e),style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},"aria-label":`Chat options`,children:(0,V.jsxs)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.5`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.5`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.5`})]})}),ke&&(0,V.jsxs)(`div`,{style:{position:`absolute`,top:`34px`,right:0,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,overflow:`hidden`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,minWidth:`210px`,border:`1px solid rgba(255,255,255,0.07)`,animation:`fe-orb-fade-in 0.18s ease`},children:[ye&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(!1),ve?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`path`,{d:`M12 1a4 4 0 014 4v6a4 4 0 01-8 0V5a4 4 0 014-4z`}),(0,V.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]}),`Enter Voice Mode`]}),(0,V.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}})]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(!1),be?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`path`,{d:`M12 5H5a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-7`}),(0,V.jsx)(`path`,{d:`M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z`})]}),`Start new chat`]}),Se&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,V.jsxs)(`button`,{type:`button`,onClick:qe,style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`path`,{d:`M12 8v4l3 3M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z`})}),`Chat history`]})]}),Me&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{Fe(),Ae(!1)},style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`8px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,minWidth:0,overflow:`hidden`},children:[(0,V.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:(0,V.jsx)(`polygon`,{points:`3 11 22 2 13 21 11 13 3 11`})}),(0,V.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:`Auto-navigate`})]}),(0,V.jsx)(`span`,{"aria-hidden":!0,style:{width:`34px`,height:`19px`,borderRadius:`999px`,background:Ne?`#22c55e`:`rgba(255,255,255,0.2)`,position:`relative`,flexShrink:0,transition:`background 0.15s ease`},children:(0,V.jsx)(`span`,{style:{position:`absolute`,top:`2px`,left:Ne?`17px`:`2px`,width:`15px`,height:`15px`,borderRadius:`50%`,background:`white`,transition:`left 0.15s ease`}})})]})]}),(0,V.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(!1),_e?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`#f87171`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(248,113,113,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,V.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,V.jsx)(`line`,{x1:`15`,y1:`9`,x2:`9`,y2:`15`}),(0,V.jsx)(`line`,{x1:`9`,y1:`9`,x2:`15`,y2:`15`})]}),`Close conversation`]})]})]})]}),(0,V.jsx)(jg,{webRTCError:oe,micError:k,setMicError:A,dismissCallError:se,isRateLimited:x,rateLimitMessage:S}),he&&(0,V.jsx)(Jg,{agentName:f,agentHeadshot:p,fallbackAgentName:m,callDurationSeconds:me,isCallMuted:de,formatCallDuration:pe,toggleCallMute:j,endWebRTCCall:fe,onExpand:ge,primaryColor:n}),(0,V.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,background:`transparent`,position:`relative`},children:[Ie?(0,V.jsxs)(`div`,{style:{position:`absolute`,inset:0,background:`white`,zIndex:20,display:`flex`,flexDirection:`column`,animation:`fe-orb-fade-in 0.2s ease`},children:[(0,V.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,padding:`16px`,borderBottom:`1px solid #f3f4f6`,flexShrink:0},children:(0,V.jsxs)(`button`,{onClick:()=>Le(!1),style:{background:`none`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,color:`#6b7280`},children:[(0,V.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),(0,V.jsx)(`span`,{style:{marginLeft:`8px`,fontWeight:500,fontSize:`15px`},children:`Return to Chat`})]})}),(0,V.jsx)(`div`,{style:{flex:1,overflowY:`auto`,position:`relative`},children:P?(0,V.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#6b7280`,fontSize:`14px`},children:`Loading past conversations...`}):Re.length>0?(0,V.jsx)(`div`,{children:Re.map(e=>(0,V.jsxs)(`div`,{onClick:()=>Je(e),style:{padding:`16px 20px`,borderBottom:`1px solid #f3f4f6`,cursor:`pointer`,transition:`background 0.15s ease`},onMouseEnter:e=>e.currentTarget.style.background=`#f9fafb`,onMouseLeave:e=>e.currentTarget.style.background=`white`,children:[(0,V.jsxs)(`div`,{style:{fontSize:`12px`,color:`#6b7280`,marginBottom:`6px`,fontWeight:500},children:[new Date(e.createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),` at `,new Date(e.createdAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})]}),(0,V.jsx)(`div`,{style:{fontSize:`14.5px`,color:`#111827`,opacity:.9,overflow:`hidden`,textOverflow:`ellipsis`,display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`,lineHeight:1.4},children:e.message||`Conversation`})]},e.chatId))}):(0,V.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#9ca3af`,fontSize:`14px`},children:`No previous chats found.`})})]}):null,Ee?(0,V.jsx)(Og,{chatHistory:c,isAiTyping:l,isLoading:y,isAgentTyping:u,setReplyContext:ae,TypingDots:N_,primaryColor:n,agentHeadshot:p,agentDisplayName:f||m,botAvatarNode:(0,V.jsx)(M_,{orbColors:t})}):we?(0,V.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`16px`},children:[(0,V.jsx)(`div`,{style:{width:`28px`,height:`28px`,border:`3px solid #f3f4f6`,borderTop:`3px solid ${n}`,borderRadius:`50%`,animation:`spin 1s linear infinite`},children:(0,V.jsx)(`style`,{children:`@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }`})}),(0,V.jsx)(`div`,{style:{color:`#6b7280`,fontSize:`14px`,fontWeight:500,animation:`fe-orb-fade-in 1s infinite alternate`},children:`Loading chat...`})]}):(0,V.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`22px`,padding:`28px 24px`},children:[(0,V.jsx)(O_,{size:94,orbColors:t}),(0,V.jsx)(`p`,{style:{margin:0,textAlign:`center`,fontSize:`16px`,color:`#374151`,lineHeight:1.55,maxWidth:`270px`},children:e.introGreeting}),a.length>0&&(0,V.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`8px`,justifyContent:`center`,width:`100%`,padding:`0 8px`},children:a.map(e=>(0,V.jsx)(`button`,{onClick:()=>o?.(e),style:{padding:`8px 16px`,borderRadius:`999px`,background:`white`,border:`1.5px solid ${n}33`,color:n||`#374151`,fontSize:`13px`,fontWeight:500,cursor:`pointer`,transition:`all 0.15s ease`,boxShadow:`0 1px 4px rgba(0,0,0,0.06)`},onMouseEnter:e=>{e.currentTarget.style.background=`${n}12`,e.currentTarget.style.borderColor=n},onMouseLeave:e=>{e.currentTarget.style.background=`white`,e.currentTarget.style.borderColor=`${n}33`},children:e.label||e.text},e.id))})]})]}),re&&(0,V.jsxs)(`div`,{style:{margin:`0 16px 8px`,padding:`9px 14px`,borderRadius:`12px`,background:`#ecfdf5`,border:`1px solid #6ee7b7`,display:`flex`,alignItems:`center`,gap:`8px`,animation:`fe-orb-fade-in 0.2s ease`,flexShrink:0},children:[(0,V.jsx)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`#10b981`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:(0,V.jsx)(`polyline`,{points:`20 6 9 17 4 12`})}),(0,V.jsx)(`span`,{style:{fontSize:`13px`,fontWeight:500,color:`#065f46`},children:`Email saved — we'll be in touch!`})]}),(0,V.jsx)(`div`,{style:{background:`transparent`,flexShrink:0,position:`relative`,zIndex:1,padding:D?`6px 0 0`:`12px 0 0`},children:(0,V.jsx)(Ag,{input:h,setInput:g,onSubmit:_,isConversationEnded:v,callUiActive:Oe,handleToggleVoice:ve,showVoiceToggle:d===`agent`,activeScreen:d,inputDisabled:De,replyContext:ie,clearReplyContext:()=>ae(null),onFileSelect:w,selectedFile:C,onRemoveSelectedFile:T,attachmentError:E,isUploadingAttachment:ee,requiresEmail:D,emailInput:te,setEmailInput:O,emailError:ne,inputPlaceholder:e.inputPlaceholder})}),!Ke&&(0,V.jsxs)(`div`,{style:{flexShrink:0,textAlign:`center`,padding:`8px 20px`,paddingBottom:`max(12px, env(safe-area-inset-bottom, 12px))`,pointerEvents:`none`},children:[N&&(0,V.jsxs)(`p`,{style:{margin:`0 0 4px`,fontSize:`10px`,color:`#9ca3af`,lineHeight:1.4,userSelect:`none`,pointerEvents:`auto`},children:[`This conversation is recorded for quality assurance purposes.`,` `,(0,V.jsx)(`a`,{href:N,target:`_blank`,rel:`noopener noreferrer`,style:{color:`#6b7280`,textDecoration:`underline`},children:`See our privacy policy`})]}),xe&&(0,V.jsxs)(`span`,{style:{fontSize:`11px`,color:`#9ca3af`,letterSpacing:`0.01em`,userSelect:`none`},children:[`Powered by `,(0,V.jsx)(`strong`,{style:{fontWeight:600,color:`#6b7280`},children:`FlowEngage`})]})]})]})}function F_(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatHistory:r,isOpen:i,activeScreen:a,isHumanHandled:o,agentName:s,agentHeadshot:c,visitorEmail:l,isAgentTyping:u,isAiTyping:d,isLoading:f,isRateLimited:p,rateLimitMessage:m,isConversationEnded:h,incomingCall:g,activeCallId:_,callConnectionState:v,callConnectedAt:y,isCallMuted:x,webRTCError:S,language:C,chatId:w,historyRef:T,onMessageSync:E,beaconSyncVoiceTranscript:ee,sendMessage:D,uploadChatFile:te,openWidget:O,captureVisitorEmail:ne,setVoiceMode:re,endConversation:ie,startNewChat:ae,acceptCall:oe,rejectCall:se,endWebRTCCall:ce,toggleCallMute:le,dismissCallError:ue,startTyping:de,stopTyping:j,updateTypingDraft:fe,getVisitorChatHistory:pe,resumeChat:me,isSessionRestoring:he,openToChatCounter:ge,voiceEndCounter:_e}=jn();(0,b.useEffect)(()=>{try{hr()}catch{}},[]),(0,b.useEffect)(()=>{ge&&L!==`voice_mode`&&L!==`text_chat`&&L!==`call_screen`&&(re?.(!1),et(`text_chat`))},[ge]);let ve=t?.widgetSettings||{},ye=n?.widgetSettings||{},M={...ve.branding||{},...ye.branding||{}},be={...ve.theme||{},...ye.theme||{}},xe={...ve.features||{},...ye.features||{}},N=xe.voice!==!1,Se=Array.isArray(be.orbColors)&&be.orbColors.length>0?be.orbColors:null,Ce=be.buttonColor||be.primaryColor||Se?.[0]||`#3B82F6`,we={small:50,medium:64,large:80},Te=we[be.orbSize]||we.small,Ee=be.position||`bottom-right`,ke=M.fallbackAgentName||`Agent`,Ae=S_(Se??be.chatBgColors),Me=M.logo||M.logoUrl||null,Ne=C||`en`,Fe=ve.recommendations?.[Ne]||[],Ie=(ye.recommendations?.[Ne]??Fe).filter(e=>String(e?.label??``).trim()).map((e,t)=>({id:e.key||`qr-${t}`,label:e.label,message:e.label,text:e.label})),Le=Array.isArray(M.quickChatOptions)&&M.quickChatOptions.length>0?M.quickChatOptions:Ie,Re=M.hideWatermark===!0?!1:M.showPoweredBy!==!1,ze=M.headerBgColor||null,P=be.bottomPosition==null?`1.5rem`:`${be.bottomPosition}px`,Be=M.privacyPolicyUrl||null,Ve=M.chatbotEnabled!==!1&&be.chatbotEnabled!==!1,[He,Ue]=(0,b.useState)(()=>typeof window<`u`?window.location.pathname:`/`);(0,b.useEffect)(()=>{if(typeof window>`u`)return;let e=()=>Ue(window.location.pathname),t=window.history.pushState.bind(window.history);return window.history.pushState=(...n)=>{t(...n),setTimeout(e,50)},window.addEventListener(`popstate`,e),()=>{window.history.pushState=t,window.removeEventListener(`popstate`,e)}},[]);let We=(()=>{let e={...ve.pageVisibility||{},...ye.pageVisibility||{}};return Array.isArray(e.allowedPaths)?e.allowedPaths.filter(Boolean):[]})(),Ge=We.length===0||We.some(e=>e===`*`||e===`/*`?!0:e.endsWith(`/*`)?He.startsWith(e.slice(0,-1)):He.replace(/\/$/,``)===e.replace(/\/$/,``)),Ke=ve.greetings?.[C]||ye.greetings?.[C]||M.introGreeting||`Hello, I'm here to help you know more about OpenSense Labs.`,qe={entryPrompt:M.entryPrompt||`Do you want to explore in a new way?`,yesLabel:M.yesLabel||`Yes`,laterLabel:M.laterLabel||`Later`,connectionTitle:M.connectionTitle||`How would you like to connect?`,connectionSubtitle:M.connectionSubtitle||``,voiceLabel:M.voiceLabel||`Voice`,textLabel:M.textLabel||`Text`,chatTitle:M.headerName||`Chat with FlowEngage`,hasCustomTitle:!!(M.headerName&&String(M.headerName).trim()),introGreeting:Ke,inputPlaceholder:M.inputPlaceholder||`Type your message`,analysingLabel:M.analysingLabel||`analysing...`},Je=ye.elevenLabsAgentId||t?.elevenLabsAgentId||null,Ye=t?.siteId||n?.siteId||null,Xe=t?.apiBaseUrl||``;(0,b.useEffect)(()=>{tr(t?.siteType||null)},[t?.siteType]);let Ze=(0,b.useMemo)(()=>s&&String(s).trim()||t?.ownerName&&String(t.ownerName).trim()||t?.websiteName&&String(t.websiteName).trim()||`Agent`,[s,t?.ownerName,t?.websiteName]),Qe=c&&String(c).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,$e=r.some(e=>e.sender===`user`),F=(0,b.useMemo)(()=>{let e=r.findIndex(e=>e.sender===`user`);return e===-1?!1:r.slice(e+1).some(e=>e.sender===`bot`||e.sender===`ai`||e.sender===`agent`)},[r]),I=!!(ye._dashboardLivePreview||ve._dashboardLivePreview),[L,et]=(0,b.useState)(()=>I?`text_chat`:`entry_prompt`),[tt,nt]=(0,b.useState)(``),[rt,it]=(0,b.useState)(null),[at,ot]=(0,b.useState)(l||``),[st,ct]=(0,b.useState)(``),[lt,ut]=(0,b.useState)(!1),[dt,R]=(0,b.useState)(0),[ft,pt]=(0,b.useState)(null),[z,mt]=(0,b.useState)(null),[ht,gt]=(0,b.useState)(``),[_t,vt]=(0,b.useState)(!1),[yt,bt]=(0,b.useState)(!1),[xt,St]=(0,b.useState)(!1),Ct=(0,b.useRef)(null),wt=(0,b.useRef)(!1),Tt=!l&&$e&&F&&L!==`voice_mode`;(0,b.useLayoutEffect)(()=>{if(e!==`ready`||wt.current)return;if(wt.current=!0,!N){et(`minimized_orb`);return}let t=!1;try{t=Dr().shouldResumeVoice}catch{}let n=je(),r=Ye?De(Ye):null,i=n||!!r?.transcript;if(t){O?.({notifyChatInitiated:!0}),re?.(!0),et(`voice_mode`);return}if(Pe()){O?.({notifyChatInitiated:!1}),et(`text_chat`);return}if(i){if((typeof performance<`u`?performance.getEntriesByType?.(`navigation`)?.[0]?.type??`navigate`:`navigate`)===`reload`){et(`minimized_orb`);return}O?.({notifyChatInitiated:!0}),re?.(!0),et(`voice_mode`);return}if(Ye)try{Oe(Ye)}catch{}if(k(Ye)){et(`minimized_orb`);return}},[e,r]);let[Et,Dt]=(0,b.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: 640px)`).matches);(0,b.useEffect)(()=>{let e=window.matchMedia(`(max-width: 640px)`),t=e=>Dt(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,b.useEffect)(()=>{ot(l||``),l&&ct(``)},[l]);let Ot=(0,b.useCallback)(()=>{mt(null),gt(``)},[]),kt=(0,b.useCallback)(e=>{let t=Sg(e);if(t){mt(null),gt(t);return}mt(e),gt(``)},[]);(0,b.useEffect)(()=>{if(!y||v!==`connected`){R(0);return}let e=()=>{let e=new Date(y).getTime();isNaN(e)||R(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[y,v]);let At=(0,b.useCallback)(()=>{et(`call_screen`),bt(!1)},[]),jt=(0,b.useCallback)(()=>{et(`text_chat`),bt(!0)},[]);(0,b.useEffect)(()=>{let e=g?.callId||_||null;if(!e){Ct.current=null;return}if(g?.callId||v===`connecting`||v===`connected`){if(L===`minimized_orb`&&yt&&_&&!g?.callId){Ct.current=e;return}!(!i||L===`minimized_orb`||L===`voice_mode`)&&Ct.current===e||(console.log(`[FlowEngageWidget] forcing call UI to front`,{forcedKey:e,isOpen:i,surface:L,hasIncomingCall:!!g?.callId,activeCallId:_,callConnectionState:v}),Ct.current=e,L===`voice_mode`&&re?.(!1),O?.(),At())}},[_,v,At,g?.callId,i,O,re,L]),(0,b.useEffect)(()=>{!g&&!_&&L===`call_screen`&&et(`text_chat`)},[g,_,L]),(0,b.useEffect)(()=>{!_&&yt&&bt(!1)},[_,yt]),(0,b.useEffect)(()=>{if(!o||h){fe?.(``),j?.();return}if(!tt.trim()||z){fe?.(``);let e=window.setTimeout(()=>j?.(),100);return()=>window.clearTimeout(e)}de?.();let e=window.setTimeout(()=>fe?.(tt),120),t=window.setTimeout(()=>j?.(),1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[tt,z,o,h,de,j,fe]);let Mt=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,Nt=async e=>{if(e.preventDefault(),h)return;if(Tt){let e=at.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){ct(`Please enter a valid email so we can continue helping you.`);return}await ne(e),ct(``),ut(!0),setTimeout(()=>ut(!1),3e3);return}let t=Mt(rt);if(!tt.trim()&&!z)return;if(z){try{vt(!0),gt(``);let e=await te(z),n=e?.data||e,r=tt.trim()||`Shared file: ${wg(z)}`;nt(``),it(null),Ot(),await D(r,``,t,{type:`file`,metadata:{fileUrl:n?.fileUrl,fileName:n?.fileName||z.name,fileType:n?.fileType||z.type,fileSize:n?.fileSize||z.size}})}catch(e){gt(e?.message||`Failed to upload the selected file.`)}finally{vt(!1)}return}let n=tt.trim();nt(``),it(null),await D(n,``,t)},Pt=(0,b.useCallback)(()=>{r.length!==0&&ae?.()},[r.length,ae]),Ft=e=>{let t=Math.floor(e/60);return`${String(t).padStart(2,`0`)}:${String(e%60).padStart(2,`0`)}`},It=(0,b.useCallback)(async e=>{if(h||f)return;let t=e.message||e.label||e.text||``;t.trim()&&await D(t.trim(),``)},[h,f,D]),Lt=Et&&L===`entry_prompt`?{inset:0}:Et&&L===`text_chat`?{left:0,right:0,bottom:0}:Et&&L===`call_screen`?{left:0,right:0,bottom:0,height:`90dvh`,overflow:`hidden`,borderRadius:`16px 16px 0 0`}:Et&&L===`connection_modal`?{left:`12px`,right:`12px`,bottom:`12px`}:L===`call_screen`?{width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,borderRadius:`22px`,overflow:`hidden`,...Ee===`bottom-left`?{left:`1.5rem`,bottom:P}:{right:`1.5rem`,bottom:P}}:Ee===`bottom-left`?{left:`1.5rem`,bottom:P}:{right:`1.5rem`,bottom:P},Rt=(0,b.useCallback)(()=>{L!==`minimized_orb`&&(St(!0),setTimeout(()=>{et(`minimized_orb`),St(!1),_&&bt(!0)},280))},[_,L]),zt=()=>et(`connection_modal`),Bt=()=>{try{let e=window.AudioContext||window.webkitAudioContext;if(e){let t=new e;t.resume().catch(()=>{}),setTimeout(()=>t.close().catch(()=>{}),3e3)}}catch{}O({notifyChatInitiated:!0}),re?.(!0),et(`voice_mode`)},Vt=()=>{O({notifyChatInitiated:!0}),re?.(!1),et(`text_chat`)},Ht=()=>{re?.(!1),Rt()};return e!==`ready`||!Ve||xe.chat===!1||!Ge?null:(0,V.jsxs)(`div`,{className:`flowengage-widget-root`,style:{position:`fixed`,zIndex:999999,...Lt},onWheel:e=>e.stopPropagation(),onTouchMove:e=>e.stopPropagation(),children:[L===`entry_prompt`&&(0,V.jsx)(k_,{copy:qe,orbColors:Se,primaryColor:Ce,onYes:()=>{A(Ye),Bt()},onLater:()=>{A(Ye),Rt()},isMobile:Et,isClosing:xt}),L===`minimized_orb`&&(0,V.jsxs)(Qm.div,{layoutId:`fe-main-orb`,initial:{scale:.4,opacity:0},animate:{scale:1,opacity:1},transition:{type:`spring`,stiffness:280,damping:18},style:{transformOrigin:`bottom right`,display:`inline-flex`,flexDirection:`column`,alignItems:Ee===`bottom-left`?`flex-start`:`flex-end`,gap:`10px`},children:[_&&(0,V.jsxs)(`button`,{type:`button`,onClick:At,style:{maxWidth:Et?`220px`:`240px`,padding:`10px 14px`,borderRadius:`18px`,border:`1px solid rgba(255,255,255,0.7)`,background:`rgba(255,255,255,0.94)`,backdropFilter:`blur(18px)`,WebkitBackdropFilter:`blur(18px)`,boxShadow:`0 10px 26px rgba(15,23,42,0.14)`,display:`flex`,alignItems:`center`,gap:`10px`,cursor:`pointer`,textAlign:`left`},children:[(0,V.jsx)(`span`,{style:{width:`9px`,height:`9px`,borderRadius:`50%`,background:`#22c55e`,boxShadow:`0 0 0 4px rgba(34,197,94,0.16)`,flexShrink:0}}),(0,V.jsxs)(`span`,{style:{minWidth:0},children:[(0,V.jsx)(`span`,{style:{display:`block`,fontSize:`12px`,fontWeight:700,color:`#111827`,lineHeight:1.2},children:v===`connected`?`Call in progress`:`Call is active`}),(0,V.jsx)(`span`,{style:{display:`block`,fontSize:`11px`,color:`#6b7280`,lineHeight:1.3,marginTop:`2px`,whiteSpace:`nowrap`},children:v===`connected`?`${Ft(dt)} with ${Ze}`:`Tap to return to ${Ze}`})]})]}),(0,V.jsx)(O_,{size:Te,orbColors:Se,onClick:_?At:N?zt:Vt})]}),L===`connection_modal`&&(0,V.jsx)(A_,{copy:qe,orbColors:Se,primaryColor:Ce,onVoice:Bt,onText:Vt,onClose:Rt,isMobile:Et,isClosing:xt}),L===`voice_mode`&&(0,V.jsx)(j_,{orbColors:Se,onEnterChat:Vt,onEndChat:Ht,agentId:Je,siteId:Ye,apiBaseUrl:Xe,chatId:w,historyRef:T,onMessageSync:E,beaconSyncVoiceTranscript:ee,widgetPosition:Ee,voiceEndCounter:_e,websiteName:t?.websiteName,voiceFirstMessage:ve.voiceFirstMessage||null,captureVisitorEmail:ne,emailRequired:!l,emailCaptureEnabled:xe.emailCapture!==!1&&M.disableEmailCapture!==!0,listeningLabel:M.voiceListeningLabel||`Listening...`,thinkingLabel:M.voiceThinkingLabel||`Thinking...`,enterChatModeLabel:M.voiceEnterChatLabel||`Enter Chat Mode`,endConversationLabel:M.voiceEndConversationLabel||`End Conversation`},`voice`),L===`call_screen`&&(0,V.jsx)(qg,{incomingCall:g,activeCallId:_,callConnectionState:v,callDurationSeconds:dt,isCallMuted:x,agentName:Ze,agentHeadshot:Qe,fallbackAgentName:ke,acceptCall:oe,rejectCall:se,endWebRTCCall:ce,toggleCallMute:le,formatCallDuration:Ft,onMinimize:jt,primaryColor:Ce,orbColors:Se,chatHistory:r}),L===`text_chat`&&(0,V.jsx)(P_,{isClosing:xt,copy:qe,orbColors:Se,primaryColor:Ce,chatBgGradient:Ae,logo:Me,quickChatOptions:Le,onQuickChatSelect:It,isMobile:Et,chatHistory:r,isAiTyping:d,isAgentTyping:u,activeScreen:a,agentName:Ze,agentHeadshot:Qe,fallbackAgentName:ke,input:tt,setInput:nt,onSubmit:Nt,isConversationEnded:h,isLoading:f,isRateLimited:p,rateLimitMessage:m,selectedFile:z,onFileSelect:kt,onRemoveSelectedFile:Ot,attachmentError:ht,isUploadingAttachment:_t,requiresEmail:Tt,emailInput:at,setEmailInput:ot,emailError:st,emailCaptureSuccess:lt,replyContext:rt,setReplyContext:it,webRTCError:S,micError:ft,setMicError:pt,dismissCallError:ue,activeCallId:_,isCallMuted:x,toggleCallMute:le,endWebRTCCall:ce,formatCallDuration:Ft,callDurationSeconds:dt,onCollapse:Rt,onStartVoice:Bt,voiceEnabled:N,onNewChat:Pt,onMinimize:jt,onExpand:At,isCallMinimized:!!_,showPoweredBy:Re,privacyPolicyUrl:Be,headerBgColor:ze,getVisitorChatHistory:pe,resumeChat:me,isSessionRestoring:he}),(0,V.jsx)(`style`,{children:`
|
|
432
436
|
/* Force any SVG (or img) inside LogoSlot to fill the container height
|
|
433
437
|
regardless of whether the component forwards its style prop. */
|
|
434
438
|
.fe-logo-slot svg,
|
|
@@ -447,4 +451,4 @@ Error generating stack: `+e.message+`
|
|
|
447
451
|
@keyframes fe-orb-bar-3 { from{height:8px} to{height:20px} }
|
|
448
452
|
@keyframes fe-orb-bar-4 { from{height:6px} to{height:16px} }
|
|
449
453
|
@keyframes fe-dot-bounce { 0%,80%,100%{transform:translateY(0);opacity:.5} 40%{transform:translateY(-5px);opacity:1} }
|
|
450
|
-
`})]})}var M_=class extends b.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){console.error(`[FlowEngage] Widget crashed:`,e,t.componentStack)}render(){return this.state.hasError?this.props.fallback??null:this.props.children}},N_=`@import "https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&display=swap";:host{all:initial;box-sizing:border-box!important;color:#111827!important;-webkit-font-smoothing:antialiased!important;z-index:2147483647!important;background:0 0!important;border:none!important;margin:0!important;padding:0!important;font-family:Poppins,system-ui,-apple-system,sans-serif!important;font-size:16px!important;line-height:1.5!important;display:block!important;position:relative!important}:host *,:host :before,:host :after{box-sizing:border-box}.flowengage-widget-root{-moz-osx-font-smoothing:grayscale;text-rendering:optimizelegibility;color:#111827!important;-webkit-font-smoothing:antialiased!important;font-family:Poppins,system-ui,-apple-system,sans-serif!important;font-size:16px!important;line-height:1.5!important}.flowengage-widget-root *,.flowengage-widget-root :before,.flowengage-widget-root :after{font-family:inherit!important}.flowengage-widget-root input,.flowengage-widget-root textarea,.flowengage-widget-root button,.flowengage-widget-root select,.flowengage-widget-root optgroup,.flowengage-widget-root option{font-size:inherit;line-height:inherit;font-family:inherit!important}.flowengage-shell,.flowengage-shell *{font-family:inherit!important}.flowengage-chat-panel{border:none;border-radius:0;outline:none;flex-direction:column;width:100%;height:100%;display:flex;position:relative;overflow:hidden;box-shadow:0 20px 50px #00000026}.flowengage-chat-text-input{margin:0!important}.flowengage-chat-text-input:focus{box-shadow:none!important;border:none!important;outline:none!important}@media (width>=768px){.flowengage-chat-panel{border-radius:24px;width:min(350px,100vw - 40px);height:min(700px,100vh - 120px)}}.flowengage-shell[data-open=true]{inset:0}@media (width>=768px){.flowengage-shell[data-open=true]{inset:auto 1.5rem 1.5rem auto}}.flowengage-logo-fallback{background:conic-gradient(from 180deg, var(--flowengage-primary) 0%, var(--flowengage-accent) 45%, var(--flowengage-primary) 100%)}.fe-bot-message p{margin:0 0 .5em}.fe-bot-message p:last-child{margin-bottom:0}.fe-bot-message ul,.fe-bot-message ol{margin:.4em 0 .4em 1.2em;padding:0}.fe-bot-message li{margin-bottom:.25em}.fe-bot-message strong{font-weight:600}.fe-bot-message a{color:var(--flowengage-primary);text-decoration:underline}.fe-bot-message a:hover{opacity:.8}.incoming-call-overlay{z-index:1000;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);background:#1a1a2ef2;justify-content:center;align-items:center;transition:all .3s ease-in-out;display:flex;position:absolute;left:0;right:0}.incoming-call-overlay.bottom-mode{border-top:2px solid #ffffff1a;min-height:120px;animation:.4s cubic-bezier(.16,1,.3,1) slideUpBanner;top:auto;bottom:0;box-shadow:0 -10px 30px #00000080}.incoming-call-overlay.header-mode{border-bottom:2px solid #ffffff1a;min-height:80px;animation:.4s cubic-bezier(.16,1,.3,1) slideDownBanner;top:0;bottom:auto;box-shadow:0 10px 30px #00000080}.incoming-call-container{justify-content:space-between;align-items:center;gap:14px;width:100%;padding:14px 16px;display:flex}.incoming-call-container.connected-layout{flex-direction:column;justify-content:center;align-items:stretch;gap:14px}.call-connected-top{justify-content:space-between;align-items:center;gap:16px;width:100%;display:flex}.call-connected-identity{flex:1;align-items:center;gap:14px;min-width:0;display:flex}.call-icon-wrapper{color:#fff;z-index:1;border-radius:9999px;flex-shrink:0;justify-content:center;align-items:center;width:54px;height:54px;margin-right:4px;display:flex;position:relative}.call-icon-wrapper.incoming{background:linear-gradient(135deg,#4caf50,#45a049);animation:1s ease-in-out infinite bounce}.call-icon-wrapper.connecting{background:linear-gradient(135deg,#2196f3,#1976d2)}.call-icon-wrapper.connected{background:linear-gradient(135deg,#4caf50,#45a049)}.call-pulse-animation{z-index:-1;background:#4caf504d;border-radius:50%;width:120px;height:120px;animation:1.5s ease-out infinite pulse;position:absolute}.call-connecting-animation{z-index:-1;border:3px solid #0000;border-top-color:#2196f3;border-radius:50%;width:100px;height:100px;animation:1s linear infinite spin;position:absolute}.call-info-group{flex-direction:column;flex:1;min-width:0;margin-right:8px;display:flex}.call-title{color:#fff;white-space:normal;text-overflow:clip;margin:0;font-size:16px;font-weight:700;line-height:1.2;overflow:visible}.call-subtitle{color:#ffffffb3;white-space:normal;text-overflow:clip;margin:4px 0 0;font-size:12px;line-height:1.35;overflow:visible}.call-timer{text-align:center;color:#fff;flex-shrink:0;min-width:54px;font-size:13px;font-weight:700}.call-actions{flex-shrink:0;align-items:center;gap:8px;display:flex}.call-actions.connected{justify-content:center;width:100%}.flowengage-call-btn{cursor:pointer;color:#fff;border:none;border-radius:8px;justify-content:center;align-items:center;gap:6px;min-width:92px;padding:8px 12px;font-size:12px;font-weight:600;line-height:1;transition:transform .2s,box-shadow .2s,background .2s;display:flex}.flowengage-call-btn svg{flex-shrink:0;display:block}.flowengage-call-btn span{justify-content:center;align-items:center;line-height:1;display:flex}.flowengage-call-btn.icon-only{border-radius:9999px;width:46px;min-width:46px;height:46px;padding:0}.flowengage-call-btn-accept{background:linear-gradient(135deg,#4caf50,#45a049);box-shadow:0 8px 24px #4caf5066}.flowengage-call-btn-reject,.flowengage-call-btn-end{background:linear-gradient(135deg,#f44336,#d32f2f);box-shadow:0 4px 12px #f4433666}.flowengage-call-btn-mute{background:#ffffff1a;border:2px solid #fff3}.flowengage-call-btn-mute.active{background:#f443364d;border-color:#f44336}.flowengage-call-btn:hover:not(:disabled){transform:scale(1.05)}.incoming-call-overlay.header-mode .flowengage-call-btn{border-radius:9999px!important;width:36px!important;min-width:36px!important;height:36px!important;padding:0!important}.incoming-call-overlay.header-mode .flowengage-call-btn span{display:none!important}.incoming-call-overlay.header-mode .call-icon-wrapper{width:40px;height:40px;margin-right:0}.incoming-call-overlay.header-mode .call-info-group{min-width:0}.incoming-call-overlay.header-mode .call-title,.incoming-call-overlay.header-mode .call-subtitle{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}@media (width<=640px){.incoming-call-container{align-items:flex-start;gap:10px;padding:12px 14px}.incoming-call-container.connected-layout{align-items:stretch}.call-connected-top{flex-direction:column;align-items:flex-start;gap:10px}.call-connected-identity{width:100%}.call-info-group{margin-right:0}.call-actions{flex-wrap:wrap;align-self:stretch;gap:6px}.call-actions.connected{justify-content:stretch}.call-actions.connected .flowengage-call-btn{flex:1}.flowengage-call-btn{min-width:78px;padding:8px 10px}}@keyframes slideUpBanner{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes slideDownBanner{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes bounce{0%,to{transform:translateY(0)}50%{transform:translateY(-10px)}}@keyframes pulse{0%{opacity:1;transform:scale(.8)}to{opacity:0;transform:scale(2)}}@keyframes spin{to{transform:rotate(360deg)}}.fe-screen-fade-in{animation:.4s cubic-bezier(.16,1,.3,1) forwards feFadeIn}@keyframes feFadeIn{0%{opacity:0;transform:translateY(12px)}to{opacity:1;transform:translateY(0)}}.flowengage-initial-bg{background-color:#fff;position:relative;overflow:hidden}.flowengage-initial-bg:before{content:"";background:linear-gradient(to bottom, var(--flowengage-primary) 0%, var(--flowengage-accent) 55%, white 82%);opacity:0;pointer-events:none;z-index:0;transition:opacity .6s cubic-bezier(.4,0,.2,1);position:absolute;inset:0}.flowengage-initial-bg.is-initial:before{opacity:1}.flowengage-content-wrapper{z-index:1;flex-direction:column;flex:1;min-height:0;display:flex;position:relative}`,P_=null,F_=!1;function I_(){let e=document.createElement(`div`);e.id=`flowengage-root`;let t=e.attachShadow({mode:`open`}),n=document.createElement(`style`);n.textContent=N_,t.appendChild(n);let r=document.createElement(`div`);return r.setAttribute(`data-flowengage-mount`,`true`),r.className=`flowengage-widget-root`,t.appendChild(r),{host:e,mount:r}}function L_(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function R_({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(F_){console.warn(`[FlowEngage] Already initialized. Call FlowEngage.destroy() first to re-initialize.`);return}if(!e){console.error(`[FlowEngage] siteId is required. Pass it via data-site-id attribute or FlowEngage.init({ siteId: 'YOUR_SITE_ID' }).`);return}if(!document.body){console.error(`[FlowEngage] document.body is not available yet. The widget will auto-retry once the DOM is ready.`),L_(()=>R_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}));return}if(document.getElementById(`flowengage-root`)){console.warn(`[FlowEngage] #flowengage-root already exists. Skipping duplicate mount.`);return}let{host:i,mount:a}=I_();document.body.appendChild(i),P_=(0,x.createRoot)(a);let o={widgetSettings:n,...r&&{apiBaseUrl:r}};P_.render(b.createElement(M_,null,b.createElement(Ci,{siteId:e,language:t,config:o},b.createElement(j_)))),F_=!0}var z_={init({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>L_(()=>R_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))):L_(()=>R_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))},destroy(){P_&&=(P_.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),F_=!1}},B_=()=>{let e=document.currentScript;(!e||!e.getAttribute(`data-site-id`)&&!e.getAttribute(`data-shop-domain`))&&(e=document.querySelector(`script[data-site-id], script[data-shop-domain]`));let t=e?.getAttribute(`data-site-id`),n=e?.getAttribute(`data-shop-domain`);if(!t&&!n)return;let r=e?.getAttribute(`data-language`)||`en`,i=e?.getAttribute(`data-api-url`)||void 0,a={};try{let t=e?.getAttribute(`data-widget-settings`);t&&(a=JSON.parse(t))}catch{}if(t){L_(()=>R_({siteId:t,language:r,widgetSettings:a,apiBaseUrl:i}));return}let o=(i||`https://be-flowengage-dev.oslabs.app`).replace(/\/+$/,``);fetch(`${o}/api/widget/resolve-shopify-tenant?shopDomain=${encodeURIComponent(n)}`).then(e=>e.json()).then(e=>{if(!e?.success||!e.siteId){console.error(`[FlowEngage] Could not resolve a FlowEngage account for shop:`,n,e?.message);return}L_(()=>R_({siteId:e.siteId,language:r,widgetSettings:a,apiBaseUrl:i}))}).catch(e=>console.error(`[FlowEngage] Failed to resolve shop tenant:`,e))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,B_):B_(),typeof window<`u`&&(window.FlowEngage=z_),z_})();
|
|
454
|
+
`})]})}var I_=class extends b.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){console.error(`[FlowEngage] Widget crashed:`,e,t.componentStack)}render(){return this.state.hasError?this.props.fallback??null:this.props.children}},L_=`@import "https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&display=swap";:host{all:initial;box-sizing:border-box!important;color:#111827!important;-webkit-font-smoothing:antialiased!important;z-index:2147483647!important;background:0 0!important;border:none!important;margin:0!important;padding:0!important;font-family:Poppins,system-ui,-apple-system,sans-serif!important;font-size:16px!important;line-height:1.5!important;display:block!important;position:relative!important}:host *,:host :before,:host :after{box-sizing:border-box}.flowengage-widget-root{-moz-osx-font-smoothing:grayscale;text-rendering:optimizelegibility;color:#111827!important;-webkit-font-smoothing:antialiased!important;font-family:Poppins,system-ui,-apple-system,sans-serif!important;font-size:16px!important;line-height:1.5!important}.flowengage-widget-root *,.flowengage-widget-root :before,.flowengage-widget-root :after{font-family:inherit!important}.flowengage-widget-root input,.flowengage-widget-root textarea,.flowengage-widget-root button,.flowengage-widget-root select,.flowengage-widget-root optgroup,.flowengage-widget-root option{font-size:inherit;line-height:inherit;font-family:inherit!important}.flowengage-shell,.flowengage-shell *{font-family:inherit!important}.flowengage-chat-panel{border:none;border-radius:0;outline:none;flex-direction:column;width:100%;height:100%;display:flex;position:relative;overflow:hidden;box-shadow:0 20px 50px #00000026}.flowengage-chat-text-input{margin:0!important}.flowengage-chat-text-input:focus{box-shadow:none!important;border:none!important;outline:none!important}@media (width>=768px){.flowengage-chat-panel{border-radius:24px;width:min(350px,100vw - 40px);height:min(700px,100vh - 120px)}}.flowengage-shell[data-open=true]{inset:0}@media (width>=768px){.flowengage-shell[data-open=true]{inset:auto 1.5rem 1.5rem auto}}.flowengage-logo-fallback{background:conic-gradient(from 180deg, var(--flowengage-primary) 0%, var(--flowengage-accent) 45%, var(--flowengage-primary) 100%)}.fe-bot-message p{margin:0 0 .5em}.fe-bot-message p:last-child{margin-bottom:0}.fe-bot-message ul,.fe-bot-message ol{margin:.4em 0 .4em 1.2em;padding:0}.fe-bot-message li{margin-bottom:.25em}.fe-bot-message strong{font-weight:600}.fe-bot-message a{color:var(--flowengage-primary);text-decoration:underline}.fe-bot-message a:hover{opacity:.8}.incoming-call-overlay{z-index:1000;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);background:#1a1a2ef2;justify-content:center;align-items:center;transition:all .3s ease-in-out;display:flex;position:absolute;left:0;right:0}.incoming-call-overlay.bottom-mode{border-top:2px solid #ffffff1a;min-height:120px;animation:.4s cubic-bezier(.16,1,.3,1) slideUpBanner;top:auto;bottom:0;box-shadow:0 -10px 30px #00000080}.incoming-call-overlay.header-mode{border-bottom:2px solid #ffffff1a;min-height:80px;animation:.4s cubic-bezier(.16,1,.3,1) slideDownBanner;top:0;bottom:auto;box-shadow:0 10px 30px #00000080}.incoming-call-container{justify-content:space-between;align-items:center;gap:14px;width:100%;padding:14px 16px;display:flex}.incoming-call-container.connected-layout{flex-direction:column;justify-content:center;align-items:stretch;gap:14px}.call-connected-top{justify-content:space-between;align-items:center;gap:16px;width:100%;display:flex}.call-connected-identity{flex:1;align-items:center;gap:14px;min-width:0;display:flex}.call-icon-wrapper{color:#fff;z-index:1;border-radius:9999px;flex-shrink:0;justify-content:center;align-items:center;width:54px;height:54px;margin-right:4px;display:flex;position:relative}.call-icon-wrapper.incoming{background:linear-gradient(135deg,#4caf50,#45a049);animation:1s ease-in-out infinite bounce}.call-icon-wrapper.connecting{background:linear-gradient(135deg,#2196f3,#1976d2)}.call-icon-wrapper.connected{background:linear-gradient(135deg,#4caf50,#45a049)}.call-pulse-animation{z-index:-1;background:#4caf504d;border-radius:50%;width:120px;height:120px;animation:1.5s ease-out infinite pulse;position:absolute}.call-connecting-animation{z-index:-1;border:3px solid #0000;border-top-color:#2196f3;border-radius:50%;width:100px;height:100px;animation:1s linear infinite spin;position:absolute}.call-info-group{flex-direction:column;flex:1;min-width:0;margin-right:8px;display:flex}.call-title{color:#fff;white-space:normal;text-overflow:clip;margin:0;font-size:16px;font-weight:700;line-height:1.2;overflow:visible}.call-subtitle{color:#ffffffb3;white-space:normal;text-overflow:clip;margin:4px 0 0;font-size:12px;line-height:1.35;overflow:visible}.call-timer{text-align:center;color:#fff;flex-shrink:0;min-width:54px;font-size:13px;font-weight:700}.call-actions{flex-shrink:0;align-items:center;gap:8px;display:flex}.call-actions.connected{justify-content:center;width:100%}.flowengage-call-btn{cursor:pointer;color:#fff;border:none;border-radius:8px;justify-content:center;align-items:center;gap:6px;min-width:92px;padding:8px 12px;font-size:12px;font-weight:600;line-height:1;transition:transform .2s,box-shadow .2s,background .2s;display:flex}.flowengage-call-btn svg{flex-shrink:0;display:block}.flowengage-call-btn span{justify-content:center;align-items:center;line-height:1;display:flex}.flowengage-call-btn.icon-only{border-radius:9999px;width:46px;min-width:46px;height:46px;padding:0}.flowengage-call-btn-accept{background:linear-gradient(135deg,#4caf50,#45a049);box-shadow:0 8px 24px #4caf5066}.flowengage-call-btn-reject,.flowengage-call-btn-end{background:linear-gradient(135deg,#f44336,#d32f2f);box-shadow:0 4px 12px #f4433666}.flowengage-call-btn-mute{background:#ffffff1a;border:2px solid #fff3}.flowengage-call-btn-mute.active{background:#f443364d;border-color:#f44336}.flowengage-call-btn:hover:not(:disabled){transform:scale(1.05)}.incoming-call-overlay.header-mode .flowengage-call-btn{border-radius:9999px!important;width:36px!important;min-width:36px!important;height:36px!important;padding:0!important}.incoming-call-overlay.header-mode .flowengage-call-btn span{display:none!important}.incoming-call-overlay.header-mode .call-icon-wrapper{width:40px;height:40px;margin-right:0}.incoming-call-overlay.header-mode .call-info-group{min-width:0}.incoming-call-overlay.header-mode .call-title,.incoming-call-overlay.header-mode .call-subtitle{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}@media (width<=640px){.incoming-call-container{align-items:flex-start;gap:10px;padding:12px 14px}.incoming-call-container.connected-layout{align-items:stretch}.call-connected-top{flex-direction:column;align-items:flex-start;gap:10px}.call-connected-identity{width:100%}.call-info-group{margin-right:0}.call-actions{flex-wrap:wrap;align-self:stretch;gap:6px}.call-actions.connected{justify-content:stretch}.call-actions.connected .flowengage-call-btn{flex:1}.flowengage-call-btn{min-width:78px;padding:8px 10px}}@keyframes slideUpBanner{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes slideDownBanner{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes bounce{0%,to{transform:translateY(0)}50%{transform:translateY(-10px)}}@keyframes pulse{0%{opacity:1;transform:scale(.8)}to{opacity:0;transform:scale(2)}}@keyframes spin{to{transform:rotate(360deg)}}.fe-screen-fade-in{animation:.4s cubic-bezier(.16,1,.3,1) forwards feFadeIn}@keyframes feFadeIn{0%{opacity:0;transform:translateY(12px)}to{opacity:1;transform:translateY(0)}}.flowengage-initial-bg{background-color:#fff;position:relative;overflow:hidden}.flowengage-initial-bg:before{content:"";background:linear-gradient(to bottom, var(--flowengage-primary) 0%, var(--flowengage-accent) 55%, white 82%);opacity:0;pointer-events:none;z-index:0;transition:opacity .6s cubic-bezier(.4,0,.2,1);position:absolute;inset:0}.flowengage-initial-bg.is-initial:before{opacity:1}.flowengage-content-wrapper{z-index:1;flex-direction:column;flex:1;min-height:0;display:flex;position:relative}`,R_=null,z_=!1;function B_(){let e=document.createElement(`div`);e.id=`flowengage-root`;let t=e.attachShadow({mode:`open`}),n=document.createElement(`style`);n.textContent=L_,t.appendChild(n);let r=document.createElement(`div`);return r.setAttribute(`data-flowengage-mount`,`true`),r.className=`flowengage-widget-root`,t.appendChild(r),{host:e,mount:r}}function V_(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function H_({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(z_){console.warn(`[FlowEngage] Already initialized. Call FlowEngage.destroy() first to re-initialize.`);return}if(!e){console.error(`[FlowEngage] siteId is required. Pass it via data-site-id attribute or FlowEngage.init({ siteId: 'YOUR_SITE_ID' }).`);return}if(!document.body){console.error(`[FlowEngage] document.body is not available yet. The widget will auto-retry once the DOM is ready.`),V_(()=>H_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}));return}if(document.getElementById(`flowengage-root`)){console.warn(`[FlowEngage] #flowengage-root already exists. Skipping duplicate mount.`);return}let{host:i,mount:a}=B_();document.body.appendChild(i),R_=(0,x.createRoot)(a);let o={widgetSettings:n,...r&&{apiBaseUrl:r}};R_.render(b.createElement(I_,null,b.createElement(Ci,{siteId:e,language:t,config:o},b.createElement(F_)))),z_=!0}var U_={init({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>V_(()=>H_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))):V_(()=>H_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))},destroy(){R_&&=(R_.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),z_=!1}},W_=()=>{let e=document.currentScript;(!e||!e.getAttribute(`data-site-id`)&&!e.getAttribute(`data-shop-domain`))&&(e=document.querySelector(`script[data-site-id], script[data-shop-domain]`));let t=e?.getAttribute(`data-site-id`),n=e?.getAttribute(`data-shop-domain`);if(!t&&!n)return;let r=e?.getAttribute(`data-language`)||`en`,i=e?.getAttribute(`data-api-url`)||void 0,a={};try{let t=e?.getAttribute(`data-widget-settings`);t&&(a=JSON.parse(t))}catch{}if(t){V_(()=>H_({siteId:t,language:r,widgetSettings:a,apiBaseUrl:i}));return}let o=(i||`https://be-flowengage-dev.oslabs.app`).replace(/\/+$/,``);fetch(`${o}/api/widget/resolve-shopify-tenant?shopDomain=${encodeURIComponent(n)}`).then(e=>e.json()).then(e=>{if(!e?.success||!e.siteId){console.error(`[FlowEngage] Could not resolve a FlowEngage account for shop:`,n,e?.message);return}V_(()=>H_({siteId:e.siteId,language:r,widgetSettings:a,apiBaseUrl:i}))}).catch(e=>console.error(`[FlowEngage] Failed to resolve shop tenant:`,e))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,W_):W_(),typeof window<`u`&&(window.FlowEngage=U_),U_})();
|