const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Chat-D2afpaur.js","assets/rolldown-runtime-Cyuzqnbw.js","assets/index-BVrdu45I.js","assets/vendor-datadog-Bq_0f1ke.js","assets/vendor-ui-BjvqsBPj.js","assets/vendor-core-BIhSIGPv.js","assets/vendor-react-BqTNj-ZI.js","assets/vendor-tanstack-CnTDU3TP.js","assets/createLucideIcon-D6HmSa4x.js","assets/button-CwKyGWmW.js","assets/index-4SnhgI3C.css","assets/proxy-BJ77EweZ.js","assets/setComponentFile-CdvgHnSh.js","assets/useEntityRestURL-BIjLbV9n.js","assets/getAnalytics-B7bI-BRL.js","assets/Chat-CwMJCYnY.css"])))=>i.map(i=>d[i]);
import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{a as t,i as n}from"./vendor-datadog-Bq_0f1ke.js";import{r}from"./vendor-react-BqTNj-ZI.js";import{a as i,c as a,i as o,l as s,n as c,o as l,r as u,s as d,t as f}from"./proxy-BJ77EweZ.js";import{$t as p,gt as m,q as h,tn as g}from"./index-BVrdu45I.js";var _=e(t(),1);function v(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}function y(...e){return t=>{let n=!1,r=e.map(e=>{let r=v(e,t);return!n&&typeof r==`function`&&(n=!0),r});if(n)return()=>{for(let t=0;t<r.length;t++){let n=r[t];typeof n==`function`?n():v(e[t],null)}}}}function b(...e){return _.useCallback(y(...e),e)}var x=r(),S=class extends _.Component{getSnapshotBeforeUpdate(e){let t=this.props.childRef.current;if(o(t)&&e.isPresent&&!this.props.isPresent&&this.props.pop!==!1){let e=t.offsetParent,n=o(e)&&e.offsetWidth||0,r=o(e)&&e.offsetHeight||0,i=getComputedStyle(t),a=this.props.sizeRef.current;a.height=parseFloat(i.height),a.width=parseFloat(i.width),a.top=t.offsetTop,a.left=t.offsetLeft,a.right=n-a.width-a.left,a.bottom=r-a.height-a.top,a.direction=i.direction}return null}componentDidUpdate(){}render(){return this.props.children}};function C({children:e,isPresent:t,anchorX:n,anchorY:r,root:i,pop:a}){let o=(0,_.useId)(),s=(0,_.useRef)(null),c=(0,_.useRef)({width:0,height:0,top:0,left:0,right:0,bottom:0,direction:`ltr`}),{nonce:l}=(0,_.useContext)(u),d=b(s,e.props?.ref??e?.ref);return(0,_.useInsertionEffect)(()=>{let{width:e,height:u,top:d,left:f,right:p,bottom:m,direction:h}=c.current;if(t||a===!1||!s.current||!e||!u)return;let g=h===`rtl`,_=n===`left`?g?`right: ${p}`:`left: ${f}`:g?`left: ${f}`:`right: ${p}`,v=r===`bottom`?`bottom: ${m}`:`top: ${d}`;s.current.dataset.motionPopId=o;let y=document.createElement(`style`);l&&(y.nonce=l);let b=i??document.head;return b.appendChild(y),y.sheet&&y.sheet.insertRule(`
          [data-motion-pop-id="${o}"] {
            position: absolute !important;
            width: ${e}px !important;
            height: ${u}px !important;
            ${_}px !important;
            ${v}px !important;
          }
        `),()=>{s.current?.removeAttribute(`data-motion-pop-id`),b.contains(y)&&b.removeChild(y)}},[t]),(0,x.jsx)(S,{isPresent:t,childRef:s,sizeRef:c,pop:a,children:a===!1?e:_.cloneElement(e,{ref:d})})}var w=({children:e,initial:t,isPresent:n,onExitComplete:r,custom:a,presenceAffectsLayout:o,mode:s,anchorX:c,anchorY:l,root:u})=>{let f=d(T),p=(0,_.useId)(),m=!0,h=(0,_.useMemo)(()=>(m=!1,{id:p,initial:t,isPresent:n,custom:a,onExitComplete:e=>{f.set(e,!0);for(let e of f.values())if(!e)return;r&&r()},register:e=>(f.set(e,!1),()=>f.delete(e))}),[n,f,r]);return o&&m&&(h={...h}),(0,_.useMemo)(()=>{f.forEach((e,t)=>f.set(t,!1))},[n]),_.useEffect(()=>{!n&&!f.size&&r&&r()},[n]),e=(0,x.jsx)(C,{pop:s===`popLayout`,isPresent:n,anchorX:c,anchorY:l,root:u,children:e}),(0,x.jsx)(i.Provider,{value:h,children:e})};function T(){return new Map}var E=e=>e.key||``;function D(e){let t=[];return _.Children.forEach(e,e=>{(0,_.isValidElement)(e)&&t.push(e)}),t}var O=({children:e,custom:t,initial:n=!0,onExitComplete:r,presenceAffectsLayout:i=!0,mode:o=`sync`,propagate:s=!1,anchorX:u=`left`,anchorY:f=`top`,root:p})=>{let[m,h]=c(s),g=(0,_.useMemo)(()=>D(e),[e]),v=s&&!m?[]:g.map(E),y=(0,_.useRef)(!0),b=(0,_.useRef)(g),S=d(()=>new Map),C=(0,_.useRef)(new Set),[T,O]=(0,_.useState)(g),[k,A]=(0,_.useState)(g);l(()=>{y.current=!1,b.current=g;for(let e=0;e<k.length;e++){let t=E(k[e]);v.includes(t)?(S.delete(t),C.current.delete(t)):S.get(t)!==!0&&S.set(t,!1)}},[k,v.length,v.join(`-`)]);let j=[];if(g!==T){let e=[...g];for(let t=0;t<k.length;t++){let n=k[t],r=E(n);v.includes(r)||(e.splice(t,0,n),j.push(n))}return o===`wait`&&j.length&&(e=j),A(D(e)),O(g),null}let{forceRender:M}=(0,_.useContext)(a);return(0,x.jsx)(x.Fragment,{children:k.map(e=>{let a=E(e),c=s&&!m?!1:g===k||v.includes(a);return(0,x.jsx)(w,{isPresent:c,initial:!y.current||n?void 0:!1,custom:t,presenceAffectsLayout:i,mode:o,root:p,onExitComplete:c?void 0:()=>{if(C.current.has(a))return;if(S.has(a))C.current.add(a),S.set(a,!0);else return;let e=!0;S.forEach(t=>{t||(e=!1)}),e&&(M?.(),A(b.current),s&&h?.(),r&&r())},anchorX:u,anchorY:f,children:e},a)})})},k=(0,_.lazy)(()=>n(()=>import(`./Chat-D2afpaur.js`).then(e=>({default:e.Chat})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),A=56,j=24;function M(){let[e,t]=(0,_.useState)(!1),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(!1),[o,c]=h(`ApplicationChatOpen`,!1),[l,u]=g(p.ApplicationChatPosition,{x:-40,y:-40}),[d,v]=g(p.ApplicationChatWidth,600),y=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=()=>{let e=window.innerWidth<768;t(e),!e&&d>window.innerWidth&&v(window.innerWidth)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[d,v]);let b=(0,_.useCallback)(e=>{e.preventDefault(),a(!0)},[]);(0,_.useEffect)(()=>{if(!i)return;let e=e=>{let t=window.innerWidth-e.clientX;v(Math.min(Math.max(t,300),window.innerWidth))},t=()=>{a(!1)};return window.addEventListener(`mousemove`,e),window.addEventListener(`mouseup`,t),()=>{window.removeEventListener(`mousemove`,e),window.removeEventListener(`mouseup`,t)}},[i,v]);let S=(0,_.useCallback)(()=>{n||c(e=>!e)},[n]),C=(0,_.useCallback)(()=>{c(!1)},[]);return(0,_.useEffect)(()=>{if(o){let e=e=>{e.key===`Escape`&&C()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[o,C]),(0,x.jsxs)(`div`,{className:`fixed inset-0 pointer-events-none z-50`,ref:y,children:[(0,x.jsx)(O,{children:o&&(0,x.jsxs)(f.div,{initial:e?{opacity:0,y:`100%`}:{opacity:0,x:`100%`},animate:e?{opacity:1,y:0}:{opacity:1,x:0},exit:e?{opacity:0,y:`100%`}:{opacity:0,x:`100%`},transition:{type:`spring`,damping:25,stiffness:200},style:e?{}:{top:0,bottom:0,right:0,width:d,maxWidth:`100vw`},className:`
							pointer-events-auto
							fixed bg-background shadow-2xl border-l border-border overflow-visible
							${e?`inset-0 w-full h-full rounded-none`:`h-full`}
						`,children:[!e&&(0,x.jsx)(`div`,{onMouseDown:b,className:`
									absolute left-0 top-0 bottom-0 w-1 cursor-ew-resize
									hover:bg-primary transition-colors z-50
									${i?`bg-primary`:``}
								`}),(0,x.jsx)(_.Suspense,{fallback:(0,x.jsx)(m,{centered:!0,text:`Loading chat…`}),children:(0,x.jsx)(k,{autoFocus:!0,closeChat:C})})]})}),!o&&(0,x.jsx)(f.button,{drag:!0,dragMomentum:!1,dragConstraints:y,onDragStart:()=>{r(!1)},onDrag:(e,t)=>{(Math.abs(t.offset.x)>5||Math.abs(t.offset.y)>5)&&r(!0)},onDragEnd:(t,n)=>{if(setTimeout(()=>{r(!1)},100),e)return;let{innerWidth:i,innerHeight:a}=window,o=l.x+n.offset.x,s=l.y+n.offset.y,c=n.point.x,d=i-n.point.x,f=n.point.y,p=a-n.point.y,m=o,h=s;c<100?m=-(i-A-j*2):d<100&&(m=0),f<100?h=-(a-A-j*2):p<100&&(h=0),u({x:m,y:h})},initial:{x:l.x,y:l.y},whileHover:{scale:1.1},whileTap:{scale:.9},onClick:S,style:{bottom:j,right:j},className:`
						pointer-events-auto
						fixed w-14 h-14 rounded-full bg-primary
						text-primary-foreground shadow-lg flex items-center justify-center cursor-pointer
						hover:bg-primary/90 transition-colors
					`,children:(0,x.jsx)(s,{size:28})})]})}export{M as FloatingChat};
//# sourceMappingURL=FloatingChat-Bom2iet7.js.map