tybotflow-widget 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -47617,7 +47617,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
47617
47617
  });
47618
47618
  })();
47619
47619
  }, [e.bot?.botId, e?.token]);
47620
- const h = u?.mainColor || "#59168b", m = u?.secondaryColor || "#6366f1", y = u?.thirdColor || "#0f172b", E = u?.headerFirstColor || "#6e11b0", v = u?.headerSecondColor || "#372aac", A = u?.inputBackgroundColor || "#1f2937", w = u?.inputTextColor || "#fff", R = u?.roundness || "1.5rem", C = u?.chatRoundness || "1rem", N = u?.minPanelWidth || 434, D = u?.maxPanelWidth || window.innerWidth, O = u?.chatMaxWidth || 88, x = u?.toggleBtnBorderTopLeftRadius || "12px", L = u?.toggleBtnBorderTopRightRadius || "0", P = u?.toggleBtnBorderBottomLeftRadius || "12px", z = u?.toggleBtnBorderBottomRightRadius || "0", B = u?.menuBackgroundColor || "#1f2937", H = u?.menuTextColor || "#e5e7eb", X = u?.menuHoverBackgroundColor || "#374151", $ = u?.agentChatResponseColor || "#e5e7eb", ne = u?.agentChatResponseBgColor || "#1f2937", re = u?.agentIconBgColor || "#59168b", q = u?.agentIconColor || "#fff", K = u?.userChatMessagesColor || "#fff", Y = u?.userChatMessagesBgColor || "#7a1ebe", oe = u?.userIconBgColor || "#7a1ebe", S = u?.userIconColor || "#fff", G = u?.ButtonColor || "#fff", te = u?.ButtonsBgColor || "#59168b", [I, ce] = ye.useState(448), he = ye.useRef(!1), ue = ye.useRef(0), Ae = ye.useRef(448), we = (M) => {
47620
+ const h = u?.mainColor || "#59168b", m = u?.secondaryColor || "#6366f1", y = u?.thirdColor || "#0f172b", E = u?.headerFirstColor || "#6e11b0", v = u?.headerSecondColor || "#372aac", A = u?.inputBackgroundColor || "#1f2937", w = u?.inputTextColor || "#fff", R = u?.roundness || 24, C = u?.chatRoundness || 16, N = (u?.minPanelWidth || 434) > window.innerWidth ? window.innerWidth : u?.minPanelWidth || 434, D = (u?.maxPanelWidth || window.innerWidth) > window.innerWidth ? window.innerWidth : u?.maxPanelWidth || window.innerWidth, O = u?.chatMaxWidth || 88, x = u?.toggleBtnBorderTopLeftRadius || 12, L = u?.toggleBtnBorderTopRightRadius || 0, P = u?.toggleBtnBorderBottomLeftRadius || 12, z = u?.toggleBtnBorderBottomRightRadius || 0, B = u?.menuBackgroundColor || "#1f2937", H = u?.menuTextColor || "#e5e7eb", X = u?.menuHoverBackgroundColor || "#374151", $ = u?.agentChatResponseColor || "#e5e7eb", ne = u?.agentChatResponseBgColor || "#1f2937", re = u?.agentIconBgColor || "#59168b", q = u?.agentIconColor || "#fff", K = u?.userChatMessagesColor || "#fff", Y = u?.userChatMessagesBgColor || "#7a1ebe", oe = u?.userIconBgColor || "#7a1ebe", S = u?.userIconColor || "#fff", G = u?.ButtonColor || "#fff", te = u?.ButtonsBgColor || "#59168b", [I, ce] = ye.useState(N), he = ye.useRef(!1), ue = ye.useRef(0), Ae = ye.useRef(N), we = (M) => {
47621
47621
  he.current = !0, ue.current = M.clientX, Ae.current = I, document.body.style.cursor = "ew-resize";
47622
47622
  };
47623
47623
  ye.useEffect(() => {
@@ -47897,7 +47897,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
47897
47897
  },
47898
47898
  style: {
47899
47899
  background: te,
47900
- borderRadius: C,
47900
+ borderRadius: `${C}px`,
47901
47901
  color: G
47902
47902
  },
47903
47903
  dir: Wt(me.title) ? "rtl" : "ltr",
@@ -47930,7 +47930,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
47930
47930
  },
47931
47931
  style: {
47932
47932
  background: te,
47933
- borderRadius: C,
47933
+ borderRadius: `${C}px`,
47934
47934
  color: G
47935
47935
  },
47936
47936
  dir: Wt(M.message || "") ? "rtl" : "ltr",
@@ -47942,7 +47942,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
47942
47942
  ] });
47943
47943
  case "carousel":
47944
47944
  const fe = (M.items?.length || 0) < 2 ? 1 : 2;
