import{r as e}from"./rolldown-runtime-C60lm6uB.js";import{i as t,r as n}from"./framework-D_rUT4EX.js";import{t as r}from"./message-circle-more-CkAa9TY6.js";import{t as i}from"./x-DWhg4rR2.js";var a=e(t(),1),o=n(),s=`https://chatbot.gapido.org`,c=`${s}/widget/?key=gpw_19bsGotZMwFhj1j38tVYD7Qm-bdoQOiA&api=${s}`,l=[`سلام! چطور می‌توانم کمکتان کنم؟`,`درباره امکانات گپیدو بپرسید.`,`دمو می‌خواهید؟ همین‌جا بپرسید.`];function u(){let[e,t]=(0,a.useState)(!1),[n,u]=(0,a.useState)(!1),[d,f]=(0,a.useState)(-1),p=(0,a.useRef)(null),m=(0,a.useCallback)(()=>{t(!1),p.current?.focus()},[]),h=(0,a.useCallback)(()=>{u(!0),t(e=>!e)},[]);return(0,a.useEffect)(()=>{function e(e){if(e.origin!==s)return;let t=e.data;if(!(!t||typeof t!=`object`)&&(t.type===`gapido:close`&&m(),t.type===`gapido:navigate`&&t.payload?.url)){let e=new URL(t.payload.url,location.href);e.origin===location.origin&&(location.href=e.href)}}return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[m]),(0,a.useEffect)(()=>{if(!e)return;function t(e){e.key===`Escape`&&m()}return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,m]),(0,a.useEffect)(()=>{if(e||d>=l.length-1)return;let t=setTimeout(()=>f(e=>e+1),d<0?4200:7e3);return()=>clearTimeout(t)},[e,d]),(0,o.jsxs)(`div`,{className:`gapido-chat`,"data-open":e||void 0,children:[!e&&d>=0&&(0,o.jsx)(`output`,{className:`gapido-chat-teaser`,children:l[d]},d),(0,o.jsxs)(`button`,{type:`button`,ref:p,className:`gapido-chat-launcher`,onClick:h,"aria-expanded":e,"aria-controls":`gapido-chat-panel`,"aria-label":e?`بستن دستیار گپیدو`:`گفت‌وگو با دستیار گپیدو`,children:[(0,o.jsx)(`span`,{className:`gapido-chat-pulse`,"aria-hidden":`true`}),(0,o.jsxs)(`span`,{className:`gapido-chat-bot`,"aria-hidden":`true`,children:[(0,o.jsxs)(`span`,{className:`gapido-bot-face`,children:[(0,o.jsx)(`i`,{className:`gapido-bot-eye`}),(0,o.jsx)(`i`,{className:`gapido-bot-eye`})]}),(0,o.jsx)(`span`,{className:`gapido-bot-mouth`})]}),(0,o.jsx)(`span`,{className:`gapido-chat-icon`,"aria-hidden":`true`,children:e?(0,o.jsx)(i,{}):(0,o.jsx)(r,{})})]}),(0,o.jsx)(`div`,{className:`gapido-chat-panel`,id:`gapido-chat-panel`,hidden:!e,"aria-label":`دستیار هوشمند گپیدو`,children:n&&(0,o.jsx)(`iframe`,{className:`gapido-chat-frame`,title:`دستیار هوشمند گپیدو`,src:c,allow:`clipboard-write`,loading:`lazy`})})]})}export{u as ChatWidget};