pih-appointment-widget 0.0.19 → 0.0.21

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.
@@ -28,6 +28,7 @@ const STORAGE_KEY_EMAIL = "pih_appointment_email";
28
28
  const STORAGE_KEY_APP_TOKEN = "pih_appointment_appToken";
29
29
  const STORAGE_KEY_DOCTOR_ID = "pih_appointment_doctorId";
30
30
  const STORAGE_KEY_USER_NAME = "pih_appointment_userName";
31
+ const STORAGE_KEY_API_BASE_URL = "pih_appointment_apiBaseUrl";
31
32
  const DEFAULT_PIP_WIDTH = 720;
32
33
  const DEFAULT_PIP_HEIGHT = 560;
33
34
 
@@ -117,7 +118,14 @@ const AppointmentPage = _ref => {
117
118
  let {
118
119
  config = {}
119
120
  } = _ref;
120
- const apiBaseUrl = config.apiBaseUrl || _apiConfig.API_BASE_URL;
121
+ const [storedApiBaseUrl, setStoredApiBaseUrl] = (0, _react.useState)(() => {
122
+ try {
123
+ return typeof localStorage !== "undefined" ? localStorage.getItem(STORAGE_KEY_API_BASE_URL) : null;
124
+ } catch {
125
+ return null;
126
+ }
127
+ });
128
+ const apiBaseUrl = config.apiBaseUrl || storedApiBaseUrl || _apiConfig.API_BASE_URL;
121
129
  const hospitalId = config.hospitalId || _apiConfig.DEFAULT_PARAMS.hospitalId;
122
130
 
123
131
  // idToken/email: config first, then localStorage. When Flutter (or parent) passes a new token, we use it and re-login.
@@ -161,8 +169,12 @@ const AppointmentPage = _ref => {
161
169
  localStorage.setItem(STORAGE_KEY_EMAIL, config.email);
162
170
  setStoredEmail(config.email);
163
171
  }
172
+ if (config.apiBaseUrl && String(config.apiBaseUrl).trim()) {
173
+ localStorage.setItem(STORAGE_KEY_API_BASE_URL, config.apiBaseUrl.trim());
174
+ setStoredApiBaseUrl(config.apiBaseUrl.trim());
175
+ }
164
176
  } catch (e) {}