47945
- return /* @__PURE__ */ F.jsx("div", { className: "mt-2 w-full", children: /* @__PURE__ */ F.jsx("div", { className: `grid grid-cols-1 sm:grid-cols-${fe} gap-3`, children: M.items?.map((me, xe) => /* @__PURE__ */ F.jsxs("div", { className: "flex-shrink-0 border p-3 shadow-md", style: { background: ne, borderRadius: C }, children: [
47945
+ return /* @__PURE__ */ F.jsx("div", { className: "mt-2 w-full", children: /* @__PURE__ */ F.jsx("div", { className: `grid grid-cols-1 sm:grid-cols-${fe} gap-3`, children: M.items?.map((me, xe) => /* @__PURE__ */ F.jsxs("div", { className: "flex-shrink-0 border p-3 shadow-md", style: { background: ne, borderRadius: `${C}px` }, children: [
47946
47946
  me.image && /* @__PURE__ */ F.jsx("img", { src: me.image, alt: me.title, className: "h-32 w-full object-cover rounded-md mb-2" }),
47947
47947
  /* @__PURE__ */ F.jsx("h3", { className: "text-sm font-bold", title: me.title, children: me.title }),
47948
47948
  /* @__PURE__ */ F.jsx("p", { className: "text-xs text-gray-300 mb-2 line-clamp-2", title: me.subtitle, children: me.subtitle }),
@@ -47967,7 +47967,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
47967
47967
  },
47968
47968
  style: {
47969
47969
  background: te,
47970
- borderRadius: C,
47970
+ borderRadius: `${C}px`,
47971
47971
  color: G
47972
47972
  },
47973
47973
  children: ht.title
@@ -48001,7 +48001,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
48001
48001
  },
48002
48002
  style: {
48003
48003
  background: te,
48004
- borderRadius: C,
48004
+ borderRadius: `${C}px`,
48005
48005
  color: G
48006
48006
  },
48007
48007
  children: me.title
@@ -48200,7 +48200,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
48200
48200
  style: {
48201
48201
  wordBreak: "break-word",
48202
48202
  overflowWrap: "break-word",
48203
- borderRadius: C,
48203
+ borderRadius: `${C}px`,
48204
48204
  maxWidth: O + "%",
48205
48205
  background: Y,
48206
48206
  color: K
@@ -48215,7 +48215,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
48215
48215
  style: {
48216
48216
  wordBreak: "break-word",
48217
48217
  overflowWrap: "break-word",
48218
- borderRadius: C,
48218
+ borderRadius: `${C}px`,
48219
48219
  maxWidth: O + "%",
48220
48220
  background: ne,
48221
48221
  color: $
@@ -48230,7 +48230,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
48230
48230
  style: {
48231
48231
  wordBreak: "break-word",
48232
48232
  overflowWrap: "break-word",
48233
- borderRadius: C,
48233
+ borderRadius: `${C}px`,
48234
48234
  maxWidth: O + "%",
48235
48235
  background: ne,
48236
48236
  color: $
@@ -48472,7 +48472,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
48472
48472
  minHeight: "48px",
48473
48473
  maxHeight: "120px",
48474
48474
  overflowY: "auto",
48475
- borderRadius: R,
48475
+ borderRadius: `${R}px`,
48476
48476
  background: A,
48477
48477
  color: w,
48478
48478
  scrollbarWidth: "thin",
@@ -48527,7 +48527,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
48527
48527
  className: "relative w-full max-w-md mx-4 p-6 rounded-2xl shadow-2xl border overflow-hidden animate-[fadeIn_0.25s_ease]",
48528
48528
  style: {
48529
48529
  background: `linear-gradient(145deg, ${y}, ${h}, ${m})`,
48530
- borderRadius: R,
48530
+ borderRadius: `${R}px`,
48531
48531
  borderColor: h
48532
48532
  },
48533
48533
  onClick: (M) => M.stopPropagation(),
@@ -48606,7 +48606,7 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
48606
48606
  type: "button",
48607
48607
  onClick: () => It(!1),
48608
48608
  className: "mt-4 px-4 py-2 rounded-lg text-sm font-medium bg-white/10 hover:bg-white/20 text-black transition-colors",
48609
- style: { borderRadius: R },
48609
+ style: { borderRadius: `${R}px` },
48610
48610
  children: "Close"
48611
48611
  }
48612
48612
  )
@@ -48631,10 +48631,10 @@ const P0 = "https://api.tybotflow.com/api/v1", dW = "https://api.tybotflow.com/a
48631
48631
  transform: He ? `translateX(-${I}px)` : "translateX(0)",
48632
48632
  transition: "transform 0.3s cubic-bezier(0.4,0,0.2,1)",
48633
48633
  background: Hi,
48634
- borderTopLeftRadius: x,
48635
- borderBottomLeftRadius: P,
48636
- borderTopRightRadius: L,
48637
- borderBottomRightRadius: z,
48634
+ borderTopLeftRadius: `${x}px`,
48635
+ borderBottomLeftRadius: `${P}px`,
48636
+ borderTopRightRadius: `${L}px`,
48637
+ borderBottomRightRadius: `${z}px`,
48638
48638
  zIndex: 999
48639
48639
  },
48640
48640
  children: [
package/dist/index.umd.js CHANGED
@@ -322,9 +322,9 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
322
322
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
323
323
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
324
324
  PERFORMANCE OF THIS SOFTWARE.
325
- ***************************************************************************** */function a0(e,t){const[n,a]=ye.useState(null),o=ye.useMemo(()=>Object.entries(t).flat(),[t]);return ye.useEffect(()=>{if(!e?.current)return;const l=wb.create(Object.assign(Object.assign({},t),{container:e.current}));return a(l),()=>{l.destroy()}},[e,...o]),n}const i0=/^on([A-Z])/,h6=e=>i0.test(e);function m6(e,t){const n=ye.useMemo(()=>Object.entries(t).flat(),[t]);ye.useEffect(()=>{if(!e)return;const a=Object.entries(t);if(!a.length)return;const o=a.map(([l,u])=>{const d=l.replace(i0,(p,f)=>f.toLowerCase());return e.on(d,(...p)=>u(e,...p))});return()=>{o.forEach(l=>l())}},[e,...n])}ye.memo(e=>{const t=ye.useRef(null),[n,a]=function(o){return ye.useMemo(()=>{const l=Object.assign({},o),u=Object.assign({},o);for(const d in l)h6(d)?delete l[d]:delete u[d];return[l,u]},[o])}(e);return m6(a0(t,n),a),B.jsx("div",{ref:t})});function b6(e){var{container:t}=e;const n=a0(t,function(o,l){var u={};for(var d in o)Object.prototype.hasOwnProperty.call(o,d)&&l.indexOf(d)<0&&(u[d]=o[d]);if(o!=null&&typeof Object.getOwnPropertySymbols=="function"){var p=0;for(d=Object.getOwnPropertySymbols(o);p<d.length;p++)l.indexOf(d[p])<0&&Object.prototype.propertyIsEnumerable.call(o,d[p])&&(u[d[p]]=o[d[p]])}return u}(e,["container"])),a=function(o){const[l,u]=ye.useState(!1),[d,p]=ye.useState(!1),[f,h]=ye.useState(!1),[m,y]=ye.useState(0);return ye.useEffect(()=>{if(!o)return;const E=[o.on("load",()=>{u(!1),p(!1),y(0)}),o.on("ready",()=>{u(!0),p(!1),h(!1),y(0)}),o.on("finish",()=>{h(!0)}),o.on("play",()=>{p(!0)}),o.on("pause",()=>{p(!1)}),o.on("timeupdate",()=>{y(o.getCurrentTime())}),o.on("destroy",()=>{u(!1),p(!1)})];return()=>{E.forEach(v=>v())}},[o]),ye.useMemo(()=>({isReady:l,isPlaying:d,hasFinished:f,currentTime:m}),[d,f,m,l])}(n);return ye.useMemo(()=>Object.assign(Object.assign({},a),{wavesurfer:n}),[a,n])}const o0="https://api.tybotflow.com/api/v1",y6="https://api.tybotflow.com/api/v1/web/send-message",E6="https://api.tybotflow.com/api/v1/chatbots-config",v6=({attachment:e,formatFileSize:t,mainColor:n,secondaryColor:a,controlsColor:o})=>{const{type:l,url:u,name:d,size:p}=e;switch(l){case"image":return B.jsxs("div",{className:"relative group",children:[B.jsx("img",{src:u,alt:d,className:"max-w-xs max-h-48 rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(u,"_blank")}),B.jsx("div",{className:"absolute bottom-2 left-2 bg-black bg-opacity-60 text-white text-xs px-2 py-1 rounded",children:t(p)})]});case"video":return B.jsxs("div",{className:"max-w-xs",children:[B.jsx("video",{src:u,controls:!0,className:"w-full max-h-48 rounded-lg",preload:"metadata",onError:()=>{console.error("Video failed to load:",u)},children:"Your browser does not support the video tag."}),B.jsxs("div",{className:"flex text-xs text-white mt-1 w-full overflow-hidden whitespace-nowrap text-ellipsis",children:[B.jsx("span",{className:"block w-full overflow-hidden whitespace-nowrap text-ellipsis",title:d,children:d}),B.jsxs("span",{className:"ml-2",children:["• ",t(p)]})]})]});case"audio":return B.jsxs("div",{className:"bg-gray-800 bg-opacity-70 p-3 rounded-lg flex-1 w-full",children:[B.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[B.jsx(Wc,{className:"w-4 h-4",style:{color:n}}),B.jsx("span",{className:"text-sm font-medium truncate text-white",title:d,children:d})]}),B.jsx(S6,{src:u,mainColor:n,secondaryColor:a,controlsColor:o}),B.jsx("p",{className:"text-xs text-gray-400 mt-1",children:t(p)})]});case"document":return B.jsx("div",{className:"bg-gray-800 bg-opacity-50 p-3 rounded-lg max-w-xs cursor-pointer hover:bg-opacity-70 transition-colors",onClick:()=>window.open(u,"_blank"),children:B.jsxs("div",{className:"flex items-center gap-3",children:[B.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-lg flex items-center justify-center",children:B.jsx(EA,{className:"w-5 h-5 text-white"})}),B.jsxs("div",{className:"flex-1 min-w-0",children:[B.jsx("p",{className:"text-sm font-medium truncate text-white",children:d}),B.jsx("p",{className:"text-xs text-gray-400",children:t(p)})]})]})});default:return null}},S6=({src:e,mainColor:t,secondaryColor:n,controlsColor:a})=>{const o=ye.useRef(null),[l,u]=ye.useState(1),{wavesurfer:d,isPlaying:p}=b6({container:o,waveColor:t,progressColor:n,barWidth:2,height:50,url:e}),f=()=>{d&&d.playPause()},h=()=>{const E=l===0?1:0;u(E),d?.setVolume(E)},m=()=>{d?.skip(-.096)},y=()=>{d?.skip(.096)};return B.jsxs("div",{className:"flex w-full flex-col items-center rounded-xl pt-1",children:[B.jsx("div",{ref:o,className:"w-full px-2"}),B.jsxs("div",{className:"flex w-full items-center justify-between",children:[B.jsx("div",{className:"relative flex items-center",children:B.jsx("button",{className:"transition-colors",style:{color:a},onClick:h,"aria-label":"Toggle volume",children:l===0?B.jsx(tz,{size:20}):B.jsx(ez,{size:20})})}),B.jsxs("div",{className:"-ml-9 flex flex-1 cursor-auto justify-center gap-2 rounded-full py-2 text-white",children:[B.jsx("button",{onClick:m,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:a},"aria-label":"Step back",children:B.jsx(KP,{})}),B.jsx("button",{onClick:f,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:a},"aria-label":p?"Pause":"Play",children:p?B.jsx(VP,{}):B.jsx(YP,{})}),B.jsx("button",{onClick:y,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:a},"aria-label":"Step forward",children:B.jsx(QP,{})})]})]})]})},A6=({config:e})=>{const t=ye.useRef(null),n=ye.useRef(null),a=ye.useRef(null),o=ye.useRef(null),l=ye.useRef(null),[u,d]=ye.useState(null),[p,f]=ye.useState(!0);ye.useEffect(()=>{(async()=>{f(!0),await Et.get(`${E6}/bot/${e.bot?.botId}`,{}).then(fe=>{d(fe.data)}).catch(fe=>{console.error("Error fetching bot config:",fe)}).finally(()=>{f(!1)})})()},[e.bot?.botId,e?.token]);const h=u?.mainColor||"#59168b",m=u?.secondaryColor||"#6366f1",y=u?.thirdColor||"#0f172b",E=u?.headerFirstColor||"#6e11b0",v=u?.headerSecondColor||"#372aac",A=u?.inputBackgroundColor||"#1f2937",w=u?.inputTextColor||"#fff",R=u?.roundness||"1.5rem",N=u?.chatRoundness||"1rem",C=u?.minPanelWidth||434,D=u?.maxPanelWidth||window.innerWidth,O=u?.chatMaxWidth||88,x=u?.toggleBtnBorderTopLeftRadius||"12px",L=u?.toggleBtnBorderTopRightRadius||"0",P=u?.toggleBtnBorderBottomLeftRadius||"12px",z=u?.toggleBtnBorderBottomRightRadius||"0",F=u?.menuBackgroundColor||"#1f2937",H=u?.menuTextColor||"#e5e7eb",X=u?.menuHoverBackgroundColor||"#374151",$=u?.agentChatResponseColor||"#e5e7eb",ne=u?.agentChatResponseBgColor||"#1f2937",re=u?.agentIconBgColor||"#59168b",q=u?.agentIconColor||"#fff",K=u?.userChatMessagesColor||"#fff",Y=u?.userChatMessagesBgColor||"#7a1ebe",oe=u?.userIconBgColor||"#7a1ebe",S=u?.userIconColor||"#fff",G=u?.ButtonColor||"#fff",te=u?.ButtonsBgColor||"#59168b",[I,ce]=ye.useState(448),he=ye.useRef(!1),ue=ye.useRef(0),Ae=ye.useRef(448),Te=M=>{he.current=!0,ue.current=M.clientX,Ae.current=I,document.body.style.cursor="ew-resize"};ye.useEffect(()=>{const M=me=>{if(!he.current)return;const xe=ue.current-me.clientX;let ht=Ae.current+xe;ht=Math.max(C,Math.min(D,ht)),ce(ht)},fe=()=>{he.current&&(he.current=!1,document.body.style.cursor="")};return window.addEventListener("mousemove",M),window.addEventListener("mouseup",fe),()=>{window.removeEventListener("mousemove",M),window.removeEventListener("mouseup",fe)}},[I,C,D]);const[Ge,Je]=ye.useState(!1),[ft,It]=ye.useState(!1),[vt,Ht]=ye.useState(""),[ge,Ee]=ye.useState(!1),[Oe,Le]=ye.useState([]),[ke,Me]=ye.useState(!1),Ze=ye.useRef(0),[it,qe]=ye.useState(!1),[Ie,Pe]=ye.useState(!1),J=ye.useRef(!1),[ie,pe]=ye.useState("00:00"),be=ye.useRef(null),Fe=ye.useRef(0),[Mt,Ft]=ye.useState([]),[ut,ct]=ye.useState([]),{startRecording:dt,stopRecording:gt,pauseRecording:Nt,resumeRecording:Bt,status:Xe,error:pt}=wH.useReactMediaRecorder({video:!1,onStop(M,fe){if(J.current){J.current=!1,pe("00:00"),Fe.current=0;return}Le(me=>[...me,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:fe,type:"audio",url:M,name:`recording-${new Date().toISOString()}.webm`,size:fe.size}]),pe("00:00"),Fe.current=0}}),bn=u?.icon||e?.bot.avatar_url||u6,yn=u?.title||e?.bot.name||"Tybot webchat",[Fr,wa]=ye.useState(()=>{if(!u?.botNeedsAuth){let M=localStorage.getItem("conversationId");if(!M){const fe=new Uint8Array(16);window.crypto.getRandomValues(fe),M=Array.from(fe).map(me=>me.toString(16).padStart(2,"0")).join("")}return localStorage.setItem("conversationId",M),M}}),[cn,lr]=ye.useState(()=>u?.botNeedsAuth?!!localStorage.getItem("conversationId"):!0),[Qn,Rl]=ye.useState(""),[oi,Zn]=ye.useState(""),[wt,Qt]=ye.useState(""),tn=ye.useRef(!1),Ta=ut.reduce((M,fe)=>fe.seen?M:M+(fe.sender==="agent"?fe.nMessage||1:0),0),xl=()=>{ct(M=>M.map(fe=>({...fe,seen:!0})))};ye.useEffect(()=>{const M=setTimeout(()=>{Je(!0),tn.current=!0,xl()},3200);return()=>clearTimeout(M)},[]),ye.useEffect(()=>{const M=async()=>{if(e?.bot){Ee(!0);try{const fe=await Jn("hi",e?.bot.botId);ct(me=>[...me,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:fe,timestamp:new Date,seen:tn.current,nMessage:typeof fe=="string"?1:fe.length}])}catch(fe){console.error("Error sending message:",fe)}finally{Ee(!1)}}};cn&&e?.bot&&ut.length===0&&(M(),localStorage.getItem("webChatAuth")&&JSON.parse(localStorage.getItem("webChatAuth"))&&u?.botNeedsAuth&&Fr&&(Qn||wt||oi)&&(setTimeout(()=>{xo(Fr)},2e3),localStorage.setItem("webChatAuth","true")))},[cn,e?.bot]),ye.useEffect(()=>(Xe==="recording"?be.current||(be.current=setInterval(()=>{Fe.current+=1;const M=Math.floor(Fe.current/60).toString().padStart(2,"0"),fe=(Fe.current%60).toString().padStart(2,"0");pe(`${M}:${fe}`)},1e3)):be.current&&(clearInterval(be.current),be.current=null),()=>{be.current&&(clearInterval(be.current),be.current=null)}),[Xe]),ye.useEffect(()=>{pt&&pt.toLowerCase().includes("permission_denied")&&(Pe(!1),pe("00:00"),Fe.current=0,be.current&&(clearInterval(be.current),be.current=null),alert("Microphone permission denied. Please allow access to record audio."))},[pt]),ye.useEffect(()=>{Xe!=="recording"&&Xe!=="paused"&&(pe("00:00"),Fe.current=0)},[Xe]);const si=ye.useRef(null);ye.useEffect(()=>{if(si&&si.current){const M=si.current;M.style.height="auto";const fe=120;M.scrollHeight>fe?(M.style.height=fe+"px",M.style.overflowY="auto"):(M.style.height=M.scrollHeight+"px",M.style.overflowY="hidden")}},[vt]),ye.useEffect(()=>{(Ge||ge)&&t.current&&(t.current.scrollTop=t.current.scrollHeight)},[ut,ge,Ge]);const Nl=M=>{const fe=M.type.toLowerCase();return fe.startsWith("image/")?"image":fe.startsWith("video/")?"video":fe.startsWith("audio/")?"audio":"document"},Cn=ye.useCallback((M,fe)=>{const me=[];Array.from(M).forEach(xe=>{if(xe.size>10*1024*1024){alert(`File ${xe.name} is too large. Maximum size is 10MB.`);return}const ht={id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:xe,type:Nl(xe),url:URL.createObjectURL(xe),name:xe.name,size:xe.size};me.push(ht)}),Le(xe=>[...xe,...me]),fe&&fe.current&&(fe.current.value="")},[]),Ro=ye.useCallback(M=>{M.preventDefault(),Ze.current=0,Me(!1);const fe=M.dataTransfer.files;fe.length>0&&Cn(fe)},[Cn]),Br=ye.useCallback(M=>{M.preventDefault(),Ze.current+=1,Me(!0)},[]),Ur=ye.useCallback(M=>{M.preventDefault()},[]),Ra=ye.useCallback(M=>{M.preventDefault(),Ze.current-=1,Ze.current<=0&&Me(!1)},[]),Pr=M=>{Le(fe=>{const me=fe.find(xe=>xe.id===M);return me&&URL.revokeObjectURL(me.url),fe.filter(xe=>xe.id!==M)})},Ct=M=>{if(M===0)return"0 Bytes";const fe=1024,me=["Bytes","KB","MB","GB"],xe=Math.floor(Math.log(M)/Math.log(fe));return Number.parseFloat((M/Math.pow(fe,xe)).toFixed(2))+" "+me[xe]},ur=async(M=vt)=>{if(M.trim()||Oe.length!==0){const me={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"user",content:M,attachments:[...Oe],timestamp:new Date};if(ct(xe=>[...xe,me]),Ht(""),Le([]),Ee(!0),e?.bot)try{try{const xe=await Jn(M,e?.bot.botId);ct(ht=>[...ht,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:xe,timestamp:new Date,seen:tn.current,nMessage:typeof xe=="string"?1:xe.length}])}catch{ct(xe=>[...xe,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Erreur du serveur",timestamp:new Date,seen:tn.current,nMessage:1}])}}catch(xe){console.error("Error parsing selectedBotInfo:",xe)}else ct(xe=>[...xe,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Aucun bot sélectionné",timestamp:new Date,seen:tn.current,nMessage:1}]);Ee(!1)}else return},xa=M=>{switch(qe(!1),M){case"image":n.current?.click();break;case"video":a.current?.click();break;case"audio":o.current?.click();break;case"document":l.current?.click();break}},Jn=async(M,fe)=>{const{data:me}=await Et.post(e?.API_URL||y6,{messageText:M,botId:fe,conversation_id:Fr,isintern:!!e?.token,host:window.location.origin});return me},zr=({attachment:M,onRemove:fe})=>B.jsxs("div",{className:"relative group w-24 h-24 rounded-xl overflow-hidden bg-gray-900 shadow-md border border-gray-700",children:[M.type==="image"&&M.url?B.jsx("img",{src:M.url,alt:M.name,className:"w-full h-full object-cover"}):B.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center text-gray-300 px-1 text-center text-xs",children:[M.type==="video"&&B.jsx(vA,{className:"w-5 h-5 mb-1 text-red-400"}),M.type==="audio"&&B.jsx(Wc,{className:"w-5 h-5 mb-1 text-green-400"}),M.type==="document"&&B.jsx(jP,{className:"w-5 h-5 mb-1 text-yellow-400"}),B.jsx("span",{className:"w-full truncate",title:M.name,children:M.name})]}),B.jsx("button",{onClick:fe,className:"absolute top-1 right-1 w-5 h-5 bg-black bg-opacity-50 rounded-full text-white flex items-center justify-center hover:bg-opacity-80",title:"Remove",children:B.jsx(Ws,{className:"w-3 h-3"})})]}),Tb=/^[\u0600-\u06FF\u0750-\u077F\s\d\p{P}]+$/u,Cl=/[\u0600-\u06FF\u0750-\u077F]/,Zt=M=>Tb.test(M),Rb=M=>Cl.test(M),$n={h1:({children:M})=>B.jsx("h1",{className:"text-2xl font-bold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),h2:({children:M})=>B.jsx("h2",{className:"text-xl font-semibold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),h3:({children:M})=>B.jsx("h3",{className:"text-lg font-semibold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),h4:({children:M})=>B.jsx("h4",{className:"text-base font-semibold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),h5:({children:M})=>B.jsx("h5",{className:"text-base font-semibold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),h6:({children:M})=>B.jsx("h6",{className:"text-base font-semibold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),p:({children:M})=>B.jsx("p",{className:"leading-relaxed",dir:Zt(M)?"rtl":"ltr",children:M}),ul:({children:M})=>B.jsx("ul",{className:"list-disc list-inside ml-4 my-2 text-gray-200",dir:Rb(M)?"rtl":"ltr",children:M}),ol:({children:M})=>{let fe=!1;return M.every(me=>me?.props?.node?.children[0].type==="text"&&Zt(me?.props?.node?.children[0].value))?fe=!0:fe=!1,B.jsx("ol",{className:"list-decimal list-inside ml-4 my-2 text-gray-200",dir:fe?"rtl":"ltr",children:M})},li:({children:M})=>B.jsx("li",{className:"my-1",dir:Zt(M)?"rtl":"ltr",children:M}),a:({href:M,children:fe})=>B.jsx("a",{href:M,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:fe}),blockquote:({children:M})=>B.jsx("blockquote",{className:"border-l-4 border-purple-500 pl-4 italic my-2",children:M}),code({node:M,className:fe,children:me,...xe}){const ht=/language-(\w+)/.exec(fe||"");return ht?B.jsx(t0,{...xe,PreTag:"div",children:String(me).replace(/\n$/,""),language:ht[1],style:l6}):B.jsx("code",{className:"bg-gray-800 px-1 rounded font-mono inline",...xe,children:me})},table:({children:M})=>B.jsx("table",{className:"min-w-full my-2 border border-gray-700",children:M}),thead:({children:M})=>B.jsx("thead",{className:"bg-gray-800",children:M}),tbody:({children:M})=>B.jsx("tbody",{children:M}),tr:({children:M})=>B.jsx("tr",{className:"border-b border-gray-700",children:M}),th:({children:M})=>B.jsx("th",{className:"px-3 py-2 font-semibold text-left bg-gray-800",children:M}),td:({children:M})=>B.jsx("td",{className:"px-3 py-2",children:M}),strong:({children:M})=>B.jsx("strong",{className:"font-bold",children:M}),em:({children:M})=>B.jsx("em",{className:"italic ",children:M}),hr:()=>B.jsx("hr",{className:"my-4 border-purple-700"})};ye.useEffect(()=>{const M=fe=>{it&&fe.target instanceof Element&&!fe.target.closest("#upload-button-toggle")&&!fe.target.closest("#document-button")&&!fe.target.closest("#image-button")&&!fe.target.closest("#video-button")&&!fe.target.closest("#audio-button")&&qe(!1)};return document.addEventListener("mousedown",M),()=>{document.removeEventListener("mousedown",M)}},[it]);const li=M=>{switch(M.type){case"text":return B.jsx(so,{remarkPlugins:[uo],components:$n,children:M.text?.replace(/\n/g,`
325
+ ***************************************************************************** */function a0(e,t){const[n,a]=ye.useState(null),o=ye.useMemo(()=>Object.entries(t).flat(),[t]);return ye.useEffect(()=>{if(!e?.current)return;const l=wb.create(Object.assign(Object.assign({},t),{container:e.current}));return a(l),()=>{l.destroy()}},[e,...o]),n}const i0=/^on([A-Z])/,h6=e=>i0.test(e);function m6(e,t){const n=ye.useMemo(()=>Object.entries(t).flat(),[t]);ye.useEffect(()=>{if(!e)return;const a=Object.entries(t);if(!a.length)return;const o=a.map(([l,u])=>{const d=l.replace(i0,(p,f)=>f.toLowerCase());return e.on(d,(...p)=>u(e,...p))});return()=>{o.forEach(l=>l())}},[e,...n])}ye.memo(e=>{const t=ye.useRef(null),[n,a]=function(o){return ye.useMemo(()=>{const l=Object.assign({},o),u=Object.assign({},o);for(const d in l)h6(d)?delete l[d]:delete u[d];return[l,u]},[o])}(e);return m6(a0(t,n),a),B.jsx("div",{ref:t})});function b6(e){var{container:t}=e;const n=a0(t,function(o,l){var u={};for(var d in o)Object.prototype.hasOwnProperty.call(o,d)&&l.indexOf(d)<0&&(u[d]=o[d]);if(o!=null&&typeof Object.getOwnPropertySymbols=="function"){var p=0;for(d=Object.getOwnPropertySymbols(o);p<d.length;p++)l.indexOf(d[p])<0&&Object.prototype.propertyIsEnumerable.call(o,d[p])&&(u[d[p]]=o[d[p]])}return u}(e,["container"])),a=function(o){const[l,u]=ye.useState(!1),[d,p]=ye.useState(!1),[f,h]=ye.useState(!1),[m,y]=ye.useState(0);return ye.useEffect(()=>{if(!o)return;const E=[o.on("load",()=>{u(!1),p(!1),y(0)}),o.on("ready",()=>{u(!0),p(!1),h(!1),y(0)}),o.on("finish",()=>{h(!0)}),o.on("play",()=>{p(!0)}),o.on("pause",()=>{p(!1)}),o.on("timeupdate",()=>{y(o.getCurrentTime())}),o.on("destroy",()=>{u(!1),p(!1)})];return()=>{E.forEach(v=>v())}},[o]),ye.useMemo(()=>({isReady:l,isPlaying:d,hasFinished:f,currentTime:m}),[d,f,m,l])}(n);return ye.useMemo(()=>Object.assign(Object.assign({},a),{wavesurfer:n}),[a,n])}const o0="https://api.tybotflow.com/api/v1",y6="https://api.tybotflow.com/api/v1/web/send-message",E6="https://api.tybotflow.com/api/v1/chatbots-config",v6=({attachment:e,formatFileSize:t,mainColor:n,secondaryColor:a,controlsColor:o})=>{const{type:l,url:u,name:d,size:p}=e;switch(l){case"image":return B.jsxs("div",{className:"relative group",children:[B.jsx("img",{src:u,alt:d,className:"max-w-xs max-h-48 rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(u,"_blank")}),B.jsx("div",{className:"absolute bottom-2 left-2 bg-black bg-opacity-60 text-white text-xs px-2 py-1 rounded",children:t(p)})]});case"video":return B.jsxs("div",{className:"max-w-xs",children:[B.jsx("video",{src:u,controls:!0,className:"w-full max-h-48 rounded-lg",preload:"metadata",onError:()=>{console.error("Video failed to load:",u)},children:"Your browser does not support the video tag."}),B.jsxs("div",{className:"flex text-xs text-white mt-1 w-full overflow-hidden whitespace-nowrap text-ellipsis",children:[B.jsx("span",{className:"block w-full overflow-hidden whitespace-nowrap text-ellipsis",title:d,children:d}),B.jsxs("span",{className:"ml-2",children:["• ",t(p)]})]})]});case"audio":return B.jsxs("div",{className:"bg-gray-800 bg-opacity-70 p-3 rounded-lg flex-1 w-full",children:[B.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[B.jsx(Wc,{className:"w-4 h-4",style:{color:n}}),B.jsx("span",{className:"text-sm font-medium truncate text-white",title:d,children:d})]}),B.jsx(S6,{src:u,mainColor:n,secondaryColor:a,controlsColor:o}),B.jsx("p",{className:"text-xs text-gray-400 mt-1",children:t(p)})]});case"document":return B.jsx("div",{className:"bg-gray-800 bg-opacity-50 p-3 rounded-lg max-w-xs cursor-pointer hover:bg-opacity-70 transition-colors",onClick:()=>window.open(u,"_blank"),children:B.jsxs("div",{className:"flex items-center gap-3",children:[B.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-lg flex items-center justify-center",children:B.jsx(EA,{className:"w-5 h-5 text-white"})}),B.jsxs("div",{className:"flex-1 min-w-0",children:[B.jsx("p",{className:"text-sm font-medium truncate text-white",children:d}),B.jsx("p",{className:"text-xs text-gray-400",children:t(p)})]})]})});default:return null}},S6=({src:e,mainColor:t,secondaryColor:n,controlsColor:a})=>{const o=ye.useRef(null),[l,u]=ye.useState(1),{wavesurfer:d,isPlaying:p}=b6({container:o,waveColor:t,progressColor:n,barWidth:2,height:50,url:e}),f=()=>{d&&d.playPause()},h=()=>{const E=l===0?1:0;u(E),d?.setVolume(E)},m=()=>{d?.skip(-.096)},y=()=>{d?.skip(.096)};return B.jsxs("div",{className:"flex w-full flex-col items-center rounded-xl pt-1",children:[B.jsx("div",{ref:o,className:"w-full px-2"}),B.jsxs("div",{className:"flex w-full items-center justify-between",children:[B.jsx("div",{className:"relative flex items-center",children:B.jsx("button",{className:"transition-colors",style:{color:a},onClick:h,"aria-label":"Toggle volume",children:l===0?B.jsx(tz,{size:20}):B.jsx(ez,{size:20})})}),B.jsxs("div",{className:"-ml-9 flex flex-1 cursor-auto justify-center gap-2 rounded-full py-2 text-white",children:[B.jsx("button",{onClick:m,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:a},"aria-label":"Step back",children:B.jsx(KP,{})}),B.jsx("button",{onClick:f,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:a},"aria-label":p?"Pause":"Play",children:p?B.jsx(VP,{}):B.jsx(YP,{})}),B.jsx("button",{onClick:y,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:a},"aria-label":"Step forward",children:B.jsx(QP,{})})]})]})]})},A6=({config:e})=>{const t=ye.useRef(null),n=ye.useRef(null),a=ye.useRef(null),o=ye.useRef(null),l=ye.useRef(null),[u,d]=ye.useState(null),[p,f]=ye.useState(!0);ye.useEffect(()=>{(async()=>{f(!0),await Et.get(`${E6}/bot/${e.bot?.botId}`,{}).then(fe=>{d(fe.data)}).catch(fe=>{console.error("Error fetching bot config:",fe)}).finally(()=>{f(!1)})})()},[e.bot?.botId,e?.token]);const h=u?.mainColor||"#59168b",m=u?.secondaryColor||"#6366f1",y=u?.thirdColor||"#0f172b",E=u?.headerFirstColor||"#6e11b0",v=u?.headerSecondColor||"#372aac",A=u?.inputBackgroundColor||"#1f2937",w=u?.inputTextColor||"#fff",R=u?.roundness||24,N=u?.chatRoundness||16,C=(u?.minPanelWidth||434)>window.innerWidth?window.innerWidth:u?.minPanelWidth||434,D=(u?.maxPanelWidth||window.innerWidth)>window.innerWidth?window.innerWidth:u?.maxPanelWidth||window.innerWidth,O=u?.chatMaxWidth||88,x=u?.toggleBtnBorderTopLeftRadius||12,L=u?.toggleBtnBorderTopRightRadius||0,P=u?.toggleBtnBorderBottomLeftRadius||12,z=u?.toggleBtnBorderBottomRightRadius||0,F=u?.menuBackgroundColor||"#1f2937",H=u?.menuTextColor||"#e5e7eb",X=u?.menuHoverBackgroundColor||"#374151",$=u?.agentChatResponseColor||"#e5e7eb",ne=u?.agentChatResponseBgColor||"#1f2937",re=u?.agentIconBgColor||"#59168b",q=u?.agentIconColor||"#fff",K=u?.userChatMessagesColor||"#fff",Y=u?.userChatMessagesBgColor||"#7a1ebe",oe=u?.userIconBgColor||"#7a1ebe",S=u?.userIconColor||"#fff",G=u?.ButtonColor||"#fff",te=u?.ButtonsBgColor||"#59168b",[I,ce]=ye.useState(C),he=ye.useRef(!1),ue=ye.useRef(0),Ae=ye.useRef(C),Te=M=>{he.current=!0,ue.current=M.clientX,Ae.current=I,document.body.style.cursor="ew-resize"};ye.useEffect(()=>{const M=me=>{if(!he.current)return;const xe=ue.current-me.clientX;let ht=Ae.current+xe;ht=Math.max(C,Math.min(D,ht)),ce(ht)},fe=()=>{he.current&&(he.current=!1,document.body.style.cursor="")};return window.addEventListener("mousemove",M),window.addEventListener("mouseup",fe),()=>{window.removeEventListener("mousemove",M),window.removeEventListener("mouseup",fe)}},[I,C,D]);const[Ge,Je]=ye.useState(!1),[ft,It]=ye.useState(!1),[vt,Ht]=ye.useState(""),[ge,Ee]=ye.useState(!1),[Oe,Le]=ye.useState([]),[ke,Me]=ye.useState(!1),Ze=ye.useRef(0),[it,qe]=ye.useState(!1),[Ie,Pe]=ye.useState(!1),J=ye.useRef(!1),[ie,pe]=ye.useState("00:00"),be=ye.useRef(null),Fe=ye.useRef(0),[Mt,Ft]=ye.useState([]),[ut,ct]=ye.useState([]),{startRecording:dt,stopRecording:gt,pauseRecording:Nt,resumeRecording:Bt,status:Xe,error:pt}=wH.useReactMediaRecorder({video:!1,onStop(M,fe){if(J.current){J.current=!1,pe("00:00"),Fe.current=0;return}Le(me=>[...me,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:fe,type:"audio",url:M,name:`recording-${new Date().toISOString()}.webm`,size:fe.size}]),pe("00:00"),Fe.current=0}}),bn=u?.icon||e?.bot.avatar_url||u6,yn=u?.title||e?.bot.name||"Tybot webchat",[Fr,wa]=ye.useState(()=>{if(!u?.botNeedsAuth){let M=localStorage.getItem("conversationId");if(!M){const fe=new Uint8Array(16);window.crypto.getRandomValues(fe),M=Array.from(fe).map(me=>me.toString(16).padStart(2,"0")).join("")}return localStorage.setItem("conversationId",M),M}}),[cn,lr]=ye.useState(()=>u?.botNeedsAuth?!!localStorage.getItem("conversationId"):!0),[Qn,Rl]=ye.useState(""),[oi,Zn]=ye.useState(""),[wt,Qt]=ye.useState(""),tn=ye.useRef(!1),Ta=ut.reduce((M,fe)=>fe.seen?M:M+(fe.sender==="agent"?fe.nMessage||1:0),0),xl=()=>{ct(M=>M.map(fe=>({...fe,seen:!0})))};ye.useEffect(()=>{const M=setTimeout(()=>{Je(!0),tn.current=!0,xl()},3200);return()=>clearTimeout(M)},[]),ye.useEffect(()=>{const M=async()=>{if(e?.bot){Ee(!0);try{const fe=await Jn("hi",e?.bot.botId);ct(me=>[...me,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:fe,timestamp:new Date,seen:tn.current,nMessage:typeof fe=="string"?1:fe.length}])}catch(fe){console.error("Error sending message:",fe)}finally{Ee(!1)}}};cn&&e?.bot&&ut.length===0&&(M(),localStorage.getItem("webChatAuth")&&JSON.parse(localStorage.getItem("webChatAuth"))&&u?.botNeedsAuth&&Fr&&(Qn||wt||oi)&&(setTimeout(()=>{xo(Fr)},2e3),localStorage.setItem("webChatAuth","true")))},[cn,e?.bot]),ye.useEffect(()=>(Xe==="recording"?be.current||(be.current=setInterval(()=>{Fe.current+=1;const M=Math.floor(Fe.current/60).toString().padStart(2,"0"),fe=(Fe.current%60).toString().padStart(2,"0");pe(`${M}:${fe}`)},1e3)):be.current&&(clearInterval(be.current),be.current=null),()=>{be.current&&(clearInterval(be.current),be.current=null)}),[Xe]),ye.useEffect(()=>{pt&&pt.toLowerCase().includes("permission_denied")&&(Pe(!1),pe("00:00"),Fe.current=0,be.current&&(clearInterval(be.current),be.current=null),alert("Microphone permission denied. Please allow access to record audio."))},[pt]),ye.useEffect(()=>{Xe!=="recording"&&Xe!=="paused"&&(pe("00:00"),Fe.current=0)},[Xe]);const si=ye.useRef(null);ye.useEffect(()=>{if(si&&si.current){const M=si.current;M.style.height="auto";const fe=120;M.scrollHeight>fe?(M.style.height=fe+"px",M.style.overflowY="auto"):(M.style.height=M.scrollHeight+"px",M.style.overflowY="hidden")}},[vt]),ye.useEffect(()=>{(Ge||ge)&&t.current&&(t.current.scrollTop=t.current.scrollHeight)},[ut,ge,Ge]);const Nl=M=>{const fe=M.type.toLowerCase();return fe.startsWith("image/")?"image":fe.startsWith("video/")?"video":fe.startsWith("audio/")?"audio":"document"},Cn=ye.useCallback((M,fe)=>{const me=[];Array.from(M).forEach(xe=>{if(xe.size>10*1024*1024){alert(`File ${xe.name} is too large. Maximum size is 10MB.`);return}const ht={id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:xe,type:Nl(xe),url:URL.createObjectURL(xe),name:xe.name,size:xe.size};me.push(ht)}),Le(xe=>[...xe,...me]),fe&&fe.current&&(fe.current.value="")},[]),Ro=ye.useCallback(M=>{M.preventDefault(),Ze.current=0,Me(!1);const fe=M.dataTransfer.files;fe.length>0&&Cn(fe)},[Cn]),Br=ye.useCallback(M=>{M.preventDefault(),Ze.current+=1,Me(!0)},[]),Ur=ye.useCallback(M=>{M.preventDefault()},[]),Ra=ye.useCallback(M=>{M.preventDefault(),Ze.current-=1,Ze.current<=0&&Me(!1)},[]),Pr=M=>{Le(fe=>{const me=fe.find(xe=>xe.id===M);return me&&URL.revokeObjectURL(me.url),fe.filter(xe=>xe.id!==M)})},Ct=M=>{if(M===0)return"0 Bytes";const fe=1024,me=["Bytes","KB","MB","GB"],xe=Math.floor(Math.log(M)/Math.log(fe));return Number.parseFloat((M/Math.pow(fe,xe)).toFixed(2))+" "+me[xe]},ur=async(M=vt)=>{if(M.trim()||Oe.length!==0){const me={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"user",content:M,attachments:[...Oe],timestamp:new Date};if(ct(xe=>[...xe,me]),Ht(""),Le([]),Ee(!0),e?.bot)try{try{const xe=await Jn(M,e?.bot.botId);ct(ht=>[...ht,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:xe,timestamp:new Date,seen:tn.current,nMessage:typeof xe=="string"?1:xe.length}])}catch{ct(xe=>[...xe,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Erreur du serveur",timestamp:new Date,seen:tn.current,nMessage:1}])}}catch(xe){console.error("Error parsing selectedBotInfo:",xe)}else ct(xe=>[...xe,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Aucun bot sélectionné",timestamp:new Date,seen:tn.current,nMessage:1}]);Ee(!1)}else return},xa=M=>{switch(qe(!1),M){case"image":n.current?.click();break;case"video":a.current?.click();break;case"audio":o.current?.click();break;case"document":l.current?.click();break}},Jn=async(M,fe)=>{const{data:me}=await Et.post(e?.API_URL||y6,{messageText:M,botId:fe,conversation_id:Fr,isintern:!!e?.token,host:window.location.origin});return me},zr=({attachment:M,onRemove:fe})=>B.jsxs("div",{className:"relative group w-24 h-24 rounded-xl overflow-hidden bg-gray-900 shadow-md border border-gray-700",children:[M.type==="image"&&M.url?B.jsx("img",{src:M.url,alt:M.name,className:"w-full h-full object-cover"}):B.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center text-gray-300 px-1 text-center text-xs",children:[M.type==="video"&&B.jsx(vA,{className:"w-5 h-5 mb-1 text-red-400"}),M.type==="audio"&&B.jsx(Wc,{className:"w-5 h-5 mb-1 text-green-400"}),M.type==="document"&&B.jsx(jP,{className:"w-5 h-5 mb-1 text-yellow-400"}),B.jsx("span",{className:"w-full truncate",title:M.name,children:M.name})]}),B.jsx("button",{onClick:fe,className:"absolute top-1 right-1 w-5 h-5 bg-black bg-opacity-50 rounded-full text-white flex items-center justify-center hover:bg-opacity-80",title:"Remove",children:B.jsx(Ws,{className:"w-3 h-3"})})]}),Tb=/^[\u0600-\u06FF\u0750-\u077F\s\d\p{P}]+$/u,Cl=/[\u0600-\u06FF\u0750-\u077F]/,Zt=M=>Tb.test(M),Rb=M=>Cl.test(M),$n={h1:({children:M})=>B.jsx("h1",{className:"text-2xl font-bold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),h2:({children:M})=>B.jsx("h2",{className:"text-xl font-semibold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),h3:({children:M})=>B.jsx("h3",{className:"text-lg font-semibold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),h4:({children:M})=>B.jsx("h4",{className:"text-base font-semibold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),h5:({children:M})=>B.jsx("h5",{className:"text-base font-semibold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),h6:({children:M})=>B.jsx("h6",{className:"text-base font-semibold my-2",dir:Zt(M)?"rtl":"ltr",children:M}),p:({children:M})=>B.jsx("p",{className:"leading-relaxed",dir:Zt(M)?"rtl":"ltr",children:M}),ul:({children:M})=>B.jsx("ul",{className:"list-disc list-inside ml-4 my-2 text-gray-200",dir:Rb(M)?"rtl":"ltr",children:M}),ol:({children:M})=>{let fe=!1;return M.every(me=>me?.props?.node?.children[0].type==="text"&&Zt(me?.props?.node?.children[0].value))?fe=!0:fe=!1,B.jsx("ol",{className:"list-decimal list-inside ml-4 my-2 text-gray-200",dir:fe?"rtl":"ltr",children:M})},li:({children:M})=>B.jsx("li",{className:"my-1",dir:Zt(M)?"rtl":"ltr",children:M}),a:({href:M,children:fe})=>B.jsx("a",{href:M,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:fe}),blockquote:({children:M})=>B.jsx("blockquote",{className:"border-l-4 border-purple-500 pl-4 italic my-2",children:M}),code({node:M,className:fe,children:me,...xe}){const ht=/language-(\w+)/.exec(fe||"");return ht?B.jsx(t0,{...xe,PreTag:"div",children:String(me).replace(/\n$/,""),language:ht[1],style:l6}):B.jsx("code",{className:"bg-gray-800 px-1 rounded font-mono inline",...xe,children:me})},table:({children:M})=>B.jsx("table",{className:"min-w-full my-2 border border-gray-700",children:M}),thead:({children:M})=>B.jsx("thead",{className:"bg-gray-800",children:M}),tbody:({children:M})=>B.jsx("tbody",{children:M}),tr:({children:M})=>B.jsx("tr",{className:"border-b border-gray-700",children:M}),th:({children:M})=>B.jsx("th",{className:"px-3 py-2 font-semibold text-left bg-gray-800",children:M}),td:({children:M})=>B.jsx("td",{className:"px-3 py-2",children:M}),strong:({children:M})=>B.jsx("strong",{className:"font-bold",children:M}),em:({children:M})=>B.jsx("em",{className:"italic ",children:M}),hr:()=>B.jsx("hr",{className:"my-4 border-purple-700"})};ye.useEffect(()=>{const M=fe=>{it&&fe.target instanceof Element&&!fe.target.closest("#upload-button-toggle")&&!fe.target.closest("#document-button")&&!fe.target.closest("#image-button")&&!fe.target.closest("#video-button")&&!fe.target.closest("#audio-button")&&qe(!1)};return document.addEventListener("mousedown",M),()=>{document.removeEventListener("mousedown",M)}},[it]);const li=M=>{switch(M.type){case"text":return B.jsx(so,{remarkPlugins:[uo],components:$n,children:M.text?.replace(/\n/g,`
326
326
  `)});case"single-choice":return B.jsxs(B.Fragment,{children:[B.jsx(so,{remarkPlugins:[uo],components:$n,children:M.text?.replace(/\n/g,`
327
- `)||""}),B.jsx("div",{className:"flex flex-wrap",dir:Zt(M.text||"")?"rtl":"ltr",children:M.choices?.map((me,xe)=>B.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{ur(me.title)},style:{background:te,borderRadius:N,color:G},dir:Zt(me.title)?"rtl":"ltr",children:me.title},xe))})]});case"image":return B.jsx(B.Fragment,{children:B.jsx("div",{className:"relative group",children:B.jsx("img",{src:M.image,className:"max-w-xs max-h-48 rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(M.image,"_blank")})})});case"dropdown":return B.jsxs(B.Fragment,{children:[B.jsx(so,{remarkPlugins:[uo],components:$n,children:M.message?.replace(/\n/g,`
328
- `)||""}),B.jsxs("div",{className:"flex flex-wrap",dir:Zt(M.message||"")?"rtl":"ltr",children:[B.jsx("p",{className:"mr-2",children:"ou"}),M.options?.map((me,xe)=>B.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{ur(me.value)},style:{background:te,borderRadius:N,color:G},dir:Zt(M.message||"")?"rtl":"ltr",children:me.label},xe))]})]});case"carousel":const fe=(M.items?.length||0)<2?1:2;return B.jsx("div",{className:"mt-2 w-full",children:B.jsx("div",{className:`grid grid-cols-1 sm:grid-cols-${fe} gap-3`,children:M.items?.map((me,xe)=>B.jsxs("div",{className:"flex-shrink-0 border p-3 shadow-md",style:{background:ne,borderRadius:N},children:[me.image&&B.jsx("img",{src:me.image,alt:me.title,className:"h-32 w-full object-cover rounded-md mb-2"}),B.jsx("h3",{className:"text-sm font-bold",title:me.title,children:me.title}),B.jsx("p",{className:"text-xs text-gray-300 mb-2 line-clamp-2",title:me.subtitle,children:me.subtitle}),me.actions?.map((ht,jn)=>{let cr;try{cr=typeof ht.payload=="string"?JSON.parse(ht.payload):ht.payload}catch{cr={productName:me.title}}return B.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{ht.action==="Open URL"?window.open(ht.url,"_blank"):ht.title==="scan"?fetch(me.image).then(nn=>nn.blob()).then(nn=>{const Ol=URL.createObjectURL(nn),Ut=document.createElement("a");Ut.href=Ol,Ut.download="qrcode.png",document.body.appendChild(Ut),Ut.click(),document.body.removeChild(Ut),URL.revokeObjectURL(Ol)}).catch(()=>{alert("Failed to download image.")}):ur(cr.productName||M.title)},style:{background:te,borderRadius:N,color:G},children:ht.title},jn)})]},xe))})});case"card":return B.jsx("div",{className:"mt-2 w-full",children:B.jsx("div",{className:"grid grid-cols-1 gap-3",children:B.jsxs("div",{className:"flex-shrink-0 border rounded-lg p-3 shadow-md",style:{background:ne},children:[M.image&&B.jsx("img",{src:M.image,alt:M.title,className:"h-32 w-full object-cover rounded-md mb-2"}),B.jsx("h3",{className:"text-sm font-bold",children:M.title}),M.actions?.map((me,xe)=>{let ht;try{ht=typeof me.payload=="string"?JSON.parse(me.payload):me.payload}catch{ht={productName:M.title}}return B.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{me.action==="Open URL"?window.open(me.url,"_blank"):me.title==="scan"?M.image&&fetch(M.image).then(jn=>jn.blob()).then(jn=>{const cr=URL.createObjectURL(jn),nn=document.createElement("a");nn.href=cr,nn.download="qrcode.png",document.body.appendChild(nn),nn.click(),document.body.removeChild(nn),URL.revokeObjectURL(cr)}).catch(()=>{alert("Failed to download image.")}):ur(ht.productName||M.title)},style:{background:te,borderRadius:N,color:G},children:me.title},xe)})]})})})}},qn=async M=>{if(!cn)return;const fe=await fetch(`${o0}/endusers/get-by-username`,{headers:{Authorization:`Bearer ${e?.token}`,"Content-Type":"application/json"},method:"POST",body:JSON.stringify({username:`web_user_${M}`})});if(!fe.ok)throw new Error(`HTTP error! status: ${fe.status}`);return(await fe.json()).id},xo=async M=>{if(!cn)return;const fe=await qn(M);let me;Qn&&(me={last_name:Qn.split(" ")[1]||Qn.split(" ")[0]||`web_user_${M}`,first_name:Qn.split(" ")[0]||`web_user_${M}`}),oi&&(me={...me,phone:oi}),wt&&(me={...me,email:wt});const xe=await fetch(`${o0}/endusers/${fe}`,{headers:{Authorization:`Bearer ${e?.token}`,"Content-Type":"application/json"},method:"PUT",body:JSON.stringify(me)});if(!xe.ok)throw new Error(`HTTP error! status: ${xe.status}`);return await xe.json()},kl=async M=>{M.preventDefault();const fe=new Uint8Array(16);window.crypto.getRandomValues(fe);const me=Array.from(fe).map(xe=>xe.toString(16).padStart(2,"0")).join("");wa(me),localStorage.setItem("conversationId",me),localStorage.setItem("webChatAuth","true"),lr(!0)},qr=`linear-gradient(to bottom right, ${y}, ${h}, ${y})`,No=`linear-gradient(to right, ${h}, ${m})`,Co=`linear-gradient(to right, ${E}, ${v})`;return p||!u?null:B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"fixed top-0 right-0 h-full shadow-2xl",style:{width:I+"px",transition:"transform 0.3s cubic-bezier(0.4,0,0.2,1)",transform:Ge?"translateX(0)":`translateX(${I}px)`,background:qr,zIndex:1e3},onDrop:Ro,onDragOver:Ur,onDragEnter:Br,onDragLeave:Ra,children:[B.jsx("div",{onMouseDown:Te,className:"absolute left-0 top-0 h-full w-2 cursor-ew-resize z-50 bg-transparent opacity-50 transition-colors",style:{userSelect:"none"},onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="transparent"}),ke&&B.jsx("div",{className:"absolute inset-0 bg-opacity-20 border-2 border-dashed flex items-center justify-center z-15",style:{borderColor:h},children:B.jsxs("div",{className:"text-center ",style:{color:w},children:[B.jsx(JP,{className:"w-12 h-12 mx-auto mb-2"}),B.jsx("p",{className:"text-lg font-semibold",children:"Drop files here"})]})}),cn?B.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",style:{background:Co,borderColor:v},children:[B.jsxs("div",{className:"flex items-center gap-3",children:[B.jsx("div",{className:"size-10 flex items-center justify-center overflow-hidden rounded-full",children:B.jsx("img",{src:bn,alt:`${yn} Logo`,className:"w-full h-full"})}),B.jsx("h2",{className:"text-lg font-semibold",style:{color:w},children:yn})]}),B.jsxs("div",{className:"flex justify-between items-center gap-2 ml-2",children:[B.jsx("button",{onClick:()=>It(!0),className:"transition-colors p-1 rounded-full",style:{color:w},title:"Bot info","aria-label":"Bot info",onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:B.jsx(GP,{className:"w-5 h-5"})}),B.jsx("button",{onClick:()=>{Je(!1),tn.current=!1},className:"transition-colors p-1 rounded-full",style:{color:w},title:"Close Chat","aria-label":"Close Chat",onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:B.jsx(Ws,{className:"w-5 h-5"})})]})]}):B.jsx("div",{className:"flex items-center justify-end px-6 py-3",children:B.jsx("div",{className:"flex items-center",children:B.jsx("button",{onClick:()=>{Je(!1),tn.current=!1},className:"transition-colors p-1 rounded-full",style:{color:e?.inputTextColor||"#FFF"},title:"Close Chat","aria-label":"Close Chat",onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:B.jsx(Ws,{className:"w-5 h-5"})})})}),cn&&B.jsxs("div",{ref:t,className:"flex-1 px-4 py-4 overflow-y-auto space-y-4 scroll-smooth",style:{height:"calc(100% - 140px)",scrollbarWidth:"thin",scrollbarColor:`${h} transparent`},children:[ut.map(M=>B.jsxs("div",{className:`flex items-start gap-3 ${M.sender==="user"?"flex-row-reverse":""}`,children:[B.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0",style:{background:M.sender==="user"?oe:re},children:M.sender==="user"?B.jsx($P,{className:"w-4 h-4",style:{color:S}}):B.jsx(yA,{className:"w-4 h-4",style:{color:q}})}),B.jsxs("div",{className:`flex flex-col flex-1 ${M.sender==="user"?"items-end":"items-start"}`,children:[M.attachments&&M.attachments.length>0&&B.jsx("div",{className:"flex flex-col items-end w-[88%] mb-2 space-y-2",children:M.attachments.map(fe=>B.jsx(v6,{attachment:fe,formatFileSize:Ct,mainColor:h,secondaryColor:m,controlsColor:w},fe.id))}),M.content&&M.sender==="user"?B.jsx("div",{className:"px-4 py-2 rounded-2xl backdrop-blur-sm break-words w-fit",style:{wordBreak:"break-word",overflowWrap:"break-word",borderRadius:N,maxWidth:O+"%",background:Y,color:K},children:B.jsx(so,{remarkPlugins:[uo],components:$n,children:typeof M.content=="string"?M.content.replace(/\n/g,`
329
- `):""})}):typeof M.content=="object"?M.content.map((fe,me)=>B.jsx("div",{className:"mb-1 px-4 py-2 rounded-2xl backdrop-blur-sm break-words w-fit",style:{wordBreak:"break-word",overflowWrap:"break-word",borderRadius:N,maxWidth:O+"%",background:ne,color:$},children:li(fe)},me)):B.jsx("div",{className:"mb-1 px-4 py-2 rounded-2xl backdrop-blur-sm break-words w-fit",style:{wordBreak:"break-word",overflowWrap:"break-word",borderRadius:N,maxWidth:O+"%",background:ne,color:$},children:B.jsx(so,{remarkPlugins:[uo],components:$n,children:typeof M.content=="string"?M.content.replace(/\n/g,`
330
- `):""})}),B.jsx("span",{className:"text-xs mt-1",style:{color:w},children:M.timestamp.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})]},M.id)),ge&&B.jsxs("div",{className:"flex items-start gap-3",children:[B.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-r flex items-center justify-center",style:{background:`linear-gradient(to right, ${m}, ${h})`},children:B.jsx(yA,{className:"w-4 h-4 text-white"})}),B.jsx("div",{className:"px-4 py-3 rounded-2xl",style:{background:ne,color:$},children:B.jsxs("div",{className:"flex space-x-1",children:[B.jsx("div",{className:"w-2 h-2 rounded-full animate-bounce",style:{background:$}}),B.jsx("div",{className:"w-2 h-2 rounded-full animate-bounce",style:{background:$,animationDelay:"0.1s"}}),B.jsx("div",{className:"w-2 h-2 rounded-full animate-bounce",style:{background:$,animationDelay:"0.2s"}})]})})]})]}),!cn&&B.jsxs("div",{className:"w-full h-full flex flex-col mt-20 items-center p-4 gap-4",children:[B.jsx("h4",{className:"text-sm font-bold mb-2",style:{color:w},children:"Veuillez fournir vos informations pour commencer à discuter"}),B.jsxs("form",{onSubmit:kl,className:"w-full max-w-xs flex flex-col gap-4 p-6 rounded-2xl shadow-lg",style:{background:h},children:[u?.formFields.includes("full_name")&&B.jsx("input",{type:"text",placeholder:"Nom et prénom",value:Qn,onChange:M=>Rl(M.target.value),className:"py-3 px-4 rounded-lg outline-none transition-all duration-200",style:{borderRadius:"14px",backgroundColor:w,color:A,borderColor:m}},"full_name"),u?.formFields.includes("phone_number")&&B.jsx("input",{type:"text",placeholder:"Téléphone",value:oi,onChange:M=>Zn(M.target.value),className:"py-3 px-4 rounded-lg outline-none transition-all duration-200",style:{borderRadius:"14px",backgroundColor:w,color:A,borderColor:m}},"phone_number"),u?.formFields.includes("email")&&B.jsx("input",{type:"email",placeholder:"Email",value:wt,onChange:M=>Qt(M.target.value),className:"py-3 px-4 rounded-lg outline-none transition-all duration-200",style:{borderRadius:"14px",backgroundColor:w,color:A,borderColor:m}},"email"),B.jsx("button",{type:"submit",className:"py-3 rounded-lg font-bold uppercase outline-none shadow-lg transition-all duration-200",style:{background:`linear-gradient(90deg, ${h}, ${m})`,letterSpacing:"2px",borderRadius:"14px",color:w},children:"Submit"})]})]}),cn&&B.jsxs("div",{className:"absolute bottom-0 left-0 right-0 p-4",style:{background:`linear-gradient(to top, ${y}, transparent)`},children:[Oe.length>0&&B.jsx("div",{className:"flex flex-wrap gap-2 mb-3 p-3 bg-opacity-70 rounded-lg",style:{background:A},children:Oe.map(M=>B.jsx(zr,{attachment:M,onRemove:()=>Pr(M.id)},M.id))}),B.jsxs("div",{className:"flex items-center w-full gap-2 relative",children:[B.jsx("div",{className:"flex-1 relative",children:B.jsxs(B.Fragment,{children:[Xe!=="recording"&&Xe!=="paused"?B.jsxs(B.Fragment,{children:[B.jsx("button",{id:"upload-button-toggle",type:"button",onClick:()=>qe(M=>!M),className:"absolute left-1 bottom-3 w-9 h-9 rounded-full flex items-center justify-center transition-all duration-200 z-10 hover:bg-opacity-10",style:{color:w},onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="",children:B.jsx(WP,{className:`w-5 h-5 transition-transform duration-200 ${it?"rotate-45":""}`})}),B.jsx("button",{type:"button",onClick:()=>{dt()},className:"absolute right-1 bottom-3 w-9 h-9 rounded-full flex items-center justify-center transition-all duration-200 z-10",style:{color:w},onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="",children:B.jsx(_P,{className:"w-5 h-5"})})]}):B.jsxs(B.Fragment,{children:[B.jsx("button",{type:"button",onClick:()=>{J.current=!0,gt()},className:"absolute left-1 bottom-3 w-9 h-9 hover:bg-red-100 hover:bg-opacity-50 rounded-full flex items-center justify-center text-red-500 hover:text-red-600 z-10 after:w-2 after:h-2 after:bg-red-500 after:absolute after:rounded-full after:top-1/2 after:-right-3 after:-translate-y-1/2 after:animate-bounce",children:B.jsx(ZP,{className:"w-5 h-5"})}),B.jsx("button",{type:"button",onClick:()=>{Ie?(Pe(!1),Bt()):(Pe(!0),Nt())},className:"absolute right-11 bottom-3 w-9 h-9 rounded-full flex items-center justify-center transition-all duration-200 z-10",style:{color:w},children:Ie?B.jsx(qP,{className:"w-7 h-7"}):B.jsx(zP,{className:"w-7 h-7"})}),B.jsxs("div",{className:"absolute left-16 bottom-4 flex items-center gap-4 z-10 ",style:{color:w},children:[B.jsx("p",{children:ie}),B.jsx("p",{className:`${Xe==="recording"?"animate-pulse":""}`,children:Xe==="recording"?"Recording...":Xe==="paused"?"Paused":"Starting..."})]}),B.jsx("button",{type:"button",onClick:()=>{gt()},className:"absolute right-1 bottom-3 w-9 h-9 rounded-full flex items-center justify-center transition-all duration-200 z-10",style:{color:w,background:"green"},children:B.jsx(PP,{className:"w-5 h-5"})})]}),it&&B.jsxs("div",{className:"absolute bottom-12 left-0 rounded-lg shadow-xl border border-gray-700 py-2 min-w-48 z-10",style:{background:F},children:[B.jsxs("button",{id:"document-button",onClick:()=>xa("document"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:H},onMouseEnter:M=>M.currentTarget.style.background=X,onMouseLeave:M=>M.currentTarget.style.background="",children:[B.jsx("div",{className:"w-8 h-8 bg-blue-600 rounded-full flex items-center justify-center",children:B.jsx(EA,{className:"w-4 h-4 text-white"})}),B.jsx("span",{children:"Document"})]}),B.jsxs("button",{id:"image-button",onClick:()=>xa("image"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:H},onMouseEnter:M=>M.currentTarget.style.background=X,onMouseLeave:M=>M.currentTarget.style.background="",children:[B.jsx("div",{className:"w-8 h-8 bg-green-600 rounded-full flex items-center justify-center",children:B.jsx(HP,{className:"w-4 h-4 text-white"})}),B.jsx("span",{children:"Photos"})]}),B.jsxs("button",{id:"video-button",onClick:()=>xa("video"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:H},onMouseEnter:M=>M.currentTarget.style.background=X,onMouseLeave:M=>M.currentTarget.style.background="",children:[B.jsx("div",{className:"w-8 h-8 bg-red-600 rounded-full flex items-center justify-center",children:B.jsx(vA,{className:"w-4 h-4 text-white"})}),B.jsx("span",{children:"Videos"})]}),B.jsxs("button",{id:"audio-button",onClick:()=>xa("audio"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:H},onMouseEnter:M=>M.currentTarget.style.background=X,onMouseLeave:M=>M.currentTarget.style.background="",children:[B.jsx("div",{className:"w-8 h-8 bg-purple-600 rounded-full flex items-center justify-center",children:B.jsx(Wc,{className:"w-4 h-4 text-white"})}),B.jsx("span",{children:"Audio"})]})]}),B.jsx("textarea",{id:"message-input",ref:si,className:`w-full pt-4 px-12 resize-none focus:outline-none backdrop-blur-sm ${Xe==="recording"||Xe==="paused"?"cursor-default":""}`,value:Xe==="recording"||Xe==="paused"?"":vt,onChange:M=>Ht(M.target.value),placeholder:Xe==="recording"||Xe==="paused"?"":"Type your message...",rows:1,onKeyDown:M=>{M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),ur())},style:{minHeight:"48px",maxHeight:"120px",overflowY:"auto",borderRadius:R,background:A,color:w,scrollbarWidth:"thin",scrollbarColor:`${h} transparent`},readOnly:Xe==="recording"||Xe==="paused"})]})}),(vt.trim()||Oe.length!==0)&&B.jsx("div",{className:"w-min",children:B.jsx("button",{onClick:()=>ur(),className:"w-10 h-10 rounded-full flex items-center justify-center transition-all duration-200 transform hover:scale-105",style:{background:h,color:w},children:B.jsx(XP,{className:"w-5 h-5"})})})]}),B.jsx("input",{ref:n,type:"file",multiple:!0,className:"hidden",accept:"image/*",onChange:M=>M.target.files&&Cn(M.target.files,n)}),B.jsx("input",{ref:a,type:"file",multiple:!0,className:"hidden",accept:"video/*",onChange:M=>M.target.files&&Cn(M.target.files,a)}),B.jsx("input",{ref:o,type:"file",multiple:!0,className:"hidden",accept:"audio/*",onChange:M=>M.target.files&&Cn(M.target.files,o)}),B.jsx("input",{ref:l,type:"file",multiple:!0,className:"hidden",accept:".pdf,.doc,.docx,.txt,.csv,.xlsx,.ppt,.pptx,.zip,.rar",onChange:M=>M.target.files&&Cn(M.target.files,l)})]}),ft&&B.jsx("div",{className:"fixed inset-0 z-[998] flex items-center justify-center",style:{background:"rgba(0,0,0,0.45)",backdropFilter:"blur(4px)"},onClick:()=>It(!1),children:B.jsxs("div",{className:"relative w-full max-w-md mx-4 p-6 rounded-2xl shadow-2xl border overflow-hidden animate-[fadeIn_0.25s_ease]",style:{background:`linear-gradient(145deg, ${y}, ${h}, ${m})`,borderRadius:R,borderColor:h},onClick:M=>M.stopPropagation(),children:[B.jsx("button",{onClick:()=>It(!1),className:"absolute top-3 right-3 p-1 rounded-full transition-colors","aria-label":"Close bot info",style:{color:w},onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:B.jsx(Ws,{className:"w-5 h-5"})}),e?.bot?B.jsxs("div",{className:"flex flex-col gap-4",children:[B.jsxs("div",{className:"flex items-center gap-4",children:[B.jsx("div",{className:"w-16 h-16 rounded-full p-1 flex items-center justify-center shadow-md overflow-hidden",style:{background:`linear-gradient(to bottom right, ${h}, ${m})`,borderRadius:"1.5rem"},children:B.jsx("img",{src:bn,alt:`${yn} logo`||"Bot avatar",className:"w-full h-full rounded-full",style:{borderRadius:"1.5rem"}})}),B.jsxs("div",{className:"min-w-0",children:[B.jsx("h3",{className:"text-lg font-semibold truncate",title:yn,style:{color:w},children:yn}),B.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:e?.bot.is_active!==void 0&&B.jsx("span",{className:"px-2 py-0.5 text-xs rounded-full font-medium",style:{backgroundColor:h,color:w},children:e?.bot.is_active?"Active":"Inactive"})})]})]}),e?.bot.description&&B.jsx("div",{className:"max-h-40 overflow-y-auto pr-1",style:{scrollbarWidth:"thin",scrollbarColor:`${h} transparent`},children:B.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-line",style:{wordBreak:"break-word",color:w},children:e?.bot.description})}),B.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",style:{color:w},children:[e?.bot.phone_number&&B.jsxs("div",{className:"flex flex-col gap-0.5",children:[B.jsx("span",{className:"uppercase tracking-wide font-bold",style:{color:w},children:"Phone number"}),B.jsx("span",{className:"font-medium break-all",children:e?.bot.phone_number})]}),e?.bot.personality&&B.jsxs("div",{className:"flex flex-col gap-0.5",children:[B.jsx("span",{className:"uppercase tracking-wide font-bold",style:{color:w},children:"Personality"}),B.jsx("span",{className:"font-medium break-all",children:e?.bot.personality})]}),e?.bot.botId==="arts-clinique"&&B.jsxs("div",{className:"flex flex-col gap-0.5",children:[B.jsx("span",{className:"uppercase tracking-wide font-bold",style:{color:w},children:"Website"}),B.jsx("a",{className:"break-all underline font-semibold",href:"https://artsclinic.com",target:"_blank",rel:"noopener noreferrer",children:"https://artsclinic.com"})]}),e?.bot.botId==="arts-clinique"&&B.jsxs("div",{className:"flex flex-col gap-0.5",children:[B.jsx("span",{className:"uppercase tracking-wide font-bold",style:{color:w},children:"Email"}),B.jsx("span",{className:"font-medium break-all",style:{color:w},children:"taj.contact@gmail.com"})]})]})]}):B.jsxs("div",{className:"text-center",style:{color:w},children:[B.jsx("p",{className:"text-sm",children:"No bot selected."}),B.jsx("button",{type:"button",onClick:()=>It(!1),className:"mt-4 px-4 py-2 rounded-lg text-sm font-medium bg-white/10 hover:bg-white/20 text-black transition-colors",style:{borderRadius:R},children:"Close"})]})]})})]}),B.jsxs("button",{onClick:()=>{Je(M=>!M),tn.current=!Ge,Ge||xl()},className:"fixed top-1/2 -translate-y-1/2 px-4 py-3 shadow-lg transform",style:{right:"0",transform:Ge?`translateX(-${I}px)`:"translateX(0)",transition:"transform 0.3s cubic-bezier(0.4,0,0.2,1)",background:No,borderTopLeftRadius:x,borderBottomLeftRadius:P,borderTopRightRadius:L,borderBottomRightRadius:z,zIndex:999},children:[B.jsx("img",{src:bn,alt:"Tybot logo",className:"w-7 h-7"}),Ta>0&&!Ge?B.jsxs(B.Fragment,{children:[B.jsx("audio",{src:"https://public-assets.content-platform.envatousercontent.com/3a5b6a9c-bead-4397-bc15-393c0f6edb9f/87e342b2-9863-4e6c-83af-edeb375b338d/preview.mp3",className:"hidden",autoPlay:!0}),B.jsx("span",{className:"absolute -top-1 -left-1 bg-red-500 text-white text-xs font-medium size-5 rounded-full flex items-center justify-center",children:Ta>9?"9+":Ta})]}):null]})]})};function w6(e){const t="tybot-widget-container";let n=document.getElementById(t);n||(n=document.createElement("div"),n.id=t,document.body.appendChild(n));const a=n.shadowRoot??n.attachShadow({mode:"open"});if(!document.querySelector("#tybot-widget-fonts")){const d=document.createElement("link");d.rel="preconnect",d.href="https://fonts.googleapis.com";const p=document.createElement("link");p.rel="preconnect",p.href="https://fonts.gstatic.com",p.crossOrigin="";const f=document.createElement("link");f.id="tybot-widget-fonts",f.rel="stylesheet",f.href="https://fonts.googleapis.com/css2?family=Nunito:ital@0;1&display=swap",document.head.append(d),document.head.append(p),document.head.append(f)}if(!a.querySelector("#tybot-widget-style")){const d=document.createElement("style");d.id="tybot-widget-style",d.textContent=QI,a.appendChild(d)}const o=a.querySelector("#tybot-widget-root");o&&o.remove();const l=document.createElement("div");l.id="tybot-widget-root",a.appendChild(l),KI.createRoot(l).render(B.jsx(A6,{config:e}))}Ga.createTybotWidget=w6,Object.defineProperty(Ga,Symbol.toStringTag,{value:"Module"})});
327
+ `)||""}),B.jsx("div",{className:"flex flex-wrap",dir:Zt(M.text||"")?"rtl":"ltr",children:M.choices?.map((me,xe)=>B.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{ur(me.title)},style:{background:te,borderRadius:`${N}px`,color:G},dir:Zt(me.title)?"rtl":"ltr",children:me.title},xe))})]});case"image":return B.jsx(B.Fragment,{children:B.jsx("div",{className:"relative group",children:B.jsx("img",{src:M.image,className:"max-w-xs max-h-48 rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(M.image,"_blank")})})});case"dropdown":return B.jsxs(B.Fragment,{children:[B.jsx(so,{remarkPlugins:[uo],components:$n,children:M.message?.replace(/\n/g,`
328
+ `)||""}),B.jsxs("div",{className:"flex flex-wrap",dir:Zt(M.message||"")?"rtl":"ltr",children:[B.jsx("p",{className:"mr-2",children:"ou"}),M.options?.map((me,xe)=>B.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{ur(me.value)},style:{background:te,borderRadius:`${N}px`,color:G},dir:Zt(M.message||"")?"rtl":"ltr",children:me.label},xe))]})]});case"carousel":const fe=(M.items?.length||0)<2?1:2;return B.jsx("div",{className:"mt-2 w-full",children:B.jsx("div",{className:`grid grid-cols-1 sm:grid-cols-${fe} gap-3`,children:M.items?.map((me,xe)=>B.jsxs("div",{className:"flex-shrink-0 border p-3 shadow-md",style:{background:ne,borderRadius:`${N}px`},children:[me.image&&B.jsx("img",{src:me.image,alt:me.title,className:"h-32 w-full object-cover rounded-md mb-2"}),B.jsx("h3",{className:"text-sm font-bold",title:me.title,children:me.title}),B.jsx("p",{className:"text-xs text-gray-300 mb-2 line-clamp-2",title:me.subtitle,children:me.subtitle}),me.actions?.map((ht,jn)=>{let cr;try{cr=typeof ht.payload=="string"?JSON.parse(ht.payload):ht.payload}catch{cr={productName:me.title}}return B.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{ht.action==="Open URL"?window.open(ht.url,"_blank"):ht.title==="scan"?fetch(me.image).then(nn=>nn.blob()).then(nn=>{const Ol=URL.createObjectURL(nn),Ut=document.createElement("a");Ut.href=Ol,Ut.download="qrcode.png",document.body.appendChild(Ut),Ut.click(),document.body.removeChild(Ut),URL.revokeObjectURL(Ol)}).catch(()=>{alert("Failed to download image.")}):ur(cr.productName||M.title)},style:{background:te,borderRadius:`${N}px`,color:G},children:ht.title},jn)})]},xe))})});case"card":return B.jsx("div",{className:"mt-2 w-full",children:B.jsx("div",{className:"grid grid-cols-1 gap-3",children:B.jsxs("div",{className:"flex-shrink-0 border rounded-lg p-3 shadow-md",style:{background:ne},children:[M.image&&B.jsx("img",{src:M.image,alt:M.title,className:"h-32 w-full object-cover rounded-md mb-2"}),B.jsx("h3",{className:"text-sm font-bold",children:M.title}),M.actions?.map((me,xe)=>{let ht;try{ht=typeof me.payload=="string"?JSON.parse(me.payload):me.payload}catch{ht={productName:M.title}}return B.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{me.action==="Open URL"?window.open(me.url,"_blank"):me.title==="scan"?M.image&&fetch(M.image).then(jn=>jn.blob()).then(jn=>{const cr=URL.createObjectURL(jn),nn=document.createElement("a");nn.href=cr,nn.download="qrcode.png",document.body.appendChild(nn),nn.click(),document.body.removeChild(nn),URL.revokeObjectURL(cr)}).catch(()=>{alert("Failed to download image.")}):ur(ht.productName||M.title)},style:{background:te,borderRadius:`${N}px`,color:G},children:me.title},xe)})]})})})}},qn=async M=>{if(!cn)return;const fe=await fetch(`${o0}/endusers/get-by-username`,{headers:{Authorization:`Bearer ${e?.token}`,"Content-Type":"application/json"},method:"POST",body:JSON.stringify({username:`web_user_${M}`})});if(!fe.ok)throw new Error(`HTTP error! status: ${fe.status}`);return(await fe.json()).id},xo=async M=>{if(!cn)return;const fe=await qn(M);let me;Qn&&(me={last_name:Qn.split(" ")[1]||Qn.split(" ")[0]||`web_user_${M}`,first_name:Qn.split(" ")[0]||`web_user_${M}`}),oi&&(me={...me,phone:oi}),wt&&(me={...me,email:wt});const xe=await fetch(`${o0}/endusers/${fe}`,{headers:{Authorization:`Bearer ${e?.token}`,"Content-Type":"application/json"},method:"PUT",body:JSON.stringify(me)});if(!xe.ok)throw new Error(`HTTP error! status: ${xe.status}`);return await xe.json()},kl=async M=>{M.preventDefault();const fe=new Uint8Array(16);window.crypto.getRandomValues(fe);const me=Array.from(fe).map(xe=>xe.toString(16).padStart(2,"0")).join("");wa(me),localStorage.setItem("conversationId",me),localStorage.setItem("webChatAuth","true"),lr(!0)},qr=`linear-gradient(to bottom right, ${y}, ${h}, ${y})`,No=`linear-gradient(to right, ${h}, ${m})`,Co=`linear-gradient(to right, ${E}, ${v})`;return p||!u?null:B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"fixed top-0 right-0 h-full shadow-2xl",style:{width:I+"px",transition:"transform 0.3s cubic-bezier(0.4,0,0.2,1)",transform:Ge?"translateX(0)":`translateX(${I}px)`,background:qr,zIndex:1e3},onDrop:Ro,onDragOver:Ur,onDragEnter:Br,onDragLeave:Ra,children:[B.jsx("div",{onMouseDown:Te,className:"absolute left-0 top-0 h-full w-2 cursor-ew-resize z-50 bg-transparent opacity-50 transition-colors",style:{userSelect:"none"},onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="transparent"}),ke&&B.jsx("div",{className:"absolute inset-0 bg-opacity-20 border-2 border-dashed flex items-center justify-center z-15",style:{borderColor:h},children:B.jsxs("div",{className:"text-center ",style:{color:w},children:[B.jsx(JP,{className:"w-12 h-12 mx-auto mb-2"}),B.jsx("p",{className:"text-lg font-semibold",children:"Drop files here"})]})}),cn?B.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",style:{background:Co,borderColor:v},children:[B.jsxs("div",{className:"flex items-center gap-3",children:[B.jsx("div",{className:"size-10 flex items-center justify-center overflow-hidden rounded-full",children:B.jsx("img",{src:bn,alt:`${yn} Logo`,className:"w-full h-full"})}),B.jsx("h2",{className:"text-lg font-semibold",style:{color:w},children:yn})]}),B.jsxs("div",{className:"flex justify-between items-center gap-2 ml-2",children:[B.jsx("button",{onClick:()=>It(!0),className:"transition-colors p-1 rounded-full",style:{color:w},title:"Bot info","aria-label":"Bot info",onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:B.jsx(GP,{className:"w-5 h-5"})}),B.jsx("button",{onClick:()=>{Je(!1),tn.current=!1},className:"transition-colors p-1 rounded-full",style:{color:w},title:"Close Chat","aria-label":"Close Chat",onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:B.jsx(Ws,{className:"w-5 h-5"})})]})]}):B.jsx("div",{className:"flex items-center justify-end px-6 py-3",children:B.jsx("div",{className:"flex items-center",children:B.jsx("button",{onClick:()=>{Je(!1),tn.current=!1},className:"transition-colors p-1 rounded-full",style:{color:e?.inputTextColor||"#FFF"},title:"Close Chat","aria-label":"Close Chat",onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:B.jsx(Ws,{className:"w-5 h-5"})})})}),cn&&B.jsxs("div",{ref:t,className:"flex-1 px-4 py-4 overflow-y-auto space-y-4 scroll-smooth",style:{height:"calc(100% - 140px)",scrollbarWidth:"thin",scrollbarColor:`${h} transparent`},children:[ut.map(M=>B.jsxs("div",{className:`flex items-start gap-3 ${M.sender==="user"?"flex-row-reverse":""}`,children:[B.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0",style:{background:M.sender==="user"?oe:re},children:M.sender==="user"?B.jsx($P,{className:"w-4 h-4",style:{color:S}}):B.jsx(yA,{className:"w-4 h-4",style:{color:q}})}),B.jsxs("div",{className:`flex flex-col flex-1 ${M.sender==="user"?"items-end":"items-start"}`,children:[M.attachments&&M.attachments.length>0&&B.jsx("div",{className:"flex flex-col items-end w-[88%] mb-2 space-y-2",children:M.attachments.map(fe=>B.jsx(v6,{attachment:fe,formatFileSize:Ct,mainColor:h,secondaryColor:m,controlsColor:w},fe.id))}),M.content&&M.sender==="user"?B.jsx("div",{className:"px-4 py-2 rounded-2xl backdrop-blur-sm break-words w-fit",style:{wordBreak:"break-word",overflowWrap:"break-word",borderRadius:`${N}px`,maxWidth:O+"%",background:Y,color:K},children:B.jsx(so,{remarkPlugins:[uo],components:$n,children:typeof M.content=="string"?M.content.replace(/\n/g,`
329
+ `):""})}):typeof M.content=="object"?M.content.map((fe,me)=>B.jsx("div",{className:"mb-1 px-4 py-2 rounded-2xl backdrop-blur-sm break-words w-fit",style:{wordBreak:"break-word",overflowWrap:"break-word",borderRadius:`${N}px`,maxWidth:O+"%",background:ne,color:$},children:li(fe)},me)):B.jsx("div",{className:"mb-1 px-4 py-2 rounded-2xl backdrop-blur-sm break-words w-fit",style:{wordBreak:"break-word",overflowWrap:"break-word",borderRadius:`${N}px`,maxWidth:O+"%",background:ne,color:$},children:B.jsx(so,{remarkPlugins:[uo],components:$n,children:typeof M.content=="string"?M.content.replace(/\n/g,`
330
+ `):""})}),B.jsx("span",{className:"text-xs mt-1",style:{color:w},children:M.timestamp.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})]},M.id)),ge&&B.jsxs("div",{className:"flex items-start gap-3",children:[B.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-r flex items-center justify-center",style:{background:`linear-gradient(to right, ${m}, ${h})`},children:B.jsx(yA,{className:"w-4 h-4 text-white"})}),B.jsx("div",{className:"px-4 py-3 rounded-2xl",style:{background:ne,color:$},children:B.jsxs("div",{className:"flex space-x-1",children:[B.jsx("div",{className:"w-2 h-2 rounded-full animate-bounce",style:{background:$}}),B.jsx("div",{className:"w-2 h-2 rounded-full animate-bounce",style:{background:$,animationDelay:"0.1s"}}),B.jsx("div",{className:"w-2 h-2 rounded-full animate-bounce",style:{background:$,animationDelay:"0.2s"}})]})})]})]}),!cn&&B.jsxs("div",{className:"w-full h-full flex flex-col mt-20 items-center p-4 gap-4",children:[B.jsx("h4",{className:"text-sm font-bold mb-2",style:{color:w},children:"Veuillez fournir vos informations pour commencer à discuter"}),B.jsxs("form",{onSubmit:kl,className:"w-full max-w-xs flex flex-col gap-4 p-6 rounded-2xl shadow-lg",style:{background:h},children:[u?.formFields.includes("full_name")&&B.jsx("input",{type:"text",placeholder:"Nom et prénom",value:Qn,onChange:M=>Rl(M.target.value),className:"py-3 px-4 rounded-lg outline-none transition-all duration-200",style:{borderRadius:"14px",backgroundColor:w,color:A,borderColor:m}},"full_name"),u?.formFields.includes("phone_number")&&B.jsx("input",{type:"text",placeholder:"Téléphone",value:oi,onChange:M=>Zn(M.target.value),className:"py-3 px-4 rounded-lg outline-none transition-all duration-200",style:{borderRadius:"14px",backgroundColor:w,color:A,borderColor:m}},"phone_number"),u?.formFields.includes("email")&&B.jsx("input",{type:"email",placeholder:"Email",value:wt,onChange:M=>Qt(M.target.value),className:"py-3 px-4 rounded-lg outline-none transition-all duration-200",style:{borderRadius:"14px",backgroundColor:w,color:A,borderColor:m}},"email"),B.jsx("button",{type:"submit",className:"py-3 rounded-lg font-bold uppercase outline-none shadow-lg transition-all duration-200",style:{background:`linear-gradient(90deg, ${h}, ${m})`,letterSpacing:"2px",borderRadius:"14px",color:w},children:"Submit"})]})]}),cn&&B.jsxs("div",{className:"absolute bottom-0 left-0 right-0 p-4",style:{background:`linear-gradient(to top, ${y}, transparent)`},children:[Oe.length>0&&B.jsx("div",{className:"flex flex-wrap gap-2 mb-3 p-3 bg-opacity-70 rounded-lg",style:{background:A},children:Oe.map(M=>B.jsx(zr,{attachment:M,onRemove:()=>Pr(M.id)},M.id))}),B.jsxs("div",{className:"flex items-center w-full gap-2 relative",children:[B.jsx("div",{className:"flex-1 relative",children:B.jsxs(B.Fragment,{children:[Xe!=="recording"&&Xe!=="paused"?B.jsxs(B.Fragment,{children:[B.jsx("button",{id:"upload-button-toggle",type:"button",onClick:()=>qe(M=>!M),className:"absolute left-1 bottom-3 w-9 h-9 rounded-full flex items-center justify-center transition-all duration-200 z-10 hover:bg-opacity-10",style:{color:w},onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="",children:B.jsx(WP,{className:`w-5 h-5 transition-transform duration-200 ${it?"rotate-45":""}`})}),B.jsx("button",{type:"button",onClick:()=>{dt()},className:"absolute right-1 bottom-3 w-9 h-9 rounded-full flex items-center justify-center transition-all duration-200 z-10",style:{color:w},onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="",children:B.jsx(_P,{className:"w-5 h-5"})})]}):B.jsxs(B.Fragment,{children:[B.jsx("button",{type:"button",onClick:()=>{J.current=!0,gt()},className:"absolute left-1 bottom-3 w-9 h-9 hover:bg-red-100 hover:bg-opacity-50 rounded-full flex items-center justify-center text-red-500 hover:text-red-600 z-10 after:w-2 after:h-2 after:bg-red-500 after:absolute after:rounded-full after:top-1/2 after:-right-3 after:-translate-y-1/2 after:animate-bounce",children:B.jsx(ZP,{className:"w-5 h-5"})}),B.jsx("button",{type:"button",onClick:()=>{Ie?(Pe(!1),Bt()):(Pe(!0),Nt())},className:"absolute right-11 bottom-3 w-9 h-9 rounded-full flex items-center justify-center transition-all duration-200 z-10",style:{color:w},children:Ie?B.jsx(qP,{className:"w-7 h-7"}):B.jsx(zP,{className:"w-7 h-7"})}),B.jsxs("div",{className:"absolute left-16 bottom-4 flex items-center gap-4 z-10 ",style:{color:w},children:[B.jsx("p",{children:ie}),B.jsx("p",{className:`${Xe==="recording"?"animate-pulse":""}`,children:Xe==="recording"?"Recording...":Xe==="paused"?"Paused":"Starting..."})]}),B.jsx("button",{type:"button",onClick:()=>{gt()},className:"absolute right-1 bottom-3 w-9 h-9 rounded-full flex items-center justify-center transition-all duration-200 z-10",style:{color:w,background:"green"},children:B.jsx(PP,{className:"w-5 h-5"})})]}),it&&B.jsxs("div",{className:"absolute bottom-12 left-0 rounded-lg shadow-xl border border-gray-700 py-2 min-w-48 z-10",style:{background:F},children:[B.jsxs("button",{id:"document-button",onClick:()=>xa("document"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:H},onMouseEnter:M=>M.currentTarget.style.background=X,onMouseLeave:M=>M.currentTarget.style.background="",children:[B.jsx("div",{className:"w-8 h-8 bg-blue-600 rounded-full flex items-center justify-center",children:B.jsx(EA,{className:"w-4 h-4 text-white"})}),B.jsx("span",{children:"Document"})]}),B.jsxs("button",{id:"image-button",onClick:()=>xa("image"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:H},onMouseEnter:M=>M.currentTarget.style.background=X,onMouseLeave:M=>M.currentTarget.style.background="",children:[B.jsx("div",{className:"w-8 h-8 bg-green-600 rounded-full flex items-center justify-center",children:B.jsx(HP,{className:"w-4 h-4 text-white"})}),B.jsx("span",{children:"Photos"})]}),B.jsxs("button",{id:"video-button",onClick:()=>xa("video"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:H},onMouseEnter:M=>M.currentTarget.style.background=X,onMouseLeave:M=>M.currentTarget.style.background="",children:[B.jsx("div",{className:"w-8 h-8 bg-red-600 rounded-full flex items-center justify-center",children:B.jsx(vA,{className:"w-4 h-4 text-white"})}),B.jsx("span",{children:"Videos"})]}),B.jsxs("button",{id:"audio-button",onClick:()=>xa("audio"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:H},onMouseEnter:M=>M.currentTarget.style.background=X,onMouseLeave:M=>M.currentTarget.style.background="",children:[B.jsx("div",{className:"w-8 h-8 bg-purple-600 rounded-full flex items-center justify-center",children:B.jsx(Wc,{className:"w-4 h-4 text-white"})}),B.jsx("span",{children:"Audio"})]})]}),B.jsx("textarea",{id:"message-input",ref:si,className:`w-full pt-4 px-12 resize-none focus:outline-none backdrop-blur-sm ${Xe==="recording"||Xe==="paused"?"cursor-default":""}`,value:Xe==="recording"||Xe==="paused"?"":vt,onChange:M=>Ht(M.target.value),placeholder:Xe==="recording"||Xe==="paused"?"":"Type your message...",rows:1,onKeyDown:M=>{M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),ur())},style:{minHeight:"48px",maxHeight:"120px",overflowY:"auto",borderRadius:`${R}px`,background:A,color:w,scrollbarWidth:"thin",scrollbarColor:`${h} transparent`},readOnly:Xe==="recording"||Xe==="paused"})]})}),(vt.trim()||Oe.length!==0)&&B.jsx("div",{className:"w-min",children:B.jsx("button",{onClick:()=>ur(),className:"w-10 h-10 rounded-full flex items-center justify-center transition-all duration-200 transform hover:scale-105",style:{background:h,color:w},children:B.jsx(XP,{className:"w-5 h-5"})})})]}),B.jsx("input",{ref:n,type:"file",multiple:!0,className:"hidden",accept:"image/*",onChange:M=>M.target.files&&Cn(M.target.files,n)}),B.jsx("input",{ref:a,type:"file",multiple:!0,className:"hidden",accept:"video/*",onChange:M=>M.target.files&&Cn(M.target.files,a)}),B.jsx("input",{ref:o,type:"file",multiple:!0,className:"hidden",accept:"audio/*",onChange:M=>M.target.files&&Cn(M.target.files,o)}),B.jsx("input",{ref:l,type:"file",multiple:!0,className:"hidden",accept:".pdf,.doc,.docx,.txt,.csv,.xlsx,.ppt,.pptx,.zip,.rar",onChange:M=>M.target.files&&Cn(M.target.files,l)})]}),ft&&B.jsx("div",{className:"fixed inset-0 z-[998] flex items-center justify-center",style:{background:"rgba(0,0,0,0.45)",backdropFilter:"blur(4px)"},onClick:()=>It(!1),children:B.jsxs("div",{className:"relative w-full max-w-md mx-4 p-6 rounded-2xl shadow-2xl border overflow-hidden animate-[fadeIn_0.25s_ease]",style:{background:`linear-gradient(145deg, ${y}, ${h}, ${m})`,borderRadius:`${R}px`,borderColor:h},onClick:M=>M.stopPropagation(),children:[B.jsx("button",{onClick:()=>It(!1),className:"absolute top-3 right-3 p-1 rounded-full transition-colors","aria-label":"Close bot info",style:{color:w},onMouseEnter:M=>M.currentTarget.style.background=h,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:B.jsx(Ws,{className:"w-5 h-5"})}),e?.bot?B.jsxs("div",{className:"flex flex-col gap-4",children:[B.jsxs("div",{className:"flex items-center gap-4",children:[B.jsx("div",{className:"w-16 h-16 rounded-full p-1 flex items-center justify-center shadow-md overflow-hidden",style:{background:`linear-gradient(to bottom right, ${h}, ${m})`,borderRadius:"1.5rem"},children:B.jsx("img",{src:bn,alt:`${yn} logo`||"Bot avatar",className:"w-full h-full rounded-full",style:{borderRadius:"1.5rem"}})}),B.jsxs("div",{className:"min-w-0",children:[B.jsx("h3",{className:"text-lg font-semibold truncate",title:yn,style:{color:w},children:yn}),B.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:e?.bot.is_active!==void 0&&B.jsx("span",{className:"px-2 py-0.5 text-xs rounded-full font-medium",style:{backgroundColor:h,color:w},children:e?.bot.is_active?"Active":"Inactive"})})]})]}),e?.bot.description&&B.jsx("div",{className:"max-h-40 overflow-y-auto pr-1",style:{scrollbarWidth:"thin",scrollbarColor:`${h} transparent`},children:B.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-line",style:{wordBreak:"break-word",color:w},children:e?.bot.description})}),B.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",style:{color:w},children:[e?.bot.phone_number&&B.jsxs("div",{className:"flex flex-col gap-0.5",children:[B.jsx("span",{className:"uppercase tracking-wide font-bold",style:{color:w},children:"Phone number"}),B.jsx("span",{className:"font-medium break-all",children:e?.bot.phone_number})]}),e?.bot.personality&&B.jsxs("div",{className:"flex flex-col gap-0.5",children:[B.jsx("span",{className:"uppercase tracking-wide font-bold",style:{color:w},children:"Personality"}),B.jsx("span",{className:"font-medium break-all",children:e?.bot.personality})]}),e?.bot.botId==="arts-clinique"&&B.jsxs("div",{className:"flex flex-col gap-0.5",children:[B.jsx("span",{className:"uppercase tracking-wide font-bold",style:{color:w},children:"Website"}),B.jsx("a",{className:"break-all underline font-semibold",href:"https://artsclinic.com",target:"_blank",rel:"noopener noreferrer",children:"https://artsclinic.com"})]}),e?.bot.botId==="arts-clinique"&&B.jsxs("div",{className:"flex flex-col gap-0.5",children:[B.jsx("span",{className:"uppercase tracking-wide font-bold",style:{color:w},children:"Email"}),B.jsx("span",{className:"font-medium break-all",style:{color:w},children:"taj.contact@gmail.com"})]})]})]}):B.jsxs("div",{className:"text-center",style:{color:w},children:[B.jsx("p",{className:"text-sm",children:"No bot selected."}),B.jsx("button",{type:"button",onClick:()=>It(!1),className:"mt-4 px-4 py-2 rounded-lg text-sm font-medium bg-white/10 hover:bg-white/20 text-black transition-colors",style:{borderRadius:`${R}px`},children:"Close"})]})]})})]}),B.jsxs("button",{onClick:()=>{Je(M=>!M),tn.current=!Ge,Ge||xl()},className:"fixed top-1/2 -translate-y-1/2 px-4 py-3 shadow-lg transform",style:{right:"0",transform:Ge?`translateX(-${I}px)`:"translateX(0)",transition:"transform 0.3s cubic-bezier(0.4,0,0.2,1)",background:No,borderTopLeftRadius:`${x}px`,borderBottomLeftRadius:`${P}px`,borderTopRightRadius:`${L}px`,borderBottomRightRadius:`${z}px`,zIndex:999},children:[B.jsx("img",{src:bn,alt:"Tybot logo",className:"w-7 h-7"}),Ta>0&&!Ge?B.jsxs(B.Fragment,{children:[B.jsx("audio",{src:"https://public-assets.content-platform.envatousercontent.com/3a5b6a9c-bead-4397-bc15-393c0f6edb9f/87e342b2-9863-4e6c-83af-edeb375b338d/preview.mp3",className:"hidden",autoPlay:!0}),B.jsx("span",{className:"absolute -top-1 -left-1 bg-red-500 text-white text-xs font-medium size-5 rounded-full flex items-center justify-center",children:Ta>9?"9+":Ta})]}):null]})]})};function w6(e){const t="tybot-widget-container";let n=document.getElementById(t);n||(n=document.createElement("div"),n.id=t,document.body.appendChild(n));const a=n.shadowRoot??n.attachShadow({mode:"open"});if(!document.querySelector("#tybot-widget-fonts")){const d=document.createElement("link");d.rel="preconnect",d.href="https://fonts.googleapis.com";const p=document.createElement("link");p.rel="preconnect",p.href="https://fonts.gstatic.com",p.crossOrigin="";const f=document.createElement("link");f.id="tybot-widget-fonts",f.rel="stylesheet",f.href="https://fonts.googleapis.com/css2?family=Nunito:ital@0;1&display=swap",document.head.append(d),document.head.append(p),document.head.append(f)}if(!a.querySelector("#tybot-widget-style")){const d=document.createElement("style");d.id="tybot-widget-style",d.textContent=QI,a.appendChild(d)}const o=a.querySelector("#tybot-widget-root");o&&o.remove();const l=document.createElement("div");l.id="tybot-widget-root",a.appendChild(l),KI.createRoot(l).render(B.jsx(A6,{config:e}))}Ga.createTybotWidget=w6,Object.defineProperty(Ga,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tybotflow-widget",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "A modern, customizable React widget for Tybot chat integration.",
5
5
  "license": "ISC",
6
6
  "main": "dist/index.umd.js",