pih-appointment-widget 0.0.24 → 0.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -272,6 +272,13 @@ const AppointmentPage = _ref => {
272
272
  };
273
273
 
274
274
  // Helper function to get date range based on option
275
+ // Format a Date using local calendar values (avoids UTC shift from toISOString)
276
+ const formatLocalDate = date => {
277
+ const y = date.getFullYear();
278
+ const m = String(date.getMonth() + 1).padStart(2, "0");
279
+ const d = String(date.getDate()).padStart(2, "0");
280
+ return `${y}-${m}-${d}`;
281
+ };
275
282
  const getDateRange = option => {
276
283
  const today = new Date();
277
284
  let from, to;
@@ -282,7 +289,7 @@ const AppointmentPage = _ref => {
282
289
  case "tomorrow":
283
290
  const tomorrow = new Date(today);
284
291
  tomorrow.setDate(tomorrow.getDate() + 1);
285
- from = to = tomorrow.toISOString().split('T')[0];
292
+ from = to = formatLocalDate(tomorrow);
286
293
  break;
287
294
  case "currentWeek":
288
295
  const firstDay = new Date(today);
@@ -291,14 +298,14 @@ const AppointmentPage = _ref => {
291
298
  const diff = day === 0 ? -6 : 1 - day; // Monday as first day
292
299
  firstDay.setDate(today.getDate() + diff);
293
300
  lastDay.setDate(firstDay.getDate() + 6);
294
- from = firstDay.toISOString().split('T')[0];
295
- to = lastDay.toISOString().split('T')[0];
301
+ from = formatLocalDate(firstDay);
302
+ to = formatLocalDate(lastDay);
296
303
  break;
297
304
  case "thisMonth":
298
305
  const firstOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
299
306
  const lastOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
300
- from = firstOfMonth.toISOString().split('T')[0];
301
- to = lastOfMonth.toISOString().split('T')[0];
307
+ from = formatLocalDate(firstOfMonth);
308
+ to = formatLocalDate(lastOfMonth);
302
309
  break;
303
310
  case "currentYear":
304
311
  from = `${today.getFullYear()}-01-01`;
@@ -602,6 +609,25 @@ const AppointmentPage = _ref => {
602
609
  fetchAppointments();
603
610
  };
604
611
 
612
+ // End call silently when user presses browser back button during an active call.
613
+ (0, _react.useEffect)(() => {
614
+ if (!showPipVideo) return;
615
+ window.history.pushState({
616
+ pipActive: true
617
+ }, "");
618
+ const handlePopState = () => {
619
+ setShowPipVideo(false);
620
+ setIsPipMinimized(false);
621
+ setIsPipFullscreen(false);
622
+ setCallToken(null);
623
+ setCallUrl(null);
624
+ setCallError(null);
625
+ window.history.back();
626
+ };
627
+ window.addEventListener("popstate", handlePopState);
628
+ return () => window.removeEventListener("popstate", handlePopState);
629
+ }, [showPipVideo]);
630
+
605
631
  // Handle PiP minimize
606
632
  const handleTogglePipSize = () => {
607
633
  if (isPipFullscreen) {
@@ -2172,7 +2198,7 @@ const AppointmentPage = _ref => {
2172
2198
  alignItems: "center",
2173
2199
  flexShrink: 0
2174
2200
  }
2175
- }, !isPipFullscreen && /*#__PURE__*/_react.default.createElement("button", {
2201
+ }, /*#__PURE__*/_react.default.createElement("button", {
2176
2202
  onClick: handleTogglePipSize,
2177
2203
  style: {
2178
2204
  background: "rgba(255, 255, 255, 0.2)",
@@ -2282,23 +2308,25 @@ const AppointmentPage = _ref => {
2282
2308
  onMouseEnter: e => e.target.style.background = "rgba(255, 255, 255, 0.3)",
2283
2309
  onMouseLeave: e => e.target.style.background = "rgba(255, 255, 255, 0.2)",
2284
2310
  title: "Close"
2285
- }, "\xD7"))), !isPipMinimized && /*#__PURE__*/_react.default.createElement("div", {
2311
+ }, "\xD7"))), /*#__PURE__*/_react.default.createElement("div", {
2286
2312
  style: {
2287
2313
  flex: 1,
2288
2314
  background: "#000000",
2289
- position: "relative"
2315
+ position: "relative",
2316
+ display: isPipMinimized ? "none" : "flex",
2317
+ flexDirection: "column"
2290
2318
  }
2291
2319
  }, /*#__PURE__*/_react.default.createElement("iframe", {
2292
2320
  src: (() => {
2293
2321
  if (!callToken) return "";
2294
2322
  const base = String(joinCallUrlBase || "").replace(/\/?$/, "/");
2295
- console.log("${base}token=${callToken}", `${base}token=${callToken}`);
2296
2323
  return `${base}token=${callToken}`;
2297
2324
  })(),
2298
2325
  style: {
2299
2326
  width: "100%",
2300
2327
  height: "100%",
2301
- border: "none"
2328
+ border: "none",
2329
+ flex: 1
2302
2330
  },
2303
2331
  allow: "camera; microphone; display-capture; autoplay",
2304
2332
  allowFullScreen: true,
@@ -474,6 +474,13 @@
474
474
  };
475
475
 
476
476
  // Helper function to get date range based on option
477
+ // Format a Date using local calendar values (avoids UTC shift from toISOString)
478
+ const formatLocalDate = date => {
479
+ const y = date.getFullYear();
480
+ const m = String(date.getMonth() + 1).padStart(2, "0");
481
+ const d = String(date.getDate()).padStart(2, "0");
482
+ return `${y}-${m}-${d}`;
483
+ };
477
484
  const getDateRange = option => {
478
485
  const today = new Date();
479
486
  let from, to;
@@ -484,7 +491,7 @@
484
491
  case "tomorrow":
485
492
  const tomorrow = new Date(today);
486
493
  tomorrow.setDate(tomorrow.getDate() + 1);
487
- from = to = tomorrow.toISOString().split('T')[0];
494
+ from = to = formatLocalDate(tomorrow);
488
495
  break;
489
496
  case "currentWeek":
490
497
  const firstDay = new Date(today);
@@ -493,14 +500,14 @@
493
500
  const diff = day === 0 ? -6 : 1 - day; // Monday as first day
494
501
  firstDay.setDate(today.getDate() + diff);
495
502
  lastDay.setDate(firstDay.getDate() + 6);
496
- from = firstDay.toISOString().split('T')[0];
497
- to = lastDay.toISOString().split('T')[0];
503
+ from = formatLocalDate(firstDay);
504
+ to = formatLocalDate(lastDay);
498
505
  break;
499
506
  case "thisMonth":
500
507
  const firstOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
501
508
  const lastOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
502
- from = firstOfMonth.toISOString().split('T')[0];
503
- to = lastOfMonth.toISOString().split('T')[0];
509
+ from = formatLocalDate(firstOfMonth);
510
+ to = formatLocalDate(lastOfMonth);
504
511
  break;
505
512
  case "currentYear":
506
513
  from = `${today.getFullYear()}-01-01`;
@@ -784,6 +791,25 @@
784
791
  fetchAppointments();
785
792
  };
786
793
 
794
+ // End call silently when user presses browser back button during an active call.
795
+ React.useEffect(() => {
796
+ if (!showPipVideo) return;
797
+ window.history.pushState({
798
+ pipActive: true
799
+ }, "");
800
+ const handlePopState = () => {
801
+ setShowPipVideo(false);
802
+ setIsPipMinimized(false);
803
+ setIsPipFullscreen(false);
804
+ setCallToken(null);
805
+ setCallUrl(null);
806
+ setCallError(null);
807
+ window.history.back();
808
+ };
809
+ window.addEventListener("popstate", handlePopState);
810
+ return () => window.removeEventListener("popstate", handlePopState);
811
+ }, [showPipVideo]);
812
+
787
813
  // Handle PiP minimize
788
814
  const handleTogglePipSize = () => {
789
815
  if (isPipFullscreen) {
@@ -2208,7 +2234,7 @@
2208
2234
  alignItems: "center",
2209
2235
  flexShrink: 0
2210
2236
  }
2211
- }, !isPipFullscreen && /*#__PURE__*/React__default["default"].createElement("button", {
2237
+ }, /*#__PURE__*/React__default["default"].createElement("button", {
2212
2238
  onClick: handleTogglePipSize,
2213
2239
  style: {
2214
2240
  background: "rgba(255, 255, 255, 0.2)",
@@ -2318,23 +2344,25 @@
2318
2344
  onMouseEnter: e => e.target.style.background = "rgba(255, 255, 255, 0.3)",
2319
2345
  onMouseLeave: e => e.target.style.background = "rgba(255, 255, 255, 0.2)",
2320
2346
  title: "Close"
2321
- }, "\xD7"))), !isPipMinimized && /*#__PURE__*/React__default["default"].createElement("div", {
2347
+ }, "\xD7"))), /*#__PURE__*/React__default["default"].createElement("div", {
2322
2348
  style: {
2323
2349
  flex: 1,
2324
2350
  background: "#000000",
2325
- position: "relative"
2351
+ position: "relative",
2352
+ display: isPipMinimized ? "none" : "flex",
2353
+ flexDirection: "column"
2326
2354
  }
2327
2355
  }, /*#__PURE__*/React__default["default"].createElement("iframe", {
2328
2356
  src: (() => {
2329
2357
  if (!callToken) return "";
2330
2358
  const base = String(joinCallUrlBase || "").replace(/\/?$/, "/");
2331
- console.log("${base}token=${callToken}", `${base}token=${callToken}`);
2332
2359
  return `${base}token=${callToken}`;
2333
2360
  })(),
2334
2361
  style: {
2335
2362
  width: "100%",
2336
2363
  height: "100%",
2337
- border: "none"
2364
+ border: "none",
2365
+ flex: 1
2338
2366
  },
2339
2367
  allow: "camera; microphone; display-capture; autoplay",
2340
2368
  allowFullScreen: true,
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).MyPackage={},e.React,e.ReactDOM)}(this,(function(e,t,n){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=o(t),i=o(n);const r="/appointment/V1/consultant/all-appointments",l="/notification/V1/consultation/online/initiate",d="https://wbafedevittisalwe01-had2b3e0a7h6fyey.westeurope-01.azurewebsites.net/call/",s=async function(e,t,n){let o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=(e||"").toUpperCase();"INPROGRESS"===a&&(a="IN_PROGRESS");const i=o.apiBaseUrl,l=o.hospitalId,d=o.doctorId,s=o.token||"",p={hospitalId:l,doctorId:d,fromDate:t,toDate:n,statuses:a,appointmentType:"ONLINE"},c=`${i}${r}`,u=await async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";const o=new URL(e);return o.search=new URLSearchParams(t).toString(),fetch(o,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`${n}`}}).then((async e=>{const t=await e.json().catch((()=>({})));return e.ok?t:{err:t?.resultInfo?.message||"Something went wrong!",status:e.status}})).catch((e=>(console.error("Fetch error:",e),{err:e?.message||String(e)||"Network error"})))}(c,p,"PIH-Appointment-Widget",s);return u},p=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};console.log("initiateConsultation -> config",t);const n=`${t.apiBaseUrl.replace(/\/$/,"")}${l}`,o=t.appToken||"";return async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=arguments.length>4?arguments[4]:void 0;const a=new URL(e);Object.keys(n).forEach((e=>{a.searchParams.append(e,n[e])}));const i={"Content-Type":"application/json"};o&&(i.Authorization=o);const r={method:"POST",headers:i,body:JSON.stringify(t)};return fetch(a.toString(),r).then((async e=>{const t=await e.json().catch((()=>({})));return e.ok?t:{err:t?.resultInfo?.message||"Something went wrong!",status:e.status}})).catch((e=>(console.error("Fetch error:",e),{err:e.message||"Network error"})))}(n,{patientId:String(e.patientId||""),primaryPatientId:String(e.primaryPatientId||e.patientId||""),hospitalId:t.hospitalId,doctorId:String(t.doctorId),patientName:e.patientName||e.name||"",doctorName:e.doctorName||t.doctorName,appointmentId:String(e.id||e.appointmentId||e._id||"")},"PIH-Appointment-Widget",{},o)};const c="pih_appointment_idToken",u="pih_appointment_email",m="pih_appointment_appToken",f="pih_appointment_doctorId",x="pih_appointment_userName",g="pih_appointment_apiBaseUrl",h="pih_appointment_hospitalId",y=720,E="pih-appointment-widget",F="data-pih-widget";class w extends t.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){"undefined"!=typeof console&&console.error&&console.error("Appointment widget error:",e,t)}render(){return this.state.hasError?a.default.createElement("div",{className:E,[F]:"teleconsult-appointments",style:{fontFamily:'"Nunito", serif',background:"#F5F5F7",boxSizing:"border-box",minHeight:"100vh",display:"flex",alignItems:"center",justifyContent:"center",padding:"24px",textAlign:"center"}},a.default.createElement("div",{style:{maxWidth:"400px"}},a.default.createElement("div",{style:{fontSize:"48px",marginBottom:"16px"}},"⚠️"),a.default.createElement("h2",{style:{fontSize:"20px",fontWeight:700,color:"#1a1a1a",margin:"0 0 8px 0"}},"Something went wrong"),a.default.createElement("p",{style:{fontSize:"14px",color:"#666",margin:0,lineHeight:1.5}},"Please refresh the page or try again later."))):this.props.children}}const b=e=>{let{config:n={}}=e;const[o,i]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(g):null}catch{return null}})),[r,l]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(h):null}catch{return null}})),b=n.apiBaseUrl||o||"https://afiyaapiqa.powermindinc.com",S=n.hospitalId||r,[v,k]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(c):null}catch{return null}})),[C,I]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(u):null}catch{return null}})),D=n.idToken||n.token||v,z=n.email||C;t.useEffect((()=>{try{if("undefined"==typeof localStorage)return;const e=n.idToken||n.token;if(e&&String(e).trim()){localStorage.getItem(c)!==e&&(T(null),A(null),N(null),localStorage.removeItem(m),localStorage.removeItem(f),localStorage.removeItem(x)),localStorage.setItem(c,e),k(e)}n.email&&String(n.email).trim()&&(localStorage.setItem(u,n.email),I(n.email)),n.apiBaseUrl&&String(n.apiBaseUrl).trim()&&(localStorage.setItem(g,n.apiBaseUrl.trim()),i(n.apiBaseUrl.trim())),null!=n.hospitalId&&String(n.hospitalId).trim()&&(localStorage.setItem(h,String(n.hospitalId).trim()),l(String(n.hospitalId).trim()))}catch(e){}}),[n.idToken,n.token,n.email,n.apiBaseUrl,n.hospitalId]);const[W,T]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(m):null}catch{return null}})),[M,A]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(f):null}catch{return null}})),[R,N]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(x):null}catch{return null}})),[P,j]=t.useState((()=>{try{if("undefined"==typeof localStorage)return!1;const e=localStorage.getItem(m),t=localStorage.getItem(c),n=localStorage.getItem(u);return!e&&!(!t||!n)}catch{return!1}})),[B,H]=t.useState(null),[L,U]=t.useState(!1),[$,_]=t.useState(0);t.useEffect((()=>{W&&P&&j(!1)}),[W,P]),t.useEffect((()=>{W||(D&&z?(U(!1),H((e=>"Sign in required. Redirecting to home..."===e?null:e))):(H("Sign in required. Redirecting to home..."),U(!0)))}),[W,D,z]),t.useEffect((()=>{if(!L)return;const e=n.homeUrl||"https://wbaemrdevittisalwe01-fnapdpfme7bvduhh.westeurope-01.azurewebsites.net/";if(!e||"undefined"==typeof window)return;const t=setTimeout((()=>{window.location.href=e}),2500);return()=>clearTimeout(t)}),[L,n.homeUrl]),t.useEffect((()=>{if(!P)return;const e=setTimeout((()=>{H("Request timed out. Please try again."),j(!1)}),3e4);return()=>clearTimeout(e)}),[P]);const O=n.joinCallUrl||d;W&&String(O||"").replace(/\/?$/,"/");const Y=function(e){if(!e||"string"!=typeof e)return{};try{const t=e.split(".");if(3!==t.length)return{};const n=t[1].replace(/-/g,"+").replace(/_/g,"/"),o=n.padEnd(n.length+(4-n.length%4)%4,"=");return JSON.parse(atob(o))}catch{return{}}}(D),V=R||Y.name||Y.sub||"User",q=()=>(new Date).toISOString().split("T")[0],[X,G]=t.useState("upcoming"),[J,K]=t.useState([]),[Q,Z]=t.useState(null),[ee,te]=t.useState(!1),[ne,oe]=t.useState(null),[ae,ie]=t.useState(window.innerWidth<768),[re,le]=t.useState("today"),[de,se]=t.useState("today"),[pe,ce]=t.useState(!1),[ue,me]=t.useState(!1),[fe,xe]=t.useState("all"),[ge,he]=t.useState("asc"),[ye,Ee]=t.useState(""),[Fe,we]=t.useState(!1),[be,Se]=t.useState(!1),[ve,ke]=t.useState(!1),[Ce,Ie]=t.useState(null),[De,ze]=t.useState(null),[We,Te]=t.useState(!1),[Me,Ae]=t.useState(null),[Re,Ne]=t.useState((()=>({x:Math.max(20,"undefined"!=typeof window?window.innerWidth-y-20:300),y:80}))),[Pe,je]=t.useState({width:y,height:560}),[Be,He]=t.useState(!1),[Le,Ue]=t.useState({x:0,y:0}),[$e,_e]=t.useState(!1),[Oe,Ye]=t.useState(null),[Ve,qe]=t.useState({x:0,y:0,width:0,height:0});t.useState(!1);const[Xe,Ge]=t.useState(1),Je=J.filter((e=>{if(!ye.trim())return!0;const t=ye.toLowerCase(),n=(e.patientName||"").toLowerCase(),o=String(e.patientId||"").toLowerCase();return n.includes(t)||o.includes(t)})),Ke=20*(Xe-1),Qe=Ke+20,Ze=Je.slice(Ke,Qe),et=Math.ceil(Je.length/20),tt=Je.length,[nt,ot]=t.useState(q()),[at,it]=t.useState(q()),[rt,lt]=t.useState(),[dt,st]=t.useState(),pt=e=>e?.id||e?._id||e?.appointmentId||e?.patientId||JSON.stringify(e),ct=e=>e?.image?e.image:null,ut=e=>e?e.charAt(0).toUpperCase():"?",mt=e=>{if(!e)return"#4C4DDC";const t=["#4C4DDC","#1CC3CE","#FF6B6B","#4ECDC4","#45B7D1","#FFA07A","#98D8C8","#F7DC6F"];return t[e.charCodeAt(0)%t.length]},ft=()=>{const e="asc"===ge?"desc":"asc";he(e);const t=[...J].sort(((t,n)=>{const o=new Date(t.appointmentDate||t.date||0),a=new Date(n.appointmentDate||n.date||0);return"asc"===e?o-a:a-o}));K(t),Ge(1),t.length>0&&Z(t[0])},xt=t.useCallback((async()=>{if(!W)return;console.log(M,"fetchAppointments -> doctorIdFromLogin");const e=M;te(!0),oe(null);try{const t={apiBaseUrl:b,hospitalId:S,doctorId:e,token:W},n=await s(X,nt,at,t);if(401===n.status||403===n.status){try{"undefined"!=typeof localStorage&&(localStorage.removeItem(m),localStorage.removeItem(f),localStorage.removeItem(x))}catch(e){}return T(null),A(null),N(null),_((e=>e+1)),void oe("Session expired. Re-authenticating...")}if(n.err)return void oe(String(n.err||"Failed to fetch appointments"));const o=n.data||n.appointments||n||[];K(Array.isArray(o)?o:[]),Array.isArray(o)&&o.length>0?Z(o[0]):Z(null)}catch(e){console.error("Error fetching appointments:",e),oe(e.message||"Failed to fetch appointments")}finally{te(!1)}}),[X,nt,at,fe,b,S,M,W]),gt=e=>{Z(e),Ae(null)},ht=async()=>{if(Q&&W){Te(!0),Ae(null);try{const e={apiBaseUrl:b,hospitalId:S,doctorId:M,doctorName:R||V,appToken:W};console.log(Q,"selectedAppointment"),console.log(e,"callConfig");const t=await p(Q,e);if(console.log(t.status,"response"),401===t.status||403===t.status){try{"undefined"!=typeof localStorage&&(localStorage.removeItem(m),localStorage.removeItem(f),localStorage.removeItem(x))}catch(e){}return T(null),A(null),N(null),_((e=>e+1)),void Ae("Session expired. Re-authenticating...")}if(t.err||!t.data?.token)return void Ae(String(t.err||"Failed to initiate call"));const o=n.joinCallUrl||d,a=t.data.token?String(o||"").replace(/\/?$/,"/")+t.data.token:"";console.log("joinCallUrl",a),Ie(t.data.token),ze(a||""),we(!0),Se(!1),ke(!1),je({width:y,height:560}),Ne({x:Math.max(20,window.innerWidth-y-20),y:80})}catch(e){Ae(e.message||"Failed to initiate call")}finally{Te(!1)}}},yt=()=>{we(!1),Se(!1),ke(!1),Ie(null),ze(null),Ae(null),xt()},Et=()=>{ve&&ke(!1),Se(!be)},Ft=()=>{be&&Se(!1),ke(!ve)},wt=e=>{if(0!==e.button)return;if(e.target.closest("button"))return;e.currentTarget.setPointerCapture&&e.currentTarget.setPointerCapture(e.pointerId),He(!0);const t=e.currentTarget.getBoundingClientRect();Ue({x:e.clientX-t.left,y:e.clientY-t.top})},bt=t.useCallback((e=>{if(!ve)if(Be){const t=e.clientX-Le.x,n=e.clientY-Le.y,o=window.innerWidth-Pe.width,a=window.innerHeight-Pe.height;Ne({x:Math.max(0,Math.min(t,o)),y:Math.max(0,Math.min(n,a))})}else if($e){const t=e.clientX-Ve.x,n=e.clientY-Ve.y;let o=Ve.width,a=Ve.height,i=Ve.posX,r=Ve.posY;const l=300,d=250,s=window.innerWidth-40,p=window.innerHeight-100;if("bottom-right"===Oe)o=Math.min(Math.max(Ve.width+t,l),s),a=Math.min(Math.max(Ve.height+n,d),p),i+o>window.innerWidth&&(o=window.innerWidth-i),r+a>window.innerHeight&&(a=window.innerHeight-r);else if("bottom-left"===Oe){o=Math.min(Math.max(Ve.width-t,l),s),i=Math.max(0,Ve.posX+t),0===i&&(o=Ve.posX+Ve.width),a=Math.min(Math.max(Ve.height+n,d),p),r+a>window.innerHeight&&(a=window.innerHeight-r)}else if("top-right"===Oe){o=Math.min(Math.max(Ve.width+t,l),s),i+o>window.innerWidth&&(o=window.innerWidth-i);a=Math.min(Math.max(Ve.height-n,d),p),r=Math.max(0,Ve.posY+n),0===r&&(a=Ve.posY+Ve.height)}else if("top-left"===Oe){o=Math.min(Math.max(Ve.width-t,l),s),i=Math.max(0,Ve.posX+t),0===i&&(o=Ve.posX+Ve.width);a=Math.min(Math.max(Ve.height-n,d),p),r=Math.max(0,Ve.posY+n),0===r&&(a=Ve.posY+Ve.height)}je({width:o,height:a}),Ne({x:i,y:r})}}),[Be,$e,Le,Oe,Ve,Re,Pe,ve]),St=()=>{He(!1),_e(!1),Ye(null)},vt=(e,t)=>{t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture&&t.currentTarget.setPointerCapture(t.pointerId),_e(!0),Ye(e),qe({x:t.clientX,y:t.clientY,width:Pe.width,height:Pe.height,posX:Re.x,posY:Re.y})};t.useEffect((()=>{if(!Fe||ve)return;const e=()=>{if(!(window.innerWidth<768)){const e=be?350:Pe.width,t=be?60:Pe.height,n=window.innerWidth-40,o=window.innerHeight-100,a=Math.min(e,n),i=Math.min(t,o);a===Pe.width&&i===Pe.height||je({width:a,height:i});const r=window.innerWidth-a-20,l=window.innerHeight-i-20;Ne((e=>({x:Math.min(e.x,r),y:Math.min(e.y,l)})))}};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)}),[Fe,be,ve,Pe]),t.useEffect((()=>{if(!(D&&z&&(!W||$>0)))return;let e=!1;return j(!0),H(null),(async(e,t,n,o)=>{const a=`${e.replace(/\/$/,"")}/um/user/V1/sso/login?hospitalId=${encodeURIComponent(t)}`,i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({idToken:n,email:o})};return console.log("[getTokenFromSso] request",{url:a,body:{idToken:n?n.slice(0,50)+"...":null,email:o}}),fetch(a,i).then((e=>(console.log("[getTokenFromSso] response status",e.status,e.statusText),e.ok?e.json().then((e=>(console.log("[getTokenFromSso] success",{hasData:!!e,dataKeys:e?Object.keys(e):[],hasAccessToken:!!e?.data?.access_token}),e))):e.json().then((t=>{const n=t?.resultInfo?.message||"SSO login failed";return console.log("[getTokenFromSso] error body",t),{err:n,status:e.status}})).catch((()=>({err:"Something went wrong!",status:e.status})))))).catch((e=>(console.error("[getTokenFromSso] catch",e),{err:e.message||"Network error"})))})(b,S,D,z).then((t=>{if(e)return;const n=function(e){return!e||e.err?null:e.data?.access_token??e.data?.token??e.token??e.accessToken??null}(t);if(400===t.status)return H(t.err||"Invalid request. Redirecting to home..."),j(!1),void U(!0);if(t.err||!n){H(String(t.err||"Failed to get token")),T(null),A(null),N(null);try{"undefined"!=typeof localStorage&&(localStorage.removeItem(m),localStorage.removeItem(f),localStorage.removeItem(x))}catch(e){}}else{const e=function(e){if(!e?.data)return null;const t=e.data.doctor_id??e.data.doctorId??null;return console.log(t,"extractDoctorIdFromLoginResponse -> id"),null!=t?String(t):null}(t);console.log(e,"extractDoctorIdFromLoginResponse -> doctorId");const o=function(e){if(!e?.data)return null;const t=e.data.name??e.data.doctor_name??e.data.userName??null;return null!=t?String(t):null}(t);T(n),A(e),N(o),H(null),U(!1);try{"undefined"!=typeof localStorage&&(localStorage.setItem(m,n),e&&localStorage.setItem(f,e),o&&localStorage.setItem(x,o))}catch(e){}}})).catch((()=>{})).finally((()=>{e||j(!1)})),()=>{e=!0}}),[b,S,D,z,$]),t.useEffect((()=>{Ge(1),Ae(null)}),[X,re,nt,at,ye,fe]),t.useEffect((()=>{!P&&W&&xt()}),[xt,W,P]),t.useEffect((()=>{const e=document.createElement("link");e.href="https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,200..1000;1,200..1000&display=swap",e.rel="stylesheet",document.head.appendChild(e);const t=document.createElement("style");t.innerHTML="\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n \n @media (max-width: 768px) {\n .appointments-grid {\n grid-template-columns: 1.5fr 1fr 0.8fr !important;\n }\n .appointments-header-grid {\n grid-template-columns: 1.5fr 1fr 0.8fr !important;\n }\n .hide-on-mobile {\n display: none !important;\n }\n }\n @media (max-width: 480px) {\n .appointments-header-grid {\n font-size: 10px !important;\n }\n .appointments-grid {\n font-size: 11px !important;\n }\n }\n ",document.head.appendChild(t);const n=()=>{ie(window.innerWidth<768)};return window.addEventListener("resize",n),()=>{document.head.removeChild(e),document.head.removeChild(t),window.removeEventListener("resize",n)}}),[]),t.useEffect((()=>{const e=e=>{!pe||e.target.closest("button")||e.target.closest('input[type="date"]')||ce(!1),ue&&!e.target.closest("[data-appointment-type-picker]")&&me(!1)};return document.addEventListener("click",e),()=>{document.removeEventListener("click",e)}}),[pe,ue]);let kt='"Nunito", serif';const Ct=B||!W&&(!D||!z),It=B||"Sign in required. Redirecting to home...";let Dt;return Dt=P&&D&&z?a.default.createElement("div",{className:E,[F]:"teleconsult-appointments",style:{fontFamily:kt,background:"#F5F5F7",boxSizing:"border-box",height:"100%",minHeight:"100vh",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"24px"}},a.default.createElement("style",null,"@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }"),a.default.createElement("div",{style:{width:"40px",height:"40px",border:"3px solid #f3f3f3",borderTop:"3px solid #4C4DDC",borderRadius:"50%",animation:"spin 1s linear infinite",marginBottom:"16px"}}),a.default.createElement("p",{style:{fontSize:"14px",color:"#666",margin:0}},"Checking authorisation...")):a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{className:E,[F]:"teleconsult-appointments",style:{fontFamily:kt,background:"#F5F5F7",boxSizing:"border-box",height:"100%",minHeight:"100vh",width:"100%",display:"flex",flexDirection:"column",overflow:"hidden"}},a.default.createElement("div",{style:{background:"#FFFFFF",padding:ae?"10px 12px":"12px 24px",display:"flex",justifyContent:"space-between",alignItems:"center",borderBottom:"1px solid #E5E5E5",flexWrap:"nowrap",gap:ae?"8px":"0"}},a.default.createElement("div",{style:{position:"relative",width:ae?"calc(100% - 90px)":"480px",maxWidth:ae?"none":"480px"}},a.default.createElement("input",{type:"text",placeholder:"Search by patient name or ID",value:ye,onChange:e=>Ee(e.target.value),style:{width:"100%",padding:ae?"8px 32px 8px 10px":"8px 36px 8px 14px",border:"1px solid #E5E5E5",borderRadius:"6px",fontSize:ae?"12px":"13px",fontFamily:kt,background:"#FFFFFF",outline:"none",boxSizing:"border-box"}}),ye&&a.default.createElement("button",{onClick:()=>Ee(""),style:{position:"absolute",right:"8px",top:"50%",transform:"translateY(-50%)",background:"none",border:"none",cursor:"pointer",padding:"4px",display:"flex",alignItems:"center",justifyContent:"center",color:"#999",fontSize:"16px"},title:"Clear search"},"✕")),!1),a.default.createElement("div",{style:{padding:ae?"12px":"16px 24px",flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"}},a.default.createElement("div",{style:{marginBottom:ae?"10px":"14px"}},a.default.createElement("h1",{style:{fontSize:ae?"18px":"22px",fontWeight:700,color:"#1a1a1a",margin:"0 0 2px 0"}},"Tele Consultation"),a.default.createElement("p",{style:{fontSize:ae?"11px":"12px",color:"#999",margin:0}},"Displaying All Tele Consultation Appointments")),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:ae?"flex-start":"center",marginBottom:ae?"10px":"14px",flexDirection:ae?"column":"row",gap:ae?"12px":"0"}},a.default.createElement("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",width:ae?"100%":"auto"}},a.default.createElement("button",{onClick:()=>G("upcoming"),style:{background:"upcoming"===X?"#4C4DDC":"#FFFFFF",padding:ae?"8px 10px":"9px 16px",border:"upcoming"===X?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ae?"10px":"13px",color:"upcoming"===X?"white":"#555555",fontWeight:600,fontFamily:kt,cursor:"pointer",flex:ae?"1 1 auto":"none",minWidth:ae?"0":"auto",transition:"all 0.3s ease",whiteSpace:"nowrap"}},"Upcoming Appointments"),a.default.createElement("button",{onClick:()=>G("completed"),style:{background:"completed"===X?"#4C4DDC":"#FFFFFF",padding:ae?"8px 10px":"9px 16px",border:"completed"===X?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ae?"10px":"13px",color:"completed"===X?"white":"#555555",fontWeight:600,fontFamily:kt,cursor:"pointer",flex:ae?"1 1 auto":"none",minWidth:ae?"0":"auto",transition:"all 0.3s ease",whiteSpace:"nowrap"}},"Completed Appointments"),a.default.createElement("button",{onClick:()=>G("cancelled"),style:{background:"cancelled"===X?"#4C4DDC":"#FFFFFF",padding:ae?"8px 10px":"9px 16px",border:"cancelled"===X?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ae?"10px":"13px",color:"cancelled"===X?"white":"#555555",fontWeight:600,fontFamily:kt,cursor:"pointer",flex:ae?"1 1 auto":"none",minWidth:ae?"0":"auto",transition:"all 0.3s ease",whiteSpace:"nowrap"}},"Cancelled Appointments")),a.default.createElement("div",{style:{display:"flex",gap:"8px",alignItems:"center",width:"auto",position:"relative",justifyContent:ae?"flex-start":"flex-end",flexWrap:"wrap"}},a.default.createElement("button",{onClick:()=>{pe||(lt(nt),st(at),se(re)),ce(!pe)},style:{padding:"8px 12px",fontFamily:kt,fontWeight:600,border:"1px solid #E5E5E5",borderRadius:"6px",fontSize:ae?"11px":"13px",color:"#1a1a1a",background:"#FFFFFF",display:"flex",alignItems:"center",gap:ae?"4px":"6px",cursor:"pointer",flex:"none",minWidth:ae?"100px":"auto",justifyContent:"center"}},a.default.createElement("svg",{width:ae?"12":"14",height:ae?"12":"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a.default.createElement("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"}),a.default.createElement("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),a.default.createElement("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),a.default.createElement("line",{x1:"3",y1:"10",x2:"21",y2:"10"})),a.default.createElement("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},(()=>{switch(re){case"today":default:return"Today";case"tomorrow":return"Tomorrow";case"currentWeek":return"Current Week";case"thisMonth":return"This Month";case"currentYear":return"Current Year";case"custom":return ae?"Custom":`${nt} to ${at}`}})()),a.default.createElement("svg",{width:ae?"8":"10",height:ae?"8":"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a.default.createElement("polyline",{points:"6 9 12 15 18 9"}))),pe&&a.default.createElement("div",{style:{position:"absolute",top:"100%",right:ae?"auto":0,left:ae?0:"auto",marginTop:"4px",background:"#FFFFFF",border:"1px solid #E5E5E5",borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.15)",padding:"8px",zIndex:1e3,minWidth:ae?"280px":"240px",width:ae?"calc(100vw - 24px)":"auto",maxWidth:ae?"calc(100vw - 24px)":"280px"}},a.default.createElement("div",{style:{marginBottom:"custom"===de?"12px":"0"}},["thisMonth","today","tomorrow","currentWeek","currentYear","custom"].map((e=>a.default.createElement("button",{key:e,onClick:()=>{if(se(e),"custom"!==e){const t=(e=>{const t=new Date;let n,o;switch(e){case"today":default:n=o=q();break;case"tomorrow":const e=new Date(t);e.setDate(e.getDate()+1),n=o=e.toISOString().split("T")[0];break;case"currentWeek":const a=new Date(t),i=new Date(t),r=t.getDay(),l=0===r?-6:1-r;a.setDate(t.getDate()+l),i.setDate(a.getDate()+6),n=a.toISOString().split("T")[0],o=i.toISOString().split("T")[0];break;case"thisMonth":const d=new Date(t.getFullYear(),t.getMonth(),1),s=new Date(t.getFullYear(),t.getMonth()+1,0);n=d.toISOString().split("T")[0],o=s.toISOString().split("T")[0];break;case"currentYear":n=`${t.getFullYear()}-01-01`,o=`${t.getFullYear()}-12-31`}return{from:n,to:o}})(e);le(e),ot(t.from),it(t.to),lt(t.from),st(t.to),ce(!1)}else lt(""),st("")},style:{width:"100%",padding:"10px 12px",background:de===e?"#E8EEF4":"#FFFFFF",border:"none",borderRadius:"4px",fontSize:"13px",fontFamily:kt,cursor:"pointer",textAlign:"left",fontWeight:de===e?600:400,color:de===e?"#4C4DDC":"#1a1a1a",marginBottom:"4px",display:"flex",justifyContent:"space-between",alignItems:"center",transition:"all 0.2s ease"},onMouseEnter:t=>{de!==e&&(t.target.style.background="#F5F5F5")},onMouseLeave:t=>{de!==e&&(t.target.style.background="#FFFFFF")}},a.default.createElement("span",null,{thisMonth:"This Month",today:"Today",tomorrow:"Tomorrow",currentWeek:"Current Week",currentYear:"Current Year",custom:"Custom"}[e]),de===e&&a.default.createElement("span",{style:{color:"#4C4DDC",fontSize:"16px"}},"✓"))))),"custom"===de&&a.default.createElement("div",{style:{paddingTop:"8px",borderTop:"1px solid #E5E5E5"}},a.default.createElement("div",{style:{marginBottom:"8px"}},a.default.createElement("input",{type:"date",value:rt,onChange:e=>lt(e.target.value),placeholder:"Start Date",style:{width:"100%",padding:"10px 8px",border:"1px solid #E5E5E5",borderRadius:"4px",fontSize:"13px",fontFamily:kt,boxSizing:"border-box",cursor:"pointer"}})),a.default.createElement("div",{style:{marginBottom:"12px"}},a.default.createElement("input",{type:"date",value:dt,onChange:e=>st(e.target.value),placeholder:"End Date",style:{width:"100%",padding:"10px 8px",border:"1px solid #E5E5E5",borderRadius:"4px",fontSize:"13px",fontFamily:kt,boxSizing:"border-box",cursor:"pointer"}})),a.default.createElement("div",{style:{display:"flex",gap:"8px"}},a.default.createElement("button",{onClick:()=>{se(re),lt(nt),st(at),ce(!1)},style:{flex:1,padding:"10px 12px",background:"#FFFFFF",color:"#4C4DDC",border:"1px solid #4C4DDC",borderRadius:"4px",fontSize:"13px",fontFamily:kt,fontWeight:600,cursor:"pointer"}},"Cancel"),a.default.createElement("button",{onClick:()=>{rt&&dt&&(le("custom"),ot(rt),it(dt),ce(!1))},style:{flex:1,padding:"10px 12px",background:"#4C4DDC",color:"#FFFFFF",border:"none",borderRadius:"4px",fontSize:"13px",fontFamily:kt,fontWeight:600,cursor:"pointer"}},"Submit")))))),a.default.createElement("div",{style:{display:"flex",flexDirection:ae?"column":"row",gap:ae?"12px":"14px",flex:1,minHeight:0,overflow:ae?"auto":"hidden"}},a.default.createElement("div",{style:{flex:ae?"none":"1 1 65%",width:ae?"100%":"auto",display:"flex",flexDirection:"column",minHeight:ae?"400px":0}},a.default.createElement("div",{style:{background:"#FFFFFF",borderRadius:"8px",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden",display:"flex",flexDirection:"column",flex:ae?"none":1,minHeight:ae?"auto":0}},a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:ae?"12px 14px":"14px 18px",borderBottom:"1px solid #F1F1F1"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ae?"6px":"8px"}},a.default.createElement("span",{style:{fontSize:ae?"14px":"15px",fontWeight:700,color:"#1a1a1a"}},"Appointments"),a.default.createElement("span",{style:{background:"#4C4DDC",color:"#fff",fontSize:ae?"10px":"11px",fontWeight:600,padding:ae?"2px 7px":"3px 8px",borderRadius:"12px"}},tt))),a.default.createElement("div",{className:"appointments-header-grid",style:{display:"grid",gridTemplateColumns:ae?"1.5fr 1fr 0.8fr":"2.5fr 1fr 1.5fr 0.8fr 1.2fr",gap:ae?"8px":"12px",padding:ae?"8px 12px":"10px 18px",background:"#F5F5F5",fontSize:ae?"10px":"12px",fontWeight:600,color:"#666"}},a.default.createElement("div",null,"Patients name"),!ae&&a.default.createElement("div",null,"Patient ID"),a.default.createElement("div",{onClick:ft,style:{display:"flex",alignItems:"center",gap:"3px",cursor:"pointer",userSelect:"none"}},"Date",a.default.createElement("span",{style:{opacity:.7,fontSize:"10px"}},"asc"===ge?"▲":"▼")),!ae&&a.default.createElement("div",null,"Slot"),!ae&&a.default.createElement("div",null,"Doctor")),a.default.createElement("div",{style:{overflow:"auto",flex:1}},P?a.default.createElement("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",padding:"40px",color:"#888"}},a.default.createElement("div",{style:{textAlign:"center"}},a.default.createElement("div",{style:{width:"40px",height:"40px",border:"3px solid #f3f3f3",borderTop:"3px solid #4C4DDC",borderRadius:"50%",animation:"spin 1s linear infinite",margin:"0 auto 10px"}}),"Getting token...")):ee?a.default.createElement("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",padding:"40px",color:"#888"}},a.default.createElement("div",{style:{textAlign:"center"}},a.default.createElement("div",{style:{width:"40px",height:"40px",border:"3px solid #f3f3f3",borderTop:"3px solid #4C4DDC",borderRadius:"50%",animation:"spin 1s linear infinite",margin:"0 auto 10px"}}),"Loading appointments...")):ne?a.default.createElement("div",{style:{padding:"40px",textAlign:"center",color:"#FF0000"}},a.default.createElement("div",{style:{fontSize:"16px",marginBottom:"8px"}},"⚠️ Error"),a.default.createElement("div",{style:{fontSize:"13px"}},ne),a.default.createElement("button",{onClick:xt,style:{marginTop:"16px",padding:"8px 16px",background:"#4C4DDC",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontFamily:kt}},"Retry")):0===Ze.length?a.default.createElement("div",{style:{padding:"40px",textAlign:"center",color:"#888"}},a.default.createElement("div",{style:{fontSize:"16px",marginBottom:"8px"}},"📋"),a.default.createElement("div",{style:{fontSize:"13px"}},ye?`No appointments found for "${ye}"`:"No appointments found"),ye&&a.default.createElement("button",{onClick:()=>Ee(""),style:{marginTop:"12px",padding:"6px 12px",background:"#4C4DDC",color:"white",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"12px",fontFamily:kt}},"Clear Search")):Ze.map((e=>a.default.createElement("div",{key:pt(e),role:"button",tabIndex:0,onClick:()=>gt(e),onKeyDown:t=>"Enter"===t.key&&gt(e),className:"appointments-grid",style:{display:"grid",gridTemplateColumns:ae?"1.5fr 1fr 0.8fr":"2.5fr 1fr 1.5fr 0.8fr 1.2fr",gap:ae?"8px":"12px",padding:ae?"10px 12px":"12px 18px",background:pt(Q)===pt(e)?"#E8EEF4":"#FFFFFF",borderTop:"1px solid #F1F1F1",alignItems:"center",cursor:"pointer",fontSize:ae?"11px":"13px"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ae?"8px":"10px"}},ct(e)?a.default.createElement("img",{src:e.image,alt:"",style:{width:ae?"32px":"36px",height:ae?"32px":"36px",borderRadius:"50%",objectFit:"cover"}}):a.default.createElement("div",{style:{width:ae?"32px":"36px",height:ae?"32px":"36px",borderRadius:"50%",background:mt(e.patientName),display:"flex",alignItems:"center",justifyContent:"center",color:"#FFFFFF",fontWeight:600,fontSize:ae?"14px":"16px"}},ut(e.patientName)),a.default.createElement("div",null,a.default.createElement("div",{style:{fontWeight:600,color:"#1a1a1a",fontSize:ae?"11px":"13px"}},e.patientName),a.default.createElement("div",{style:{fontSize:ae?"9px":"11px",color:"#888"}},e.email))),!ae&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.patientId),a.default.createElement("div",{style:{color:"#555",fontSize:ae?"10px":"12px"}},(()=>{const t=e.appointmentDate||"",n=t.match(/\s(\d{1,2}:\d{2}(?:\s*(?:AM|PM))?)$/i);return n?a.default.createElement(a.default.Fragment,null,a.default.createElement("div",null,t.slice(0,n.index).trim()),a.default.createElement("div",{style:{fontSize:ae?"9px":"11px",color:"#888"}},n[1].trim())):a.default.createElement("div",null,t)})()),!ae&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.appointmentTime||"-"),!ae&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.doctorName||e.doctor||"-"))))),!ee&&!ne&&Ze.length>0&&a.default.createElement("div",{style:{padding:ae?"12px 14px":"14px 18px",borderTop:"1px solid #F1F1F1",display:"flex",justifyContent:"space-between",alignItems:"center",background:"#FFFFFF",flexWrap:ae?"wrap":"nowrap",gap:ae?"10px":"0"}},a.default.createElement("div",{style:{fontSize:ae?"11px":"12px",color:"#666"}},"Showing page ",Xe," of ",et," (",tt," total)"),a.default.createElement("div",{style:{display:"flex",gap:"6px",alignItems:"center"}},a.default.createElement("button",{onClick:()=>Ge((e=>Math.max(1,e-1))),disabled:1===Xe,style:{padding:ae?"6px 10px":"6px 12px",border:"1px solid #E5E5E5",borderRadius:"4px",background:1===Xe?"#F5F5F5":"#FFFFFF",color:1===Xe?"#999":"#1a1a1a",fontSize:ae?"11px":"12px",fontFamily:kt,fontWeight:600,cursor:1===Xe?"not-allowed":"pointer",opacity:1===Xe?.5:1}},"Previous"),a.default.createElement("div",{style:{display:"flex",gap:"4px"}},[...Array(Math.min(5,et))].map(((e,t)=>{let n;return n=et<=5||Xe<=3?t+1:Xe>=et-2?et-4+t:Xe-2+t,a.default.createElement("button",{key:n,onClick:()=>Ge(n),style:{padding:ae?"6px 10px":"6px 12px",border:Xe===n?"none":"1px solid #E5E5E5",borderRadius:"4px",background:Xe===n?"#4C4DDC":"#FFFFFF",color:Xe===n?"#FFFFFF":"#1a1a1a",fontSize:ae?"11px":"12px",fontFamily:kt,fontWeight:600,cursor:"pointer",minWidth:ae?"32px":"36px"}},n)}))),a.default.createElement("button",{onClick:()=>Ge((e=>Math.min(et,e+1))),disabled:Xe===et,style:{padding:ae?"6px 10px":"6px 12px",border:"1px solid #E5E5E5",borderRadius:"4px",background:Xe===et?"#F5F5F5":"#FFFFFF",color:Xe===et?"#999":"#1a1a1a",fontSize:ae?"11px":"12px",fontFamily:kt,fontWeight:600,cursor:Xe===et?"not-allowed":"pointer",opacity:Xe===et?.5:1}},"Next"))))),a.default.createElement("div",{style:{flex:ae?"none":"1 1 35%",width:ae?"100%":"auto",display:Q||!ae?"flex":"none",flexDirection:"column",minHeight:ae?"auto":0}},a.default.createElement("div",{style:{border:"1px solid #E5E5E5",borderRadius:"8px",overflow:"hidden",background:"#FFFFFF",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",display:"flex",flexDirection:"column",flex:ae?"none":1,minHeight:ae?"auto":0}},Q?a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:ae?"12px 14px":"16px 18px",background:"#E8EEF4",borderBottom:"1px solid #E5E5E5"}},a.default.createElement("div",null,a.default.createElement("div",{style:{color:"#002668",fontSize:ae?"14px":"16px",fontWeight:"700"}},Q.patientName||"N/A"),a.default.createElement("div",{style:{color:"#002668",fontSize:ae?"11px":"13px"}},Q.patientId||Q.mrn||"N/A")),a.default.createElement("div",null,ct(Q)?a.default.createElement("img",{style:{width:ae?"36px":"44px",height:ae?"36px":"44px",borderRadius:"50%",objectFit:"cover"},src:Q.image,alt:Q.patientName}):a.default.createElement("div",{style:{width:ae?"36px":"44px",height:ae?"36px":"44px",borderRadius:"50%",background:mt(Q.patientName),display:"flex",alignItems:"center",justifyContent:"center",color:"#FFFFFF",fontWeight:700,fontSize:ae?"16px":"20px"}},ut(Q.patientName)))),a.default.createElement("div",{style:{padding:ae?"12px 14px":"14px 18px",gap:ae?"10px":"12px",display:"flex",flexDirection:"column",background:"white",overflow:"auto",flex:1,position:"relative"}},a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between"}},a.default.createElement("div",{style:{textAlign:"left"}},a.default.createElement("div",{style:{fontSize:ae?"10px":"11px",color:"#888",marginBottom:"3px"}},"Speciality"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ae?"12px":"13px"}},Q?.specialisation||Q?.speciality||"N/A")),a.default.createElement("div",{style:{textAlign:"right"}},a.default.createElement("div",{style:{fontSize:ae?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Type"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ae?"12px":"13px"}},Q?.type||Q?.appointmentType||"Online"))),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between"}},a.default.createElement("div",{style:{textAlign:"left"}},a.default.createElement("div",{style:{fontSize:ae?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Date"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ae?"12px":"13px"}},Q?.date||Q?.appointmentDate||"N/A")),a.default.createElement("div",{style:{textAlign:"right"}},a.default.createElement("div",{style:{fontSize:ae?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Time"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ae?"12px":"13px"}},Q?.time||Q?.appointmentTime||"N/A"))),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between"}},a.default.createElement("div",{style:{textAlign:"left"}},a.default.createElement("div",{style:{fontSize:ae?"10px":"11px",color:"#888",marginBottom:"3px"}},"Doctor"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ae?"12px":"13px"}},Q?.doctor||Q?.doctorName||"N/A"))),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between"}},a.default.createElement("div",{style:{textAlign:"left"}},a.default.createElement("div",{style:{fontSize:ae?"10px":"11px",color:"#888",marginBottom:"3px"}},"Hospital"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ae?"12px":"13px"}},Q?.hospital||Q?.hospitalName||"N/A"))),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between"}},a.default.createElement("div",{style:{textAlign:"left"}},a.default.createElement("div",{style:{fontSize:ae?"10px":"11px",color:"#888",marginBottom:"3px"}},"Reason for Appointment"),a.default.createElement("div",{style:{fontWeight:"600",fontSize:ae?"11px":"12px",lineHeight:"1.4"}},Q?.reason||Q?.reasonForAppointment||"No reason provided"))),"upcoming"===X&&a.default.createElement("div",{style:{display:"flex",flexDirection:ae?"column":"row",gap:"6px",marginTop:"10px"}},a.default.createElement("button",{type:"button",onClick:ht,disabled:We,style:{flex:1,background:We?"#99e4e8":"#1CC3CE",color:"#FFFFFF",border:"1px solid #1CC3CE",borderRadius:"6px",padding:ae?"10px 8px":"8px 6px",fontFamily:kt,fontWeight:600,fontSize:ae?"11px":"12px",cursor:We?"not-allowed":"pointer"}},We?"Connecting...":"Join Call >")),"upcoming"===X&&Me&&a.default.createElement("div",{style:{fontSize:"11px",color:"#e53935",marginTop:"6px",textAlign:"center",width:"100%"}},"⚠️ ",Me))):a.default.createElement("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%",padding:"40px",color:"#888",textAlign:"center"}},a.default.createElement("div",null,a.default.createElement("div",{style:{fontSize:"16px",marginBottom:"8px"}},"📋"),a.default.createElement("div",{style:{fontSize:"13px"}},"Select an appointment to view details"))))))),Fe&&a.default.createElement("div",{style:{position:"fixed",left:ve?"0":ae?"10px":`${Re.x}px`,top:ve?"0":ae?"70px":`${Re.y}px`,right:ve?"0":ae?"10px":"auto",bottom:ve?"0":"auto",width:ve?"100vw":ae?"calc(100vw - 20px)":be?"350px":`${Pe.width}px`,height:ve?"100vh":be?"auto":ae?"300px":`${Pe.height}px`,background:"#FFFFFF",borderRadius:ve?"0":"8px",boxShadow:"0 8px 24px rgba(0, 0, 0, 0.3)",zIndex:1e5,overflow:"hidden",display:"flex",flexDirection:"column",transition:Be||$e?"none":"all 0.3s ease"}},a.default.createElement("div",{onPointerDown:ae||ve?void 0:wt,onPointerMove:ae||ve?void 0:bt,onPointerUp:ae||ve?void 0:St,onPointerCancel:ae||ve?void 0:St,style:{background:"linear-gradient(135deg, #4C4DDC 0%, #3A3BBD 100%)",color:"#FFFFFF",padding:ae?"8px 10px":"10px 12px",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:ae||ve?"default":"move",userSelect:"none"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ae?"6px":"8px",flex:1,minWidth:0}},a.default.createElement("div",{style:{width:ae?"6px":"8px",height:ae?"6px":"8px",borderRadius:"50%",background:"#FF4444",animation:"pulse 2s infinite",flexShrink:0}}),a.default.createElement("span",{style:{fontSize:ae?"11px":"13px",fontWeight:600,fontFamily:kt,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},"Video Call - ",Q?.patientName||"Patient")),a.default.createElement("div",{style:{display:"flex",gap:ae?"4px":"6px",alignItems:"center",flexShrink:0}},!ve&&a.default.createElement("button",{onClick:Et,style:{background:"rgba(255, 255, 255, 0.2)",border:"1px solid rgba(255, 255, 255, 0.3)",borderRadius:"6px",color:"#FFFFFF",cursor:"pointer",padding:ae?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ae?"28px":"32px",height:ae?"28px":"32px",transition:"background 0.2s ease"},onMouseEnter:e=>e.target.style.background="rgba(255, 255, 255, 0.3)",onMouseLeave:e=>e.target.style.background="rgba(255, 255, 255, 0.2)",title:be?"Restore":"Minimize"},be?a.default.createElement("svg",{width:ae?"14":"16",height:ae?"14":"16",viewBox:"0 0 16 16",fill:"none"},a.default.createElement("rect",{x:"3",y:"3",width:"10",height:"10",stroke:"white",strokeWidth:"1.8",fill:"none"})):a.default.createElement("svg",{width:ae?"14":"16",height:ae?"14":"16",viewBox:"0 0 16 16",fill:"none"},a.default.createElement("line",{x1:"3",y1:"8",x2:"13",y2:"8",stroke:"white",strokeWidth:"1.8",strokeLinecap:"round"}))),a.default.createElement("button",{onClick:Ft,style:{background:"rgba(255, 255, 255, 0.2)",border:"1px solid rgba(255, 255, 255, 0.3)",borderRadius:"6px",color:"#FFFFFF",cursor:"pointer",padding:ae?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ae?"28px":"32px",height:ae?"28px":"32px",transition:"background 0.2s ease"},onMouseEnter:e=>e.target.style.background="rgba(255, 255, 255, 0.3)",onMouseLeave:e=>e.target.style.background="rgba(255, 255, 255, 0.2)",title:ve?"Exit Fullscreen":"Fullscreen"},ve?a.default.createElement("svg",{width:ae?"14":"16",height:ae?"14":"16",viewBox:"0 0 16 16",fill:"none"},a.default.createElement("path",{d:"M10 3H13V6M6 13H3V10M13 10V13H10M3 6V3H6",stroke:"white",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})):a.default.createElement("svg",{width:ae?"14":"16",height:ae?"14":"16",viewBox:"0 0 16 16",fill:"none"},a.default.createElement("path",{d:"M3 6V3H6M13 10V13H10M10 3H13V6M6 13H3V10",stroke:"white",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"}))),a.default.createElement("button",{onClick:yt,style:{background:"rgba(255, 255, 255, 0.2)",border:"1px solid rgba(255, 255, 255, 0.3)",borderRadius:"6px",color:"#FFFFFF",cursor:"pointer",padding:ae?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ae?"28px":"32px",height:ae?"28px":"32px",fontWeight:"bold",fontSize:ae?"18px":"22px",transition:"background 0.2s ease"},onMouseEnter:e=>e.target.style.background="rgba(255, 255, 255, 0.3)",onMouseLeave:e=>e.target.style.background="rgba(255, 255, 255, 0.2)",title:"Close"},"×"))),!be&&a.default.createElement("div",{style:{flex:1,background:"#000000",position:"relative"}},a.default.createElement("iframe",{src:(()=>{if(!Ce)return"";const e=String(O||"").replace(/\/?$/,"/");return console.log("${base}token=${callToken}",`${e}token=${Ce}`),`${e}token=${Ce}`})(),style:{width:"100%",height:"100%",border:"none"},allow:"camera; microphone; display-capture; autoplay",allowFullScreen:!0,title:"Video Call"})),!ae&&!ve&&!be&&a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{onPointerDown:e=>vt("top-left",e),onPointerMove:bt,onPointerUp:St,onPointerCancel:St,style:{position:"absolute",left:0,top:0,width:"16px",height:"16px",cursor:"nwse-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>vt("top-right",e),onPointerMove:bt,onPointerUp:St,onPointerCancel:St,style:{position:"absolute",right:0,top:0,width:"16px",height:"16px",cursor:"nesw-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>vt("bottom-left",e),onPointerMove:bt,onPointerUp:St,onPointerCancel:St,style:{position:"absolute",left:0,bottom:0,width:"16px",height:"16px",cursor:"nesw-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>vt("bottom-right",e),onPointerMove:bt,onPointerUp:St,onPointerCancel:St,style:{position:"absolute",right:0,bottom:0,width:"16px",height:"16px",cursor:"nwse-resize",background:"transparent",zIndex:10001}})),a.default.createElement("style",null,"\n @keyframes pulse {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.5; }\n }\n "))),Ct&&a.default.createElement("div",{style:{position:"fixed",inset:0,zIndex:1e5,display:"flex",alignItems:"center",justifyContent:"center",padding:"24px",background:"rgba(0,0,0,0.4)",boxSizing:"border-box"}},a.default.createElement("div",{style:{fontFamily:kt,maxWidth:"400px",width:"100%",padding:"32px 24px",background:"#FFFFFF",borderRadius:"12px",boxShadow:"0 8px 32px rgba(0,0,0,0.2)",textAlign:"center"}},a.default.createElement("div",{style:{fontSize:"48px",marginBottom:"16px"}},"🔒"),a.default.createElement("h2",{style:{fontSize:"20px",fontWeight:700,color:"#1a1a1a",margin:"0 0 8px 0"}},B?"Not authorised":"Sign in required"),a.default.createElement("p",{style:{fontSize:"14px",color:"#666",margin:0,lineHeight:1.5}},It),a.default.createElement("p",{style:{fontSize:"13px",color:"#999",marginTop:"16px",marginBottom:0}},"Redirecting to login...")))),a.default.createElement(w,null,Dt)};let S=null;const v={showWidget:(e,t)=>{S||(S=document.createElement("div"),document.body.appendChild(S));const n=()=>a.default.createElement(a.default.Fragment,null,a.default.createElement(b,{config:e}));i.default.render(a.default.createElement(n,null),S)},closePopup:()=>{S&&(i.default.unmountComponentAtNode(S),S=null)}};window.BookingSDK=v,e.AppointmentPage=b,e.PIH_APPOINTMENT_WIDGET_CLASS=E,e.default=v,Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).MyPackage={},e.React,e.ReactDOM)}(this,(function(e,t,n){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=o(t),i=o(n);const r="/appointment/V1/consultant/all-appointments",l="/notification/V1/consultation/online/initiate",d="https://wbafedevittisalwe01-had2b3e0a7h6fyey.westeurope-01.azurewebsites.net/call/",s=async function(e,t,n){let o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=(e||"").toUpperCase();"INPROGRESS"===a&&(a="IN_PROGRESS");const i=o.apiBaseUrl,l=o.hospitalId,d=o.doctorId,s=o.token||"",p={hospitalId:l,doctorId:d,fromDate:t,toDate:n,statuses:a,appointmentType:"ONLINE"},c=`${i}${r}`,u=await async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";const o=new URL(e);return o.search=new URLSearchParams(t).toString(),fetch(o,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`${n}`}}).then((async e=>{const t=await e.json().catch((()=>({})));return e.ok?t:{err:t?.resultInfo?.message||"Something went wrong!",status:e.status}})).catch((e=>(console.error("Fetch error:",e),{err:e?.message||String(e)||"Network error"})))}(c,p,"PIH-Appointment-Widget",s);return u},p=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};console.log("initiateConsultation -> config",t);const n=`${t.apiBaseUrl.replace(/\/$/,"")}${l}`,o=t.appToken||"";return async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=arguments.length>4?arguments[4]:void 0;const a=new URL(e);Object.keys(n).forEach((e=>{a.searchParams.append(e,n[e])}));const i={"Content-Type":"application/json"};o&&(i.Authorization=o);const r={method:"POST",headers:i,body:JSON.stringify(t)};return fetch(a.toString(),r).then((async e=>{const t=await e.json().catch((()=>({})));return e.ok?t:{err:t?.resultInfo?.message||"Something went wrong!",status:e.status}})).catch((e=>(console.error("Fetch error:",e),{err:e.message||"Network error"})))}(n,{patientId:String(e.patientId||""),primaryPatientId:String(e.primaryPatientId||e.patientId||""),hospitalId:t.hospitalId,doctorId:String(t.doctorId),patientName:e.patientName||e.name||"",doctorName:e.doctorName||t.doctorName,appointmentId:String(e.id||e.appointmentId||e._id||"")},"PIH-Appointment-Widget",{},o)};const c="pih_appointment_idToken",u="pih_appointment_email",m="pih_appointment_appToken",f="pih_appointment_doctorId",x="pih_appointment_userName",g="pih_appointment_apiBaseUrl",h="pih_appointment_hospitalId",y=720,E="pih-appointment-widget",F="data-pih-widget";class w extends t.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){"undefined"!=typeof console&&console.error&&console.error("Appointment widget error:",e,t)}render(){return this.state.hasError?a.default.createElement("div",{className:E,[F]:"teleconsult-appointments",style:{fontFamily:'"Nunito", serif',background:"#F5F5F7",boxSizing:"border-box",minHeight:"100vh",display:"flex",alignItems:"center",justifyContent:"center",padding:"24px",textAlign:"center"}},a.default.createElement("div",{style:{maxWidth:"400px"}},a.default.createElement("div",{style:{fontSize:"48px",marginBottom:"16px"}},"⚠️"),a.default.createElement("h2",{style:{fontSize:"20px",fontWeight:700,color:"#1a1a1a",margin:"0 0 8px 0"}},"Something went wrong"),a.default.createElement("p",{style:{fontSize:"14px",color:"#666",margin:0,lineHeight:1.5}},"Please refresh the page or try again later."))):this.props.children}}const b=e=>{let{config:n={}}=e;const[o,i]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(g):null}catch{return null}})),[r,l]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(h):null}catch{return null}})),b=n.apiBaseUrl||o||"https://afiyaapiqa.powermindinc.com",S=n.hospitalId||r,[v,k]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(c):null}catch{return null}})),[C,I]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(u):null}catch{return null}})),D=n.idToken||n.token||v,z=n.email||C;t.useEffect((()=>{try{if("undefined"==typeof localStorage)return;const e=n.idToken||n.token;if(e&&String(e).trim()){localStorage.getItem(c)!==e&&(M(null),A(null),N(null),localStorage.removeItem(m),localStorage.removeItem(f),localStorage.removeItem(x)),localStorage.setItem(c,e),k(e)}n.email&&String(n.email).trim()&&(localStorage.setItem(u,n.email),I(n.email)),n.apiBaseUrl&&String(n.apiBaseUrl).trim()&&(localStorage.setItem(g,n.apiBaseUrl.trim()),i(n.apiBaseUrl.trim())),null!=n.hospitalId&&String(n.hospitalId).trim()&&(localStorage.setItem(h,String(n.hospitalId).trim()),l(String(n.hospitalId).trim()))}catch(e){}}),[n.idToken,n.token,n.email,n.apiBaseUrl,n.hospitalId]);const[W,M]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(m):null}catch{return null}})),[T,A]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(f):null}catch{return null}})),[R,N]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(x):null}catch{return null}})),[P,j]=t.useState((()=>{try{if("undefined"==typeof localStorage)return!1;const e=localStorage.getItem(m),t=localStorage.getItem(c),n=localStorage.getItem(u);return!e&&!(!t||!n)}catch{return!1}})),[B,H]=t.useState(null),[L,U]=t.useState(!1),[$,_]=t.useState(0);t.useEffect((()=>{W&&P&&j(!1)}),[W,P]),t.useEffect((()=>{W||(D&&z?(U(!1),H((e=>"Sign in required. Redirecting to home..."===e?null:e))):(H("Sign in required. Redirecting to home..."),U(!0)))}),[W,D,z]),t.useEffect((()=>{if(!L)return;const e=n.homeUrl||"https://wbaemrdevittisalwe01-fnapdpfme7bvduhh.westeurope-01.azurewebsites.net/";if(!e||"undefined"==typeof window)return;const t=setTimeout((()=>{window.location.href=e}),2500);return()=>clearTimeout(t)}),[L,n.homeUrl]),t.useEffect((()=>{if(!P)return;const e=setTimeout((()=>{H("Request timed out. Please try again."),j(!1)}),3e4);return()=>clearTimeout(e)}),[P]);const Y=n.joinCallUrl||d;W&&String(Y||"").replace(/\/?$/,"/");const O=function(e){if(!e||"string"!=typeof e)return{};try{const t=e.split(".");if(3!==t.length)return{};const n=t[1].replace(/-/g,"+").replace(/_/g,"/"),o=n.padEnd(n.length+(4-n.length%4)%4,"=");return JSON.parse(atob(o))}catch{return{}}}(D),V=R||O.name||O.sub||"User",q=()=>(new Date).toISOString().split("T")[0],X=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,[G,J]=t.useState("upcoming"),[K,Q]=t.useState([]),[Z,ee]=t.useState(null),[te,ne]=t.useState(!1),[oe,ae]=t.useState(null),[ie,re]=t.useState(window.innerWidth<768),[le,de]=t.useState("today"),[se,pe]=t.useState("today"),[ce,ue]=t.useState(!1),[me,fe]=t.useState(!1),[xe,ge]=t.useState("all"),[he,ye]=t.useState("asc"),[Ee,Fe]=t.useState(""),[we,be]=t.useState(!1),[Se,ve]=t.useState(!1),[ke,Ce]=t.useState(!1),[Ie,De]=t.useState(null),[ze,We]=t.useState(null),[Me,Te]=t.useState(!1),[Ae,Re]=t.useState(null),[Ne,Pe]=t.useState((()=>({x:Math.max(20,"undefined"!=typeof window?window.innerWidth-y-20:300),y:80}))),[je,Be]=t.useState({width:y,height:560}),[He,Le]=t.useState(!1),[Ue,$e]=t.useState({x:0,y:0}),[_e,Ye]=t.useState(!1),[Oe,Ve]=t.useState(null),[qe,Xe]=t.useState({x:0,y:0,width:0,height:0});t.useState(!1);const[Ge,Je]=t.useState(1),Ke=K.filter((e=>{if(!Ee.trim())return!0;const t=Ee.toLowerCase(),n=(e.patientName||"").toLowerCase(),o=String(e.patientId||"").toLowerCase();return n.includes(t)||o.includes(t)})),Qe=20*(Ge-1),Ze=Qe+20,et=Ke.slice(Qe,Ze),tt=Math.ceil(Ke.length/20),nt=Ke.length,[ot,at]=t.useState(q()),[it,rt]=t.useState(q()),[lt,dt]=t.useState(),[st,pt]=t.useState(),ct=e=>e?.id||e?._id||e?.appointmentId||e?.patientId||JSON.stringify(e),ut=e=>e?.image?e.image:null,mt=e=>e?e.charAt(0).toUpperCase():"?",ft=e=>{if(!e)return"#4C4DDC";const t=["#4C4DDC","#1CC3CE","#FF6B6B","#4ECDC4","#45B7D1","#FFA07A","#98D8C8","#F7DC6F"];return t[e.charCodeAt(0)%t.length]},xt=()=>{const e="asc"===he?"desc":"asc";ye(e);const t=[...K].sort(((t,n)=>{const o=new Date(t.appointmentDate||t.date||0),a=new Date(n.appointmentDate||n.date||0);return"asc"===e?o-a:a-o}));Q(t),Je(1),t.length>0&&ee(t[0])},gt=t.useCallback((async()=>{if(!W)return;console.log(T,"fetchAppointments -> doctorIdFromLogin");const e=T;ne(!0),ae(null);try{const t={apiBaseUrl:b,hospitalId:S,doctorId:e,token:W},n=await s(G,ot,it,t);if(401===n.status||403===n.status){try{"undefined"!=typeof localStorage&&(localStorage.removeItem(m),localStorage.removeItem(f),localStorage.removeItem(x))}catch(e){}return M(null),A(null),N(null),_((e=>e+1)),void ae("Session expired. Re-authenticating...")}if(n.err)return void ae(String(n.err||"Failed to fetch appointments"));const o=n.data||n.appointments||n||[];Q(Array.isArray(o)?o:[]),Array.isArray(o)&&o.length>0?ee(o[0]):ee(null)}catch(e){console.error("Error fetching appointments:",e),ae(e.message||"Failed to fetch appointments")}finally{ne(!1)}}),[G,ot,it,xe,b,S,T,W]),ht=e=>{ee(e),Re(null)},yt=async()=>{if(Z&&W){Te(!0),Re(null);try{const e={apiBaseUrl:b,hospitalId:S,doctorId:T,doctorName:R||V,appToken:W};console.log(Z,"selectedAppointment"),console.log(e,"callConfig");const t=await p(Z,e);if(console.log(t.status,"response"),401===t.status||403===t.status){try{"undefined"!=typeof localStorage&&(localStorage.removeItem(m),localStorage.removeItem(f),localStorage.removeItem(x))}catch(e){}return M(null),A(null),N(null),_((e=>e+1)),void Re("Session expired. Re-authenticating...")}if(t.err||!t.data?.token)return void Re(String(t.err||"Failed to initiate call"));const o=n.joinCallUrl||d,a=t.data.token?String(o||"").replace(/\/?$/,"/")+t.data.token:"";console.log("joinCallUrl",a),De(t.data.token),We(a||""),be(!0),ve(!1),Ce(!1),Be({width:y,height:560}),Pe({x:Math.max(20,window.innerWidth-y-20),y:80})}catch(e){Re(e.message||"Failed to initiate call")}finally{Te(!1)}}},Et=()=>{be(!1),ve(!1),Ce(!1),De(null),We(null),Re(null),gt()};t.useEffect((()=>{if(!we)return;window.history.pushState({pipActive:!0},"");const e=()=>{be(!1),ve(!1),Ce(!1),De(null),We(null),Re(null),window.history.back()};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[we]);const Ft=()=>{ke&&Ce(!1),ve(!Se)},wt=()=>{Se&&ve(!1),Ce(!ke)},bt=e=>{if(0!==e.button)return;if(e.target.closest("button"))return;e.currentTarget.setPointerCapture&&e.currentTarget.setPointerCapture(e.pointerId),Le(!0);const t=e.currentTarget.getBoundingClientRect();$e({x:e.clientX-t.left,y:e.clientY-t.top})},St=t.useCallback((e=>{if(!ke)if(He){const t=e.clientX-Ue.x,n=e.clientY-Ue.y,o=window.innerWidth-je.width,a=window.innerHeight-je.height;Pe({x:Math.max(0,Math.min(t,o)),y:Math.max(0,Math.min(n,a))})}else if(_e){const t=e.clientX-qe.x,n=e.clientY-qe.y;let o=qe.width,a=qe.height,i=qe.posX,r=qe.posY;const l=300,d=250,s=window.innerWidth-40,p=window.innerHeight-100;if("bottom-right"===Oe)o=Math.min(Math.max(qe.width+t,l),s),a=Math.min(Math.max(qe.height+n,d),p),i+o>window.innerWidth&&(o=window.innerWidth-i),r+a>window.innerHeight&&(a=window.innerHeight-r);else if("bottom-left"===Oe){o=Math.min(Math.max(qe.width-t,l),s),i=Math.max(0,qe.posX+t),0===i&&(o=qe.posX+qe.width),a=Math.min(Math.max(qe.height+n,d),p),r+a>window.innerHeight&&(a=window.innerHeight-r)}else if("top-right"===Oe){o=Math.min(Math.max(qe.width+t,l),s),i+o>window.innerWidth&&(o=window.innerWidth-i);a=Math.min(Math.max(qe.height-n,d),p),r=Math.max(0,qe.posY+n),0===r&&(a=qe.posY+qe.height)}else if("top-left"===Oe){o=Math.min(Math.max(qe.width-t,l),s),i=Math.max(0,qe.posX+t),0===i&&(o=qe.posX+qe.width);a=Math.min(Math.max(qe.height-n,d),p),r=Math.max(0,qe.posY+n),0===r&&(a=qe.posY+qe.height)}Be({width:o,height:a}),Pe({x:i,y:r})}}),[He,_e,Ue,Oe,qe,Ne,je,ke]),vt=()=>{Le(!1),Ye(!1),Ve(null)},kt=(e,t)=>{t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture&&t.currentTarget.setPointerCapture(t.pointerId),Ye(!0),Ve(e),Xe({x:t.clientX,y:t.clientY,width:je.width,height:je.height,posX:Ne.x,posY:Ne.y})};t.useEffect((()=>{if(!we||ke)return;const e=()=>{if(!(window.innerWidth<768)){const e=Se?350:je.width,t=Se?60:je.height,n=window.innerWidth-40,o=window.innerHeight-100,a=Math.min(e,n),i=Math.min(t,o);a===je.width&&i===je.height||Be({width:a,height:i});const r=window.innerWidth-a-20,l=window.innerHeight-i-20;Pe((e=>({x:Math.min(e.x,r),y:Math.min(e.y,l)})))}};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)}),[we,Se,ke,je]),t.useEffect((()=>{if(!(D&&z&&(!W||$>0)))return;let e=!1;return j(!0),H(null),(async(e,t,n,o)=>{const a=`${e.replace(/\/$/,"")}/um/user/V1/sso/login?hospitalId=${encodeURIComponent(t)}`,i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({idToken:n,email:o})};return console.log("[getTokenFromSso] request",{url:a,body:{idToken:n?n.slice(0,50)+"...":null,email:o}}),fetch(a,i).then((e=>(console.log("[getTokenFromSso] response status",e.status,e.statusText),e.ok?e.json().then((e=>(console.log("[getTokenFromSso] success",{hasData:!!e,dataKeys:e?Object.keys(e):[],hasAccessToken:!!e?.data?.access_token}),e))):e.json().then((t=>{const n=t?.resultInfo?.message||"SSO login failed";return console.log("[getTokenFromSso] error body",t),{err:n,status:e.status}})).catch((()=>({err:"Something went wrong!",status:e.status})))))).catch((e=>(console.error("[getTokenFromSso] catch",e),{err:e.message||"Network error"})))})(b,S,D,z).then((t=>{if(e)return;const n=function(e){return!e||e.err?null:e.data?.access_token??e.data?.token??e.token??e.accessToken??null}(t);if(400===t.status)return H(t.err||"Invalid request. Redirecting to home..."),j(!1),void U(!0);if(t.err||!n){H(String(t.err||"Failed to get token")),M(null),A(null),N(null);try{"undefined"!=typeof localStorage&&(localStorage.removeItem(m),localStorage.removeItem(f),localStorage.removeItem(x))}catch(e){}}else{const e=function(e){if(!e?.data)return null;const t=e.data.doctor_id??e.data.doctorId??null;return console.log(t,"extractDoctorIdFromLoginResponse -> id"),null!=t?String(t):null}(t);console.log(e,"extractDoctorIdFromLoginResponse -> doctorId");const o=function(e){if(!e?.data)return null;const t=e.data.name??e.data.doctor_name??e.data.userName??null;return null!=t?String(t):null}(t);M(n),A(e),N(o),H(null),U(!1);try{"undefined"!=typeof localStorage&&(localStorage.setItem(m,n),e&&localStorage.setItem(f,e),o&&localStorage.setItem(x,o))}catch(e){}}})).catch((()=>{})).finally((()=>{e||j(!1)})),()=>{e=!0}}),[b,S,D,z,$]),t.useEffect((()=>{Je(1),Re(null)}),[G,le,ot,it,Ee,xe]),t.useEffect((()=>{!P&&W&&gt()}),[gt,W,P]),t.useEffect((()=>{const e=document.createElement("link");e.href="https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,200..1000;1,200..1000&display=swap",e.rel="stylesheet",document.head.appendChild(e);const t=document.createElement("style");t.innerHTML="\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n \n @media (max-width: 768px) {\n .appointments-grid {\n grid-template-columns: 1.5fr 1fr 0.8fr !important;\n }\n .appointments-header-grid {\n grid-template-columns: 1.5fr 1fr 0.8fr !important;\n }\n .hide-on-mobile {\n display: none !important;\n }\n }\n @media (max-width: 480px) {\n .appointments-header-grid {\n font-size: 10px !important;\n }\n .appointments-grid {\n font-size: 11px !important;\n }\n }\n ",document.head.appendChild(t);const n=()=>{re(window.innerWidth<768)};return window.addEventListener("resize",n),()=>{document.head.removeChild(e),document.head.removeChild(t),window.removeEventListener("resize",n)}}),[]),t.useEffect((()=>{const e=e=>{!ce||e.target.closest("button")||e.target.closest('input[type="date"]')||ue(!1),me&&!e.target.closest("[data-appointment-type-picker]")&&fe(!1)};return document.addEventListener("click",e),()=>{document.removeEventListener("click",e)}}),[ce,me]);let Ct='"Nunito", serif';const It=B||!W&&(!D||!z),Dt=B||"Sign in required. Redirecting to home...";let zt;return zt=P&&D&&z?a.default.createElement("div",{className:E,[F]:"teleconsult-appointments",style:{fontFamily:Ct,background:"#F5F5F7",boxSizing:"border-box",height:"100%",minHeight:"100vh",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"24px"}},a.default.createElement("style",null,"@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }"),a.default.createElement("div",{style:{width:"40px",height:"40px",border:"3px solid #f3f3f3",borderTop:"3px solid #4C4DDC",borderRadius:"50%",animation:"spin 1s linear infinite",marginBottom:"16px"}}),a.default.createElement("p",{style:{fontSize:"14px",color:"#666",margin:0}},"Checking authorisation...")):a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{className:E,[F]:"teleconsult-appointments",style:{fontFamily:Ct,background:"#F5F5F7",boxSizing:"border-box",height:"100%",minHeight:"100vh",width:"100%",display:"flex",flexDirection:"column",overflow:"hidden"}},a.default.createElement("div",{style:{background:"#FFFFFF",padding:ie?"10px 12px":"12px 24px",display:"flex",justifyContent:"space-between",alignItems:"center",borderBottom:"1px solid #E5E5E5",flexWrap:"nowrap",gap:ie?"8px":"0"}},a.default.createElement("div",{style:{position:"relative",width:ie?"calc(100% - 90px)":"480px",maxWidth:ie?"none":"480px"}},a.default.createElement("input",{type:"text",placeholder:"Search by patient name or ID",value:Ee,onChange:e=>Fe(e.target.value),style:{width:"100%",padding:ie?"8px 32px 8px 10px":"8px 36px 8px 14px",border:"1px solid #E5E5E5",borderRadius:"6px",fontSize:ie?"12px":"13px",fontFamily:Ct,background:"#FFFFFF",outline:"none",boxSizing:"border-box"}}),Ee&&a.default.createElement("button",{onClick:()=>Fe(""),style:{position:"absolute",right:"8px",top:"50%",transform:"translateY(-50%)",background:"none",border:"none",cursor:"pointer",padding:"4px",display:"flex",alignItems:"center",justifyContent:"center",color:"#999",fontSize:"16px"},title:"Clear search"},"✕")),!1),a.default.createElement("div",{style:{padding:ie?"12px":"16px 24px",flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"}},a.default.createElement("div",{style:{marginBottom:ie?"10px":"14px"}},a.default.createElement("h1",{style:{fontSize:ie?"18px":"22px",fontWeight:700,color:"#1a1a1a",margin:"0 0 2px 0"}},"Tele Consultation"),a.default.createElement("p",{style:{fontSize:ie?"11px":"12px",color:"#999",margin:0}},"Displaying All Tele Consultation Appointments")),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:ie?"flex-start":"center",marginBottom:ie?"10px":"14px",flexDirection:ie?"column":"row",gap:ie?"12px":"0"}},a.default.createElement("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",width:ie?"100%":"auto"}},a.default.createElement("button",{onClick:()=>J("upcoming"),style:{background:"upcoming"===G?"#4C4DDC":"#FFFFFF",padding:ie?"8px 10px":"9px 16px",border:"upcoming"===G?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ie?"10px":"13px",color:"upcoming"===G?"white":"#555555",fontWeight:600,fontFamily:Ct,cursor:"pointer",flex:ie?"1 1 auto":"none",minWidth:ie?"0":"auto",transition:"all 0.3s ease",whiteSpace:"nowrap"}},"Upcoming Appointments"),a.default.createElement("button",{onClick:()=>J("completed"),style:{background:"completed"===G?"#4C4DDC":"#FFFFFF",padding:ie?"8px 10px":"9px 16px",border:"completed"===G?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ie?"10px":"13px",color:"completed"===G?"white":"#555555",fontWeight:600,fontFamily:Ct,cursor:"pointer",flex:ie?"1 1 auto":"none",minWidth:ie?"0":"auto",transition:"all 0.3s ease",whiteSpace:"nowrap"}},"Completed Appointments"),a.default.createElement("button",{onClick:()=>J("cancelled"),style:{background:"cancelled"===G?"#4C4DDC":"#FFFFFF",padding:ie?"8px 10px":"9px 16px",border:"cancelled"===G?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ie?"10px":"13px",color:"cancelled"===G?"white":"#555555",fontWeight:600,fontFamily:Ct,cursor:"pointer",flex:ie?"1 1 auto":"none",minWidth:ie?"0":"auto",transition:"all 0.3s ease",whiteSpace:"nowrap"}},"Cancelled Appointments")),a.default.createElement("div",{style:{display:"flex",gap:"8px",alignItems:"center",width:"auto",position:"relative",justifyContent:ie?"flex-start":"flex-end",flexWrap:"wrap"}},a.default.createElement("button",{onClick:()=>{ce||(dt(ot),pt(it),pe(le)),ue(!ce)},style:{padding:"8px 12px",fontFamily:Ct,fontWeight:600,border:"1px solid #E5E5E5",borderRadius:"6px",fontSize:ie?"11px":"13px",color:"#1a1a1a",background:"#FFFFFF",display:"flex",alignItems:"center",gap:ie?"4px":"6px",cursor:"pointer",flex:"none",minWidth:ie?"100px":"auto",justifyContent:"center"}},a.default.createElement("svg",{width:ie?"12":"14",height:ie?"12":"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a.default.createElement("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"}),a.default.createElement("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),a.default.createElement("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),a.default.createElement("line",{x1:"3",y1:"10",x2:"21",y2:"10"})),a.default.createElement("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},(()=>{switch(le){case"today":default:return"Today";case"tomorrow":return"Tomorrow";case"currentWeek":return"Current Week";case"thisMonth":return"This Month";case"currentYear":return"Current Year";case"custom":return ie?"Custom":`${ot} to ${it}`}})()),a.default.createElement("svg",{width:ie?"8":"10",height:ie?"8":"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a.default.createElement("polyline",{points:"6 9 12 15 18 9"}))),ce&&a.default.createElement("div",{style:{position:"absolute",top:"100%",right:ie?"auto":0,left:ie?0:"auto",marginTop:"4px",background:"#FFFFFF",border:"1px solid #E5E5E5",borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.15)",padding:"8px",zIndex:1e3,minWidth:ie?"280px":"240px",width:ie?"calc(100vw - 24px)":"auto",maxWidth:ie?"calc(100vw - 24px)":"280px"}},a.default.createElement("div",{style:{marginBottom:"custom"===se?"12px":"0"}},["thisMonth","today","tomorrow","currentWeek","currentYear","custom"].map((e=>a.default.createElement("button",{key:e,onClick:()=>{if(pe(e),"custom"!==e){const t=(e=>{const t=new Date;let n,o;switch(e){case"today":default:n=o=q();break;case"tomorrow":const e=new Date(t);e.setDate(e.getDate()+1),n=o=X(e);break;case"currentWeek":const a=new Date(t),i=new Date(t),r=t.getDay(),l=0===r?-6:1-r;a.setDate(t.getDate()+l),i.setDate(a.getDate()+6),n=X(a),o=X(i);break;case"thisMonth":const d=new Date(t.getFullYear(),t.getMonth(),1),s=new Date(t.getFullYear(),t.getMonth()+1,0);n=X(d),o=X(s);break;case"currentYear":n=`${t.getFullYear()}-01-01`,o=`${t.getFullYear()}-12-31`}return{from:n,to:o}})(e);de(e),at(t.from),rt(t.to),dt(t.from),pt(t.to),ue(!1)}else dt(""),pt("")},style:{width:"100%",padding:"10px 12px",background:se===e?"#E8EEF4":"#FFFFFF",border:"none",borderRadius:"4px",fontSize:"13px",fontFamily:Ct,cursor:"pointer",textAlign:"left",fontWeight:se===e?600:400,color:se===e?"#4C4DDC":"#1a1a1a",marginBottom:"4px",display:"flex",justifyContent:"space-between",alignItems:"center",transition:"all 0.2s ease"},onMouseEnter:t=>{se!==e&&(t.target.style.background="#F5F5F5")},onMouseLeave:t=>{se!==e&&(t.target.style.background="#FFFFFF")}},a.default.createElement("span",null,{thisMonth:"This Month",today:"Today",tomorrow:"Tomorrow",currentWeek:"Current Week",currentYear:"Current Year",custom:"Custom"}[e]),se===e&&a.default.createElement("span",{style:{color:"#4C4DDC",fontSize:"16px"}},"✓"))))),"custom"===se&&a.default.createElement("div",{style:{paddingTop:"8px",borderTop:"1px solid #E5E5E5"}},a.default.createElement("div",{style:{marginBottom:"8px"}},a.default.createElement("input",{type:"date",value:lt,onChange:e=>dt(e.target.value),placeholder:"Start Date",style:{width:"100%",padding:"10px 8px",border:"1px solid #E5E5E5",borderRadius:"4px",fontSize:"13px",fontFamily:Ct,boxSizing:"border-box",cursor:"pointer"}})),a.default.createElement("div",{style:{marginBottom:"12px"}},a.default.createElement("input",{type:"date",value:st,onChange:e=>pt(e.target.value),placeholder:"End Date",style:{width:"100%",padding:"10px 8px",border:"1px solid #E5E5E5",borderRadius:"4px",fontSize:"13px",fontFamily:Ct,boxSizing:"border-box",cursor:"pointer"}})),a.default.createElement("div",{style:{display:"flex",gap:"8px"}},a.default.createElement("button",{onClick:()=>{pe(le),dt(ot),pt(it),ue(!1)},style:{flex:1,padding:"10px 12px",background:"#FFFFFF",color:"#4C4DDC",border:"1px solid #4C4DDC",borderRadius:"4px",fontSize:"13px",fontFamily:Ct,fontWeight:600,cursor:"pointer"}},"Cancel"),a.default.createElement("button",{onClick:()=>{lt&&st&&(de("custom"),at(lt),rt(st),ue(!1))},style:{flex:1,padding:"10px 12px",background:"#4C4DDC",color:"#FFFFFF",border:"none",borderRadius:"4px",fontSize:"13px",fontFamily:Ct,fontWeight:600,cursor:"pointer"}},"Submit")))))),a.default.createElement("div",{style:{display:"flex",flexDirection:ie?"column":"row",gap:ie?"12px":"14px",flex:1,minHeight:0,overflow:ie?"auto":"hidden"}},a.default.createElement("div",{style:{flex:ie?"none":"1 1 65%",width:ie?"100%":"auto",display:"flex",flexDirection:"column",minHeight:ie?"400px":0}},a.default.createElement("div",{style:{background:"#FFFFFF",borderRadius:"8px",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden",display:"flex",flexDirection:"column",flex:ie?"none":1,minHeight:ie?"auto":0}},a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:ie?"12px 14px":"14px 18px",borderBottom:"1px solid #F1F1F1"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ie?"6px":"8px"}},a.default.createElement("span",{style:{fontSize:ie?"14px":"15px",fontWeight:700,color:"#1a1a1a"}},"Appointments"),a.default.createElement("span",{style:{background:"#4C4DDC",color:"#fff",fontSize:ie?"10px":"11px",fontWeight:600,padding:ie?"2px 7px":"3px 8px",borderRadius:"12px"}},nt))),a.default.createElement("div",{className:"appointments-header-grid",style:{display:"grid",gridTemplateColumns:ie?"1.5fr 1fr 0.8fr":"2.5fr 1fr 1.5fr 0.8fr 1.2fr",gap:ie?"8px":"12px",padding:ie?"8px 12px":"10px 18px",background:"#F5F5F5",fontSize:ie?"10px":"12px",fontWeight:600,color:"#666"}},a.default.createElement("div",null,"Patients name"),!ie&&a.default.createElement("div",null,"Patient ID"),a.default.createElement("div",{onClick:xt,style:{display:"flex",alignItems:"center",gap:"3px",cursor:"pointer",userSelect:"none"}},"Date",a.default.createElement("span",{style:{opacity:.7,fontSize:"10px"}},"asc"===he?"▲":"▼")),!ie&&a.default.createElement("div",null,"Slot"),!ie&&a.default.createElement("div",null,"Doctor")),a.default.createElement("div",{style:{overflow:"auto",flex:1}},P?a.default.createElement("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",padding:"40px",color:"#888"}},a.default.createElement("div",{style:{textAlign:"center"}},a.default.createElement("div",{style:{width:"40px",height:"40px",border:"3px solid #f3f3f3",borderTop:"3px solid #4C4DDC",borderRadius:"50%",animation:"spin 1s linear infinite",margin:"0 auto 10px"}}),"Getting token...")):te?a.default.createElement("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",padding:"40px",color:"#888"}},a.default.createElement("div",{style:{textAlign:"center"}},a.default.createElement("div",{style:{width:"40px",height:"40px",border:"3px solid #f3f3f3",borderTop:"3px solid #4C4DDC",borderRadius:"50%",animation:"spin 1s linear infinite",margin:"0 auto 10px"}}),"Loading appointments...")):oe?a.default.createElement("div",{style:{padding:"40px",textAlign:"center",color:"#FF0000"}},a.default.createElement("div",{style:{fontSize:"16px",marginBottom:"8px"}},"⚠️ Error"),a.default.createElement("div",{style:{fontSize:"13px"}},oe),a.default.createElement("button",{onClick:gt,style:{marginTop:"16px",padding:"8px 16px",background:"#4C4DDC",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontFamily:Ct}},"Retry")):0===et.length?a.default.createElement("div",{style:{padding:"40px",textAlign:"center",color:"#888"}},a.default.createElement("div",{style:{fontSize:"16px",marginBottom:"8px"}},"📋"),a.default.createElement("div",{style:{fontSize:"13px"}},Ee?`No appointments found for "${Ee}"`:"No appointments found"),Ee&&a.default.createElement("button",{onClick:()=>Fe(""),style:{marginTop:"12px",padding:"6px 12px",background:"#4C4DDC",color:"white",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"12px",fontFamily:Ct}},"Clear Search")):et.map((e=>a.default.createElement("div",{key:ct(e),role:"button",tabIndex:0,onClick:()=>ht(e),onKeyDown:t=>"Enter"===t.key&&ht(e),className:"appointments-grid",style:{display:"grid",gridTemplateColumns:ie?"1.5fr 1fr 0.8fr":"2.5fr 1fr 1.5fr 0.8fr 1.2fr",gap:ie?"8px":"12px",padding:ie?"10px 12px":"12px 18px",background:ct(Z)===ct(e)?"#E8EEF4":"#FFFFFF",borderTop:"1px solid #F1F1F1",alignItems:"center",cursor:"pointer",fontSize:ie?"11px":"13px"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ie?"8px":"10px"}},ut(e)?a.default.createElement("img",{src:e.image,alt:"",style:{width:ie?"32px":"36px",height:ie?"32px":"36px",borderRadius:"50%",objectFit:"cover"}}):a.default.createElement("div",{style:{width:ie?"32px":"36px",height:ie?"32px":"36px",borderRadius:"50%",background:ft(e.patientName),display:"flex",alignItems:"center",justifyContent:"center",color:"#FFFFFF",fontWeight:600,fontSize:ie?"14px":"16px"}},mt(e.patientName)),a.default.createElement("div",null,a.default.createElement("div",{style:{fontWeight:600,color:"#1a1a1a",fontSize:ie?"11px":"13px"}},e.patientName),a.default.createElement("div",{style:{fontSize:ie?"9px":"11px",color:"#888"}},e.email))),!ie&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.patientId),a.default.createElement("div",{style:{color:"#555",fontSize:ie?"10px":"12px"}},(()=>{const t=e.appointmentDate||"",n=t.match(/\s(\d{1,2}:\d{2}(?:\s*(?:AM|PM))?)$/i);return n?a.default.createElement(a.default.Fragment,null,a.default.createElement("div",null,t.slice(0,n.index).trim()),a.default.createElement("div",{style:{fontSize:ie?"9px":"11px",color:"#888"}},n[1].trim())):a.default.createElement("div",null,t)})()),!ie&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.appointmentTime||"-"),!ie&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.doctorName||e.doctor||"-"))))),!te&&!oe&&et.length>0&&a.default.createElement("div",{style:{padding:ie?"12px 14px":"14px 18px",borderTop:"1px solid #F1F1F1",display:"flex",justifyContent:"space-between",alignItems:"center",background:"#FFFFFF",flexWrap:ie?"wrap":"nowrap",gap:ie?"10px":"0"}},a.default.createElement("div",{style:{fontSize:ie?"11px":"12px",color:"#666"}},"Showing page ",Ge," of ",tt," (",nt," total)"),a.default.createElement("div",{style:{display:"flex",gap:"6px",alignItems:"center"}},a.default.createElement("button",{onClick:()=>Je((e=>Math.max(1,e-1))),disabled:1===Ge,style:{padding:ie?"6px 10px":"6px 12px",border:"1px solid #E5E5E5",borderRadius:"4px",background:1===Ge?"#F5F5F5":"#FFFFFF",color:1===Ge?"#999":"#1a1a1a",fontSize:ie?"11px":"12px",fontFamily:Ct,fontWeight:600,cursor:1===Ge?"not-allowed":"pointer",opacity:1===Ge?.5:1}},"Previous"),a.default.createElement("div",{style:{display:"flex",gap:"4px"}},[...Array(Math.min(5,tt))].map(((e,t)=>{let n;return n=tt<=5||Ge<=3?t+1:Ge>=tt-2?tt-4+t:Ge-2+t,a.default.createElement("button",{key:n,onClick:()=>Je(n),style:{padding:ie?"6px 10px":"6px 12px",border:Ge===n?"none":"1px solid #E5E5E5",borderRadius:"4px",background:Ge===n?"#4C4DDC":"#FFFFFF",color:Ge===n?"#FFFFFF":"#1a1a1a",fontSize:ie?"11px":"12px",fontFamily:Ct,fontWeight:600,cursor:"pointer",minWidth:ie?"32px":"36px"}},n)}))),a.default.createElement("button",{onClick:()=>Je((e=>Math.min(tt,e+1))),disabled:Ge===tt,style:{padding:ie?"6px 10px":"6px 12px",border:"1px solid #E5E5E5",borderRadius:"4px",background:Ge===tt?"#F5F5F5":"#FFFFFF",color:Ge===tt?"#999":"#1a1a1a",fontSize:ie?"11px":"12px",fontFamily:Ct,fontWeight:600,cursor:Ge===tt?"not-allowed":"pointer",opacity:Ge===tt?.5:1}},"Next"))))),a.default.createElement("div",{style:{flex:ie?"none":"1 1 35%",width:ie?"100%":"auto",display:Z||!ie?"flex":"none",flexDirection:"column",minHeight:ie?"auto":0}},a.default.createElement("div",{style:{border:"1px solid #E5E5E5",borderRadius:"8px",overflow:"hidden",background:"#FFFFFF",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",display:"flex",flexDirection:"column",flex:ie?"none":1,minHeight:ie?"auto":0}},Z?a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:ie?"12px 14px":"16px 18px",background:"#E8EEF4",borderBottom:"1px solid #E5E5E5"}},a.default.createElement("div",null,a.default.createElement("div",{style:{color:"#002668",fontSize:ie?"14px":"16px",fontWeight:"700"}},Z.patientName||"N/A"),a.default.createElement("div",{style:{color:"#002668",fontSize:ie?"11px":"13px"}},Z.patientId||Z.mrn||"N/A")),a.default.createElement("div",null,ut(Z)?a.default.createElement("img",{style:{width:ie?"36px":"44px",height:ie?"36px":"44px",borderRadius:"50%",objectFit:"cover"},src:Z.image,alt:Z.patientName}):a.default.createElement("div",{style:{width:ie?"36px":"44px",height:ie?"36px":"44px",borderRadius:"50%",background:ft(Z.patientName),display:"flex",alignItems:"center",justifyContent:"center",color:"#FFFFFF",fontWeight:700,fontSize:ie?"16px":"20px"}},mt(Z.patientName)))),a.default.createElement("div",{style:{padding:ie?"12px 14px":"14px 18px",gap:ie?"10px":"12px",display:"flex",flexDirection:"column",background:"white",overflow:"auto",flex:1,position:"relative"}},a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between"}},a.default.createElement("div",{style:{textAlign:"left"}},a.default.createElement("div",{style:{fontSize:ie?"10px":"11px",color:"#888",marginBottom:"3px"}},"Speciality"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ie?"12px":"13px"}},Z?.specialisation||Z?.speciality||"N/A")),a.default.createElement("div",{style:{textAlign:"right"}},a.default.createElement("div",{style:{fontSize:ie?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Type"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ie?"12px":"13px"}},Z?.type||Z?.appointmentType||"Online"))),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between"}},a.default.createElement("div",{style:{textAlign:"left"}},a.default.createElement("div",{style:{fontSize:ie?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Date"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ie?"12px":"13px"}},Z?.date||Z?.appointmentDate||"N/A")),a.default.createElement("div",{style:{textAlign:"right"}},a.default.createElement("div",{style:{fontSize:ie?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Time"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ie?"12px":"13px"}},Z?.time||Z?.appointmentTime||"N/A"))),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between"}},a.default.createElement("div",{style:{textAlign:"left"}},a.default.createElement("div",{style:{fontSize:ie?"10px":"11px",color:"#888",marginBottom:"3px"}},"Doctor"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ie?"12px":"13px"}},Z?.doctor||Z?.doctorName||"N/A"))),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between"}},a.default.createElement("div",{style:{textAlign:"left"}},a.default.createElement("div",{style:{fontSize:ie?"10px":"11px",color:"#888",marginBottom:"3px"}},"Hospital"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ie?"12px":"13px"}},Z?.hospital||Z?.hospitalName||"N/A"))),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between"}},a.default.createElement("div",{style:{textAlign:"left"}},a.default.createElement("div",{style:{fontSize:ie?"10px":"11px",color:"#888",marginBottom:"3px"}},"Reason for Appointment"),a.default.createElement("div",{style:{fontWeight:"600",fontSize:ie?"11px":"12px",lineHeight:"1.4"}},Z?.reason||Z?.reasonForAppointment||"No reason provided"))),"upcoming"===G&&a.default.createElement("div",{style:{display:"flex",flexDirection:ie?"column":"row",gap:"6px",marginTop:"10px"}},a.default.createElement("button",{type:"button",onClick:yt,disabled:Me,style:{flex:1,background:Me?"#99e4e8":"#1CC3CE",color:"#FFFFFF",border:"1px solid #1CC3CE",borderRadius:"6px",padding:ie?"10px 8px":"8px 6px",fontFamily:Ct,fontWeight:600,fontSize:ie?"11px":"12px",cursor:Me?"not-allowed":"pointer"}},Me?"Connecting...":"Join Call >")),"upcoming"===G&&Ae&&a.default.createElement("div",{style:{fontSize:"11px",color:"#e53935",marginTop:"6px",textAlign:"center",width:"100%"}},"⚠️ ",Ae))):a.default.createElement("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%",padding:"40px",color:"#888",textAlign:"center"}},a.default.createElement("div",null,a.default.createElement("div",{style:{fontSize:"16px",marginBottom:"8px"}},"📋"),a.default.createElement("div",{style:{fontSize:"13px"}},"Select an appointment to view details"))))))),we&&a.default.createElement("div",{style:{position:"fixed",left:ke?"0":ie?"10px":`${Ne.x}px`,top:ke?"0":ie?"70px":`${Ne.y}px`,right:ke?"0":ie?"10px":"auto",bottom:ke?"0":"auto",width:ke?"100vw":ie?"calc(100vw - 20px)":Se?"350px":`${je.width}px`,height:ke?"100vh":Se?"auto":ie?"300px":`${je.height}px`,background:"#FFFFFF",borderRadius:ke?"0":"8px",boxShadow:"0 8px 24px rgba(0, 0, 0, 0.3)",zIndex:1e5,overflow:"hidden",display:"flex",flexDirection:"column",transition:He||_e?"none":"all 0.3s ease"}},a.default.createElement("div",{onPointerDown:ie||ke?void 0:bt,onPointerMove:ie||ke?void 0:St,onPointerUp:ie||ke?void 0:vt,onPointerCancel:ie||ke?void 0:vt,style:{background:"linear-gradient(135deg, #4C4DDC 0%, #3A3BBD 100%)",color:"#FFFFFF",padding:ie?"8px 10px":"10px 12px",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:ie||ke?"default":"move",userSelect:"none"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ie?"6px":"8px",flex:1,minWidth:0}},a.default.createElement("div",{style:{width:ie?"6px":"8px",height:ie?"6px":"8px",borderRadius:"50%",background:"#FF4444",animation:"pulse 2s infinite",flexShrink:0}}),a.default.createElement("span",{style:{fontSize:ie?"11px":"13px",fontWeight:600,fontFamily:Ct,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},"Video Call - ",Z?.patientName||"Patient")),a.default.createElement("div",{style:{display:"flex",gap:ie?"4px":"6px",alignItems:"center",flexShrink:0}},a.default.createElement("button",{onClick:Ft,style:{background:"rgba(255, 255, 255, 0.2)",border:"1px solid rgba(255, 255, 255, 0.3)",borderRadius:"6px",color:"#FFFFFF",cursor:"pointer",padding:ie?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ie?"28px":"32px",height:ie?"28px":"32px",transition:"background 0.2s ease"},onMouseEnter:e=>e.target.style.background="rgba(255, 255, 255, 0.3)",onMouseLeave:e=>e.target.style.background="rgba(255, 255, 255, 0.2)",title:Se?"Restore":"Minimize"},Se?a.default.createElement("svg",{width:ie?"14":"16",height:ie?"14":"16",viewBox:"0 0 16 16",fill:"none"},a.default.createElement("rect",{x:"3",y:"3",width:"10",height:"10",stroke:"white",strokeWidth:"1.8",fill:"none"})):a.default.createElement("svg",{width:ie?"14":"16",height:ie?"14":"16",viewBox:"0 0 16 16",fill:"none"},a.default.createElement("line",{x1:"3",y1:"8",x2:"13",y2:"8",stroke:"white",strokeWidth:"1.8",strokeLinecap:"round"}))),a.default.createElement("button",{onClick:wt,style:{background:"rgba(255, 255, 255, 0.2)",border:"1px solid rgba(255, 255, 255, 0.3)",borderRadius:"6px",color:"#FFFFFF",cursor:"pointer",padding:ie?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ie?"28px":"32px",height:ie?"28px":"32px",transition:"background 0.2s ease"},onMouseEnter:e=>e.target.style.background="rgba(255, 255, 255, 0.3)",onMouseLeave:e=>e.target.style.background="rgba(255, 255, 255, 0.2)",title:ke?"Exit Fullscreen":"Fullscreen"},ke?a.default.createElement("svg",{width:ie?"14":"16",height:ie?"14":"16",viewBox:"0 0 16 16",fill:"none"},a.default.createElement("path",{d:"M10 3H13V6M6 13H3V10M13 10V13H10M3 6V3H6",stroke:"white",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})):a.default.createElement("svg",{width:ie?"14":"16",height:ie?"14":"16",viewBox:"0 0 16 16",fill:"none"},a.default.createElement("path",{d:"M3 6V3H6M13 10V13H10M10 3H13V6M6 13H3V10",stroke:"white",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"}))),a.default.createElement("button",{onClick:Et,style:{background:"rgba(255, 255, 255, 0.2)",border:"1px solid rgba(255, 255, 255, 0.3)",borderRadius:"6px",color:"#FFFFFF",cursor:"pointer",padding:ie?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ie?"28px":"32px",height:ie?"28px":"32px",fontWeight:"bold",fontSize:ie?"18px":"22px",transition:"background 0.2s ease"},onMouseEnter:e=>e.target.style.background="rgba(255, 255, 255, 0.3)",onMouseLeave:e=>e.target.style.background="rgba(255, 255, 255, 0.2)",title:"Close"},"×"))),a.default.createElement("div",{style:{flex:1,background:"#000000",position:"relative",display:Se?"none":"flex",flexDirection:"column"}},a.default.createElement("iframe",{src:(()=>{if(!Ie)return"";return`${String(Y||"").replace(/\/?$/,"/")}token=${Ie}`})(),style:{width:"100%",height:"100%",border:"none",flex:1},allow:"camera; microphone; display-capture; autoplay",allowFullScreen:!0,title:"Video Call"})),!ie&&!ke&&!Se&&a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{onPointerDown:e=>kt("top-left",e),onPointerMove:St,onPointerUp:vt,onPointerCancel:vt,style:{position:"absolute",left:0,top:0,width:"16px",height:"16px",cursor:"nwse-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>kt("top-right",e),onPointerMove:St,onPointerUp:vt,onPointerCancel:vt,style:{position:"absolute",right:0,top:0,width:"16px",height:"16px",cursor:"nesw-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>kt("bottom-left",e),onPointerMove:St,onPointerUp:vt,onPointerCancel:vt,style:{position:"absolute",left:0,bottom:0,width:"16px",height:"16px",cursor:"nesw-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>kt("bottom-right",e),onPointerMove:St,onPointerUp:vt,onPointerCancel:vt,style:{position:"absolute",right:0,bottom:0,width:"16px",height:"16px",cursor:"nwse-resize",background:"transparent",zIndex:10001}})),a.default.createElement("style",null,"\n @keyframes pulse {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.5; }\n }\n "))),It&&a.default.createElement("div",{style:{position:"fixed",inset:0,zIndex:1e5,display:"flex",alignItems:"center",justifyContent:"center",padding:"24px",background:"rgba(0,0,0,0.4)",boxSizing:"border-box"}},a.default.createElement("div",{style:{fontFamily:Ct,maxWidth:"400px",width:"100%",padding:"32px 24px",background:"#FFFFFF",borderRadius:"12px",boxShadow:"0 8px 32px rgba(0,0,0,0.2)",textAlign:"center"}},a.default.createElement("div",{style:{fontSize:"48px",marginBottom:"16px"}},"🔒"),a.default.createElement("h2",{style:{fontSize:"20px",fontWeight:700,color:"#1a1a1a",margin:"0 0 8px 0"}},B?"Not authorised":"Sign in required"),a.default.createElement("p",{style:{fontSize:"14px",color:"#666",margin:0,lineHeight:1.5}},Dt),a.default.createElement("p",{style:{fontSize:"13px",color:"#999",marginTop:"16px",marginBottom:0}},"Redirecting to login...")))),a.default.createElement(w,null,zt)};let S=null;const v={showWidget:(e,t)=>{S||(S=document.createElement("div"),document.body.appendChild(S));const n=()=>a.default.createElement(a.default.Fragment,null,a.default.createElement(b,{config:e}));i.default.render(a.default.createElement(n,null),S)},closePopup:()=>{S&&(i.default.unmountComponentAtNode(S),S=null)}};window.BookingSDK=v,e.AppointmentPage=b,e.PIH_APPOINTMENT_WIDGET_CLASS=E,e.default=v,Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pih-appointment-widget",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "main": "dist/App.js",
5
5
  "module": "dist/App.js",
6
6
  "exports": {
@@ -254,6 +254,14 @@ const AppointmentPage = ({ config = {} }) => {
254
254
  };
255
255
 
256
256
  // Helper function to get date range based on option
257
+ // Format a Date using local calendar values (avoids UTC shift from toISOString)
258
+ const formatLocalDate = (date) => {
259
+ const y = date.getFullYear();
260
+ const m = String(date.getMonth() + 1).padStart(2, "0");
261
+ const d = String(date.getDate()).padStart(2, "0");
262
+ return `${y}-${m}-${d}`;
263
+ };
264
+
257
265
  const getDateRange = (option) => {
258
266
  const today = new Date();
259
267
  let from, to;
@@ -265,7 +273,7 @@ const AppointmentPage = ({ config = {} }) => {
265
273
  case "tomorrow":
266
274
  const tomorrow = new Date(today);
267
275
  tomorrow.setDate(tomorrow.getDate() + 1);
268
- from = to = tomorrow.toISOString().split('T')[0];
276
+ from = to = formatLocalDate(tomorrow);
269
277
  break;
270
278
  case "currentWeek":
271
279
  const firstDay = new Date(today);
@@ -274,14 +282,14 @@ const AppointmentPage = ({ config = {} }) => {
274
282
  const diff = day === 0 ? -6 : 1 - day; // Monday as first day
275
283
  firstDay.setDate(today.getDate() + diff);
276
284
  lastDay.setDate(firstDay.getDate() + 6);
277
- from = firstDay.toISOString().split('T')[0];
278
- to = lastDay.toISOString().split('T')[0];
285
+ from = formatLocalDate(firstDay);
286
+ to = formatLocalDate(lastDay);
279
287
  break;
280
288
  case "thisMonth":
281
289
  const firstOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
282
290
  const lastOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
283
- from = firstOfMonth.toISOString().split('T')[0];
284
- to = lastOfMonth.toISOString().split('T')[0];
291
+ from = formatLocalDate(firstOfMonth);
292
+ to = formatLocalDate(lastOfMonth);
285
293
  break;
286
294
  case "currentYear":
287
295
  from = `${today.getFullYear()}-01-01`;
@@ -569,6 +577,23 @@ const AppointmentPage = ({ config = {} }) => {
569
577
  fetchAppointments();
570
578
  };
571
579
 
580
+ // End call silently when user presses browser back button during an active call.
581
+ useEffect(() => {
582
+ if (!showPipVideo) return;
583
+ window.history.pushState({ pipActive: true }, "");
584
+ const handlePopState = () => {
585
+ setShowPipVideo(false);
586
+ setIsPipMinimized(false);
587
+ setIsPipFullscreen(false);
588
+ setCallToken(null);
589
+ setCallUrl(null);
590
+ setCallError(null);
591
+ window.history.back();
592
+ };
593
+ window.addEventListener("popstate", handlePopState);
594
+ return () => window.removeEventListener("popstate", handlePopState);
595
+ }, [showPipVideo]);
596
+
572
597
  // Handle PiP minimize
573
598
  const handleTogglePipSize = () => {
574
599
  if (isPipFullscreen) {
@@ -2184,8 +2209,7 @@ const AppointmentPage = ({ config = {} }) => {
2184
2209
  alignItems: "center",
2185
2210
  flexShrink: 0
2186
2211
  }}>
2187
- {!isPipFullscreen && (
2188
- <button
2212
+ <button
2189
2213
  onClick={handleTogglePipSize}
2190
2214
  style={{
2191
2215
  background: "rgba(255, 255, 255, 0.2)",
@@ -2216,7 +2240,6 @@ const AppointmentPage = ({ config = {} }) => {
2216
2240
  </svg>
2217
2241
  )}
2218
2242
  </button>
2219
- )}
2220
2243
  <button
2221
2244
  onClick={handleTogglePipFullscreen}
2222
2245
  style={{
@@ -2276,31 +2299,31 @@ const AppointmentPage = ({ config = {} }) => {
2276
2299
  </div>
2277
2300
  </div>
2278
2301
 
2279
- {/* PiP Video Content */}
2280
- {!isPipMinimized && (
2281
- <div style={{
2282
- flex: 1,
2283
- background: "#000000",
2284
- position: "relative",
2285
- }}>
2286
- <iframe
2287
- src={(() => {
2288
- if (!callToken) return "";
2289
- const base = String(joinCallUrlBase || "").replace(/\/?$/, "/");
2290
- console.log("${base}token=${callToken}", `${base}token=${callToken}`)
2291
- return `${base}token=${callToken}`;
2292
- })()}
2293
- style={{
2294
- width: "100%",
2295
- height: "100%",
2296
- border: "none",
2297
- }}
2298
- allow="camera; microphone; display-capture; autoplay"
2299
- allowFullScreen
2300
- title="Video Call"
2301
- />
2302
- </div>
2303
- )}
2302
+ {/* PiP Video Content — always in DOM to keep LiveKit connection alive; hidden via display:none when minimized */}
2303
+ <div style={{
2304
+ flex: 1,
2305
+ background: "#000000",
2306
+ position: "relative",
2307
+ display: isPipMinimized ? "none" : "flex",
2308
+ flexDirection: "column",
2309
+ }}>
2310
+ <iframe
2311
+ src={(() => {
2312
+ if (!callToken) return "";
2313
+ const base = String(joinCallUrlBase || "").replace(/\/?$/, "/");
2314
+ return `${base}token=${callToken}`;
2315
+ })()}
2316
+ style={{
2317
+ width: "100%",
2318
+ height: "100%",
2319
+ border: "none",
2320
+ flex: 1,
2321
+ }}
2322
+ allow="camera; microphone; display-capture; autoplay"
2323
+ allowFullScreen
2324
+ title="Video Call"
2325
+ />
2326
+ </div>
2304
2327
 
2305
2328
  {/* Resize handles — corners only; pointer capture so release outside PiP still ends resize */}
2306
2329
  {!isMobile && !isPipFullscreen && !isPipMinimized && (