(function(){"use strict";var tt,C,$t,j,Mt,Tt,Bt,_t,et,J,It,wt,bt,xt,Pt,it={},nt=[],le=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ot=Array.isArray;function A(t,e){for(var n in e)t[n]=e[n];return t}function vt(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function ae(t,e,n){var o,l,r,s={};for(r in e)r=="key"?o=e[r]:r=="ref"?l=e[r]:s[r]=e[r];if(arguments.length>2&&(s.children=arguments.length>3?tt.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(r in t.defaultProps)s[r]===void 0&&(s[r]=t.defaultProps[r]);return rt(t,s,o,l,null)}function rt(t,e,n,o,l){var r={type:t,props:e,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:l??++$t,__i:-1,__u:0};return l==null&&C.vnode!=null&&C.vnode(r),r}function O(t){return t.children}function lt(t,e){this.props=t,this.context=e}function q(t,e){if(e==null)return t.__?q(t.__,t.__i+1):null;for(var n;ee&&j.sort(Bt),t=j.shift(),e=j.length,ce(t)}finally{j.length=at.__r=0}}function Dt(t,e,n,o,l,r,s,p,u,c,d){var a,g,h,m,k,w,x,_=o&&o.__k||nt,I=e.length;for(u=se(n,e,_,u,I),a=0;a0?s=t.__k[r]=rt(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):t.__k[r]=s,u=r+g,s.__=t,s.__b=t.__b+1,p=null,(c=s.__i=de(s,n,u,a))!=-1&&(a--,(p=n[c])&&(p.__u|=2)),p==null||p.__v==null?(c==-1&&(l>d?g--:lu?g--:g++,s.__u|=4))):t.__k[r]=null;if(a)for(r=0;r(d?1:0)){for(l=n-1,r=n+1;l>=0||r=0?l--:r++])!=null&&(2&c.__u)==0&&p==c.key&&u==c.type)return s}return-1}function Et(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||le.test(e)?n:n+"px"}function ct(t,e,n,o,l){var r,s;t:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof o=="string"&&(t.style.cssText=o=""),o)for(e in o)n&&e in n||Et(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||Et(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")r=e!=(e=e.replace(It,"$1")),s=e.toLowerCase(),e=s in t||e=="onFocusOut"||e=="onFocusIn"?s.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+r]=n,n?o?n[J]=o[J]:(n[J]=wt,t.addEventListener(e,r?xt:bt,r)):t.removeEventListener(e,r?xt:bt,r);else{if(l=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break t}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function Wt(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e[et]==null)e[et]=wt++;else if(e[et]0?t:ot(t)?t.map(Ft):A({},t)}function pe(t,e,n,o,l,r,s,p,u){var c,d,a,g,h,m,k,w=n.props||it,x=e.props,_=e.type;if(_=="svg"?l="http://www.w3.org/2000/svg":_=="math"?l="http://www.w3.org/1998/Math/MathML":l||(l="http://www.w3.org/1999/xhtml"),r!=null){for(c=0;c{U=t,F=e},st=()=>({"Content-Type":"application/json","X-Widget-Key":F}),_e=async()=>{const t=await fetch(`${U}/api/widget/init?key=${F}`);if(!t.ok)throw new Error("Widget init failed");return t.json()},we=async()=>{const t=await fetch(`${U}/api/widget/doctors?key=${F}`);if(!t.ok)throw new Error("Failed to load doctors");return t.json()},be=async(t,e)=>{const n=await fetch(`${U}/api/widget/slots?key=${F}&doctorId=${t}&date=${e}`);if(!n.ok)throw new Error("Failed to load slots");return n.json()},xe=async t=>{const e=await fetch(`${U}/api/widget/book?key=${F}`,{method:"POST",headers:st(),body:JSON.stringify(t)});if(!e.ok)throw new Error("Booking failed");return e.json()},ve=async t=>{const e=await fetch(`${U}/api/widget/lead?key=${F}`,{method:"POST",headers:st(),body:JSON.stringify(t)});if(!e.ok)throw new Error("Submission failed");return e.json()},ye=async(t,e)=>{const n=await fetch(`${U}/api/widget/chat-start?key=${F}`,{method:"POST",headers:st(),body:JSON.stringify({name:t,phone:e})});if(!n.ok)throw new Error("Chat start failed");return n.json()},ke=async(t,e,n)=>{const o=await fetch(`${U}/api/widget/chat?key=${F}`,{method:"POST",headers:st(),body:JSON.stringify({leadId:t,messages:e,branch:n})});if(!o.ok||!o.body)throw new Error("Chat failed");return o.body};var K,L,St,Ot,G=0,Ut=[],M=C,Rt=M.__b,qt=M.__r,Kt=M.diffed,Vt=M.__c,Yt=M.unmount,Jt=M.__;function dt(t,e){M.__h&&M.__h(L,t,G||e),G=0;var n=L.__H||(L.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function v(t){return G=1,Ce(Xt,t)}function Ce(t,e,n){var o=dt(K++,2);if(o.t=t,!o.__c&&(o.__=[Xt(void 0,e),function(p){var u=o.__N?o.__N[0]:o.__[0],c=o.t(u,p);u!==c&&(o.__N=[c,o.__[1]],o.__c.setState({}))}],o.__c=L,!L.__f)){var l=function(p,u,c){if(!o.__c.__H)return!0;var d=o.__c.__H.__.filter(function(g){return g.__c});if(d.every(function(g){return!g.__N}))return!r||r.call(this,p,u,c);var a=o.__c.props!==p;return d.some(function(g){if(g.__N){var h=g.__[0];g.__=g.__N,g.__N=void 0,h!==g.__[0]&&(a=!0)}}),r&&r.call(this,p,u,c)||a};L.__f=!0;var r=L.shouldComponentUpdate,s=L.componentWillUpdate;L.componentWillUpdate=function(p,u,c){if(this.__e){var d=r;r=void 0,l(p,u,c),r=d}s&&s.call(this,p,u,c)},L.shouldComponentUpdate=l}return o.__N||o.__}function W(t,e){var n=dt(K++,3);!M.__s&&Qt(n.__H,e)&&(n.__=t,n.u=e,L.__H.__h.push(n))}function V(t){return G=5,Q(function(){return{current:t}},[])}function Q(t,e){var n=dt(K++,7);return Qt(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function ze(t,e){return G=8,Q(function(){return t},e)}function Se(t){var e=L.context[t.__c],n=dt(K++,9);return n.c=t,e?(n.__==null&&(n.__=!0,e.sub(L)),e.props.value):t.__}function Le(){for(var t;t=Ut.shift();){var e=t.__H;if(t.__P&&e)try{e.__h.some(pt),e.__h.some(Lt),e.__h=[]}catch(n){e.__h=[],M.__e(n,t.__v)}}}M.__b=function(t){L=null,Rt&&Rt(t)},M.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Jt&&Jt(t,e)},M.__r=function(t){qt&&qt(t),K=0;var e=(L=t.__c).__H;e&&(St===L?(e.__h=[],L.__h=[],e.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.some(pt),e.__h.some(Lt),e.__h=[],K=0)),St=L},M.diffed=function(t){Kt&&Kt(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Ut.push(e)!==1&&Ot===M.requestAnimationFrame||((Ot=M.requestAnimationFrame)||$e)(Le)),e.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),St=L=null},M.__c=function(t,e){e.some(function(n){try{n.__h.some(pt),n.__h=n.__h.filter(function(o){return!o.__||Lt(o)})}catch(o){e.some(function(l){l.__h&&(l.__h=[])}),e=[],M.__e(o,n.__v)}}),Vt&&Vt(t,e)},M.unmount=function(t){Yt&&Yt(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.some(function(o){try{pt(o)}catch(l){e=l}}),n.__H=void 0,e&&M.__e(e,n.__v))};var Gt=typeof requestAnimationFrame=="function";function $e(t){var e,n=function(){clearTimeout(o),Gt&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,35);Gt&&(e=requestAnimationFrame(n))}function pt(t){var e=L,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),L=e}function Lt(t){var e=L;t.__c=t.__(),L=e}function Qt(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Xt(t,e){return typeof e=="function"?e(t):e}const Me="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",Zt=()=>typeof window>"u"||window.turnstile?Promise.resolve():(window.__helixTurnstileLoading||(window.__helixTurnstileLoading=new Promise((t,e)=>{const n=document.createElement("script");n.src=Me,n.async=!0,n.defer=!0,n.onload=()=>{const o=()=>{window.turnstile?t():setTimeout(o,50)};o()},n.onerror=()=>e(new Error("Turnstile failed to load")),document.head.appendChild(n)})),window.__helixTurnstileLoading),Te=({siteKey:t,onToken:e,onError:n})=>{const o=V(null),l=V(null),r=V(null),s=V(e),p=V(n),[u,c]=v("loading");return s.current=e,p.current=n,W(()=>{if(!t||!o.current)return;let d=!1;const a=document.createElement("div");a.setAttribute("data-helix-turnstile",""),a.style.cssText=["position:fixed","z-index:2147483647","width:300px","height:65px","pointer-events:auto"].join(";"),document.body.appendChild(a),l.current=a;const g=()=>{if(!o.current||!l.current)return;const k=o.current.getBoundingClientRect();l.current.style.top=`${k.top}px`,l.current.style.left=`${k.left}px`};g(),window.addEventListener("resize",g),window.addEventListener("scroll",g,!0);let h=0;const m=()=>{g(),h=requestAnimationFrame(m)};return h=requestAnimationFrame(m),Zt().then(()=>{var k;if(!(d||!l.current||!window.turnstile))try{r.current=window.turnstile.render(l.current,{sitekey:t,callback:w=>s.current(w),"error-callback":()=>{var w;c("error"),(w=p.current)==null||w.call(p)},"expired-callback":()=>s.current(""),theme:"light",size:"normal"}),c("ready")}catch{c("error"),(k=p.current)==null||k.call(p)}}).catch(()=>{var k;c("error"),(k=p.current)==null||k.call(p)}),()=>{if(d=!0,cancelAnimationFrame(h),window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0),r.current&&window.turnstile){try{window.turnstile.remove(r.current)}catch{}r.current=null}a.remove(),l.current=null}},[t]),i("div",{class:"widget-captcha",children:[i("div",{class:"widget-captcha-mount",ref:o}),u==="loading"&&i("div",{class:"widget-captcha-status",children:"Loading verification…"}),u==="error"&&i("div",{class:"widget-captcha-status widget-captcha-error",children:"Verification failed to load. Please refresh."})]})},Be=t=>` /* all: initial isolates the widget from host-page style bleed, but we then explicitly re-enable font-family inheritance so the widget picks up the host page's font stack instead of falling back to system default. */ :host { all: initial; font-family: inherit; font-size: 14px; line-height: 1.4; color: #1f2937; } * { margin: 0; padding: 0; box-sizing: border-box; } input, select, textarea, button { font-family: inherit; font-size: inherit; color: inherit; } .widget-bubble { width: 56px; height: 56px; border-radius: 50%; background: #fff; color: ${t.colors.primary}; display: flex; align-items: center; justify-content: center; cursor: pointer; border: 1px solid #e5e7eb; box-shadow: 0 6px 20px rgba(17, 24, 39, 0.15), 0 2px 4px rgba(17, 24, 39, 0.08); transition: transform 0.2s, box-shadow 0.2s; outline: none; } .widget-bubble:hover { transform: scale(1.08); box-shadow: 0 10px 28px rgba(17, 24, 39, 0.2), 0 4px 8px rgba(17, 24, 39, 0.1); } .widget-bubble img { width: 32px; height: 32px; border-radius: 6px; } .widget-bubble svg { width: 26px; height: 26px; } .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; transition: width 0.25s ease, height 0.25s ease, border-radius 0.25s ease; } @keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } } @keyframes widgetFadeIn { from { opacity: 0; } to { opacity: 1; } } /* Maximized modal mode */ .widget-backdrop { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.55); backdrop-filter: blur(2px); animation: widgetFadeIn 0.2s ease-out; z-index: 1; } .widget-panel-maximized { position: fixed; top: 50%; left: 50%; right: auto; bottom: auto; transform: translate(-50%, -50%); width: min(960px, 92vw); height: min(720px, 88vh); max-width: 92vw; max-height: 88vh; border-radius: 20px; box-shadow: 0 24px 64px rgba(0,0,0,0.25); z-index: 2; animation: widgetFadeIn 0.2s ease-out; } .widget-header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: ${t.colors.primary}; color: #fff; } .widget-header img { width: 32px; height: 32px; border-radius: 8px; } .widget-header-text { flex: 1; min-width: 0; } .widget-header-name { font-size: 14px; font-weight: 600; } .widget-header-sub { font-size: 11px; opacity: 0.85; } .widget-header-branch { display: inline-flex; align-items: center; gap: 3px; font-weight: 500; } .widget-header-btn { background: none; border: none; color: #fff; cursor: pointer; padding: 6px; opacity: 0.8; display: flex; align-items: center; justify-content: center; border-radius: 6px; margin-left: 2px; transition: background 0.15s, opacity 0.15s; } .widget-header-btn:hover { opacity: 1; background: rgba(255,255,255,0.15); } .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; display: inline-flex; align-items: center; justify-content: center; gap: 6px; } .widget-tab.active { color: ${t.colors.primary}; border-bottom-color: ${t.colors.primary}; font-weight: 600; } .widget-body { flex: 1; overflow-y: auto; padding: 16px; } .widget-panel-maximized .widget-body { padding: 24px 32px; } .widget-panel-maximized .widget-tabs { padding: 0 16px; } .widget-panel-maximized .widget-tab { padding: 14px 0; font-size: 13px; } .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: ${t.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-section-title { font-size: 13px; font-weight: 600; color: #1f2937; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; } .widget-section-sub { font-size: 12px; color: #6b7280; margin-bottom: 16px; } .widget-error { color: #dc2626; font-size: 12px; margin-bottom: 8px; padding: 8px 10px; background: #fef2f2; border-radius: 6px; border: 1px solid #fecaca; } .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: ${t.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-btn-with-icon { display: inline-flex; align-items: center; justify-content: center; gap: 6px; } .widget-btn-row { display: flex; gap: 8px; margin-top: 12px; } .widget-btn-row > .widget-btn { flex: 1; } /* Row buttons — department list, doctor list, etc. */ .widget-row-btn { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 6px; border: 1px solid #e5e7eb; border-radius: 10px; background: #fff; cursor: pointer; text-align: left; color: #1f2937; transition: all 0.15s; font-family: inherit; } .widget-row-btn:hover { border-color: ${t.colors.primary}; background: ${t.colors.primaryLight}; } .widget-row-btn.widget-row-btn-stack { align-items: flex-start; } .widget-row-icon { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 8px; background: ${t.colors.primaryLight}; color: ${t.colors.primary}; flex-shrink: 0; } .widget-row-main { flex: 1; min-width: 0; } .widget-row-label { font-size: 13px; font-weight: 600; color: #1f2937; } .widget-row-sub { font-size: 11px; color: #6b7280; margin-top: 2px; } .widget-row-chevron { display: inline-flex; color: #9ca3af; flex-shrink: 0; } .widget-row-btn:hover .widget-row-chevron { color: ${t.colors.primary}; } .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: ${t.colors.primary}; } .widget-slot.selected { background: ${t.colors.primary}; color: #fff; border-color: ${t.colors.primary}; } .widget-slot.unavailable { opacity: 0.4; cursor: not-allowed; text-decoration: line-through; } .widget-success { text-align: center; padding: 32px 16px; display: flex; flex-direction: column; align-items: center; } .widget-success-icon { display: flex; align-items: center; justify-content: center; width: 80px; height: 80px; border-radius: 50%; background: #ecfdf5; margin-bottom: 16px; } .widget-success-title { font-size: 16px; font-weight: 600; color: #059669; margin-bottom: 8px; } .widget-success-text { font-size: 13px; color: #6b7280; line-height: 1.6; } /* Chat empty state */ .chat-empty { text-align: center; padding: 32px 8px 16px; } .chat-intro { padding: 24px 4px 8px; display: flex; flex-direction: column; } .chat-intro .chat-empty-icon { align-self: center; } .chat-intro .chat-empty-title { text-align: center; font-size: 15px; font-weight: 600; color: #1f2937; margin-bottom: 6px; } .chat-intro .chat-empty-text { text-align: center; font-size: 12px; color: #6b7280; margin-bottom: 20px; line-height: 1.5; } .chat-empty-icon { display: flex; align-items: center; justify-content: center; margin-bottom: 12px; } .chat-empty-title { font-size: 15px; font-weight: 600; color: #1f2937; margin-bottom: 6px; } .chat-empty-text { font-size: 12px; color: #6b7280; margin-bottom: 18px; line-height: 1.5; } .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-msg.assistant { justify-content: flex-start; } .chat-msg-stack { display: flex; flex-direction: column; gap: 6px; max-width: 85%; } .chat-msg.user .chat-msg-stack { align-items: flex-end; } .chat-msg.assistant .chat-msg-stack { align-items: flex-start; } .chat-bubble { padding: 10px 14px; border-radius: 12px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; } .chat-msg.user .chat-bubble { background: ${t.colors.primary}; color: #fff; border-bottom-right-radius: 4px; } .chat-msg.assistant .chat-bubble { background: #f3f4f6; color: #1f2937; border-bottom-left-radius: 4px; } /* Typing indicator (animated dots) */ .chat-typing-dots { display: inline-flex; gap: 4px; align-items: center; padding: 2px 0; } .chat-typing-dots > span { width: 6px; height: 6px; border-radius: 50%; background: #9ca3af; display: inline-block; animation: chatDot 1.4s ease-in-out infinite both; } .chat-typing-dots > span:nth-child(2) { animation-delay: 0.16s; } .chat-typing-dots > span:nth-child(3) { animation-delay: 0.32s; } @keyframes chatDot { 0%, 80%, 100% { transform: translateY(0); opacity: 0.35; } 40% { transform: translateY(-4px); opacity: 1; } } /* Generic chat widget (tool UI) container */ .chat-widget { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 12px; font-size: 12px; color: #1f2937; width: 100%; max-width: 300px; } .chat-widget-title { font-size: 12px; font-weight: 600; color: #374151; display: flex; align-items: center; gap: 6px; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.03em; } .chat-widget-loading { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; background: #f3f4f6; border-radius: 10px; font-size: 12px; color: #6b7280; } .chat-widget-loading-label { font-style: italic; } .chat-widget-empty { font-size: 12px; color: #6b7280; font-style: italic; } .chat-widget-error { font-size: 12px; color: #dc2626; padding: 8px 12px; background: #fef2f2; border-radius: 8px; border: 1px solid #fecaca; } /* Branch picker cards */ .chat-widget-branches .chat-widget-branch-card { width: 100%; display: block; text-align: left; padding: 10px 12px; margin-bottom: 6px; background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; cursor: pointer; font-family: inherit; transition: all 0.15s; } .chat-widget-branches .chat-widget-branch-card:last-child { margin-bottom: 0; } .chat-widget-branches .chat-widget-branch-card:hover { border-color: ${t.colors.primary}; background: ${t.colors.primaryLight}; } .chat-widget-branch-name { font-size: 13px; font-weight: 600; color: #1f2937; margin-bottom: 2px; } .chat-widget-branch-meta { font-size: 11px; color: #6b7280; } /* Department chip grid */ .chat-widget-dept-grid { display: flex; flex-wrap: wrap; gap: 6px; } .chat-widget-dept-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; border: 1px solid ${t.colors.primary}; background: ${t.colors.primaryLight}; color: ${t.colors.primary}; font-size: 11px; font-weight: 500; cursor: pointer; font-family: inherit; transition: all 0.15s; } .chat-widget-dept-chip:hover { background: ${t.colors.primary}; color: #fff; } /* Doctor cards */ .chat-widget-doctor-card { padding: 10px; background: #f9fafb; border-radius: 8px; border: 1px solid #f3f4f6; margin-bottom: 6px; } .chat-widget-doctor-card:last-child { margin-bottom: 0; } .chat-widget-doctor-name { font-size: 13px; font-weight: 600; color: #1f2937; margin-bottom: 2px; } .chat-widget-doctor-meta { font-size: 11px; color: #6b7280; line-height: 1.4; } .chat-widget-doctor-action { margin-top: 8px; width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 10px; font-size: 11px; font-weight: 600; color: ${t.colors.primary}; background: #fff; border: 1px solid ${t.colors.primary}; border-radius: 6px; cursor: pointer; font-family: inherit; transition: all 0.15s; } .chat-widget-doctor-action:hover { background: ${t.colors.primary}; color: #fff; } /* Clinic timings widget */ .chat-widget-timings .chat-widget-timing-dept { margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid #f3f4f6; } .chat-widget-timings .chat-widget-timing-dept:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; } .chat-widget-timing-dept-name { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: ${t.colors.primary}; margin-bottom: 4px; } .chat-widget-timing-row { padding: 4px 0 4px 22px; } .chat-widget-timing-doctor { font-size: 12px; font-weight: 500; color: #1f2937; } .chat-widget-timing-hours { font-size: 11px; color: #4b5563; line-height: 1.4; } .chat-widget-timing-clinic { font-size: 11px; color: #9ca3af; font-style: italic; } /* Slots grid widget */ .chat-widget-slots-doctor { font-size: 13px; font-weight: 600; color: #1f2937; } .chat-widget-slots-meta { font-size: 11px; color: #6b7280; margin-bottom: 8px; } .chat-widget-slots-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; } .chat-widget-slot-btn { padding: 8px 6px; font-size: 12px; font-weight: 500; color: ${t.colors.primary}; background: ${t.colors.primaryLight}; border: 1px solid ${t.colors.primary}; border-radius: 6px; cursor: pointer; font-family: inherit; transition: all 0.15s; } .chat-widget-slot-btn:hover { background: ${t.colors.primary}; color: #fff; } .chat-widget-slot-btn.unavailable { color: #9ca3af; background: #f3f4f6; border-color: #e5e7eb; cursor: not-allowed; text-decoration: line-through; } /* Booking suggestion card */ .chat-widget-booking { display: flex; gap: 12px; align-items: flex-start; background: ${t.colors.primaryLight}; border-color: ${t.colors.primary}; } .chat-widget-booking-icon { flex-shrink: 0; width: 40px; height: 40px; border-radius: 10px; background: #fff; display: flex; align-items: center; justify-content: center; color: ${t.colors.primary}; } .chat-widget-booking-body { flex: 1; min-width: 0; } .chat-widget-booking-title { font-size: 13px; font-weight: 600; color: #1f2937; margin-bottom: 2px; } .chat-widget-booking-reason { font-size: 12px; color: #4b5563; line-height: 1.5; margin-bottom: 6px; } .chat-widget-booking-dept { font-size: 11px; color: ${t.colors.primary}; font-weight: 500; margin-bottom: 8px; } .chat-widget-booking .widget-btn { padding: 8px 14px; font-size: 12px; } .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: ${t.colors.primary}; color: #fff; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; } .chat-send:hover { opacity: 0.9; } .chat-send:disabled { opacity: 0.5; cursor: not-allowed; } .quick-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 12px; } .quick-action { padding: 6px 12px; border-radius: 16px; font-size: 11px; border: 1px solid ${t.colors.primary}; color: ${t.colors.primary}; background: ${t.colors.primaryLight}; cursor: pointer; transition: all 0.15s; font-family: inherit; } .quick-action:hover { background: ${t.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: ${t.colors.primary}; } .widget-step.done { background: #059669; } /* Captcha gate — full-panel verification screen */ .widget-captcha-gate { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 24px; text-align: center; background: #fafafa; } .widget-captcha-gate-icon { display: flex; align-items: center; justify-content: center; width: 96px; height: 96px; border-radius: 50%; background: ${t.colors.primaryLight}; margin-bottom: 20px; } .widget-captcha-gate-title { font-size: 17px; font-weight: 600; color: #1f2937; margin-bottom: 8px; } .widget-captcha-gate-text { font-size: 13px; color: #6b7280; margin-bottom: 24px; line-height: 1.5; max-width: 280px; } .widget-captcha { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; } /* Placeholder reserves space for the Turnstile widget which is portaled to document.body (light DOM) and visually positioned over this element. */ .widget-captcha-mount { width: 300px; height: 65px; display: block; } .widget-captcha-status { font-size: 11px; color: #6b7280; text-align: center; } .widget-captcha-error { color: #dc2626; } `,Ie={"message-dots":'',calendar:'',phone:'',"paper-plane-top":'',xmark:'',"circle-check":'',sparkles:'',"hands-praying":'',"hand-wave":'',"shield-check":'',"arrow-left":'',"arrow-right":'',"up-right-and-down-left-from-center":'',"down-left-and-up-right-to-center":'',hospital:'',"location-dot":'',stethoscope:'',"heart-pulse":'',bone:'',"person-pregnant":'',ear:'',baby:'',brain:'',eye:'',tooth:''},Pe=(t,e=16,n="currentColor")=>Ie[t].replace("{const e=t.toLowerCase().replace(/_/g," ");return e.includes("cardio")||e.includes("heart")?"heart-pulse":e.includes("ortho")||e.includes("bone")||e.includes("spine")?"bone":e.includes("gyn")||e.includes("obstet")||e.includes("maternity")||e.includes("pregnan")?"person-pregnant":e.includes("ent")||e.includes("otolaryn")||e.includes("ear")||e.includes("nose")||e.includes("throat")?"ear":e.includes("pediatric")||e.includes("paediatric")||e.includes("child")||e.includes("neonat")?"baby":e.includes("neuro")||e.includes("psych")||e.includes("mental")?"brain":e.includes("ophthal")||e.includes("eye")||e.includes("vision")||e.includes("retina")?"eye":e.includes("dental")||e.includes("dent")||e.includes("tooth")?"tooth":"stethoscope"},y=({name:t,size:e=16,color:n="currentColor",class:o})=>{const l=Pe(t,e,n);return i("span",{class:o,dangerouslySetInnerHTML:{__html:l}})};async function*Ne(t){const e=t.getReader(),n=new TextDecoder;let o="";try{for(;;){const{done:l,value:r}=await e.read();if(l)break;o+=n.decode(r,{stream:!0});let s;for(;(s=o.indexOf(` `))!==-1;){const p=o.slice(0,s);o=o.slice(s+2);const u=p.split(` `);for(const c of u){if(!c.startsWith("data:"))continue;const d=c.slice(5).trimStart();if(!(!d||d==="[DONE]"))try{yield JSON.parse(d)}catch{}}}}}finally{e.releaseLock()}}const De=({part:t,onDepartmentClick:e,onShowDoctorSlots:n,onSuggestBooking:o,onPickSlot:l,onPickBranch:r})=>{var s,p,u,c;if(t.state==="input-streaming"||t.state==="input-available")return i(Ee,{toolName:t.toolName});if(t.state==="output-error")return i("div",{class:"chat-widget-error",children:["Couldn't load: ",t.errorText??"unknown error"]});switch(t.toolName){case"pick_branch":{const d=t.output;return(s=d==null?void 0:d.branches)!=null&&s.length?i(We,{branches:d.branches,onPick:r}):null}case"list_departments":{const d=t.output;return(p=d==null?void 0:d.departments)!=null&&p.length?i(Ae,{departments:d.departments,onPick:e}):null}case"show_clinic_timings":{const d=t.output;return(u=d==null?void 0:d.departments)!=null&&u.length?i(Fe,{departments:d.departments}):null}case"show_doctors":{const d=t.output;return(c=d==null?void 0:d.doctors)!=null&&c.length?i(je,{department:d.department,doctors:d.doctors,onPickDoctor:n}):i("div",{class:"chat-widget-empty",children:["No doctors found in ",(d==null?void 0:d.department)??"this department","."]})}case"show_doctor_slots":{const d=t.output;return d?d.error||!d.doctor?i("div",{class:"chat-widget-empty",children:d.error??"Doctor not found."}):i(Oe,{data:d,onPickSlot:l}):null}case"suggest_booking":{const d=t.output;return i(Re,{reason:(d==null?void 0:d.reason)??"Book an appointment.",department:(d==null?void 0:d.department)??null,onBook:o})}default:return null}},He={pick_branch:"Fetching branches…",list_departments:"Looking up departments…",show_clinic_timings:"Fetching clinic hours…",show_doctors:"Looking up doctors…",show_doctor_slots:"Checking availability…",suggest_booking:"Thinking about booking options…"},Ee=({toolName:t})=>i("div",{class:"chat-widget-loading",children:[i("span",{class:"chat-typing-dots","aria-hidden":"true",children:[i("span",{}),i("span",{}),i("span",{})]}),i("span",{class:"chat-widget-loading-label",children:He[t]??"Working…"})]}),We=({branches:t,onPick:e})=>i("div",{class:"chat-widget chat-widget-branches",children:[i("div",{class:"chat-widget-title",children:"Which branch?"}),t.map(n=>i("button",{class:"chat-widget-branch-card",onClick:()=>e(n.name),children:[i("div",{class:"chat-widget-branch-name",children:n.name}),i("div",{class:"chat-widget-branch-meta",children:[n.doctorCount," ",n.doctorCount===1?"doctor":"doctors",n.departmentCount>0?` • ${n.departmentCount} ${n.departmentCount===1?"department":"departments"}`:""]})]},n.name))]}),Ae=({departments:t,onPick:e})=>i("div",{class:"chat-widget chat-widget-departments",children:[i("div",{class:"chat-widget-title",children:"Departments"}),i("div",{class:"chat-widget-dept-grid",children:t.map(n=>i("button",{class:"chat-widget-dept-chip",onClick:()=>e(n),title:`Show doctors in ${n}`,children:[i(y,{name:X(n),size:16}),i("span",{children:n})]},n))})]}),Fe=({departments:t})=>i("div",{class:"chat-widget chat-widget-timings",children:[i("div",{class:"chat-widget-title",children:[i(y,{name:"calendar",size:14})," Clinic hours"]}),t.map(e=>i("div",{class:"chat-widget-timing-dept",children:[i("div",{class:"chat-widget-timing-dept-name",children:[i(y,{name:X(e.name),size:14}),i("span",{children:e.name})]}),e.entries.map(n=>i("div",{class:"chat-widget-timing-row",children:[i("div",{class:"chat-widget-timing-doctor",children:n.name}),i("div",{class:"chat-widget-timing-hours",children:n.hours}),n.clinic&&i("div",{class:"chat-widget-timing-clinic",children:n.clinic})]},`${e.name}-${n.name}`))]},e.name))]}),je=({department:t,doctors:e,onPickDoctor:n})=>i("div",{class:"chat-widget chat-widget-doctors",children:[i("div",{class:"chat-widget-title",children:[i(y,{name:X(t),size:14})," ",t]}),e.map(o=>i("div",{class:"chat-widget-doctor-card",children:[i("div",{class:"chat-widget-doctor-name",children:o.name}),o.specialty&&i("div",{class:"chat-widget-doctor-meta",children:o.specialty}),o.visitingHours&&i("div",{class:"chat-widget-doctor-meta",children:o.visitingHours}),o.clinic&&i("div",{class:"chat-widget-doctor-meta",children:o.clinic}),i("button",{class:"chat-widget-doctor-action",onClick:()=>n(o.name),children:[i(y,{name:"calendar",size:12})," See available appointments"]})]},o.id))]}),Oe=({data:t,onPickSlot:e})=>{if(!t.doctor)return null;const n=t.doctor,l=t.slots.filter(r=>r.available).length>0;return i("div",{class:"chat-widget chat-widget-slots",children:[i("div",{class:"chat-widget-title",children:[i(y,{name:"calendar",size:14})," Available slots"]}),i("div",{class:"chat-widget-slots-doctor",children:n.name}),i("div",{class:"chat-widget-slots-meta",children:[Ue(t.date),n.clinic?` • ${n.clinic}`:""]}),l?i("div",{class:"chat-widget-slots-grid",children:t.slots.map(r=>i("button",{class:`chat-widget-slot-btn ${r.available?"":"unavailable"}`,disabled:!r.available,onClick:()=>r.available&&e({doctorId:n.id,date:t.date,time:r.time}),children:r.time},r.time))}):i("div",{class:"chat-widget-empty",children:"No slots available on this date."})]})},Ue=t=>{const e=new Date(t+"T00:00:00");return isNaN(e.getTime())?t:e.toLocaleDateString(void 0,{weekday:"short",day:"numeric",month:"short"})},Re=({reason:t,department:e,onBook:n})=>i("div",{class:"chat-widget chat-widget-booking",children:[i("div",{class:"chat-widget-booking-icon",children:i(y,{name:"calendar",size:28})}),i("div",{class:"chat-widget-booking-body",children:[i("div",{class:"chat-widget-booking-title",children:"Book an appointment"}),i("div",{class:"chat-widget-booking-reason",children:t}),e&&i("div",{class:"chat-widget-booking-dept",children:["Suggested: ",e]}),i("button",{class:"widget-btn",onClick:n,children:"Book now"})]})]}),te=ge(null),qe=({children:t})=>{const[e,n]=v({name:"",phone:""}),[o,l]=v(null),[r,s]=v(""),[p,u]=v(null),[c,d]=v([]),[a,g]=v(!1),[h,m]=v(""),[k,w]=v(null),x=ze(z=>{n(N=>({...N,...z}))},[]),_=Q(()=>{var N,D;const z=new Set;for(const b of c){const T=(D=(N=b.clinic)==null?void 0:N.clinicName)==null?void 0:D.trim();T&&z.add(T)}return Array.from(z).sort()},[c]);W(()=>{k||_.length===1&&w(_[0])},[_,k]),W(()=>{let z=!1;return g(!0),m(""),we().then(N=>{z||(d(N),g(!1))}).catch(()=>{z||(m("Failed to load doctors"),g(!1))}),()=>{z=!0}},[]);const I={visitor:e,updateVisitor:x,leadId:o,setLeadId:l,captchaToken:r,setCaptchaToken:s,bookingPrefill:p,setBookingPrefill:u,doctors:c,doctorsLoading:a,doctorsError:h,branches:_,selectedBranch:k,setSelectedBranch:w};return i(te.Provider,{value:I,children:t})},ht=()=>{const t=Se(te);if(!t)throw new Error("useWidgetStore must be used inside a WidgetStoreProvider");return t},Ke=["What departments do you have?","Show me cardiologists","Clinic timings","How do I book?"],Ve=t=>t.parts.filter(e=>e.type==="text").map(e=>e.text).join(""),R=(t,e,n)=>{t(o=>o.map(l=>l.id===e?n(l):l))},Ye=(t,e,n)=>{const o=t[t.length-1];return(o==null?void 0:o.type)==="text"?[...t.slice(0,-1),{type:"text",text:o.text+e,state:n}]:[...t,{type:"text",text:e,state:n}]},ut=(t,e,n,o)=>{const l=t.findIndex(r=>r.type==="tool"&&r.toolCallId===e);if(l>=0){const s={...t[l],...n};return[...t.slice(0,l),s,...t.slice(l+1)]}return[...t,{...o,...n}]},ee=()=>`m_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,Je=({onRequestBooking:t})=>{const{visitor:e,updateVisitor:n,leadId:o,setLeadId:l,setBookingPrefill:r,selectedBranch:s,setSelectedBranch:p}=ht(),[u,c]=v([]),[d,a]=v(""),[g,h]=v(!1),[m,k]=v(!1),[w,x]=v(""),_=V(null);W(()=>{_.current&&(_.current.scrollTop=_.current.scrollHeight)},[u]);const I=async()=>{const b=e.name.trim(),T=e.phone.trim();if(!(!b||!T)){k(!0),x("");try{const{leadId:P}=await ye(b,T);l(P)}catch{x("Could not start chat. Please try again.")}finally{k(!1)}}},z=async(b,T)=>{if(!b.trim()||g||!o)return;const P={id:ee(),role:"user",parts:[{type:"text",text:b.trim(),state:"done"}]},B=ee(),gt={id:B,role:"assistant",parts:[]},ft=[...u,P].map(E=>({role:E.role,content:Ve(E)}));c(E=>[...E,P,gt]),a(""),h(!0);const Z=T!==void 0?T:s;try{const E=await ke(o,ft,Z);for await(const $ of Ne(E))switch($.type){case"text-delta":typeof $.delta=="string"&&R(c,B,S=>({...S,parts:Ye(S.parts,$.delta,"streaming")}));break;case"text-end":R(c,B,S=>({...S,parts:S.parts.map(Y=>Y.type==="text"?{...Y,state:"done"}:Y)}));break;case"tool-input-start":R(c,B,S=>({...S,parts:ut(S.parts,$.toolCallId,{state:"input-streaming",toolName:$.toolName},{type:"tool",toolCallId:$.toolCallId,toolName:$.toolName,state:"input-streaming"})}));break;case"tool-input-available":R(c,B,S=>({...S,parts:ut(S.parts,$.toolCallId,{state:"input-available",toolName:$.toolName,input:$.input},{type:"tool",toolCallId:$.toolCallId,toolName:$.toolName,state:"input-available",input:$.input})}));break;case"tool-output-available":R(c,B,S=>({...S,parts:ut(S.parts,$.toolCallId,{state:"output-available",output:$.output},{type:"tool",toolCallId:$.toolCallId,toolName:"unknown",state:"output-available",output:$.output})}));break;case"tool-output-error":R(c,B,S=>({...S,parts:ut(S.parts,$.toolCallId,{state:"output-error",errorText:$.errorText},{type:"tool",toolCallId:$.toolCallId,toolName:"unknown",state:"output-error",errorText:$.errorText})}));break;case"error":R(c,B,S=>({...S,parts:[...S.parts,{type:"text",text:"Sorry, I encountered an error. Please try again.",state:"done"}]}));break;default:break}}catch{R(c,B,E=>({...E,parts:[...E.parts,{type:"text",text:"Sorry, I encountered an error. Please try again.",state:"done"}]}))}finally{h(!1)}},N=b=>{r(b),t(b)},D=b=>{p(b),z(`I'm interested in the ${b} branch.`,b)};return o?i("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[i("div",{class:"chat-messages",ref:_,children:[u.length===0&&i("div",{class:"chat-empty",children:[i("div",{class:"chat-empty-icon",children:i(y,{name:"hand-wave",size:40,color:"#f59e0b"})}),i("div",{class:"chat-empty-title",children:["Hi ",e.name.split(" ")[0]||"there",", how can we help?"]}),i("div",{class:"chat-empty-text",children:"Ask about doctors, clinics, packages, or book an appointment."}),i("div",{class:"quick-actions",children:Ke.map(b=>i("button",{class:"quick-action",onClick:()=>z(b),children:b},b))})]}),u.map(b=>i(Ge,{msg:b,onDepartmentClick:T=>z(`Show me doctors in ${T}`),onShowDoctorSlots:T=>z(`Show available appointments for ${T}`),onSuggestBooking:()=>t(),onPickSlot:N,onPickBranch:D},b.id))]}),i("div",{class:"chat-input-row",children:[i("input",{class:"widget-input chat-input",placeholder:"Type a message...",value:d,onInput:b=>a(b.target.value),onKeyDown:b=>b.key==="Enter"&&z(d),disabled:g}),i("button",{class:"chat-send",onClick:()=>z(d),disabled:g||!d.trim(),"aria-label":"Send message",children:i(y,{name:"paper-plane-top",size:16,color:"#fff"})})]})]}):i("div",{class:"chat-intro",children:[i("div",{class:"chat-empty-icon",children:i(y,{name:"hand-wave",size:40,color:"#f59e0b"})}),i("div",{class:"chat-empty-title",children:"Hi! How can we help?"}),i("div",{class:"chat-empty-text",children:"Share your name and phone so we can follow up if needed."}),w&&i("div",{class:"widget-error",children:w}),i("div",{class:"widget-field",children:[i("label",{class:"widget-label",children:"Full Name *"}),i("input",{class:"widget-input",placeholder:"Your name",value:e.name,onInput:b=>n({name:b.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:e.phone,onInput:b=>n({phone:b.target.value}),onKeyDown:b=>b.key==="Enter"&&I()})]}),i("button",{class:"widget-btn",onClick:I,disabled:!e.name.trim()||!e.phone.trim()||m,children:m?"Starting…":"Start Chat"})]})},Ge=({msg:t,onDepartmentClick:e,onShowDoctorSlots:n,onSuggestBooking:o,onPickSlot:l,onPickBranch:r})=>{const s=t.role==="assistant"&&t.parts.length===0,u=t.parts.some(c=>c.type==="tool")?t.parts.filter(c=>c.type==="tool"):t.parts;return i("div",{class:`chat-msg ${t.role}`,children:i("div",{class:"chat-msg-stack",children:[s&&i("div",{class:"chat-bubble",children:i(ie,{})}),u.map((c,d)=>c.type==="text"?i("div",{class:"chat-bubble",children:c.text||i(ie,{})},d):i(De,{part:c,onDepartmentClick:e,onShowDoctorSlots:n,onSuggestBooking:o,onPickSlot:l,onPickBranch:r},d))]})})},ie=()=>i("span",{class:"chat-typing-dots","aria-label":"Assistant is typing",children:[i("span",{}),i("span",{}),i("span",{})]}),Qe=()=>{const{visitor:t,updateVisitor:e,captchaToken:n,bookingPrefill:o,setBookingPrefill:l,doctors:r,doctorsLoading:s,doctorsError:p,branches:u,selectedBranch:c,setSelectedBranch:d}=ht(),a=u.length>1&&!c,[g,h]=v(a?"branch":"department"),[m,k]=v(""),[w,x]=v(null),[_,I]=v(""),[z,N]=v([]),[D,b]=v(""),[T,P]=v(""),[B,gt]=v(!1),[ft,Z]=v(""),[E,$]=v(""),S=Q(()=>{if(!c)return r;const f=c.toLowerCase();return r.filter(H=>{var mt;return String(((mt=H.clinic)==null?void 0:mt.clinicName)??"").toLowerCase().includes(f)})},[r,c]),Y=Q(()=>[...new Set(S.map(f=>f.department).filter(Boolean))],[S]),ei=m?S.filter(f=>f.department===m):[];W(()=>{p&&Z(p)},[p]),W(()=>{var H;if(!o||r.length===0)return;const f=r.find(mt=>mt.id===o.doctorId);f&&((H=f.clinic)!=null&&H.clinicName&&!c&&d(f.clinic.clinicName),k(f.department),x(f),I(o.date),b(o.time),h("details"),l(null))},[o,r]);const ii=f=>{x(f),I(new Date().toISOString().split("T")[0]),h("datetime")};W(()=>{w&&_&&be(w.id,_).then(N).catch(()=>{})},[w,_]);const ni=async()=>{if(!(!w||!D||!t.name.trim()||!t.phone.trim())){gt(!0),Z("");try{const f=`${_}T${D}:00`,H=await xe({departmentId:m,doctorId:w.id,scheduledAt:f,patientName:t.name.trim(),patientPhone:t.phone.trim(),chiefComplaint:T,captchaToken:n});$(H.reference),h("success")}catch{Z("Booking failed. Please try again.")}finally{gt(!1)}}},oe=a?["branch","department","doctor","datetime","details"]:["department","doctor","datetime","details"],re=oe.indexOf(g);return i("div",{children:[g!=="success"&&i("div",{class:"widget-steps",children:oe.map((f,H)=>i("div",{class:`widget-step ${Hi("button",{class:"widget-row-btn",onClick:()=>{d(f),h("department")},children:[i(y,{class:"widget-row-icon",name:"hospital",size:20}),i("span",{class:"widget-row-label",children:f}),i(y,{class:"widget-row-chevron",name:"arrow-right",size:14})]},f))]}),g==="department"&&i("div",{children:[i("div",{class:"widget-section-title",children:[c&&i(O,{children:[i(y,{class:"widget-row-icon",name:"hospital",size:16}),c," — "]}),"Select Department"]}),s&&Y.length===0&&i("div",{class:"widget-section-sub",children:"Loading…"}),Y.map(f=>i("button",{class:"widget-row-btn",onClick:()=>{k(f),h("doctor")},children:[i(y,{class:"widget-row-icon",name:X(f),size:20}),i("span",{class:"widget-row-label",children:f.replace(/_/g," ")}),i(y,{class:"widget-row-chevron",name:"arrow-right",size:14})]},f)),u.length>1&&i("button",{class:"widget-btn widget-btn-secondary widget-btn-with-icon",style:{marginTop:"8px"},onClick:()=>h("branch"),children:[i(y,{name:"arrow-left",size:14}),"Change branch"]})]}),g==="doctor"&&i("div",{children:[i("div",{class:"widget-section-title",children:[i(y,{class:"widget-row-icon",name:X(m),size:16}),m.replace(/_/g," ")]}),ei.map(f=>{var H;return i("button",{class:"widget-row-btn widget-row-btn-stack",onClick:()=>ii(f),children:[i("div",{class:"widget-row-main",children:[i("div",{class:"widget-row-label",children:f.name}),i("div",{class:"widget-row-sub",children:[f.visitingHours??""," ",(H=f.clinic)!=null&&H.clinicName?`• ${f.clinic.clinicName}`:""]})]}),i(y,{class:"widget-row-chevron",name:"arrow-right",size:14})]},f.id)}),i("button",{class:"widget-btn widget-btn-secondary widget-btn-with-icon",style:{marginTop:"8px"},onClick:()=>h("department"),children:[i(y,{name:"arrow-left",size:14}),"Back"]})]}),g==="datetime"&&i("div",{children:[i("div",{class:"widget-section-title",children:[w==null?void 0:w.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:_,min:new Date().toISOString().split("T")[0],onInput:f=>{I(f.target.value),b("")}})]}),z.length>0&&i("div",{children:[i("label",{class:"widget-label",children:"Available Slots"}),i("div",{class:"widget-slots",children:z.map(f=>i("button",{class:`widget-slot ${f.time===D?"selected":""} ${f.available?"":"unavailable"}`,onClick:()=>f.available&&b(f.time),disabled:!f.available,children:f.time},f.time))})]}),i("div",{class:"widget-btn-row",children:[i("button",{class:"widget-btn widget-btn-secondary widget-btn-with-icon",onClick:()=>h("doctor"),children:[i(y,{name:"arrow-left",size:14}),"Back"]}),i("button",{class:"widget-btn widget-btn-with-icon",disabled:!D,onClick:()=>h("details"),children:["Next",i(y,{name:"arrow-right",size:14,color:"#fff"})]})]})]}),g==="details"&&i("div",{children:[i("div",{class:"widget-section-title",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:t.name,onInput:f=>e({name: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:t.phone,onInput:f=>e({phone: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:T,onInput:f=>P(f.target.value)})]}),i("div",{class:"widget-btn-row",children:[i("button",{class:"widget-btn widget-btn-secondary widget-btn-with-icon",onClick:()=>h("datetime"),children:[i(y,{name:"arrow-left",size:14}),"Back"]}),i("button",{class:"widget-btn",disabled:!t.name.trim()||!t.phone.trim()||B,onClick:ni,children:B?"Booking...":"Book Appointment"})]})]}),g==="success"&&i("div",{class:"widget-success",children:[i("div",{class:"widget-success-icon",children:i(y,{name:"circle-check",size:56,color:"#059669"})}),i("div",{class:"widget-success-title",children:"Appointment Booked!"}),i("div",{class:"widget-success-text",children:["Reference: ",i("strong",{children:E}),i("br",{}),w==null?void 0:w.name," • ",_," at ",D,i("br",{}),i("br",{}),"We'll send a confirmation SMS to your phone."]})]})]})},Xe=()=>{const{visitor:t,updateVisitor:e,captchaToken:n}=ht(),[o,l]=v(""),[r,s]=v(""),[p,u]=v(!1),[c,d]=v(!1),[a,g]=v(""),h=async()=>{if(!(!t.name.trim()||!t.phone.trim())){u(!0),g("");try{await ve({name:t.name.trim(),phone:t.phone.trim(),interest:o.trim()||void 0,message:r.trim()||void 0,captchaToken:n}),d(!0)}catch{g("Submission failed. Please try again.")}finally{u(!1)}}};return c?i("div",{class:"widget-success",children:[i("div",{class:"widget-success-icon",children:i(y,{name:"hands-praying",size:56,color:"#059669"})}),i("div",{class:"widget-success-title",children:"Thank you!"}),i("div",{class:"widget-success-text",children:["An agent will call you shortly on ",t.phone,".",i("br",{}),"We typically respond within 30 minutes during business hours."]})]}):i("div",{children:[i("div",{class:"widget-section-title",children:"Get in touch"}),i("div",{class:"widget-section-sub",children:"Leave your details and we'll call you back."}),a&&i("div",{class:"widget-error",children:a}),i("div",{class:"widget-field",children:[i("label",{class:"widget-label",children:"Full Name *"}),i("input",{class:"widget-input",placeholder:"Your name",value:t.name,onInput:m=>e({name:m.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:t.phone,onInput:m=>e({phone:m.target.value})})]}),i("div",{class:"widget-field",children:[i("label",{class:"widget-label",children:"Interested In"}),i("select",{class:"widget-select",value:o,onChange:m=>l(m.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:r,onInput:m=>s(m.target.value)})]}),i("button",{class:"widget-btn",disabled:!t.name.trim()||!t.phone.trim()||p,onClick:h,children:p?"Sending...":"Send Message"})]})},Ze=({config:t,shadow:e})=>(W(()=>{const n=document.createElement("style");return n.textContent=Be(t),e.appendChild(n),()=>{e.removeChild(n)}},[t,e]),i(qe,{children:i(ti,{config:t,shadow:e})})),ti=({config:t,shadow:e})=>{const[n,o]=v(!1),[l,r]=v("chat"),[s,p]=v(!1),{captchaToken:u,setCaptchaToken:c,selectedBranch:d}=ht();W(()=>{if(!s)return;const h=e.host,m=h.getAttribute("style");h.style.cssText="position:fixed;inset:0;z-index:999999;";const k=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{m!==null?h.setAttribute("style",m):h.removeAttribute("style"),document.body.style.overflow=k}},[s,e]),W(()=>{if(!s)return;const h=m=>{m.key==="Escape"&&p(!1)};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[s]);const a=!!t.captchaSiteKey&&!u,g=()=>{p(!1),o(!1)};return i("div",{children:[!n&&i("button",{class:"widget-bubble",onClick:()=>o(!0),"aria-label":"Open chat",children:t.brand.logo?i("img",{src:t.brand.logo,alt:t.brand.name}):i(y,{name:"message-dots",size:26,color:t.colors.primary})}),n&&i(O,{children:[s&&i("div",{class:"widget-backdrop",onClick:()=>p(!1)}),i("div",{class:`widget-panel ${s?"widget-panel-maximized":""}`,children:[i("div",{class:"widget-header",children:[t.brand.logo&&i("img",{src:t.brand.logo,alt:""}),i("div",{class:"widget-header-text",children:[i("div",{class:"widget-header-name",children:t.brand.name}),i("div",{class:"widget-header-sub",children:["We're here to help",d&&i(O,{children:[" • ",i("span",{class:"widget-header-branch",children:[i(y,{name:"location-dot",size:10,color:"#fff"}),d]})]})]})]}),i("button",{class:"widget-header-btn",onClick:()=>p(h=>!h),"aria-label":s?"Restore":"Maximize",title:s?"Restore":"Maximize",children:i(y,{name:s?"down-left-and-up-right-to-center":"up-right-and-down-left-from-center",size:14,color:"#fff"})}),i("button",{class:"widget-header-btn",onClick:g,"aria-label":"Close",title:"Close",children:i(y,{name:"xmark",size:16,color:"#fff"})})]}),a?i("div",{class:"widget-captcha-gate",children:[i("div",{class:"widget-captcha-gate-icon",children:i(y,{name:"shield-check",size:56,color:t.colors.primary})}),i("div",{class:"widget-captcha-gate-title",children:"Quick security check"}),i("div",{class:"widget-captcha-gate-text",children:"Please verify you're not a bot to continue."}),i(Te,{siteKey:t.captchaSiteKey,onToken:c})]}):i(O,{children:[i("div",{class:"widget-tabs",children:[i("button",{class:`widget-tab ${l==="chat"?"active":""}`,onClick:()=>r("chat"),children:[i(y,{name:"message-dots",size:14})," Chat"]}),i("button",{class:`widget-tab ${l==="book"?"active":""}`,onClick:()=>r("book"),children:[i(y,{name:"calendar",size:14})," Book"]}),i("button",{class:`widget-tab ${l==="contact"?"active":""}`,onClick:()=>r("contact"),children:[i(y,{name:"phone",size:14})," Contact"]})]}),i("div",{class:"widget-body",children:[l==="chat"&&i(Je,{onRequestBooking:()=>r("book")}),l==="book"&&i(Qe,{}),l==="contact"&&i(Xe,{})]})]})]})]})]})},ne=async()=>{const t=document.querySelector("script[data-key]");if(!t){console.error("[HelixWidget] Missing data-key attribute");return}const e=t.getAttribute("data-key")??"",n=t.src.replace(/\/widget\.js.*$/,"");me(n,e);let o;try{o=await _e()}catch(p){console.error("[HelixWidget] Init failed:",p);return}o.captchaSiteKey&&Zt().catch(()=>{console.warn("[HelixWidget] Turnstile preload failed — gate will retry on open")});const l=document.createElement("div");l.id="helix-widget-host",l.style.cssText="position:fixed;bottom:20px;right:20px;z-index:999999;",document.body.appendChild(l);const r=l.attachShadow({mode:"open"}),s=document.createElement("div");r.appendChild(s),ue(i(Ze,{config:o,shadow:r}),s)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",ne):ne()})();