165
- }, [config.idToken, config.token, config.email]);
177
+ }, [config.idToken, config.token, config.email, config.apiBaseUrl]);
166
178
  const [appToken, setAppToken] = (0, _react.useState)(() => {
167
179
  try {
168
180
  return typeof localStorage !== "undefined" ? localStorage.getItem(STORAGE_KEY_APP_TOKEN) : null;
@@ -442,7 +454,7 @@ const AppointmentPage = _ref => {
442
454
  doctorId,
443
455
  token: appToken
444
456
  };
445
- const response = await (0, _appointmentService.getAppointmentsByStatus)(activeTab, fromDate, toDate, serviceConfig);
457
+ const response = await (0, _appointmentService.getAppointmentsByStatus)(activeTab, fromDate, toDate, 'PHYSICAL', serviceConfig);
446
458
  if (response.status === 401 || response.status === 403) {
447
459
  // Token expired — clear stored token and trigger re-login (SSO effect will fire)
448
460
  try {
@@ -492,6 +504,7 @@ const AppointmentPage = _ref => {
492
504
  localStorage.removeItem(STORAGE_KEY_APP_TOKEN);
493
505
  localStorage.removeItem(STORAGE_KEY_DOCTOR_ID);
494
506
  localStorage.removeItem(STORAGE_KEY_USER_NAME);
507
+ localStorage.removeItem(STORAGE_KEY_API_BASE_URL);
495
508
  }
496
509
  } catch (e) {}
497
510
  setShowProfileDropdown(false);
@@ -553,7 +566,7 @@ const AppointmentPage = _ref => {
553
566
  }
554
567
  };
555
568
 
556
- // Handle PiP close
569
+ // Handle PiP close — refresh list so completed call is reflected (e.g. moved to Completed)
557
570
  const handleClosePip = () => {
558
571
  setShowPipVideo(false);
559
572
  setIsPipMinimized(false);
@@ -561,6 +574,7 @@ const AppointmentPage = _ref => {
561
574
  setCallToken(null);
562
575
  setCallUrl(null);
563
576
  setCallError(null);
577
+ fetchAppointments();
564
578
  };
565
579
 
566
580
  // Handle PiP minimize
@@ -2012,7 +2026,7 @@ const AppointmentPage = _ref => {
2012
2026
  fontSize: isMobile ? "11px" : "12px",
2013
2027
  lineHeight: "1.4"
2014
2028
  }
2015
- }, selectedAppointment?.reason || selectedAppointment?.reasonForAppointment || "No reason provided"))), /*#__PURE__*/_react.default.createElement("div", {
2029
+ }, selectedAppointment?.reason || selectedAppointment?.reasonForAppointment || "No reason provided"))), activeTab === "upcoming" && /*#__PURE__*/_react.default.createElement("div", {
2016
2030
  style: {
2017
2031
  display: "flex",
2018
2032
  flexDirection: isMobile ? "column" : "row",
@@ -2035,7 +2049,7 @@ const AppointmentPage = _ref => {
2035
2049
  fontSize: isMobile ? "11px" : "12px",
2036
2050
  cursor: callLoading ? "not-allowed" : "pointer"
2037
2051
  }
2038
- }, callLoading ? "Connecting..." : "Join Call >")), callError && /*#__PURE__*/_react.default.createElement("div", {
2052
+ }, callLoading ? "Connecting..." : "Join Call >")), activeTab === "upcoming" && callError && /*#__PURE__*/_react.default.createElement("div", {
2039
2053
  style: {
2040
2054
  fontSize: "11px",
2041
2055
  color: "#e53935",
@@ -22,8 +22,7 @@ const API_PATHS = exports.API_PATHS = {
22
22
 
23
23
  // Default request parameters (will be fetched from auth API later)
24
24
  const DEFAULT_PARAMS = exports.DEFAULT_PARAMS = {
25
- hospitalId: "dMtEGhak",
26
- doctorId: 6694
25
+ hospitalId: "dMtEGhak"
27
26
  };
28
27
 
29
28
  // Request timeout (milliseconds)
@@ -149,8 +149,7 @@
149
149
 
150
150
  // Default request parameters (will be fetched from auth API later)
151
151
  const DEFAULT_PARAMS = {
152
- hospitalId: "dMtEGhak",
153
- doctorId: 6694
152
+ hospitalId: "dMtEGhak"
154
153
  };
155
154
 
156
155
  // Join call URL (will be dynamic from auth API later)
@@ -166,22 +165,24 @@
166
165
  * @returns {Promise} Appointments data
167
166
  */
168
167
  const getAppointmentsByStatus = async function (status, fromDate, toDate) {
169
- let config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
168
+ let type = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'ONLINE';
169
+ let config = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
170
170
  // Map status to API format
171
171
  let apiStatus = (status || "").toUpperCase();
172
172
  if (apiStatus === "INPROGRESS") {
173
173
  apiStatus = "IN_PROGRESS";
174
174
  }
175
- const baseURL = config.apiBaseUrl || API_BASE_URL;
175
+ const baseURL = config.apiBaseUrl;
176
176
  const hospitalId = config.hospitalId || DEFAULT_PARAMS.hospitalId;
177
- const doctorId = config.doctorId || DEFAULT_PARAMS.doctorId;
177
+ const doctorId = config.doctorId;
178
178
  const token = config.token || '';
179
179
  const params = {
180
180
  hospitalId,
181
181
  doctorId,
182
182
  fromDate,
183
183
  toDate,
184
- statuses: apiStatus
184
+ statuses: apiStatus,
185
+ type
185
186
  };
186
187
  const url = `${baseURL}${API_PATHS.APPOINTMENTS}`;
187
188
 
@@ -198,14 +199,15 @@
198
199
  */
199
200
  const initiateConsultation = async function (appointment) {
200
201
  let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
201
- const baseURL = (config.apiBaseUrl || API_BASE_URL).replace(/\/$/, "");
202
+ console.log("initiateConsultation -> config", config);
203
+ const baseURL = config.apiBaseUrl.replace(/\/$/, "");
202
204
  const url = `${baseURL}${API_PATHS.INITIATE_CALL}`;
203
205
  const appToken = config.appToken || "";
204
206
  const body = {
205
207
  patientId: String(appointment.patientId || ""),
206
208
  primaryPatientId: String(appointment.primaryPatientId || appointment.patientId || ""),
207
209
  hospitalId: config.hospitalId || DEFAULT_PARAMS.hospitalId,
208
- doctorId: String(config.doctor_id || DEFAULT_PARAMS.doctorId),
210
+ doctorId: String(config.doctorId),
209
211
  patientName: appointment.patientName || appointment.name || "",
210
212
  doctorName: appointment.doctorName || config.doctorName,
211
213
  appointmentId: String(appointment.id || appointment.appointmentId || appointment._id || "")
@@ -231,6 +233,7 @@
231
233
  const STORAGE_KEY_APP_TOKEN = "pih_appointment_appToken";
232
234
  const STORAGE_KEY_DOCTOR_ID = "pih_appointment_doctorId";
233
235
  const STORAGE_KEY_USER_NAME = "pih_appointment_userName";
236
+ const STORAGE_KEY_API_BASE_URL = "pih_appointment_apiBaseUrl";
234
237
  const DEFAULT_PIP_WIDTH = 720;
235
238
  const DEFAULT_PIP_HEIGHT = 560;
236
239
 
@@ -320,7 +323,14 @@
320
323
  let {
321
324
  config = {}
322
325
  } = _ref;
323
- const apiBaseUrl = config.apiBaseUrl || API_BASE_URL;
326
+ const [storedApiBaseUrl, setStoredApiBaseUrl] = React.useState(() => {
327
+ try {
328
+ return typeof localStorage !== "undefined" ? localStorage.getItem(STORAGE_KEY_API_BASE_URL) : null;
329
+ } catch {
330
+ return null;
331
+ }
332
+ });
333
+ const apiBaseUrl = config.apiBaseUrl || storedApiBaseUrl || API_BASE_URL;
324
334
  const hospitalId = config.hospitalId || DEFAULT_PARAMS.hospitalId;
325
335
 
326
336
  // idToken/email: config first, then localStorage. When Flutter (or parent) passes a new token, we use it and re-login.
@@ -364,8 +374,12 @@
364
374
  localStorage.setItem(STORAGE_KEY_EMAIL, config.email);
365
375
  setStoredEmail(config.email);
366
376
  }
377
+ if (config.apiBaseUrl && String(config.apiBaseUrl).trim()) {
378
+ localStorage.setItem(STORAGE_KEY_API_BASE_URL, config.apiBaseUrl.trim());
379
+ setStoredApiBaseUrl(config.apiBaseUrl.trim());
380
+ }
367
381
  } catch (e) {}
368
- }, [config.idToken, config.token, config.email]);
382
+ }, [config.idToken, config.token, config.email, config.apiBaseUrl]);
369
383
  const [appToken, setAppToken] = React.useState(() => {
370
384
  try {
371
385
  return typeof localStorage !== "undefined" ? localStorage.getItem(STORAGE_KEY_APP_TOKEN) : null;
@@ -645,7 +659,7 @@
645
659
  doctorId,
646
660
  token: appToken
647
661
  };
648
- const response = await getAppointmentsByStatus(activeTab, fromDate, toDate, serviceConfig);
662
+ const response = await getAppointmentsByStatus(activeTab, fromDate, toDate, 'PHYSICAL', serviceConfig);
649
663
  if (response.status === 401 || response.status === 403) {
650
664
  // Token expired — clear stored token and trigger re-login (SSO effect will fire)
651
665
  try {
@@ -738,7 +752,7 @@
738
752
  }
739
753
  };
740
754
 
741
- // Handle PiP close
755
+ // Handle PiP close — refresh list so completed call is reflected (e.g. moved to Completed)
742
756
  const handleClosePip = () => {
743
757
  setShowPipVideo(false);
744
758
  setIsPipMinimized(false);
@@ -746,6 +760,7 @@
746
760
  setCallToken(null);
747
761
  setCallUrl(null);
748
762
  setCallError(null);
763
+ fetchAppointments();
749
764
  };
750
765
 
751
766
  // Handle PiP minimize
@@ -2051,7 +2066,7 @@
2051
2066
  fontSize: isMobile ? "11px" : "12px",
2052
2067
  lineHeight: "1.4"
2053
2068
  }
2054
- }, selectedAppointment?.reason || selectedAppointment?.reasonForAppointment || "No reason provided"))), /*#__PURE__*/React__default["default"].createElement("div", {
2069
+ }, selectedAppointment?.reason || selectedAppointment?.reasonForAppointment || "No reason provided"))), activeTab === "upcoming" && /*#__PURE__*/React__default["default"].createElement("div", {
2055
2070
  style: {
2056
2071
  display: "flex",
2057
2072
  flexDirection: isMobile ? "column" : "row",
@@ -2074,7 +2089,7 @@
2074
2089
  fontSize: isMobile ? "11px" : "12px",
2075
2090
  cursor: callLoading ? "not-allowed" : "pointer"
2076
2091
  }
2077
- }, callLoading ? "Connecting..." : "Join Call >")), callError && /*#__PURE__*/React__default["default"].createElement("div", {
2092
+ }, callLoading ? "Connecting..." : "Join Call >")), activeTab === "upcoming" && callError && /*#__PURE__*/React__default["default"].createElement("div", {
2078
2093
  style: {
2079
2094
  fontSize: "11px",
2080
2095
  color: "#e53935",
@@ -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="https://afiyaapiqa.powermindinc.com",l="/appointment/V1/consultant/all-appointments",d="/notification/V1/consultation/online/initiate",s="dMtEGhak",p=6694,c="https://wbafedevittisalwe01-had2b3e0a7h6fyey.westeurope-01.azurewebsites.net/call/",u=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||r,d=o.hospitalId||s,c=o.doctorId||p,u=o.token||"",f={hospitalId:d,doctorId:c,fromDate:t,toDate:n,statuses:a},m=`${i}${l}`,x=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"})))}(m,f,"PIH-Appointment-Widget",u);return x},f=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=`${(t.apiBaseUrl||r).replace(/\/$/,"")}${d}`,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||s,doctorId:String(t.doctor_id||p),patientName:e.patientName||e.name||"",doctorName:e.doctorName||t.doctorName,appointmentId:String(e.id||e.appointmentId||e._id||"")},"PIH-Appointment-Widget",{},o)};const m="pih_appointment_idToken",x="pih_appointment_email",g="pih_appointment_appToken",h="pih_appointment_doctorId",y="pih_appointment_userName",E=720,F="pih-appointment-widget",b="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:F,[b]:"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 S=e=>{let{config:n={}}=e;const o=n.apiBaseUrl||r,i=n.hospitalId||s,[l,d]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(m):null}catch{return null}})),[p,S]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(x):null}catch{return null}})),v=n.idToken||n.token||l,k=n.email||p;t.useEffect((()=>{try{if("undefined"==typeof localStorage)return;const e=n.idToken||n.token;if(e&&String(e).trim()){localStorage.getItem(m)!==e&&(I(null),z(null),T(null),localStorage.removeItem(g),localStorage.removeItem(h),localStorage.removeItem(y)),localStorage.setItem(m,e),d(e)}n.email&&String(n.email).trim()&&(localStorage.setItem(x,n.email),S(n.email))}catch(e){}}),[n.idToken,n.token,n.email]);const[C,I]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(g):null}catch{return null}})),[D,z]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(h):null}catch{return null}})),[W,T]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(y):null}catch{return null}})),[M,A]=t.useState((()=>{try{if("undefined"==typeof localStorage)return!1;const e=localStorage.getItem(g),t=localStorage.getItem(m),n=localStorage.getItem(x);return!e&&!(!t||!n)}catch{return!1}})),[R,N]=t.useState(null),[P,j]=t.useState(!1),[B,H]=t.useState(0);t.useEffect((()=>{C&&M&&A(!1)}),[C,M]),t.useEffect((()=>{C||(v&&k?(j(!1),N((e=>"Sign in required. Redirecting to home..."===e?null:e))):(N("Sign in required. Redirecting to home..."),j(!0)))}),[C,v,k]),t.useEffect((()=>{if(!P)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)}),[P,n.homeUrl]),t.useEffect((()=>{if(!M)return;const e=setTimeout((()=>{N("Request timed out. Please try again."),A(!1)}),3e4);return()=>clearTimeout(e)}),[M]);const L=n.joinCallUrl||c;C&&String(L||"").replace(/\/?$/,"/");const $=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{}}}(v),_=W||$.name||$.sub||"User",O=()=>(new Date).toISOString().split("T")[0],[U,Y]=t.useState("upcoming"),[V,q]=t.useState([]),[X,G]=t.useState(null),[J,K]=t.useState(!1),[Q,Z]=t.useState(null),[ee,te]=t.useState(window.innerWidth<768),[ne,oe]=t.useState("today"),[ae,ie]=t.useState("today"),[re,le]=t.useState(!1),[de,se]=t.useState("asc"),[pe,ce]=t.useState(""),[ue,fe]=t.useState(!1),[me,xe]=t.useState(!1),[ge,he]=t.useState(!1),[ye,Ee]=t.useState(null),[Fe,be]=t.useState(null),[we,Se]=t.useState(!1),[ve,ke]=t.useState(null),[Ce,Ie]=t.useState((()=>({x:Math.max(20,"undefined"!=typeof window?window.innerWidth-E-20:300),y:80}))),[De,ze]=t.useState({width:E,height:560}),[We,Te]=t.useState(!1),[Me,Ae]=t.useState({x:0,y:0}),[Re,Ne]=t.useState(!1),[Pe,je]=t.useState(null),[Be,He]=t.useState({x:0,y:0,width:0,height:0});t.useState(!1);const[Le,$e]=t.useState(1),_e=V.filter((e=>{if(!pe.trim())return!0;const t=pe.toLowerCase(),n=(e.patientName||"").toLowerCase(),o=String(e.patientId||"").toLowerCase();return n.includes(t)||o.includes(t)})),Oe=20*(Le-1),Ue=Oe+20,Ye=_e.slice(Oe,Ue),Ve=Math.ceil(_e.length/20),qe=_e.length,[Xe,Ge]=t.useState(O()),[Je,Ke]=t.useState(O()),[Qe,Ze]=t.useState(),[et,tt]=t.useState(),nt=e=>e?.id||e?._id||e?.appointmentId||e?.patientId||JSON.stringify(e),ot=e=>e?.image?e.image:null,at=e=>e?e.charAt(0).toUpperCase():"?",it=e=>{if(!e)return"#4C4DDC";const t=["#4C4DDC","#1CC3CE","#FF6B6B","#4ECDC4","#45B7D1","#FFA07A","#98D8C8","#F7DC6F"];return t[e.charCodeAt(0)%t.length]},rt=()=>{const e="asc"===de?"desc":"asc";se(e);const t=[...V].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),$e(1),t.length>0&&G(t[0])},lt=t.useCallback((async()=>{if(!C)return;console.log(D,"fetchAppointments -> doctorIdFromLogin");const e=D;K(!0),Z(null);try{const t={apiBaseUrl:o,hospitalId:i,doctorId:e,token:C},n=await u(U,Xe,Je,t);if(401===n.status||403===n.status){try{"undefined"!=typeof localStorage&&(localStorage.removeItem(g),localStorage.removeItem(h),localStorage.removeItem(y))}catch(e){}return I(null),z(null),T(null),H((e=>e+1)),void Z("Session expired. Re-authenticating...")}if(n.err)return void Z(String(n.err||"Failed to fetch appointments"));const a=n.data||n.appointments||n||[];q(Array.isArray(a)?a:[]),Array.isArray(a)&&a.length>0?G(a[0]):G(null)}catch(e){console.error("Error fetching appointments:",e),Z(e.message||"Failed to fetch appointments")}finally{K(!1)}}),[U,Xe,Je,o,i,D,C]),dt=e=>{G(e)},st=async()=>{if(X&&C){Se(!0),ke(null);try{const e={apiBaseUrl:o,hospitalId:i,doctorId:D,doctorName:W||_,appToken:C};console.log(X,"selectedAppointment"),console.log(e,"callConfig");const t=await f(X,e);if(401===t.status||403===t.status)return ke("Session expired. Please try again."),void Se(!1);if(t.err||!t.data?.token)return ke(String(t.err||"Failed to initiate call")),void Se(!1);const a=n.joinCallUrl||c,r=t.data.token?String(a||"").replace(/\/?$/,"/")+t.data.token:"";console.log("joinCallUrl",r),Ee(t.data.token),be(r||""),fe(!0),xe(!1),he(!1),ze({width:E,height:560}),Ie({x:Math.max(20,window.innerWidth-E-20),y:80})}catch(e){ke(e.message||"Failed to initiate call")}finally{ke(null),Se(!1)}}},pt=()=>{fe(!1),xe(!1),he(!1),Ee(null),be(null),ke(null)},ct=()=>{ge&&he(!1),xe(!me)},ut=()=>{me&&xe(!1),he(!ge)},ft=e=>{if(0!==e.button)return;if(e.target.closest("button"))return;e.currentTarget.setPointerCapture&&e.currentTarget.setPointerCapture(e.pointerId),Te(!0);const t=e.currentTarget.getBoundingClientRect();Ae({x:e.clientX-t.left,y:e.clientY-t.top})},mt=t.useCallback((e=>{if(!ge)if(We){const t=e.clientX-Me.x,n=e.clientY-Me.y,o=window.innerWidth-De.width,a=window.innerHeight-De.height;Ie({x:Math.max(0,Math.min(t,o)),y:Math.max(0,Math.min(n,a))})}else if(Re){const t=e.clientX-Be.x,n=e.clientY-Be.y;let o=Be.width,a=Be.height,i=Be.posX,r=Be.posY;const l=300,d=250,s=window.innerWidth-40,p=window.innerHeight-100;if("bottom-right"===Pe)o=Math.min(Math.max(Be.width+t,l),s),a=Math.min(Math.max(Be.height+n,d),p),i+o>window.innerWidth&&(o=window.innerWidth-i),r+a>window.innerHeight&&(a=window.innerHeight-r);else if("bottom-left"===Pe){o=Math.min(Math.max(Be.width-t,l),s),i=Math.max(0,Be.posX+t),0===i&&(o=Be.posX+Be.width),a=Math.min(Math.max(Be.height+n,d),p),r+a>window.innerHeight&&(a=window.innerHeight-r)}else if("top-right"===Pe){o=Math.min(Math.max(Be.width+t,l),s),i+o>window.innerWidth&&(o=window.innerWidth-i);a=Math.min(Math.max(Be.height-n,d),p),r=Math.max(0,Be.posY+n),0===r&&(a=Be.posY+Be.height)}else if("top-left"===Pe){o=Math.min(Math.max(Be.width-t,l),s),i=Math.max(0,Be.posX+t),0===i&&(o=Be.posX+Be.width);a=Math.min(Math.max(Be.height-n,d),p),r=Math.max(0,Be.posY+n),0===r&&(a=Be.posY+Be.height)}ze({width:o,height:a}),Ie({x:i,y:r})}}),[We,Re,Me,Pe,Be,Ce,De,ge]),xt=()=>{Te(!1),Ne(!1),je(null)},gt=(e,t)=>{t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture&&t.currentTarget.setPointerCapture(t.pointerId),Ne(!0),je(e),He({x:t.clientX,y:t.clientY,width:De.width,height:De.height,posX:Ce.x,posY:Ce.y})};t.useEffect((()=>{if(!ue||ge)return;const e=()=>{if(!(window.innerWidth<768)){const e=me?350:De.width,t=me?60:De.height,n=window.innerWidth-40,o=window.innerHeight-100,a=Math.min(e,n),i=Math.min(t,o);a===De.width&&i===De.height||ze({width:a,height:i});const r=window.innerWidth-a-20,l=window.innerHeight-i-20;Ie((e=>({x:Math.min(e.x,r),y:Math.min(e.y,l)})))}};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)}),[ue,me,ge,De]),t.useEffect((()=>{if(!(v&&k&&(!C||B>0)))return;let e=!1;return A(!0),N(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"})))})(o,i,v,k).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 N(t.err||"Invalid request. Redirecting to home..."),A(!1),void j(!0);if(t.err||!n){N(String(t.err||"Failed to get token")),I(null),z(null),T(null);try{"undefined"!=typeof localStorage&&(localStorage.removeItem(g),localStorage.removeItem(h),localStorage.removeItem(y))}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);I(n),z(e),T(o),N(null),j(!1);try{"undefined"!=typeof localStorage&&(localStorage.setItem(g,n),e&&localStorage.setItem(h,e),o&&localStorage.setItem(y,o))}catch(e){}}})).catch((()=>{})).finally((()=>{e||A(!1)})),()=>{e=!0}}),[o,i,v,k,B]),t.useEffect((()=>{$e(1)}),[U,ne,Xe,Je,pe]),t.useEffect((()=>{!M&&C&&lt()}),[lt,C,M]),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=()=>{te(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=>{!re||e.target.closest("button")||e.target.closest('input[type="date"]')||le(!1)};return document.addEventListener("click",e),()=>{document.removeEventListener("click",e)}}),[re]);let ht='"Nunito", serif';const yt=R||!C&&(!v||!k),Et=R||"Sign in required. Redirecting to home...";let Ft;return Ft=M&&v&&k?a.default.createElement("div",{className:F,[b]:"teleconsult-appointments",style:{fontFamily:ht,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:F,[b]:"teleconsult-appointments",style:{fontFamily:ht,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:ee?"10px 12px":"12px 24px",display:"flex",justifyContent:"space-between",alignItems:"center",borderBottom:"1px solid #E5E5E5",flexWrap:"nowrap",gap:ee?"8px":"0"}},a.default.createElement("div",{style:{position:"relative",width:ee?"calc(100% - 90px)":"480px",maxWidth:ee?"none":"480px"}},a.default.createElement("input",{type:"text",placeholder:"Search by patient name or ID",value:pe,onChange:e=>ce(e.target.value),style:{width:"100%",padding:ee?"8px 32px 8px 10px":"8px 36px 8px 14px",border:"1px solid #E5E5E5",borderRadius:"6px",fontSize:ee?"12px":"13px",fontFamily:ht,background:"#FFFFFF",outline:"none",boxSizing:"border-box"}}),pe&&a.default.createElement("button",{onClick:()=>ce(""),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:ee?"12px":"16px 24px",flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"}},a.default.createElement("div",{style:{marginBottom:ee?"10px":"14px"}},a.default.createElement("h1",{style:{fontSize:ee?"18px":"22px",fontWeight:700,color:"#1a1a1a",margin:"0 0 2px 0"}},"Tele Consultation"),a.default.createElement("p",{style:{fontSize:ee?"11px":"12px",color:"#999",margin:0}},"Displaying All Tele Consultation Appointments")),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:ee?"flex-start":"center",marginBottom:ee?"10px":"14px",flexDirection:ee?"column":"row",gap:ee?"12px":"0"}},a.default.createElement("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",width:ee?"100%":"auto"}},a.default.createElement("button",{onClick:()=>Y("upcoming"),style:{background:"upcoming"===U?"#4C4DDC":"#FFFFFF",padding:ee?"8px 10px":"9px 16px",border:"upcoming"===U?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ee?"10px":"13px",color:"upcoming"===U?"white":"#555555",fontWeight:600,fontFamily:ht,cursor:"pointer",flex:ee?"1 1 auto":"none",minWidth:ee?"0":"auto",transition:"all 0.3s ease",whiteSpace:"nowrap"}},"Upcoming Appointments"),a.default.createElement("button",{onClick:()=>Y("completed"),style:{background:"completed"===U?"#4C4DDC":"#FFFFFF",padding:ee?"8px 10px":"9px 16px",border:"completed"===U?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ee?"10px":"13px",color:"completed"===U?"white":"#555555",fontWeight:600,fontFamily:ht,cursor:"pointer",flex:ee?"1 1 auto":"none",minWidth:ee?"0":"auto",transition:"all 0.3s ease",whiteSpace:"nowrap"}},"Completed Appointments"),a.default.createElement("button",{onClick:()=>Y("cancelled"),style:{background:"cancelled"===U?"#4C4DDC":"#FFFFFF",padding:ee?"8px 10px":"9px 16px",border:"cancelled"===U?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ee?"10px":"13px",color:"cancelled"===U?"white":"#555555",fontWeight:600,fontFamily:ht,cursor:"pointer",flex:ee?"1 1 auto":"none",minWidth:ee?"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:ee?"flex-start":"flex-end"}},a.default.createElement("button",{onClick:()=>{re||(Ze(Xe),tt(Je),ie(ne)),le(!re)},style:{padding:"8px 12px",fontFamily:ht,fontWeight:600,border:"1px solid #E5E5E5",borderRadius:"6px",fontSize:ee?"11px":"13px",color:"#1a1a1a",background:"#FFFFFF",display:"flex",alignItems:"center",gap:ee?"4px":"6px",cursor:"pointer",flex:"none",minWidth:ee?"100px":"auto",justifyContent:"center"}},a.default.createElement("svg",{width:ee?"12":"14",height:ee?"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(ne){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 ee?"Custom":`${Xe} to ${Je}`}})()),a.default.createElement("svg",{width:ee?"8":"10",height:ee?"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"}))),re&&a.default.createElement("div",{style:{position:"absolute",top:"100%",right:ee?"auto":0,left:ee?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:ee?"280px":"240px",width:ee?"calc(100vw - 24px)":"auto",maxWidth:ee?"calc(100vw - 24px)":"280px"}},a.default.createElement("div",{style:{marginBottom:"custom"===ae?"12px":"0"}},["thisMonth","today","tomorrow","currentWeek","currentYear","custom"].map((e=>a.default.createElement("button",{key:e,onClick:()=>{if(ie(e),"custom"!==e){const t=(e=>{const t=new Date;let n,o;switch(e){case"today":default:n=o=O();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);oe(e),Ge(t.from),Ke(t.to),Ze(t.from),tt(t.to),le(!1)}else Ze(""),tt("")},style:{width:"100%",padding:"10px 12px",background:ae===e?"#E8EEF4":"#FFFFFF",border:"none",borderRadius:"4px",fontSize:"13px",fontFamily:ht,cursor:"pointer",textAlign:"left",fontWeight:ae===e?600:400,color:ae===e?"#4C4DDC":"#1a1a1a",marginBottom:"4px",display:"flex",justifyContent:"space-between",alignItems:"center",transition:"all 0.2s ease"},onMouseEnter:t=>{ae!==e&&(t.target.style.background="#F5F5F5")},onMouseLeave:t=>{ae!==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]),ae===e&&a.default.createElement("span",{style:{color:"#4C4DDC",fontSize:"16px"}},"✓"))))),"custom"===ae&&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:Qe,onChange:e=>Ze(e.target.value),placeholder:"Start Date",style:{width:"100%",padding:"10px 8px",border:"1px solid #E5E5E5",borderRadius:"4px",fontSize:"13px",fontFamily:ht,boxSizing:"border-box",cursor:"pointer"}})),a.default.createElement("div",{style:{marginBottom:"12px"}},a.default.createElement("input",{type:"date",value:et,onChange:e=>tt(e.target.value),placeholder:"End Date",style:{width:"100%",padding:"10px 8px",border:"1px solid #E5E5E5",borderRadius:"4px",fontSize:"13px",fontFamily:ht,boxSizing:"border-box",cursor:"pointer"}})),a.default.createElement("div",{style:{display:"flex",gap:"8px"}},a.default.createElement("button",{onClick:()=>{ie(ne),Ze(Xe),tt(Je),le(!1)},style:{flex:1,padding:"10px 12px",background:"#FFFFFF",color:"#4C4DDC",border:"1px solid #4C4DDC",borderRadius:"4px",fontSize:"13px",fontFamily:ht,fontWeight:600,cursor:"pointer"}},"Cancel"),a.default.createElement("button",{onClick:()=>{Qe&&et&&(oe("custom"),Ge(Qe),Ke(et),le(!1))},style:{flex:1,padding:"10px 12px",background:"#4C4DDC",color:"#FFFFFF",border:"none",borderRadius:"4px",fontSize:"13px",fontFamily:ht,fontWeight:600,cursor:"pointer"}},"Submit")))))),a.default.createElement("div",{style:{display:"flex",flexDirection:ee?"column":"row",gap:ee?"12px":"14px",flex:1,minHeight:0,overflow:ee?"auto":"hidden"}},a.default.createElement("div",{style:{flex:ee?"none":"1 1 65%",width:ee?"100%":"auto",display:"flex",flexDirection:"column",minHeight:ee?"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:ee?"none":1,minHeight:ee?"auto":0}},a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:ee?"12px 14px":"14px 18px",borderBottom:"1px solid #F1F1F1"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ee?"6px":"8px"}},a.default.createElement("span",{style:{fontSize:ee?"14px":"15px",fontWeight:700,color:"#1a1a1a"}},"Appointments"),a.default.createElement("span",{style:{background:"#4C4DDC",color:"#fff",fontSize:ee?"10px":"11px",fontWeight:600,padding:ee?"2px 7px":"3px 8px",borderRadius:"12px"}},qe))),a.default.createElement("div",{className:"appointments-header-grid",style:{display:"grid",gridTemplateColumns:ee?"1.5fr 1fr 0.8fr":"2.5fr 1fr 1.5fr 0.8fr 1.2fr",gap:ee?"8px":"12px",padding:ee?"8px 12px":"10px 18px",background:"#F5F5F5",fontSize:ee?"10px":"12px",fontWeight:600,color:"#666"}},a.default.createElement("div",null,"Patients name"),!ee&&a.default.createElement("div",null,"Patient ID"),a.default.createElement("div",{onClick:rt,style:{display:"flex",alignItems:"center",gap:"3px",cursor:"pointer",userSelect:"none"}},"Date",a.default.createElement("span",{style:{opacity:.7,fontSize:"10px"}},"asc"===de?"▲":"▼")),!ee&&a.default.createElement("div",null,"Slot"),!ee&&a.default.createElement("div",null,"Doctor")),a.default.createElement("div",{style:{overflow:"auto",flex:1}},M?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...")):J?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...")):Q?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"}},Q),a.default.createElement("button",{onClick:lt,style:{marginTop:"16px",padding:"8px 16px",background:"#4C4DDC",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontFamily:ht}},"Retry")):0===Ye.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"}},pe?`No appointments found for "${pe}"`:"No appointments found"),pe&&a.default.createElement("button",{onClick:()=>ce(""),style:{marginTop:"12px",padding:"6px 12px",background:"#4C4DDC",color:"white",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"12px",fontFamily:ht}},"Clear Search")):Ye.map((e=>a.default.createElement("div",{key:nt(e),role:"button",tabIndex:0,onClick:()=>dt(e),onKeyDown:t=>"Enter"===t.key&&dt(e),className:"appointments-grid",style:{display:"grid",gridTemplateColumns:ee?"1.5fr 1fr 0.8fr":"2.5fr 1fr 1.5fr 0.8fr 1.2fr",gap:ee?"8px":"12px",padding:ee?"10px 12px":"12px 18px",background:nt(X)===nt(e)?"#E8EEF4":"#FFFFFF",borderTop:"1px solid #F1F1F1",alignItems:"center",cursor:"pointer",fontSize:ee?"11px":"13px"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ee?"8px":"10px"}},ot(e)?a.default.createElement("img",{src:e.image,alt:"",style:{width:ee?"32px":"36px",height:ee?"32px":"36px",borderRadius:"50%",objectFit:"cover"}}):a.default.createElement("div",{style:{width:ee?"32px":"36px",height:ee?"32px":"36px",borderRadius:"50%",background:it(e.patientName),display:"flex",alignItems:"center",justifyContent:"center",color:"#FFFFFF",fontWeight:600,fontSize:ee?"14px":"16px"}},at(e.patientName)),a.default.createElement("div",null,a.default.createElement("div",{style:{fontWeight:600,color:"#1a1a1a",fontSize:ee?"11px":"13px"}},e.patientName),a.default.createElement("div",{style:{fontSize:ee?"9px":"11px",color:"#888"}},e.email))),!ee&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.patientId),a.default.createElement("div",{style:{color:"#555",fontSize:ee?"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:ee?"9px":"11px",color:"#888"}},n[1].trim())):a.default.createElement("div",null,t)})()),!ee&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.appointmentTime||"-"),!ee&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.doctorName||e.doctor||"-"))))),!J&&!Q&&Ye.length>0&&a.default.createElement("div",{style:{padding:ee?"12px 14px":"14px 18px",borderTop:"1px solid #F1F1F1",display:"flex",justifyContent:"space-between",alignItems:"center",background:"#FFFFFF",flexWrap:ee?"wrap":"nowrap",gap:ee?"10px":"0"}},a.default.createElement("div",{style:{fontSize:ee?"11px":"12px",color:"#666"}},"Showing page ",Le," of ",Ve," (",qe," total)"),a.default.createElement("div",{style:{display:"flex",gap:"6px",alignItems:"center"}},a.default.createElement("button",{onClick:()=>$e((e=>Math.max(1,e-1))),disabled:1===Le,style:{padding:ee?"6px 10px":"6px 12px",border:"1px solid #E5E5E5",borderRadius:"4px",background:1===Le?"#F5F5F5":"#FFFFFF",color:1===Le?"#999":"#1a1a1a",fontSize:ee?"11px":"12px",fontFamily:ht,fontWeight:600,cursor:1===Le?"not-allowed":"pointer",opacity:1===Le?.5:1}},"Previous"),a.default.createElement("div",{style:{display:"flex",gap:"4px"}},[...Array(Math.min(5,Ve))].map(((e,t)=>{let n;return n=Ve<=5||Le<=3?t+1:Le>=Ve-2?Ve-4+t:Le-2+t,a.default.createElement("button",{key:n,onClick:()=>$e(n),style:{padding:ee?"6px 10px":"6px 12px",border:Le===n?"none":"1px solid #E5E5E5",borderRadius:"4px",background:Le===n?"#4C4DDC":"#FFFFFF",color:Le===n?"#FFFFFF":"#1a1a1a",fontSize:ee?"11px":"12px",fontFamily:ht,fontWeight:600,cursor:"pointer",minWidth:ee?"32px":"36px"}},n)}))),a.default.createElement("button",{onClick:()=>$e((e=>Math.min(Ve,e+1))),disabled:Le===Ve,style:{padding:ee?"6px 10px":"6px 12px",border:"1px solid #E5E5E5",borderRadius:"4px",background:Le===Ve?"#F5F5F5":"#FFFFFF",color:Le===Ve?"#999":"#1a1a1a",fontSize:ee?"11px":"12px",fontFamily:ht,fontWeight:600,cursor:Le===Ve?"not-allowed":"pointer",opacity:Le===Ve?.5:1}},"Next"))))),a.default.createElement("div",{style:{flex:ee?"none":"1 1 35%",width:ee?"100%":"auto",display:X||!ee?"flex":"none",flexDirection:"column",minHeight:ee?"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:ee?"none":1,minHeight:ee?"auto":0}},X?a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:ee?"12px 14px":"16px 18px",background:"#E8EEF4",borderBottom:"1px solid #E5E5E5"}},a.default.createElement("div",null,a.default.createElement("div",{style:{color:"#002668",fontSize:ee?"14px":"16px",fontWeight:"700"}},X.patientName||"N/A"),a.default.createElement("div",{style:{color:"#002668",fontSize:ee?"11px":"13px"}},X.patientId||X.mrn||"N/A")),a.default.createElement("div",null,ot(X)?a.default.createElement("img",{style:{width:ee?"36px":"44px",height:ee?"36px":"44px",borderRadius:"50%",objectFit:"cover"},src:X.image,alt:X.patientName}):a.default.createElement("div",{style:{width:ee?"36px":"44px",height:ee?"36px":"44px",borderRadius:"50%",background:it(X.patientName),display:"flex",alignItems:"center",justifyContent:"center",color:"#FFFFFF",fontWeight:700,fontSize:ee?"16px":"20px"}},at(X.patientName)))),a.default.createElement("div",{style:{padding:ee?"12px 14px":"14px 18px",gap:ee?"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:ee?"10px":"11px",color:"#888",marginBottom:"3px"}},"Speciality"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ee?"12px":"13px"}},X?.specialisation||X?.speciality||"N/A")),a.default.createElement("div",{style:{textAlign:"right"}},a.default.createElement("div",{style:{fontSize:ee?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Type"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ee?"12px":"13px"}},X?.type||X?.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:ee?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Date"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ee?"12px":"13px"}},X?.date||X?.appointmentDate||"N/A")),a.default.createElement("div",{style:{textAlign:"right"}},a.default.createElement("div",{style:{fontSize:ee?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Time"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ee?"12px":"13px"}},X?.time||X?.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:ee?"10px":"11px",color:"#888",marginBottom:"3px"}},"Doctor"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ee?"12px":"13px"}},X?.doctor||X?.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:ee?"10px":"11px",color:"#888",marginBottom:"3px"}},"Hospital"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ee?"12px":"13px"}},X?.hospital||X?.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:ee?"10px":"11px",color:"#888",marginBottom:"3px"}},"Reason for Appointment"),a.default.createElement("div",{style:{fontWeight:"600",fontSize:ee?"11px":"12px",lineHeight:"1.4"}},X?.reason||X?.reasonForAppointment||"No reason provided"))),a.default.createElement("div",{style:{display:"flex",flexDirection:ee?"column":"row",gap:"6px",marginTop:"10px"}},a.default.createElement("button",{type:"button",onClick:st,disabled:we,style:{flex:1,background:we?"#99e4e8":"#1CC3CE",color:"#FFFFFF",border:"1px solid #1CC3CE",borderRadius:"6px",padding:ee?"10px 8px":"8px 6px",fontFamily:ht,fontWeight:600,fontSize:ee?"11px":"12px",cursor:we?"not-allowed":"pointer"}},we?"Connecting...":"Join Call >")),ve&&a.default.createElement("div",{style:{fontSize:"11px",color:"#e53935",marginTop:"6px",textAlign:"center",width:"100%"}},"⚠️ ",ve))):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"))))))),ue&&a.default.createElement("div",{style:{position:"fixed",left:ge?"0":ee?"10px":`${Ce.x}px`,top:ge?"0":ee?"70px":`${Ce.y}px`,right:ge?"0":ee?"10px":"auto",bottom:ge?"0":"auto",width:ge?"100vw":ee?"calc(100vw - 20px)":me?"350px":`${De.width}px`,height:ge?"100vh":me?"auto":ee?"300px":`${De.height}px`,background:"#FFFFFF",borderRadius:ge?"0":"8px",boxShadow:"0 8px 24px rgba(0, 0, 0, 0.3)",zIndex:1e4,overflow:"hidden",display:"flex",flexDirection:"column",transition:We||Re?"none":"all 0.3s ease"}},a.default.createElement("div",{onPointerDown:ee||ge?void 0:ft,onPointerMove:ee||ge?void 0:mt,onPointerUp:ee||ge?void 0:xt,onPointerCancel:ee||ge?void 0:xt,style:{background:"linear-gradient(135deg, #4C4DDC 0%, #3A3BBD 100%)",color:"#FFFFFF",padding:ee?"8px 10px":"10px 12px",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:ee||ge?"default":"move",userSelect:"none"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ee?"6px":"8px",flex:1,minWidth:0}},a.default.createElement("div",{style:{width:ee?"6px":"8px",height:ee?"6px":"8px",borderRadius:"50%",background:"#FF4444",animation:"pulse 2s infinite",flexShrink:0}}),a.default.createElement("span",{style:{fontSize:ee?"11px":"13px",fontWeight:600,fontFamily:ht,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},"Video Call - ",X?.patientName||"Patient")),a.default.createElement("div",{style:{display:"flex",gap:ee?"4px":"6px",alignItems:"center",flexShrink:0}},!ge&&a.default.createElement("button",{onClick:ct,style:{background:"rgba(255, 255, 255, 0.2)",border:"1px solid rgba(255, 255, 255, 0.3)",borderRadius:"6px",color:"#FFFFFF",cursor:"pointer",padding:ee?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ee?"28px":"32px",height:ee?"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:me?"Restore":"Minimize"},me?a.default.createElement("svg",{width:ee?"14":"16",height:ee?"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:ee?"14":"16",height:ee?"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:ut,style:{background:"rgba(255, 255, 255, 0.2)",border:"1px solid rgba(255, 255, 255, 0.3)",borderRadius:"6px",color:"#FFFFFF",cursor:"pointer",padding:ee?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ee?"28px":"32px",height:ee?"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:ge?"Exit Fullscreen":"Fullscreen"},ge?a.default.createElement("svg",{width:ee?"14":"16",height:ee?"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:ee?"14":"16",height:ee?"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:pt,style:{background:"rgba(255, 255, 255, 0.2)",border:"1px solid rgba(255, 255, 255, 0.3)",borderRadius:"6px",color:"#FFFFFF",cursor:"pointer",padding:ee?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ee?"28px":"32px",height:ee?"28px":"32px",fontWeight:"bold",fontSize:ee?"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"},"×"))),!me&&a.default.createElement("div",{style:{flex:1,background:"#000000",position:"relative"}},a.default.createElement("iframe",{src:(()=>{if(!ye)return"";const e=String(L||"").replace(/\/?$/,"/");return console.log("${base}token=${callToken}",`${e}token=${ye}`),`${e}token=${ye}`})(),style:{width:"100%",height:"100%",border:"none"},allow:"camera; microphone; display-capture; autoplay",allowFullScreen:!0,title:"Video Call"})),!ee&&!ge&&!me&&a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{onPointerDown:e=>gt("top-left",e),onPointerMove:mt,onPointerUp:xt,onPointerCancel:xt,style:{position:"absolute",left:0,top:0,width:"16px",height:"16px",cursor:"nwse-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>gt("top-right",e),onPointerMove:mt,onPointerUp:xt,onPointerCancel:xt,style:{position:"absolute",right:0,top:0,width:"16px",height:"16px",cursor:"nesw-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>gt("bottom-left",e),onPointerMove:mt,onPointerUp:xt,onPointerCancel:xt,style:{position:"absolute",left:0,bottom:0,width:"16px",height:"16px",cursor:"nesw-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>gt("bottom-right",e),onPointerMove:mt,onPointerUp:xt,onPointerCancel:xt,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 "))),yt&&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:ht,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"}},R?"Not authorised":"Sign in required"),a.default.createElement("p",{style:{fontSize:"14px",color:"#666",margin:0,lineHeight:1.5}},Et),a.default.createElement("p",{style:{fontSize:"13px",color:"#999",marginTop:"16px",marginBottom:0}},"Redirecting to login...")))),a.default.createElement(w,null,Ft)};let v=null;const k={showWidget:(e,t)=>{v||(v=document.createElement("div"),document.body.appendChild(v));const n=()=>a.default.createElement(a.default.Fragment,null,a.default.createElement(S,{config:e}));i.default.render(a.default.createElement(n,null),v)},closePopup:()=>{v&&(i.default.unmountComponentAtNode(v),v=null)}};window.BookingSDK=k,e.AppointmentPage=S,e.PIH_APPOINTMENT_WIDGET_CLASS=F,e.default=k,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="dMtEGhak",s="https://wbafedevittisalwe01-had2b3e0a7h6fyey.westeurope-01.azurewebsites.net/call/",p=async function(e,t,n){let o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"ONLINE",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},i=(e||"").toUpperCase();"INPROGRESS"===i&&(i="IN_PROGRESS");const l=a.apiBaseUrl,s=a.hospitalId||d,p=a.doctorId,c=a.token||"",u={hospitalId:s,doctorId:p,fromDate:t,toDate:n,statuses:i,type:o},f=`${l}${r}`,m=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"})))}(f,u,"PIH-Appointment-Widget",c);return m},c=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||d,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 u="pih_appointment_idToken",f="pih_appointment_email",m="pih_appointment_appToken",x="pih_appointment_doctorId",g="pih_appointment_userName",h="pih_appointment_apiBaseUrl",y=720,E="pih-appointment-widget",F="data-pih-widget";class b 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 w=e=>{let{config:n={}}=e;const[o,i]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(h):null}catch{return null}})),r=n.apiBaseUrl||o||"https://afiyaapiqa.powermindinc.com",l=n.hospitalId||d,[w,S]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(u):null}catch{return null}})),[v,k]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(f):null}catch{return null}})),C=n.idToken||n.token||w,I=n.email||v;t.useEffect((()=>{try{if("undefined"==typeof localStorage)return;const e=n.idToken||n.token;if(e&&String(e).trim()){localStorage.getItem(u)!==e&&(z(null),T(null),A(null),localStorage.removeItem(m),localStorage.removeItem(x),localStorage.removeItem(g)),localStorage.setItem(u,e),S(e)}n.email&&String(n.email).trim()&&(localStorage.setItem(f,n.email),k(n.email)),n.apiBaseUrl&&String(n.apiBaseUrl).trim()&&(localStorage.setItem(h,n.apiBaseUrl.trim()),i(n.apiBaseUrl.trim()))}catch(e){}}),[n.idToken,n.token,n.email,n.apiBaseUrl]);const[D,z]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(m):null}catch{return null}})),[W,T]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(x):null}catch{return null}})),[M,A]=t.useState((()=>{try{return"undefined"!=typeof localStorage?localStorage.getItem(g):null}catch{return null}})),[R,N]=t.useState((()=>{try{if("undefined"==typeof localStorage)return!1;const e=localStorage.getItem(m),t=localStorage.getItem(u),n=localStorage.getItem(f);return!e&&!(!t||!n)}catch{return!1}})),[P,j]=t.useState(null),[B,H]=t.useState(!1),[L,U]=t.useState(0);t.useEffect((()=>{D&&R&&N(!1)}),[D,R]),t.useEffect((()=>{D||(C&&I?(H(!1),j((e=>"Sign in required. Redirecting to home..."===e?null:e))):(j("Sign in required. Redirecting to home..."),H(!0)))}),[D,C,I]),t.useEffect((()=>{if(!B)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)}),[B,n.homeUrl]),t.useEffect((()=>{if(!R)return;const e=setTimeout((()=>{j("Request timed out. Please try again."),N(!1)}),3e4);return()=>clearTimeout(e)}),[R]);const $=n.joinCallUrl||s;D&&String($||"").replace(/\/?$/,"/");const _=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{}}}(C),O=M||_.name||_.sub||"User",Y=()=>(new Date).toISOString().split("T")[0],[V,q]=t.useState("upcoming"),[X,G]=t.useState([]),[J,K]=t.useState(null),[Q,Z]=t.useState(!1),[ee,te]=t.useState(null),[ne,oe]=t.useState(window.innerWidth<768),[ae,ie]=t.useState("today"),[re,le]=t.useState("today"),[de,se]=t.useState(!1),[pe,ce]=t.useState("asc"),[ue,fe]=t.useState(""),[me,xe]=t.useState(!1),[ge,he]=t.useState(!1),[ye,Ee]=t.useState(!1),[Fe,be]=t.useState(null),[we,Se]=t.useState(null),[ve,ke]=t.useState(!1),[Ce,Ie]=t.useState(null),[De,ze]=t.useState((()=>({x:Math.max(20,"undefined"!=typeof window?window.innerWidth-y-20:300),y:80}))),[We,Te]=t.useState({width:y,height:560}),[Me,Ae]=t.useState(!1),[Re,Ne]=t.useState({x:0,y:0}),[Pe,je]=t.useState(!1),[Be,He]=t.useState(null),[Le,Ue]=t.useState({x:0,y:0,width:0,height:0});t.useState(!1);const[$e,_e]=t.useState(1),Oe=X.filter((e=>{if(!ue.trim())return!0;const t=ue.toLowerCase(),n=(e.patientName||"").toLowerCase(),o=String(e.patientId||"").toLowerCase();return n.includes(t)||o.includes(t)})),Ye=20*($e-1),Ve=Ye+20,qe=Oe.slice(Ye,Ve),Xe=Math.ceil(Oe.length/20),Ge=Oe.length,[Je,Ke]=t.useState(Y()),[Qe,Ze]=t.useState(Y()),[et,tt]=t.useState(),[nt,ot]=t.useState(),at=e=>e?.id||e?._id||e?.appointmentId||e?.patientId||JSON.stringify(e),it=e=>e?.image?e.image:null,rt=e=>e?e.charAt(0).toUpperCase():"?",lt=e=>{if(!e)return"#4C4DDC";const t=["#4C4DDC","#1CC3CE","#FF6B6B","#4ECDC4","#45B7D1","#FFA07A","#98D8C8","#F7DC6F"];return t[e.charCodeAt(0)%t.length]},dt=()=>{const e="asc"===pe?"desc":"asc";ce(e);const t=[...X].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}));G(t),_e(1),t.length>0&&K(t[0])},st=t.useCallback((async()=>{if(!D)return;console.log(W,"fetchAppointments -> doctorIdFromLogin");const e=W;Z(!0),te(null);try{const t={apiBaseUrl:r,hospitalId:l,doctorId:e,token:D},n=await p(V,Je,Qe,"PHYSICAL",t);if(401===n.status||403===n.status){try{"undefined"!=typeof localStorage&&(localStorage.removeItem(m),localStorage.removeItem(x),localStorage.removeItem(g))}catch(e){}return z(null),T(null),A(null),U((e=>e+1)),void te("Session expired. Re-authenticating...")}if(n.err)return void te(String(n.err||"Failed to fetch appointments"));const o=n.data||n.appointments||n||[];G(Array.isArray(o)?o:[]),Array.isArray(o)&&o.length>0?K(o[0]):K(null)}catch(e){console.error("Error fetching appointments:",e),te(e.message||"Failed to fetch appointments")}finally{Z(!1)}}),[V,Je,Qe,r,l,W,D]),pt=e=>{K(e)},ct=async()=>{if(J&&D){ke(!0),Ie(null);try{const e={apiBaseUrl:r,hospitalId:l,doctorId:W,doctorName:M||O,appToken:D};console.log(J,"selectedAppointment"),console.log(e,"callConfig");const t=await c(J,e);if(401===t.status||403===t.status)return Ie("Session expired. Please try again."),void ke(!1);if(t.err||!t.data?.token)return Ie(String(t.err||"Failed to initiate call")),void ke(!1);const o=n.joinCallUrl||s,a=t.data.token?String(o||"").replace(/\/?$/,"/")+t.data.token:"";console.log("joinCallUrl",a),be(t.data.token),Se(a||""),xe(!0),he(!1),Ee(!1),Te({width:y,height:560}),ze({x:Math.max(20,window.innerWidth-y-20),y:80})}catch(e){Ie(e.message||"Failed to initiate call")}finally{Ie(null),ke(!1)}}},ut=()=>{xe(!1),he(!1),Ee(!1),be(null),Se(null),Ie(null),st()},ft=()=>{ye&&Ee(!1),he(!ge)},mt=()=>{ge&&he(!1),Ee(!ye)},xt=e=>{if(0!==e.button)return;if(e.target.closest("button"))return;e.currentTarget.setPointerCapture&&e.currentTarget.setPointerCapture(e.pointerId),Ae(!0);const t=e.currentTarget.getBoundingClientRect();Ne({x:e.clientX-t.left,y:e.clientY-t.top})},gt=t.useCallback((e=>{if(!ye)if(Me){const t=e.clientX-Re.x,n=e.clientY-Re.y,o=window.innerWidth-We.width,a=window.innerHeight-We.height;ze({x:Math.max(0,Math.min(t,o)),y:Math.max(0,Math.min(n,a))})}else if(Pe){const t=e.clientX-Le.x,n=e.clientY-Le.y;let o=Le.width,a=Le.height,i=Le.posX,r=Le.posY;const l=300,d=250,s=window.innerWidth-40,p=window.innerHeight-100;if("bottom-right"===Be)o=Math.min(Math.max(Le.width+t,l),s),a=Math.min(Math.max(Le.height+n,d),p),i+o>window.innerWidth&&(o=window.innerWidth-i),r+a>window.innerHeight&&(a=window.innerHeight-r);else if("bottom-left"===Be){o=Math.min(Math.max(Le.width-t,l),s),i=Math.max(0,Le.posX+t),0===i&&(o=Le.posX+Le.width),a=Math.min(Math.max(Le.height+n,d),p),r+a>window.innerHeight&&(a=window.innerHeight-r)}else if("top-right"===Be){o=Math.min(Math.max(Le.width+t,l),s),i+o>window.innerWidth&&(o=window.innerWidth-i);a=Math.min(Math.max(Le.height-n,d),p),r=Math.max(0,Le.posY+n),0===r&&(a=Le.posY+Le.height)}else if("top-left"===Be){o=Math.min(Math.max(Le.width-t,l),s),i=Math.max(0,Le.posX+t),0===i&&(o=Le.posX+Le.width);a=Math.min(Math.max(Le.height-n,d),p),r=Math.max(0,Le.posY+n),0===r&&(a=Le.posY+Le.height)}Te({width:o,height:a}),ze({x:i,y:r})}}),[Me,Pe,Re,Be,Le,De,We,ye]),ht=()=>{Ae(!1),je(!1),He(null)},yt=(e,t)=>{t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture&&t.currentTarget.setPointerCapture(t.pointerId),je(!0),He(e),Ue({x:t.clientX,y:t.clientY,width:We.width,height:We.height,posX:De.x,posY:De.y})};t.useEffect((()=>{if(!me||ye)return;const e=()=>{if(!(window.innerWidth<768)){const e=ge?350:We.width,t=ge?60:We.height,n=window.innerWidth-40,o=window.innerHeight-100,a=Math.min(e,n),i=Math.min(t,o);a===We.width&&i===We.height||Te({width:a,height:i});const r=window.innerWidth-a-20,l=window.innerHeight-i-20;ze((e=>({x:Math.min(e.x,r),y:Math.min(e.y,l)})))}};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)}),[me,ge,ye,We]),t.useEffect((()=>{if(!(C&&I&&(!D||L>0)))return;let e=!1;return N(!0),j(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"})))})(r,l,C,I).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 j(t.err||"Invalid request. Redirecting to home..."),N(!1),void H(!0);if(t.err||!n){j(String(t.err||"Failed to get token")),z(null),T(null),A(null);try{"undefined"!=typeof localStorage&&(localStorage.removeItem(m),localStorage.removeItem(x),localStorage.removeItem(g))}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);z(n),T(e),A(o),j(null),H(!1);try{"undefined"!=typeof localStorage&&(localStorage.setItem(m,n),e&&localStorage.setItem(x,e),o&&localStorage.setItem(g,o))}catch(e){}}})).catch((()=>{})).finally((()=>{e||N(!1)})),()=>{e=!0}}),[r,l,C,I,L]),t.useEffect((()=>{_e(1)}),[V,ae,Je,Qe,ue]),t.useEffect((()=>{!R&&D&&st()}),[st,D,R]),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=()=>{oe(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=>{!de||e.target.closest("button")||e.target.closest('input[type="date"]')||se(!1)};return document.addEventListener("click",e),()=>{document.removeEventListener("click",e)}}),[de]);let Et='"Nunito", serif';const Ft=P||!D&&(!C||!I),bt=P||"Sign in required. Redirecting to home...";let wt;return wt=R&&C&&I?a.default.createElement("div",{className:E,[F]:"teleconsult-appointments",style:{fontFamily:Et,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:Et,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:ne?"10px 12px":"12px 24px",display:"flex",justifyContent:"space-between",alignItems:"center",borderBottom:"1px solid #E5E5E5",flexWrap:"nowrap",gap:ne?"8px":"0"}},a.default.createElement("div",{style:{position:"relative",width:ne?"calc(100% - 90px)":"480px",maxWidth:ne?"none":"480px"}},a.default.createElement("input",{type:"text",placeholder:"Search by patient name or ID",value:ue,onChange:e=>fe(e.target.value),style:{width:"100%",padding:ne?"8px 32px 8px 10px":"8px 36px 8px 14px",border:"1px solid #E5E5E5",borderRadius:"6px",fontSize:ne?"12px":"13px",fontFamily:Et,background:"#FFFFFF",outline:"none",boxSizing:"border-box"}}),ue&&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:ne?"12px":"16px 24px",flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"}},a.default.createElement("div",{style:{marginBottom:ne?"10px":"14px"}},a.default.createElement("h1",{style:{fontSize:ne?"18px":"22px",fontWeight:700,color:"#1a1a1a",margin:"0 0 2px 0"}},"Tele Consultation"),a.default.createElement("p",{style:{fontSize:ne?"11px":"12px",color:"#999",margin:0}},"Displaying All Tele Consultation Appointments")),a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:ne?"flex-start":"center",marginBottom:ne?"10px":"14px",flexDirection:ne?"column":"row",gap:ne?"12px":"0"}},a.default.createElement("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",width:ne?"100%":"auto"}},a.default.createElement("button",{onClick:()=>q("upcoming"),style:{background:"upcoming"===V?"#4C4DDC":"#FFFFFF",padding:ne?"8px 10px":"9px 16px",border:"upcoming"===V?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ne?"10px":"13px",color:"upcoming"===V?"white":"#555555",fontWeight:600,fontFamily:Et,cursor:"pointer",flex:ne?"1 1 auto":"none",minWidth:ne?"0":"auto",transition:"all 0.3s ease",whiteSpace:"nowrap"}},"Upcoming Appointments"),a.default.createElement("button",{onClick:()=>q("completed"),style:{background:"completed"===V?"#4C4DDC":"#FFFFFF",padding:ne?"8px 10px":"9px 16px",border:"completed"===V?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ne?"10px":"13px",color:"completed"===V?"white":"#555555",fontWeight:600,fontFamily:Et,cursor:"pointer",flex:ne?"1 1 auto":"none",minWidth:ne?"0":"auto",transition:"all 0.3s ease",whiteSpace:"nowrap"}},"Completed Appointments"),a.default.createElement("button",{onClick:()=>q("cancelled"),style:{background:"cancelled"===V?"#4C4DDC":"#FFFFFF",padding:ne?"8px 10px":"9px 16px",border:"cancelled"===V?"none":"1px solid #E5E5E5",borderRadius:"6px",fontSize:ne?"10px":"13px",color:"cancelled"===V?"white":"#555555",fontWeight:600,fontFamily:Et,cursor:"pointer",flex:ne?"1 1 auto":"none",minWidth:ne?"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:ne?"flex-start":"flex-end"}},a.default.createElement("button",{onClick:()=>{de||(tt(Je),ot(Qe),le(ae)),se(!de)},style:{padding:"8px 12px",fontFamily:Et,fontWeight:600,border:"1px solid #E5E5E5",borderRadius:"6px",fontSize:ne?"11px":"13px",color:"#1a1a1a",background:"#FFFFFF",display:"flex",alignItems:"center",gap:ne?"4px":"6px",cursor:"pointer",flex:"none",minWidth:ne?"100px":"auto",justifyContent:"center"}},a.default.createElement("svg",{width:ne?"12":"14",height:ne?"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(ae){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 ne?"Custom":`${Je} to ${Qe}`}})()),a.default.createElement("svg",{width:ne?"8":"10",height:ne?"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"}))),de&&a.default.createElement("div",{style:{position:"absolute",top:"100%",right:ne?"auto":0,left:ne?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:ne?"280px":"240px",width:ne?"calc(100vw - 24px)":"auto",maxWidth:ne?"calc(100vw - 24px)":"280px"}},a.default.createElement("div",{style:{marginBottom:"custom"===re?"12px":"0"}},["thisMonth","today","tomorrow","currentWeek","currentYear","custom"].map((e=>a.default.createElement("button",{key:e,onClick:()=>{if(le(e),"custom"!==e){const t=(e=>{const t=new Date;let n,o;switch(e){case"today":default:n=o=Y();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);ie(e),Ke(t.from),Ze(t.to),tt(t.from),ot(t.to),se(!1)}else tt(""),ot("")},style:{width:"100%",padding:"10px 12px",background:re===e?"#E8EEF4":"#FFFFFF",border:"none",borderRadius:"4px",fontSize:"13px",fontFamily:Et,cursor:"pointer",textAlign:"left",fontWeight:re===e?600:400,color:re===e?"#4C4DDC":"#1a1a1a",marginBottom:"4px",display:"flex",justifyContent:"space-between",alignItems:"center",transition:"all 0.2s ease"},onMouseEnter:t=>{re!==e&&(t.target.style.background="#F5F5F5")},onMouseLeave:t=>{re!==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]),re===e&&a.default.createElement("span",{style:{color:"#4C4DDC",fontSize:"16px"}},"✓"))))),"custom"===re&&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:et,onChange:e=>tt(e.target.value),placeholder:"Start Date",style:{width:"100%",padding:"10px 8px",border:"1px solid #E5E5E5",borderRadius:"4px",fontSize:"13px",fontFamily:Et,boxSizing:"border-box",cursor:"pointer"}})),a.default.createElement("div",{style:{marginBottom:"12px"}},a.default.createElement("input",{type:"date",value:nt,onChange:e=>ot(e.target.value),placeholder:"End Date",style:{width:"100%",padding:"10px 8px",border:"1px solid #E5E5E5",borderRadius:"4px",fontSize:"13px",fontFamily:Et,boxSizing:"border-box",cursor:"pointer"}})),a.default.createElement("div",{style:{display:"flex",gap:"8px"}},a.default.createElement("button",{onClick:()=>{le(ae),tt(Je),ot(Qe),se(!1)},style:{flex:1,padding:"10px 12px",background:"#FFFFFF",color:"#4C4DDC",border:"1px solid #4C4DDC",borderRadius:"4px",fontSize:"13px",fontFamily:Et,fontWeight:600,cursor:"pointer"}},"Cancel"),a.default.createElement("button",{onClick:()=>{et&&nt&&(ie("custom"),Ke(et),Ze(nt),se(!1))},style:{flex:1,padding:"10px 12px",background:"#4C4DDC",color:"#FFFFFF",border:"none",borderRadius:"4px",fontSize:"13px",fontFamily:Et,fontWeight:600,cursor:"pointer"}},"Submit")))))),a.default.createElement("div",{style:{display:"flex",flexDirection:ne?"column":"row",gap:ne?"12px":"14px",flex:1,minHeight:0,overflow:ne?"auto":"hidden"}},a.default.createElement("div",{style:{flex:ne?"none":"1 1 65%",width:ne?"100%":"auto",display:"flex",flexDirection:"column",minHeight:ne?"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:ne?"none":1,minHeight:ne?"auto":0}},a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:ne?"12px 14px":"14px 18px",borderBottom:"1px solid #F1F1F1"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ne?"6px":"8px"}},a.default.createElement("span",{style:{fontSize:ne?"14px":"15px",fontWeight:700,color:"#1a1a1a"}},"Appointments"),a.default.createElement("span",{style:{background:"#4C4DDC",color:"#fff",fontSize:ne?"10px":"11px",fontWeight:600,padding:ne?"2px 7px":"3px 8px",borderRadius:"12px"}},Ge))),a.default.createElement("div",{className:"appointments-header-grid",style:{display:"grid",gridTemplateColumns:ne?"1.5fr 1fr 0.8fr":"2.5fr 1fr 1.5fr 0.8fr 1.2fr",gap:ne?"8px":"12px",padding:ne?"8px 12px":"10px 18px",background:"#F5F5F5",fontSize:ne?"10px":"12px",fontWeight:600,color:"#666"}},a.default.createElement("div",null,"Patients name"),!ne&&a.default.createElement("div",null,"Patient ID"),a.default.createElement("div",{onClick:dt,style:{display:"flex",alignItems:"center",gap:"3px",cursor:"pointer",userSelect:"none"}},"Date",a.default.createElement("span",{style:{opacity:.7,fontSize:"10px"}},"asc"===pe?"▲":"▼")),!ne&&a.default.createElement("div",null,"Slot"),!ne&&a.default.createElement("div",null,"Doctor")),a.default.createElement("div",{style:{overflow:"auto",flex:1}},R?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...")):Q?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...")):ee?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"}},ee),a.default.createElement("button",{onClick:st,style:{marginTop:"16px",padding:"8px 16px",background:"#4C4DDC",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontFamily:Et}},"Retry")):0===qe.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"}},ue?`No appointments found for "${ue}"`:"No appointments found"),ue&&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:Et}},"Clear Search")):qe.map((e=>a.default.createElement("div",{key:at(e),role:"button",tabIndex:0,onClick:()=>pt(e),onKeyDown:t=>"Enter"===t.key&&pt(e),className:"appointments-grid",style:{display:"grid",gridTemplateColumns:ne?"1.5fr 1fr 0.8fr":"2.5fr 1fr 1.5fr 0.8fr 1.2fr",gap:ne?"8px":"12px",padding:ne?"10px 12px":"12px 18px",background:at(J)===at(e)?"#E8EEF4":"#FFFFFF",borderTop:"1px solid #F1F1F1",alignItems:"center",cursor:"pointer",fontSize:ne?"11px":"13px"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ne?"8px":"10px"}},it(e)?a.default.createElement("img",{src:e.image,alt:"",style:{width:ne?"32px":"36px",height:ne?"32px":"36px",borderRadius:"50%",objectFit:"cover"}}):a.default.createElement("div",{style:{width:ne?"32px":"36px",height:ne?"32px":"36px",borderRadius:"50%",background:lt(e.patientName),display:"flex",alignItems:"center",justifyContent:"center",color:"#FFFFFF",fontWeight:600,fontSize:ne?"14px":"16px"}},rt(e.patientName)),a.default.createElement("div",null,a.default.createElement("div",{style:{fontWeight:600,color:"#1a1a1a",fontSize:ne?"11px":"13px"}},e.patientName),a.default.createElement("div",{style:{fontSize:ne?"9px":"11px",color:"#888"}},e.email))),!ne&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.patientId),a.default.createElement("div",{style:{color:"#555",fontSize:ne?"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:ne?"9px":"11px",color:"#888"}},n[1].trim())):a.default.createElement("div",null,t)})()),!ne&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.appointmentTime||"-"),!ne&&a.default.createElement("div",{style:{color:"#555",fontSize:"12px"}},e.doctorName||e.doctor||"-"))))),!Q&&!ee&&qe.length>0&&a.default.createElement("div",{style:{padding:ne?"12px 14px":"14px 18px",borderTop:"1px solid #F1F1F1",display:"flex",justifyContent:"space-between",alignItems:"center",background:"#FFFFFF",flexWrap:ne?"wrap":"nowrap",gap:ne?"10px":"0"}},a.default.createElement("div",{style:{fontSize:ne?"11px":"12px",color:"#666"}},"Showing page ",$e," of ",Xe," (",Ge," total)"),a.default.createElement("div",{style:{display:"flex",gap:"6px",alignItems:"center"}},a.default.createElement("button",{onClick:()=>_e((e=>Math.max(1,e-1))),disabled:1===$e,style:{padding:ne?"6px 10px":"6px 12px",border:"1px solid #E5E5E5",borderRadius:"4px",background:1===$e?"#F5F5F5":"#FFFFFF",color:1===$e?"#999":"#1a1a1a",fontSize:ne?"11px":"12px",fontFamily:Et,fontWeight:600,cursor:1===$e?"not-allowed":"pointer",opacity:1===$e?.5:1}},"Previous"),a.default.createElement("div",{style:{display:"flex",gap:"4px"}},[...Array(Math.min(5,Xe))].map(((e,t)=>{let n;return n=Xe<=5||$e<=3?t+1:$e>=Xe-2?Xe-4+t:$e-2+t,a.default.createElement("button",{key:n,onClick:()=>_e(n),style:{padding:ne?"6px 10px":"6px 12px",border:$e===n?"none":"1px solid #E5E5E5",borderRadius:"4px",background:$e===n?"#4C4DDC":"#FFFFFF",color:$e===n?"#FFFFFF":"#1a1a1a",fontSize:ne?"11px":"12px",fontFamily:Et,fontWeight:600,cursor:"pointer",minWidth:ne?"32px":"36px"}},n)}))),a.default.createElement("button",{onClick:()=>_e((e=>Math.min(Xe,e+1))),disabled:$e===Xe,style:{padding:ne?"6px 10px":"6px 12px",border:"1px solid #E5E5E5",borderRadius:"4px",background:$e===Xe?"#F5F5F5":"#FFFFFF",color:$e===Xe?"#999":"#1a1a1a",fontSize:ne?"11px":"12px",fontFamily:Et,fontWeight:600,cursor:$e===Xe?"not-allowed":"pointer",opacity:$e===Xe?.5:1}},"Next"))))),a.default.createElement("div",{style:{flex:ne?"none":"1 1 35%",width:ne?"100%":"auto",display:J||!ne?"flex":"none",flexDirection:"column",minHeight:ne?"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:ne?"none":1,minHeight:ne?"auto":0}},J?a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:ne?"12px 14px":"16px 18px",background:"#E8EEF4",borderBottom:"1px solid #E5E5E5"}},a.default.createElement("div",null,a.default.createElement("div",{style:{color:"#002668",fontSize:ne?"14px":"16px",fontWeight:"700"}},J.patientName||"N/A"),a.default.createElement("div",{style:{color:"#002668",fontSize:ne?"11px":"13px"}},J.patientId||J.mrn||"N/A")),a.default.createElement("div",null,it(J)?a.default.createElement("img",{style:{width:ne?"36px":"44px",height:ne?"36px":"44px",borderRadius:"50%",objectFit:"cover"},src:J.image,alt:J.patientName}):a.default.createElement("div",{style:{width:ne?"36px":"44px",height:ne?"36px":"44px",borderRadius:"50%",background:lt(J.patientName),display:"flex",alignItems:"center",justifyContent:"center",color:"#FFFFFF",fontWeight:700,fontSize:ne?"16px":"20px"}},rt(J.patientName)))),a.default.createElement("div",{style:{padding:ne?"12px 14px":"14px 18px",gap:ne?"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:ne?"10px":"11px",color:"#888",marginBottom:"3px"}},"Speciality"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ne?"12px":"13px"}},J?.specialisation||J?.speciality||"N/A")),a.default.createElement("div",{style:{textAlign:"right"}},a.default.createElement("div",{style:{fontSize:ne?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Type"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ne?"12px":"13px"}},J?.type||J?.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:ne?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Date"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ne?"12px":"13px"}},J?.date||J?.appointmentDate||"N/A")),a.default.createElement("div",{style:{textAlign:"right"}},a.default.createElement("div",{style:{fontSize:ne?"10px":"11px",color:"#888",marginBottom:"3px"}},"Appointment Time"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ne?"12px":"13px"}},J?.time||J?.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:ne?"10px":"11px",color:"#888",marginBottom:"3px"}},"Doctor"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ne?"12px":"13px"}},J?.doctor||J?.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:ne?"10px":"11px",color:"#888",marginBottom:"3px"}},"Hospital"),a.default.createElement("div",{style:{fontWeight:"700",fontSize:ne?"12px":"13px"}},J?.hospital||J?.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:ne?"10px":"11px",color:"#888",marginBottom:"3px"}},"Reason for Appointment"),a.default.createElement("div",{style:{fontWeight:"600",fontSize:ne?"11px":"12px",lineHeight:"1.4"}},J?.reason||J?.reasonForAppointment||"No reason provided"))),"upcoming"===V&&a.default.createElement("div",{style:{display:"flex",flexDirection:ne?"column":"row",gap:"6px",marginTop:"10px"}},a.default.createElement("button",{type:"button",onClick:ct,disabled:ve,style:{flex:1,background:ve?"#99e4e8":"#1CC3CE",color:"#FFFFFF",border:"1px solid #1CC3CE",borderRadius:"6px",padding:ne?"10px 8px":"8px 6px",fontFamily:Et,fontWeight:600,fontSize:ne?"11px":"12px",cursor:ve?"not-allowed":"pointer"}},ve?"Connecting...":"Join Call >")),"upcoming"===V&&Ce&&a.default.createElement("div",{style:{fontSize:"11px",color:"#e53935",marginTop:"6px",textAlign:"center",width:"100%"}},"⚠️ ",Ce))):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"))))))),me&&a.default.createElement("div",{style:{position:"fixed",left:ye?"0":ne?"10px":`${De.x}px`,top:ye?"0":ne?"70px":`${De.y}px`,right:ye?"0":ne?"10px":"auto",bottom:ye?"0":"auto",width:ye?"100vw":ne?"calc(100vw - 20px)":ge?"350px":`${We.width}px`,height:ye?"100vh":ge?"auto":ne?"300px":`${We.height}px`,background:"#FFFFFF",borderRadius:ye?"0":"8px",boxShadow:"0 8px 24px rgba(0, 0, 0, 0.3)",zIndex:1e4,overflow:"hidden",display:"flex",flexDirection:"column",transition:Me||Pe?"none":"all 0.3s ease"}},a.default.createElement("div",{onPointerDown:ne||ye?void 0:xt,onPointerMove:ne||ye?void 0:gt,onPointerUp:ne||ye?void 0:ht,onPointerCancel:ne||ye?void 0:ht,style:{background:"linear-gradient(135deg, #4C4DDC 0%, #3A3BBD 100%)",color:"#FFFFFF",padding:ne?"8px 10px":"10px 12px",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:ne||ye?"default":"move",userSelect:"none"}},a.default.createElement("div",{style:{display:"flex",alignItems:"center",gap:ne?"6px":"8px",flex:1,minWidth:0}},a.default.createElement("div",{style:{width:ne?"6px":"8px",height:ne?"6px":"8px",borderRadius:"50%",background:"#FF4444",animation:"pulse 2s infinite",flexShrink:0}}),a.default.createElement("span",{style:{fontSize:ne?"11px":"13px",fontWeight:600,fontFamily:Et,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},"Video Call - ",J?.patientName||"Patient")),a.default.createElement("div",{style:{display:"flex",gap:ne?"4px":"6px",alignItems:"center",flexShrink:0}},!ye&&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:ne?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ne?"28px":"32px",height:ne?"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:ge?"Restore":"Minimize"},ge?a.default.createElement("svg",{width:ne?"14":"16",height:ne?"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:ne?"14":"16",height:ne?"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:mt,style:{background:"rgba(255, 255, 255, 0.2)",border:"1px solid rgba(255, 255, 255, 0.3)",borderRadius:"6px",color:"#FFFFFF",cursor:"pointer",padding:ne?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ne?"28px":"32px",height:ne?"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:ye?"Exit Fullscreen":"Fullscreen"},ye?a.default.createElement("svg",{width:ne?"14":"16",height:ne?"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:ne?"14":"16",height:ne?"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:ut,style:{background:"rgba(255, 255, 255, 0.2)",border:"1px solid rgba(255, 255, 255, 0.3)",borderRadius:"6px",color:"#FFFFFF",cursor:"pointer",padding:ne?"5px 8px":"6px 10px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",minWidth:ne?"28px":"32px",height:ne?"28px":"32px",fontWeight:"bold",fontSize:ne?"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"},"×"))),!ge&&a.default.createElement("div",{style:{flex:1,background:"#000000",position:"relative"}},a.default.createElement("iframe",{src:(()=>{if(!Fe)return"";const e=String($||"").replace(/\/?$/,"/");return console.log("${base}token=${callToken}",`${e}token=${Fe}`),`${e}token=${Fe}`})(),style:{width:"100%",height:"100%",border:"none"},allow:"camera; microphone; display-capture; autoplay",allowFullScreen:!0,title:"Video Call"})),!ne&&!ye&&!ge&&a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{onPointerDown:e=>yt("top-left",e),onPointerMove:gt,onPointerUp:ht,onPointerCancel:ht,style:{position:"absolute",left:0,top:0,width:"16px",height:"16px",cursor:"nwse-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>yt("top-right",e),onPointerMove:gt,onPointerUp:ht,onPointerCancel:ht,style:{position:"absolute",right:0,top:0,width:"16px",height:"16px",cursor:"nesw-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>yt("bottom-left",e),onPointerMove:gt,onPointerUp:ht,onPointerCancel:ht,style:{position:"absolute",left:0,bottom:0,width:"16px",height:"16px",cursor:"nesw-resize",background:"transparent",zIndex:10001}}),a.default.createElement("div",{onPointerDown:e=>yt("bottom-right",e),onPointerMove:gt,onPointerUp:ht,onPointerCancel:ht,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 "))),Ft&&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:Et,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"}},P?"Not authorised":"Sign in required"),a.default.createElement("p",{style:{fontSize:"14px",color:"#666",margin:0,lineHeight:1.5}},bt),a.default.createElement("p",{style:{fontSize:"13px",color:"#999",marginTop:"16px",marginBottom:0}},"Redirecting to login...")))),a.default.createElement(b,null,wt)};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(w,{config:e}));i.default.render(a.default.createElement(n,null),S)},closePopup:()=>{S&&(i.default.unmountComponentAtNode(S),S=null)}};window.BookingSDK=v,e.AppointmentPage=w,e.PIH_APPOINTMENT_WIDGET_CLASS=E,e.default=v,Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -15,22 +15,24 @@ var _apiConfig = require("../constants/apiConfig");
15
15
  * @returns {Promise} Appointments data
16
16
  */
17
17
  const getAppointmentsByStatus = async function (status, fromDate, toDate) {
18
- let config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
18
+ let type = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'ONLINE';
19
+ let config = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
19
20
  // Map status to API format
20
21
  let apiStatus = (status || "").toUpperCase();
21
22
  if (apiStatus === "INPROGRESS") {
22
23
  apiStatus = "IN_PROGRESS";
23
24
  }
24
- const baseURL = config.apiBaseUrl || _apiConfig.API_BASE_URL;
25
+ const baseURL = config.apiBaseUrl;
25
26
  const hospitalId = config.hospitalId || _apiConfig.DEFAULT_PARAMS.hospitalId;
26
- const doctorId = config.doctorId || _apiConfig.DEFAULT_PARAMS.doctorId;
27
+ const doctorId = config.doctorId;
27
28
  const token = config.token || '';
28
29
  const params = {
29
30
  hospitalId,
30
31
  doctorId,
31
32
  fromDate,
32
33
  toDate,
33
- statuses: apiStatus
34
+ statuses: apiStatus,
35
+ type
34
36
  };
35
37
  const url = `${baseURL}${_apiConfig.API_PATHS.APPOINTMENTS}`;
36
38
 
@@ -49,7 +51,7 @@ exports.getAppointmentsByStatus = getAppointmentsByStatus;
49
51
  const getAppointmentDetails = async function (appointmentId) {
50
52
  let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
51
53
  try {
52
- const baseURL = config.apiBaseUrl || _apiConfig.API_BASE_URL;
54
+ const baseURL = config.apiBaseUrl;
53
55
  const url = `${baseURL}${_apiConfig.API_PATHS.APPOINTMENT_DETAILS}/${appointmentId}`;
54
56
  const response = await (0, _httpService.getApi)(url, {}, "PIH-Appointment-Widget");
55
57
  if (response.err) {
@@ -71,14 +73,15 @@ const getAppointmentDetails = async function (appointmentId) {
71
73
  exports.getAppointmentDetails = getAppointmentDetails;
72
74
  const initiateConsultation = async function (appointment) {
73
75
  let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
74
- const baseURL = (config.apiBaseUrl || _apiConfig.API_BASE_URL).replace(/\/$/, "");
76
+ console.log("initiateConsultation -> config", config);
77
+ const baseURL = config.apiBaseUrl.replace(/\/$/, "");
75
78
  const url = `${baseURL}${_apiConfig.API_PATHS.INITIATE_CALL}`;
76
79
  const appToken = config.appToken || "";
77
80
  const body = {
78
81
  patientId: String(appointment.patientId || ""),
79
82
  primaryPatientId: String(appointment.primaryPatientId || appointment.patientId || ""),
80
83
  hospitalId: config.hospitalId || _apiConfig.DEFAULT_PARAMS.hospitalId,
81
- doctorId: String(config.doctor_id || _apiConfig.DEFAULT_PARAMS.doctorId),
84
+ doctorId: String(config.doctorId),
82
85
  patientName: appointment.patientName || appointment.name || "",
83
86
  doctorName: appointment.doctorName || config.doctorName,
84
87
  appointmentId: String(appointment.id || appointment.appointmentId || appointment._id || "")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pih-appointment-widget",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "main": "dist/App.js",
5
5
  "module": "dist/App.js",
6
6
  "exports": {
@@ -25,6 +25,7 @@ const STORAGE_KEY_EMAIL = "pih_appointment_email";
25
25
  const STORAGE_KEY_APP_TOKEN = "pih_appointment_appToken";
26
26
  const STORAGE_KEY_DOCTOR_ID = "pih_appointment_doctorId";
27
27
  const STORAGE_KEY_USER_NAME = "pih_appointment_userName";
28
+ const STORAGE_KEY_API_BASE_URL = "pih_appointment_apiBaseUrl";
28
29
 
29
30
  const DEFAULT_PIP_WIDTH = 720;
30
31
  const DEFAULT_PIP_HEIGHT = 560;
@@ -96,8 +97,15 @@ class AppointmentErrorBoundary extends Component {
96
97
  }
97
98
 
98
99
  // SDK Component - accepts configuration from parent app
99
- const AppointmentPage = ({ config = {}}) => {
100
- const apiBaseUrl = config.apiBaseUrl || API_BASE_URL;
100
+ const AppointmentPage = ({ config = {} }) => {
101
+ const [storedApiBaseUrl, setStoredApiBaseUrl] = useState(() => {
102
+ try {
103
+ return typeof localStorage !== "undefined" ? localStorage.getItem(STORAGE_KEY_API_BASE_URL) : null;
104
+ } catch {
105
+ return null;
106
+ }
107
+ });
108
+ const apiBaseUrl = config.apiBaseUrl || storedApiBaseUrl || API_BASE_URL;
101
109
  const hospitalId = config.hospitalId || DEFAULT_PARAMS.hospitalId;
102
110
 
103
111
  // idToken/email: config first, then localStorage. When Flutter (or parent) passes a new token, we use it and re-login.
@@ -141,8 +149,12 @@ const AppointmentPage = ({ config = {}}) => {
141
149
  localStorage.setItem(STORAGE_KEY_EMAIL, config.email);
142
150
  setStoredEmail(config.email);
143
151
  }
152
+ if (config.apiBaseUrl && String(config.apiBaseUrl).trim()) {
153
+ localStorage.setItem(STORAGE_KEY_API_BASE_URL, config.apiBaseUrl.trim());
154
+ setStoredApiBaseUrl(config.apiBaseUrl.trim());
155
+ }
144
156
  } catch (e) {}
145
- }, [config.idToken, config.token, config.email]);
157
+ }, [config.idToken, config.token, config.email, config.apiBaseUrl]);
146
158
 
147
159
  const [appToken, setAppToken] = useState(() => {
148
160
  try {
@@ -412,7 +424,7 @@ const AppointmentPage = ({ config = {}}) => {
412
424
  doctorId,
413
425
  token: appToken,
414
426
  };
415
- const response = await getAppointmentsByStatus(activeTab, fromDate, toDate, serviceConfig);
427
+ const response = await getAppointmentsByStatus(activeTab, fromDate, toDate, 'PHYSICAL', serviceConfig);
416
428
  if (response.status === 401 || response.status === 403) {
417
429
  // Token expired — clear stored token and trigger re-login (SSO effect will fire)
418
430
  try {
@@ -462,6 +474,7 @@ const AppointmentPage = ({ config = {}}) => {
462
474
  localStorage.removeItem(STORAGE_KEY_APP_TOKEN);
463
475
  localStorage.removeItem(STORAGE_KEY_DOCTOR_ID);
464
476
  localStorage.removeItem(STORAGE_KEY_USER_NAME);
477
+ localStorage.removeItem(STORAGE_KEY_API_BASE_URL);
465
478
  }
466
479
  } catch (e) {}
467
480
  setShowProfileDropdown(false);
@@ -520,7 +533,7 @@ const AppointmentPage = ({ config = {}}) => {
520
533
  }
521
534
  };
522
535
 
523
- // Handle PiP close
536
+ // Handle PiP close — refresh list so completed call is reflected (e.g. moved to Completed)
524
537
  const handleClosePip = () => {
525
538
  setShowPipVideo(false);
526
539
  setIsPipMinimized(false);
@@ -528,6 +541,7 @@ const AppointmentPage = ({ config = {}}) => {
528
541
  setCallToken(null);
529
542
  setCallUrl(null);
530
543
  setCallError(null);
544
+ fetchAppointments();
531
545
  };
532
546
 
533
547
  // Handle PiP minimize
@@ -1911,6 +1925,8 @@ const AppointmentPage = ({ config = {}}) => {
1911
1925
  </div>
1912
1926
  </div>
1913
1927
  </div>
1928
+ {/* Join Call only for upcoming appointments */}
1929
+ {activeTab === "upcoming" && (
1914
1930
  <div style={{
1915
1931
  display: "flex",
1916
1932
  flexDirection: isMobile ? "column" : "row",
@@ -1937,7 +1953,8 @@ const AppointmentPage = ({ config = {}}) => {
1937
1953
  {callLoading ? "Connecting..." : "Join Call >"}
1938
1954
  </button>
1939
1955
  </div>
1940
- {callError && (
1956
+ )}
1957
+ {activeTab === "upcoming" && callError && (
1941
1958
  <div style={{ fontSize: "11px", color: "#e53935", marginTop: "6px", textAlign: "center", width: "100%" }}>
1942
1959
  ⚠️ {callError}
1943
1960
  </div>
@@ -16,8 +16,7 @@ export const API_PATHS = {
16
16
 
17
17
  // Default request parameters (will be fetched from auth API later)
18
18
  export const DEFAULT_PARAMS = {
19
- hospitalId: "dMtEGhak",
20
- doctorId: 6694
19
+ hospitalId: "dMtEGhak"
21
20
  };
22
21
 
23
22
  // Request timeout (milliseconds)
@@ -13,19 +13,20 @@ import {
13
13
  * @param {object} config - Optional configuration { apiBaseUrl, hospitalId, doctorId }
14
14
  * @returns {Promise} Appointments data
15
15
  */
16
- export const getAppointmentsByStatus = async (status, fromDate, toDate, config = {}) => {
16
+ export const getAppointmentsByStatus = async (status, fromDate, toDate, type = 'ONLINE', config = {}) => {
17
17
  // Map status to API format
18
18
  let apiStatus = (status || "").toUpperCase();
19
+
19
20
  if (apiStatus === "INPROGRESS") {
20
21
  apiStatus = "IN_PROGRESS";
21
22
  }
22
23
 
23
- const baseURL = config.apiBaseUrl || API_BASE_URL;
24
+ const baseURL = config.apiBaseUrl;
24
25
  const hospitalId = config.hospitalId || DEFAULT_PARAMS.hospitalId;
25
- const doctorId = config.doctorId || DEFAULT_PARAMS.doctorId;
26
+ const doctorId = config.doctorId;
26
27
  const token = config.token || '';
27
28
 
28
- const params = { hospitalId, doctorId, fromDate, toDate, statuses: apiStatus };
29
+ const params = { hospitalId, doctorId, fromDate, toDate, statuses: apiStatus, type };
29
30
  const url = `${baseURL}${API_PATHS.APPOINTMENTS}`;
30
31
 
31
32
  // Return raw response (including status) so caller can detect 401 and re-login
@@ -41,7 +42,7 @@ export const getAppointmentsByStatus = async (status, fromDate, toDate, config =
41
42
  */
42
43
  export const getAppointmentDetails = async (appointmentId, config = {}) => {
43
44
  try {
44
- const baseURL = config.apiBaseUrl || API_BASE_URL;
45
+ const baseURL = config.apiBaseUrl;
45
46
  const url = `${baseURL}${API_PATHS.APPOINTMENT_DETAILS}/${appointmentId}`;
46
47
 
47
48
  const response = await getApi(url, {}, "PIH-Appointment-Widget");
@@ -64,7 +65,8 @@ export const getAppointmentDetails = async (appointmentId, config = {}) => {
64
65
  * @returns {Promise<{ data: { token, url, roomName, participantName }, err?, status? }>}
65
66
  */
66
67
  export const initiateConsultation = async (appointment, config = {}) => {
67
- const baseURL = (config.apiBaseUrl || API_BASE_URL).replace(/\/$/, "");
68
+ console.log("initiateConsultation -> config", config)
69
+ const baseURL = (config.apiBaseUrl).replace(/\/$/, "");
68
70
  const url = `${baseURL}${API_PATHS.INITIATE_CALL}`;
69
71
  const appToken = config.appToken || "";
70
72
 
@@ -72,7 +74,7 @@ export const initiateConsultation = async (appointment, config = {}) => {
72
74
  patientId: String(appointment.patientId || ""),
73
75
  primaryPatientId: String(appointment.primaryPatientId || appointment.patientId || ""),
74
76
  hospitalId: config.hospitalId || DEFAULT_PARAMS.hospitalId,
75
- doctorId: String(config.doctor_id || DEFAULT_PARAMS.doctorId),
77
+ doctorId: String(config.doctorId),
76
78
  patientName: appointment.patientName || appointment.name || "",
77
79
  doctorName: appointment.doctorName || config.doctorName,
78
80
  appointmentId: String(appointment.id || appointment.appointmentId || appointment._id || ""),