Files
helix-engage-server/public/widget.js
saridsa2 76fa6f51de feat: website widget + omnichannel lead webhooks
Widget (embeddable):
- Preact + Vite library mode → 35KB IIFE bundle served from sidecar
- Shadow DOM for CSS isolation, themed from sidecar theme API
- AI chatbot (streaming), appointment booking (4-step wizard), lead capture form
- FontAwesome Pro duotone SVGs bundled as inline strings
- HMAC-signed site keys (Redis storage, origin validation)
- Captcha guard (Cloudflare Turnstile ready)

Sidecar endpoints:
- GET/PUT/DELETE /api/widget/keys/* — site key management
- GET /api/widget/init — theme + config (key-gated)
- GET /api/widget/doctors, /slots — doctor list + availability
- POST /api/widget/book — appointment booking (captcha-gated)
- POST /api/widget/lead — lead capture (captcha-gated)

Omnichannel webhooks:
- POST /api/webhook/facebook — Meta Lead Ads (verification + lead ingestion)
- POST /api/webhook/google — Google Ads lead form extension
- POST /api/webhook/whatsapp — Ozonetel WhatsApp callback (receiver ready)
- POST /api/webhook/sms — Ozonetel SMS callback (receiver ready)

Infrastructure:
- SessionService.setCachePersistent() for non-expiring Redis keys
- Static file serving from /public (widget.js)
- WidgetModule registered in AppModule

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 06:49:02 +05:30

137 lines
35 KiB
JavaScript

(function(){"use strict";var O,b,ue,M,he,fe,ge,ee,F,W,me,te,ne,oe,j={},R=[],Ue=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,q=Array.isArray;function L(e,t){for(var n in t)e[n]=t[n];return e}function ie(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function Oe(e,t,n){var r,l,o,a={};for(o in t)o=="key"?r=t[o]:o=="ref"?l=t[o]:a[o]=t[o];if(arguments.length>2&&(a.children=arguments.length>3?O.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(o in e.defaultProps)a[o]===void 0&&(a[o]=e.defaultProps[o]);return K(e,a,r,l,null)}function K(e,t,n,r,l){var o={type:e,props:t,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:l??++ue,__i:-1,__u:0};return l==null&&b.vnode!=null&&b.vnode(o),o}function Y(e){return e.children}function J(e,t){this.props=e,this.context=t}function D(e,t){if(t==null)return e.__?D(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type=="function"?D(e):null}function Fe(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,r=[],l=[],o=L({},t);o.__v=t.__v+1,b.vnode&&b.vnode(o),re(e.__P,o,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,r,n??D(t),!!(32&t.__u),l),o.__v=t.__v,o.__.__k[o.__i]=o,Se(r,o,l),t.__e=t.__=null,o.__e!=n&&ye(o)}}function ye(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),ye(e)}function be(e){(!e.__d&&(e.__d=!0)&&M.push(e)&&!V.__r++||he!=b.debounceRendering)&&((he=b.debounceRendering)||fe)(V)}function V(){try{for(var e,t=1;M.length;)M.length>t&&M.sort(ge),e=M.shift(),t=M.length,Fe(e)}finally{M.length=V.__r=0}}function ve(e,t,n,r,l,o,a,d,_,c,p){var s,h,u,m,w,x,y,g=r&&r.__k||R,C=t.length;for(_=je(n,t,g,_,C),s=0;s<C;s++)(u=n.__k[s])!=null&&(h=u.__i!=-1&&g[u.__i]||j,u.__i=s,x=re(e,u,h,l,o,a,d,_,c,p),m=u.__e,u.ref&&h.ref!=u.ref&&(h.ref&&le(h.ref,null,u),p.push(u.ref,u.__c||m,u)),w==null&&m!=null&&(w=m),(y=!!(4&u.__u))||h.__k===u.__k?(_=we(u,_,e,y),y&&h.__e&&(h.__e=null)):typeof u.type=="function"&&x!==void 0?_=x:m&&(_=m.nextSibling),u.__u&=-7);return n.__e=w,_}function je(e,t,n,r,l){var o,a,d,_,c,p=n.length,s=p,h=0;for(e.__k=new Array(l),o=0;o<l;o++)(a=t[o])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=e.__k[o]=K(null,a,null,null,null):q(a)?a=e.__k[o]=K(Y,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=e.__k[o]=K(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):e.__k[o]=a,_=o+h,a.__=e,a.__b=e.__b+1,d=null,(c=a.__i=Re(a,n,_,s))!=-1&&(s--,(d=n[c])&&(d.__u|=2)),d==null||d.__v==null?(c==-1&&(l>p?h--:l<p&&h++),typeof a.type!="function"&&(a.__u|=4)):c!=_&&(c==_-1?h--:c==_+1?h++:(c>_?h--:h++,a.__u|=4))):e.__k[o]=null;if(s)for(o=0;o<p;o++)(d=n[o])!=null&&(2&d.__u)==0&&(d.__e==r&&(r=D(d)),Ce(d,d));return r}function we(e,t,n,r){var l,o;if(typeof e.type=="function"){for(l=e.__k,o=0;l&&o<l.length;o++)l[o]&&(l[o].__=e,t=we(l[o],t,n,r));return t}e.__e!=t&&(r&&(t&&e.type&&!t.parentNode&&(t=D(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function Re(e,t,n,r){var l,o,a,d=e.key,_=e.type,c=t[n],p=c!=null&&(2&c.__u)==0;if(c===null&&d==null||p&&d==c.key&&_==c.type)return n;if(r>(p?1:0)){for(l=n-1,o=n+1;l>=0||o<t.length;)if((c=t[a=l>=0?l--:o++])!=null&&(2&c.__u)==0&&d==c.key&&_==c.type)return a}return-1}function xe(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||Ue.test(t)?n:n+"px"}function G(e,t,n,r,l){var o,a;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof r=="string"&&(e.style.cssText=r=""),r)for(t in r)n&&t in n||xe(e.style,t,"");if(n)for(t in n)r&&n[t]==r[t]||xe(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")o=t!=(t=t.replace(me,"$1")),a=t.toLowerCase(),t=a in e||t=="onFocusOut"||t=="onFocusIn"?a.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+o]=n,n?r?n[W]=r[W]:(n[W]=te,e.addEventListener(t,o?oe:ne,o)):e.removeEventListener(t,o?oe:ne,o);else{if(l=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function ke(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[F]==null)t[F]=te++;else if(t[F]<n[W])return;return n(b.event?b.event(t):t)}}}function re(e,t,n,r,l,o,a,d,_,c){var p,s,h,u,m,w,x,y,g,C,z,P,U,N,I,$=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(_=!!(32&n.__u),o=[d=t.__e=n.__e]),(p=b.__b)&&p(t);e:if(typeof $=="function")try{if(y=t.props,g=$.prototype&&$.prototype.render,C=(p=$.contextType)&&r[p.__c],z=p?C?C.props.value:p.__:r,n.__c?x=(s=t.__c=n.__c).__=s.__E:(g?t.__c=s=new $(y,z):(t.__c=s=new J(y,z),s.constructor=$,s.render=Ke),C&&C.sub(s),s.state||(s.state={}),s.__n=r,h=s.__d=!0,s.__h=[],s._sb=[]),g&&s.__s==null&&(s.__s=s.state),g&&$.getDerivedStateFromProps!=null&&(s.__s==s.state&&(s.__s=L({},s.__s)),L(s.__s,$.getDerivedStateFromProps(y,s.__s))),u=s.props,m=s.state,s.__v=t,h)g&&$.getDerivedStateFromProps==null&&s.componentWillMount!=null&&s.componentWillMount(),g&&s.componentDidMount!=null&&s.__h.push(s.componentDidMount);else{if(g&&$.getDerivedStateFromProps==null&&y!==u&&s.componentWillReceiveProps!=null&&s.componentWillReceiveProps(y,z),t.__v==n.__v||!s.__e&&s.shouldComponentUpdate!=null&&s.shouldComponentUpdate(y,s.__s,z)===!1){t.__v!=n.__v&&(s.props=y,s.state=s.__s,s.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(B){B&&(B.__=t)}),R.push.apply(s.__h,s._sb),s._sb=[],s.__h.length&&a.push(s);break e}s.componentWillUpdate!=null&&s.componentWillUpdate(y,s.__s,z),g&&s.componentDidUpdate!=null&&s.__h.push(function(){s.componentDidUpdate(u,m,w)})}if(s.context=z,s.props=y,s.__P=e,s.__e=!1,P=b.__r,U=0,g)s.state=s.__s,s.__d=!1,P&&P(t),p=s.render(s.props,s.state,s.context),R.push.apply(s.__h,s._sb),s._sb=[];else do s.__d=!1,P&&P(t),p=s.render(s.props,s.state,s.context),s.state=s.__s;while(s.__d&&++U<25);s.state=s.__s,s.getChildContext!=null&&(r=L(L({},r),s.getChildContext())),g&&!h&&s.getSnapshotBeforeUpdate!=null&&(w=s.getSnapshotBeforeUpdate(u,m)),N=p!=null&&p.type===Y&&p.key==null?$e(p.props.children):p,d=ve(e,q(N)?N:[N],t,n,r,l,o,a,d,_,c),s.base=t.__e,t.__u&=-161,s.__h.length&&a.push(s),x&&(s.__E=s.__=null)}catch(B){if(t.__v=null,_||o!=null)if(B.then){for(t.__u|=_?160:128;d&&d.nodeType==8&&d.nextSibling;)d=d.nextSibling;o[o.indexOf(d)]=null,t.__e=d}else{for(I=o.length;I--;)ie(o[I]);se(t)}else t.__e=n.__e,t.__k=n.__k,B.then||se(t);b.__e(B,t,n)}else o==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):d=t.__e=qe(n.__e,t,n,r,l,o,a,_,c);return(p=b.diffed)&&p(t),128&t.__u?void 0:d}function se(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(se))}function Se(e,t,n){for(var r=0;r<n.length;r++)le(n[r],n[++r],n[++r]);b.__c&&b.__c(t,e),e.some(function(l){try{e=l.__h,l.__h=[],e.some(function(o){o.call(l)})}catch(o){b.__e(o,l.__v)}})}function $e(e){return typeof e!="object"||e==null||e.__b>0?e:q(e)?e.map($e):L({},e)}function qe(e,t,n,r,l,o,a,d,_){var c,p,s,h,u,m,w,x=n.props||j,y=t.props,g=t.type;if(g=="svg"?l="http://www.w3.org/2000/svg":g=="math"?l="http://www.w3.org/1998/Math/MathML":l||(l="http://www.w3.org/1999/xhtml"),o!=null){for(c=0;c<o.length;c++)if((u=o[c])&&"setAttribute"in u==!!g&&(g?u.localName==g:u.nodeType==3)){e=u,o[c]=null;break}}if(e==null){if(g==null)return document.createTextNode(y);e=document.createElementNS(l,g,y.is&&y),d&&(b.__m&&b.__m(t,o),d=!1),o=null}if(g==null)x===y||d&&e.data==y||(e.data=y);else{if(o=o&&O.call(e.childNodes),!d&&o!=null)for(x={},c=0;c<e.attributes.length;c++)x[(u=e.attributes[c]).name]=u.value;for(c in x)u=x[c],c=="dangerouslySetInnerHTML"?s=u:c=="children"||c in y||c=="value"&&"defaultValue"in y||c=="checked"&&"defaultChecked"in y||G(e,c,null,u,l);for(c in y)u=y[c],c=="children"?h=u:c=="dangerouslySetInnerHTML"?p=u:c=="value"?m=u:c=="checked"?w=u:d&&typeof u!="function"||x[c]===u||G(e,c,u,x[c],l);if(p)d||s&&(p.__html==s.__html||p.__html==e.innerHTML)||(e.innerHTML=p.__html),t.__k=[];else if(s&&(e.innerHTML=""),ve(t.type=="template"?e.content:e,q(h)?h:[h],t,n,r,g=="foreignObject"?"http://www.w3.org/1999/xhtml":l,o,a,o?o[0]:n.__k&&D(n,0),d,_),o!=null)for(c=o.length;c--;)ie(o[c]);d||(c="value",g=="progress"&&m==null?e.removeAttribute("value"):m!=null&&(m!==e[c]||g=="progress"&&!m||g=="option"&&m!=x[c])&&G(e,c,m,x[c],l),c="checked",w!=null&&w!=e[c]&&G(e,c,w,x[c],l))}return e}function le(e,t,n){try{if(typeof e=="function"){var r=typeof e.__u=="function";r&&e.__u(),r&&t==null||(e.__u=e(t))}else e.current=t}catch(l){b.__e(l,n)}}function Ce(e,t,n){var r,l;if(b.unmount&&b.unmount(e),(r=e.ref)&&(r.current&&r.current!=e.__e||le(r,null,t)),(r=e.__c)!=null){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(o){b.__e(o,t)}r.base=r.__P=null}if(r=e.__k)for(l=0;l<r.length;l++)r[l]&&Ce(r[l],t,n||typeof e.type!="function");n||ie(e.__e),e.__c=e.__=e.__e=void 0}function Ke(e,t,n){return this.constructor(e,n)}function Ye(e,t,n){var r,l,o,a;t==document&&(t=document.documentElement),b.__&&b.__(e,t),l=(r=!1)?null:t.__k,o=[],a=[],re(t,e=t.__k=Oe(Y,null,[e]),l||j,j,t.namespaceURI,l?null:t.firstChild?O.call(t.childNodes):null,o,l?l.__e:t.firstChild,r,a),Se(o,e,a)}O=R.slice,b={__e:function(e,t,n,r){for(var l,o,a;t=t.__;)if((l=t.__c)&&!l.__)try{if((o=l.constructor)&&o.getDerivedStateFromError!=null&&(l.setState(o.getDerivedStateFromError(e)),a=l.__d),l.componentDidCatch!=null&&(l.componentDidCatch(e,r||{}),a=l.__d),a)return l.__E=l}catch(d){e=d}throw e}},ue=0,J.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=L({},this.state),typeof e=="function"&&(e=e(L({},n),this.props)),e&&L(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),be(this))},J.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),be(this))},J.prototype.render=Y,M=[],fe=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,ge=function(e,t){return e.__v.__b-t.__v.__b},V.__r=0,ee=Math.random().toString(8),F="__d"+ee,W="__a"+ee,me=/(PointerCapture)$|Capture$/i,te=0,ne=ke(!1),oe=ke(!0);var Je=0;function i(e,t,n,r,l,o){t||(t={});var a,d,_=t;if("ref"in _)for(d in _={},t)d=="ref"?a=t[d]:_[d]=t[d];var c={type:e,props:_,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Je,__i:-1,__u:0,__source:l,__self:o};if(typeof e=="function"&&(a=e.defaultProps))for(d in a)_[d]===void 0&&(_[d]=a[d]);return b.vnode&&b.vnode(c),c}let H="",T="";const Ve=(e,t)=>{H=e,T=t},ae=()=>({"Content-Type":"application/json","X-Widget-Key":T}),Ge=async()=>{const e=await fetch(`${H}/api/widget/init?key=${T}`);if(!e.ok)throw new Error("Widget init failed");return e.json()},Qe=async()=>{const e=await fetch(`${H}/api/widget/doctors?key=${T}`);if(!e.ok)throw new Error("Failed to load doctors");return e.json()},Xe=async(e,t)=>{const n=await fetch(`${H}/api/widget/slots?key=${T}&doctorId=${e}&date=${t}`);if(!n.ok)throw new Error("Failed to load slots");return n.json()},Ze=async e=>{const t=await fetch(`${H}/api/widget/book?key=${T}`,{method:"POST",headers:ae(),body:JSON.stringify(e)});if(!t.ok)throw new Error("Booking failed");return t.json()},et=async e=>{const t=await fetch(`${H}/api/widget/lead?key=${T}`,{method:"POST",headers:ae(),body:JSON.stringify(e)});if(!t.ok)throw new Error("Submission failed");return t.json()},tt=async(e,t)=>{const n=await fetch(`${H}/api/widget/chat?key=${T}`,{method:"POST",headers:ae(),body:JSON.stringify({messages:e,captchaToken:t})});if(!n.ok||!n.body)throw new Error("Chat failed");return n.body};var E,k,ce,ze,Q=0,Le=[],S=b,Me=S.__b,Te=S.__r,Be=S.diffed,He=S.__c,Pe=S.unmount,Ne=S.__;function de(e,t){S.__h&&S.__h(k,e,Q||t),Q=0;var n=k.__H||(k.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function v(e){return Q=1,nt(Ae,e)}function nt(e,t,n){var r=de(E++,2);if(r.t=e,!r.__c&&(r.__=[Ae(void 0,t),function(d){var _=r.__N?r.__N[0]:r.__[0],c=r.t(_,d);_!==c&&(r.__N=[c,r.__[1]],r.__c.setState({}))}],r.__c=k,!k.__f)){var l=function(d,_,c){if(!r.__c.__H)return!0;var p=r.__c.__H.__.filter(function(h){return h.__c});if(p.every(function(h){return!h.__N}))return!o||o.call(this,d,_,c);var s=r.__c.props!==d;return p.some(function(h){if(h.__N){var u=h.__[0];h.__=h.__N,h.__N=void 0,u!==h.__[0]&&(s=!0)}}),o&&o.call(this,d,_,c)||s};k.__f=!0;var o=k.shouldComponentUpdate,a=k.componentWillUpdate;k.componentWillUpdate=function(d,_,c){if(this.__e){var p=o;o=void 0,l(d,_,c),o=p}a&&a.call(this,d,_,c)},k.shouldComponentUpdate=l}return r.__N||r.__}function X(e,t){var n=de(E++,3);!S.__s&&Ie(n.__H,t)&&(n.__=e,n.u=t,k.__H.__h.push(n))}function ot(e){return Q=5,it(function(){return{current:e}},[])}function it(e,t){var n=de(E++,7);return Ie(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function rt(){for(var e;e=Le.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Z),t.__h.some(_e),t.__h=[]}catch(n){t.__h=[],S.__e(n,e.__v)}}}S.__b=function(e){k=null,Me&&Me(e)},S.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ne&&Ne(e,t)},S.__r=function(e){Te&&Te(e),E=0;var t=(k=e.__c).__H;t&&(ce===k?(t.__h=[],k.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(Z),t.__h.some(_e),t.__h=[],E=0)),ce=k},S.diffed=function(e){Be&&Be(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Le.push(t)!==1&&ze===S.requestAnimationFrame||((ze=S.requestAnimationFrame)||st)(rt)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ce=k=null},S.__c=function(e,t){t.some(function(n){try{n.__h.some(Z),n.__h=n.__h.filter(function(r){return!r.__||_e(r)})}catch(r){t.some(function(l){l.__h&&(l.__h=[])}),t=[],S.__e(r,n.__v)}}),He&&He(e,t)},S.unmount=function(e){Pe&&Pe(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(r){try{Z(r)}catch(l){t=l}}),n.__H=void 0,t&&S.__e(t,n.__v))};var De=typeof requestAnimationFrame=="function";function st(e){var t,n=function(){clearTimeout(r),De&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);De&&(t=requestAnimationFrame(n))}function Z(e){var t=k,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),k=t}function _e(e){var t=k;e.__c=e.__(),k=t}function Ie(e,t){return!e||e.length!==t.length||t.some(function(n,r){return n!==e[r]})}function Ae(e,t){return typeof t=="function"?t(e):t}const lt=e=>`
:host { all: initial; font-family: -apple-system, 'Segoe UI', Roboto, sans-serif; }
* { margin: 0; padding: 0; box-sizing: border-box; }
.widget-bubble {
width: 56px; height: 56px; border-radius: 50%;
background: ${e.colors.primary}; color: #fff;
display: flex; align-items: center; justify-content: center;
cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
transition: transform 0.2s; border: none; outline: none;
}
.widget-bubble:hover { transform: scale(1.08); }
.widget-bubble img { width: 28px; height: 28px; border-radius: 6px; }
.widget-bubble svg { width: 24px; height: 24px; fill: currentColor; }
.widget-panel {
width: 380px; height: 520px; border-radius: 16px;
background: #fff; box-shadow: 0 8px 32px rgba(0,0,0,0.12);
display: flex; flex-direction: column; overflow: hidden;
border: 1px solid #e5e7eb; position: absolute; bottom: 68px; right: 0;
animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
from { opacity: 0; transform: translateY(12px); }
to { opacity: 1; transform: translateY(0); }
}
.widget-header {
display: flex; align-items: center; gap: 10px;
padding: 14px 16px; background: ${e.colors.primary}; color: #fff;
}
.widget-header img { width: 32px; height: 32px; border-radius: 8px; }
.widget-header-text { flex: 1; }
.widget-header-name { font-size: 14px; font-weight: 600; }
.widget-header-sub { font-size: 11px; opacity: 0.8; }
.widget-close {
background: none; border: none; color: #fff; cursor: pointer;
font-size: 18px; padding: 4px; opacity: 0.8;
}
.widget-close:hover { opacity: 1; }
.widget-tabs {
display: flex; border-bottom: 1px solid #e5e7eb; background: #fafafa;
}
.widget-tab {
flex: 1; padding: 10px 0; text-align: center; font-size: 12px;
font-weight: 500; cursor: pointer; border: none; background: none;
color: #6b7280; border-bottom: 2px solid transparent;
transition: all 0.15s;
}
.widget-tab.active {
color: ${e.colors.primary}; border-bottom-color: ${e.colors.primary};
font-weight: 600;
}
.widget-body { flex: 1; overflow-y: auto; padding: 16px; }
.widget-input {
width: 100%; padding: 10px 12px; border: 1px solid #d1d5db;
border-radius: 8px; font-size: 13px; outline: none;
transition: border-color 0.15s;
}
.widget-input:focus { border-color: ${e.colors.primary}; }
.widget-textarea { resize: vertical; min-height: 60px; font-family: inherit; }
.widget-select {
width: 100%; padding: 10px 12px; border: 1px solid #d1d5db;
border-radius: 8px; font-size: 13px; background: #fff; outline: none;
}
.widget-label { font-size: 12px; font-weight: 500; color: #374151; margin-bottom: 4px; display: block; }
.widget-field { margin-bottom: 12px; }
.widget-btn {
width: 100%; padding: 10px 16px; border: none; border-radius: 8px;
font-size: 13px; font-weight: 600; cursor: pointer;
transition: opacity 0.15s; color: #fff; background: ${e.colors.primary};
}
.widget-btn:hover { opacity: 0.9; }
.widget-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.widget-btn-secondary { background: #f3f4f6; color: #374151; }
.widget-slots {
display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0;
}
.widget-slot {
padding: 8px; text-align: center; font-size: 12px; border-radius: 6px;
border: 1px solid #e5e7eb; cursor: pointer; background: #fff;
transition: all 0.15s;
}
.widget-slot:hover { border-color: ${e.colors.primary}; }
.widget-slot.selected { background: ${e.colors.primary}; color: #fff; border-color: ${e.colors.primary}; }
.widget-slot.unavailable { opacity: 0.4; cursor: not-allowed; text-decoration: line-through; }
.widget-success {
text-align: center; padding: 24px 16px;
}
.widget-success-icon { font-size: 40px; margin-bottom: 12px; }
.widget-success-title { font-size: 16px; font-weight: 600; color: #059669; margin-bottom: 8px; }
.widget-success-text { font-size: 13px; color: #6b7280; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 0; }
.chat-msg { margin-bottom: 10px; display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble {
max-width: 80%; padding: 10px 14px; border-radius: 12px;
font-size: 13px; line-height: 1.5;
}
.chat-msg.user .chat-bubble { background: ${e.colors.primary}; color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.assistant .chat-bubble { background: #f3f4f6; color: #1f2937; border-bottom-left-radius: 4px; }
.chat-input-row { display: flex; gap: 8px; padding-top: 8px; border-top: 1px solid #e5e7eb; }
.chat-input { flex: 1; }
.chat-send {
width: 36px; height: 36px; border-radius: 8px;
background: ${e.colors.primary}; color: #fff;
border: none; cursor: pointer; display: flex;
align-items: center; justify-content: center; font-size: 16px;
}
.chat-send:disabled { opacity: 0.5; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.quick-action {
padding: 6px 12px; border-radius: 16px; font-size: 11px;
border: 1px solid ${e.colors.primary}; color: ${e.colors.primary};
background: ${e.colors.primaryLight}; cursor: pointer;
transition: all 0.15s;
}
.quick-action:hover { background: ${e.colors.primary}; color: #fff; }
.widget-steps { display: flex; gap: 4px; margin-bottom: 16px; }
.widget-step {
flex: 1; height: 3px; border-radius: 2px; background: #e5e7eb;
}
.widget-step.active { background: ${e.colors.primary}; }
.widget-step.done { background: #059669; }
`,at={chat:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><defs><style>.fa-secondary{opacity:.4}</style></defs><path class="fa-secondary" d="M0 64C0 28.7 28.7 0 64 0L448 0c35.3 0 64 28.7 64 64l0 288c0 35.3-28.7 64-64 64l-138.7 0L185.6 508.8c-4.8 3.6-11.3 4.2-16.8 1.5s-8.8-8.2-8.8-14.3l0-80-96 0c-35.3 0-64-28.7-64-64L0 64zM96 208a32 32 0 1 0 64 0 32 32 0 1 0 -64 0zm128 0a32 32 0 1 0 64 0 32 32 0 1 0 -64 0zm128 0a32 32 0 1 0 64 0 32 32 0 1 0 -64 0z"/><path class="fa-primary" d="M96 208a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zm128 0a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zm160-32a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>',calendar:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><defs><style>.fa-secondary{opacity:.4}</style></defs><path class="fa-secondary" d="M0 192l448 0 0 272c0 26.5-21.5 48-48 48L48 512c-26.5 0-48-21.5-48-48L0 192zM119 319c-9.4 9.4-9.4 24.6 0 33.9l64 64c4.7 4.7 10.8 7 17 7s12.3-2.3 17-7L329 305c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-95 95-47-47c-9.4-9.4-24.6-9.4-33.9 0z"/><path class="fa-primary" d="M128 0C110.3 0 96 14.3 96 32l0 32L48 64C21.5 64 0 85.5 0 112l0 80 448 0 0-80c0-26.5-21.5-48-48-48l-48 0 0-32c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 32L160 64l0-32c0-17.7-14.3-32-32-32zM329 305c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-95 95-47-47c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9l64 64c9.4 9.4 24.6 9.4 33.9 0L329 305z"/></svg>',phone:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><defs><style>.fa-secondary{opacity:.4}</style></defs><path class="fa-secondary" d="M0 64C0 311.4 200.6 512 448 512c18 0 33.8-12.1 38.6-29.5l24-88c1-3.5 1.4-7 1.4-10.5c0-15.8-9.4-30.6-24.6-36.9l-96-40c-16.3-6.8-35.2-2.1-46.3 11.6L304.7 368C234.3 334.7 177.3 277.7 144 207.3L193.3 167c13.7-11.2 18.4-30 11.6-46.3l-40-96C158.6 9.4 143.8 0 128 0c-3.5 0-7 .5-10.5 1.4l-88 24C12.1 30.2 0 46 0 64z"/><path class="fa-primary" d="M295 217c-9.4-9.4-9.4-24.6 0-33.9l135-135L384 48c-13.3 0-24-10.7-24-24s10.7-24 24-24L488 0c13.3 0 24 10.7 24 24l0 104c0 13.3-10.7 24-24 24s-24-10.7-24-24l0-46.1L329 217c-9.4 9.4-24.6 9.4-33.9 0z"/></svg>',send:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><defs><style>.fa-secondary{opacity:.4}</style></defs><path class="fa-secondary" d="M1.4 72.3c0 6.1 1.4 12.4 4.7 18.6l70 134.6c63.3 7.9 126.6 15.8 190 23.7c3.4 .4 6 3.3 6 6.7s-2.6 6.3-6 6.7l-190 23.7L6.1 421.1c-14.6 28.1 7.3 58.6 35.2 58.6c5.3 0 10.8-1.1 16.3-3.5L492.9 285.3c11.6-5.1 19.1-16.6 19.1-29.3s-7.5-24.2-19.1-29.3L57.6 35.8C29.5 23.5 1.4 45.6 1.4 72.3z"/><path class="fa-primary" d="M76.1 286.5l190-23.7c3.4-.4 6-3.3 6-6.7s-2.6-6.3-6-6.7l-190-23.7 8.2 15.7c4.8 9.3 4.8 20.3 0 29.5l-8.2 15.7z"/></svg>',close:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><defs><style>.fa-secondary{opacity:.4}</style></defs><path class="fa-secondary" d="M297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6z"/></svg>',check:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><defs><style>.fa-secondary{opacity:.4}</style></defs><path class="fa-secondary" d="M0 256a256 256 0 1 0 512 0A256 256 0 1 0 0 256zm136 0c0-6.1 2.3-12.3 7-17c9.4-9.4 24.6-9.4 33.9 0l47 47c37-37 74-74 111-111c4.7-4.7 10.8-7 17-7s12.3 2.3 17 7c2.3 2.3 4.1 5 5.3 7.9c.6 1.5 1 2.9 1.3 4.4c.2 1.1 .3 2.2 .3 2.2c.1 1.2 .1 1.2 .1 2.5c-.1 1.5-.1 1.9-.1 2.3c-.1 .7-.2 1.5-.3 2.2c-.3 1.5-.7 3-1.3 4.4c-1.2 2.9-2.9 5.6-5.3 7.9c-42.7 42.7-85.3 85.3-128 128c-4.7 4.7-10.8 7-17 7s-12.3-2.3-17-7c-21.3-21.3-42.7-42.7-64-64c-4.7-4.7-7-10.8-7-17z"/><path class="fa-primary" d="M369 175c9.4 9.4 9.4 24.6 0 33.9L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0z"/></svg>',sparkles:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><defs><style>.fa-secondary{opacity:.4}</style></defs><path class="fa-secondary" d="M320 96c0 4.8 3 9.1 7.5 10.8L384 128l21.2 56.5c1.7 4.5 6 7.5 10.8 7.5s9.1-3 10.8-7.5L448 128l56.5-21.2c4.5-1.7 7.5-6 7.5-10.8s-3-9.1-7.5-10.8L448 64 426.8 7.5C425.1 3 420.8 0 416 0s-9.1 3-10.8 7.5L384 64 327.5 85.2c-4.5 1.7-7.5 6-7.5 10.8zm0 320c0 4.8 3 9.1 7.5 10.8L384 448l21.2 56.5c1.7 4.5 6 7.5 10.8 7.5s9.1-3 10.8-7.5L448 448l56.5-21.2c4.5-1.7 7.5-6 7.5-10.8s-3-9.1-7.5-10.8L448 384l-21.2-56.5c-1.7-4.5-6-7.5-10.8-7.5s-9.1 3-10.8 7.5L384 384l-56.5 21.2c-4.5 1.7-7.5 6-7.5 10.8z"/><path class="fa-primary" d="M205.1 73.3c-2.6-5.7-8.3-9.3-14.5-9.3s-11.9 3.6-14.5 9.3L123.4 187.4 9.3 240C3.6 242.6 0 248.3 0 254.6s3.6 11.9 9.3 14.5l114.1 52.7L176 435.8c2.6 5.7 8.3 9.3 14.5 9.3s11.9-3.6 14.5-9.3l52.7-114.1 114.1-52.7c5.7-2.6 9.3-8.3 9.3-14.5s-3.6-11.9-9.3-14.5L257.8 187.4 205.1 73.3z"/></svg>'},pe=(e,t=16,n="currentColor")=>at[e].replace("<svg",`<svg width="${t}" height="${t}" style="fill:${n};vertical-align:middle;"`).replace(/\.fa-primary/g,".p").replace(/\.fa-secondary\{opacity:\.4\}/g,`.s{opacity:.4;fill:${n}}`),ct=["Doctor availability","Clinic timings","Book appointment","Health packages"],dt=()=>{const[e,t]=v([]),[n,r]=v(""),[l,o]=v(!1),a=ot(null);X(()=>{a.current&&(a.current.scrollTop=a.current.scrollHeight)},[e]);const d=async _=>{if(!_.trim()||l)return;const c={role:"user",content:_.trim()},p=[...e,c];t(p),r(""),o(!0);try{const h=(await tt(p)).getReader(),u=new TextDecoder;let m="";for(t([...p,{role:"assistant",content:""}]);;){const{done:w,value:x}=await h.read();if(w)break;m+=u.decode(x,{stream:!0}),t([...p,{role:"assistant",content:m}])}}catch{t([...p,{role:"assistant",content:"Sorry, I encountered an error. Please try again."}])}finally{o(!1)}};return i("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[i("div",{class:"chat-messages",ref:a,children:[e.length===0&&i("div",{style:{textAlign:"center",padding:"20px 0"},children:[i("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"👋"}),i("div",{style:{fontSize:"14px",fontWeight:600,color:"#1f2937",marginBottom:"4px"},children:"How can we help you?"}),i("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"16px"},children:"Ask about doctors, clinics, packages, or book an appointment."}),i("div",{class:"quick-actions",children:ct.map(_=>i("button",{class:"quick-action",onClick:()=>d(_),children:_},_))})]}),e.map((_,c)=>i("div",{class:`chat-msg ${_.role}`,children:i("div",{class:"chat-bubble",children:_.content||"..."})},c))]}),i("div",{class:"chat-input-row",children:[i("input",{class:"widget-input chat-input",placeholder:"Type a message...",value:n,onInput:_=>r(_.target.value),onKeyDown:_=>_.key==="Enter"&&d(n),disabled:l}),i("button",{class:"chat-send",onClick:()=>d(n),disabled:l||!n.trim(),children:"↑"})]})]})},_t=()=>{const[e,t]=v("department"),[n,r]=v([]),[l,o]=v([]),[a,d]=v(""),[_,c]=v(null),[p,s]=v(""),[h,u]=v([]),[m,w]=v(""),[x,y]=v(""),[g,C]=v(""),[z,P]=v(""),[U,N]=v(!1),[I,$]=v(""),[B,ht]=v("");X(()=>{Qe().then(f=>{r(f),o([...new Set(f.map(A=>A.department).filter(Boolean))])}).catch(()=>$("Failed to load doctors"))},[]);const ft=a?n.filter(f=>f.department===a):[],gt=f=>{c(f),s(new Date().toISOString().split("T")[0]),t("datetime")};X(()=>{_&&p&&Xe(_.id,p).then(u).catch(()=>{})},[_,p]);const mt=async()=>{if(!(!_||!m||!x||!g)){N(!0),$("");try{const f=`${p}T${m}:00`,A=await Ze({departmentId:a,doctorId:_.id,scheduledAt:f,patientName:x,patientPhone:g,chiefComplaint:z,captchaToken:"dev-bypass"});ht(A.reference),t("success")}catch{$("Booking failed. Please try again.")}finally{N(!1)}}},Ee={department:0,doctor:1,datetime:2,details:3,success:4}[e];return i("div",{children:[e!=="success"&&i("div",{class:"widget-steps",children:[0,1,2,3].map(f=>i("div",{class:`widget-step ${f<Ee?"done":f===Ee?"active":""}`},f))}),I&&i("div",{style:{color:"#dc2626",fontSize:"12px",marginBottom:"8px"},children:I}),e==="department"&&i("div",{children:[i("div",{class:"widget-label",style:{marginBottom:"8px",fontSize:"13px",fontWeight:600},children:"Select Department"}),l.map(f=>i("button",{class:"widget-btn widget-btn-secondary",style:{marginBottom:"6px",textAlign:"left"},onClick:()=>{d(f),t("doctor")},children:f.replace(/_/g," ")},f))]}),e==="doctor"&&i("div",{children:[i("div",{class:"widget-label",style:{marginBottom:"8px",fontSize:"13px",fontWeight:600},children:["Select Doctor — ",a.replace(/_/g," ")]}),ft.map(f=>{var A;return i("button",{class:"widget-btn widget-btn-secondary",style:{marginBottom:"6px",textAlign:"left"},onClick:()=>gt(f),children:[i("div",{style:{fontWeight:600},children:f.name}),i("div",{style:{fontSize:"11px",color:"#6b7280"},children:[f.visitingHours??""," ",(A=f.clinic)!=null&&A.clinicName?`${f.clinic.clinicName}`:""]})]},f.id)}),i("button",{class:"widget-btn widget-btn-secondary",style:{marginTop:"8px"},onClick:()=>t("department"),children:"← Back"})]}),e==="datetime"&&i("div",{children:[i("div",{class:"widget-label",style:{marginBottom:"8px",fontSize:"13px",fontWeight:600},children:[_==null?void 0:_.name," — Pick Date & Time"]}),i("div",{class:"widget-field",children:[i("label",{class:"widget-label",children:"Date"}),i("input",{class:"widget-input",type:"date",value:p,min:new Date().toISOString().split("T")[0],onInput:f=>{s(f.target.value),w("")}})]}),h.length>0&&i("div",{children:[i("label",{class:"widget-label",children:"Available Slots"}),i("div",{class:"widget-slots",children:h.map(f=>i("button",{class:`widget-slot ${f.time===m?"selected":""} ${f.available?"":"unavailable"}`,onClick:()=>f.available&&w(f.time),disabled:!f.available,children:f.time},f.time))})]}),i("div",{style:{display:"flex",gap:"8px",marginTop:"12px"},children:[i("button",{class:"widget-btn widget-btn-secondary",style:{flex:1},onClick:()=>t("doctor"),children:"← Back"}),i("button",{class:"widget-btn",style:{flex:1},disabled:!m,onClick:()=>t("details"),children:"Next →"})]})]}),e==="details"&&i("div",{children:[i("div",{class:"widget-label",style:{marginBottom:"8px",fontSize:"13px",fontWeight:600},children:"Your Details"}),i("div",{class:"widget-field",children:[i("label",{class:"widget-label",children:"Full Name *"}),i("input",{class:"widget-input",placeholder:"Your name",value:x,onInput:f=>y(f.target.value)})]}),i("div",{class:"widget-field",children:[i("label",{class:"widget-label",children:"Phone Number *"}),i("input",{class:"widget-input",placeholder:"+91 9876543210",value:g,onInput:f=>C(f.target.value)})]}),i("div",{class:"widget-field",children:[i("label",{class:"widget-label",children:"Chief Complaint"}),i("textarea",{class:"widget-input widget-textarea",placeholder:"Describe your concern...",value:z,onInput:f=>P(f.target.value)})]}),i("div",{style:{display:"flex",gap:"8px"},children:[i("button",{class:"widget-btn widget-btn-secondary",style:{flex:1},onClick:()=>t("datetime"),children:"← Back"}),i("button",{class:"widget-btn",style:{flex:1},disabled:!x||!g||U,onClick:mt,children:U?"Booking...":"Book Appointment"})]})]}),e==="success"&&i("div",{class:"widget-success",children:[i("div",{class:"widget-success-icon",children:"✅"}),i("div",{class:"widget-success-title",children:"Appointment Booked!"}),i("div",{class:"widget-success-text",children:["Reference: ",i("strong",{children:B}),i("br",{}),_==null?void 0:_.name," • ",p," at ",m,i("br",{}),i("br",{}),"We'll send a confirmation SMS to your phone."]})]})]})},pt=()=>{const[e,t]=v(""),[n,r]=v(""),[l,o]=v(""),[a,d]=v(""),[_,c]=v(!1),[p,s]=v(!1),[h,u]=v(""),m=async()=>{if(!(!e.trim()||!n.trim())){c(!0),u("");try{await et({name:e.trim(),phone:n.trim(),interest:l.trim()||void 0,message:a.trim()||void 0,captchaToken:"dev-bypass"}),s(!0)}catch{u("Submission failed. Please try again.")}finally{c(!1)}}};return p?i("div",{class:"widget-success",children:[i("div",{class:"widget-success-icon",children:"🙏"}),i("div",{class:"widget-success-title",children:"Thank you!"}),i("div",{class:"widget-success-text",children:["An agent will call you shortly on ",n,".",i("br",{}),"We typically respond within 30 minutes during business hours."]})]}):i("div",{children:[i("div",{style:{fontSize:"13px",fontWeight:600,color:"#1f2937",marginBottom:"12px"},children:"Get in touch"}),i("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"16px"},children:"Leave your details and we'll call you back."}),h&&i("div",{style:{color:"#dc2626",fontSize:"12px",marginBottom:"8px"},children:h}),i("div",{class:"widget-field",children:[i("label",{class:"widget-label",children:"Full Name *"}),i("input",{class:"widget-input",placeholder:"Your name",value:e,onInput:w=>t(w.target.value)})]}),i("div",{class:"widget-field",children:[i("label",{class:"widget-label",children:"Phone Number *"}),i("input",{class:"widget-input",placeholder:"+91 9876543210",value:n,onInput:w=>r(w.target.value)})]}),i("div",{class:"widget-field",children:[i("label",{class:"widget-label",children:"Interested In"}),i("select",{class:"widget-select",value:l,onChange:w=>o(w.target.value),children:[i("option",{value:"",children:"Select (optional)"}),i("option",{value:"Consultation",children:"General Consultation"}),i("option",{value:"Health Checkup",children:"Health Checkup"}),i("option",{value:"Surgery",children:"Surgery"}),i("option",{value:"Second Opinion",children:"Second Opinion"}),i("option",{value:"Other",children:"Other"})]})]}),i("div",{class:"widget-field",children:[i("label",{class:"widget-label",children:"Message"}),i("textarea",{class:"widget-input widget-textarea",placeholder:"How can we help? (optional)",value:a,onInput:w=>d(w.target.value)})]}),i("button",{class:"widget-btn",disabled:!e.trim()||!n.trim()||_,onClick:m,children:_?"Sending...":"Send Message"})]})},ut=({config:e,shadow:t})=>{const[n,r]=v(!1),[l,o]=v("chat");return X(()=>{const a=document.createElement("style");return a.textContent=lt(e),t.appendChild(a),()=>{t.removeChild(a)}},[e,t]),i("div",{children:[!n&&i("button",{class:"widget-bubble",onClick:()=>r(!0),children:e.brand.logo?i("img",{src:e.brand.logo,alt:e.brand.name}):i("svg",{viewBox:"0 0 24 24",children:i("path",{d:"M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"})})}),n&&i("div",{class:"widget-panel",children:[i("div",{class:"widget-header",children:[e.brand.logo&&i("img",{src:e.brand.logo,alt:""}),i("div",{class:"widget-header-text",children:[i("div",{class:"widget-header-name",children:e.brand.name}),i("div",{class:"widget-header-sub",children:"We're here to help"})]}),i("button",{class:"widget-close",onClick:()=>r(!1),children:"✕"})]}),i("div",{class:"widget-tabs",children:[i("button",{class:`widget-tab ${l==="chat"?"active":""}`,onClick:()=>o("chat"),children:[i("span",{innerHTML:pe("chat",14)})," Chat"]}),i("button",{class:`widget-tab ${l==="book"?"active":""}`,onClick:()=>o("book"),children:[i("span",{innerHTML:pe("calendar",14)})," Book"]}),i("button",{class:`widget-tab ${l==="contact"?"active":""}`,onClick:()=>o("contact"),children:[i("span",{innerHTML:pe("phone",14)})," Contact"]})]}),i("div",{class:"widget-body",children:[l==="chat"&&i(dt,{}),l==="book"&&i(_t,{}),l==="contact"&&i(pt,{})]})]})]})},We=async()=>{const e=document.querySelector("script[data-key]");if(!e){console.error("[HelixWidget] Missing data-key attribute");return}const t=e.getAttribute("data-key")??"",n=e.src.replace(/\/widget\.js.*$/,"");Ve(n,t);let r;try{r=await Ge()}catch(d){console.error("[HelixWidget] Init failed:",d);return}const l=document.createElement("div");l.id="helix-widget-host",l.style.cssText="position:fixed;bottom:20px;right:20px;z-index:999999;font-family:-apple-system,sans-serif;",document.body.appendChild(l);const o=l.attachShadow({mode:"open"}),a=document.createElement("div");o.appendChild(a),Ye(i(ut,{config:r,shadow:o}),a)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",We):We()})();