hplx-feature-library 1.0.259 → 1.0.261

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.
Files changed (26) hide show
  1. package/dist/{APIAction-BgDEMmVd.cjs → APIAction-DZ6jFXOq.cjs} +1 -1
  2. package/dist/{APIAction-DT8TOViB.js → APIAction-VHoA7gHt.js} +1 -1
  3. package/dist/Attachments/index.js +1 -1
  4. package/dist/{Attachments-C-xXXQ_t.cjs → Attachments-CEyxq22h.cjs} +1 -1
  5. package/dist/{Attachments-imJatd2A.js → Attachments-Dsb_1p7x.js} +274 -269
  6. package/dist/PatientAddEdit/index.js +1 -1
  7. package/dist/{PatientAddEdit-C5MnysOS.js → PatientAddEdit-OJOcJQ2m.js} +2 -2
  8. package/dist/{PatientAddEdit-CuYCmfEb.cjs → PatientAddEdit-svjtGpiz.cjs} +1 -1
  9. package/dist/PatientPopup/index.js +1 -1
  10. package/dist/{PatientPopupContainer-ByfLLuRE.cjs → PatientPopupContainer-Bgo9gldx.cjs} +1 -1
  11. package/dist/{PatientPopupContainer-BcogPwe7.js → PatientPopupContainer-D4ip9SKW.js} +3 -3
  12. package/dist/{PrintModal-BIjnq6R5.cjs → PrintModal-ClPSnO5C.cjs} +4 -4
  13. package/dist/{PrintModal-CwTm7s39.js → PrintModal-Dq0Z1WeK.js} +2 -2
  14. package/dist/SearchPatients/index.js +1 -1
  15. package/dist/{SearchPatients-BjIvDU18.cjs → SearchPatients-C4Vnh3N8.cjs} +1 -1
  16. package/dist/{SearchPatients-B91CFBhq.js → SearchPatients-Db-rZQFH.js} +2 -2
  17. package/dist/UserProfile/index.js +1 -1
  18. package/dist/{UserProfile-1Pll0yKL.js → UserProfile-BxJOxt0y.js} +1 -1
  19. package/dist/{UserProfile-C47Wg1As.cjs → UserProfile-V_7POQiQ.cjs} +1 -1
  20. package/dist/common/utils/NetworkInstance.d.ts +1 -0
  21. package/dist/common-utils-BuL9g3zT.cjs +6 -0
  22. package/dist/{common-utils-DOjdqsiU.js → common-utils-DvF5Rjeq.js} +336 -320
  23. package/dist/index.js +6 -6
  24. package/dist/print-pdf/index.js +1 -1
  25. package/package.json +1 -1
  26. package/dist/common-utils-Cw6aYEiU.cjs +0 -6
@@ -1 +1 @@
1
- "use strict";const i=require("./common-utils-Cw6aYEiU.cjs"),P=require("./dayjs.min-DXp74Ozx.cjs"),m="/preferences/doctor",d="/preferences/visitpad",E="/preferences/branch",u="patient/search",A="../api/modelGetAddPatientSuggestion.php",g="appointments/get",_="/v1/patient/add",h="/v1/patients",f="../api/modelSavePatientImage.php",I="../api/modelDeletePatientImage.php",l="/patient/detail",D=async(s="",t={},e,n,r)=>{const{doc_rid:o=""}=t;let a="";Array.isArray(s)?a=s.map(c=>`&fields_required=${encodeURIComponent(c)}`).join(""):s&&(a=`&fields_required=${encodeURIComponent(s)}`);try{const c=await i.hplxAPI(r?.token,r.envName).get(`${m}/${o||e}?branch_id=${n}`+a),{data:p}=c||{};return Promise.resolve(p)}catch(c){return console.error("Error fetching doctor preference:",c),Promise.reject(c)}},T=async(s="",t,e)=>{try{const n=await i.ReArchAPI(e.token,e.envName).get(`${E}/${t}?fields_required=${s}`),{data:r}=n||{};return Promise.resolve(r)}catch(n){return console.log(n),Promise.reject(n)}},w=async(s,t,e,n,r)=>{try{const o={appnt_date:s,doctor_role_id:t,doctor_id:n,org_branch_id:e},a=await i.ReArchAPI(r.token,r.envName).post(g,{...o}),{data:c}=a||{};return Promise.resolve(c)}catch(o){return o instanceof Error&&console.error("Error fetching appointments:",o.message),o?.response?.status===401&&i.handle401Status(),Promise.reject(o)}},y=async(s,t)=>{let e=[];const n=await w(P.dayjs().format("YYYY-MM-DD"),s.doctor_role_id,s.branch_id,s.doctor_id,t);n?.appointments?.length&&(e=n.appointments),window.filteredUpcomingAppts=[],e.length&&(s.term?.length?window.filteredUpcomingAppts=e.filter(r=>r.org_person_name.length&&r.org_person_name.toLowerCase().includes(s.term.toLowerCase())&&r.appnt_date>=P.dayjs(new Date).format("YYYY-MM-DD")&&(r.remote_appnt_status==="CONFIRMED"||r.appnt_status===0||r.appnt_status===3||r.appnt_status===5)):window.filteredUpcomingAppts=e.filter(r=>r.appnt_date>=P.dayjs(new Date).format("YYYY-MM-DD")&&(r.remote_appnt_status==="CONFIRMED"||r.appnt_status===0||r.appnt_status===3||r.appnt_status===5)));try{const r=await i.ReArchAPI(t.token,t.envName).post(u,s),{data:o}=r||{};return Promise.resolve(o)}catch(r){return console.log(r),null}},N=async s=>{try{const t=await i.hplxAPI(s.token,s.envName).post(A),{data:e}=t||{},{apiError:n}=e||{};if(n)throw new Error(n);return Promise.resolve(e)}catch(t){return t instanceof Error&&console.error("Error fetching referred by list:",t.message),t?.response?.status===401&&i.handle401Status(),Promise.reject(t)}},R=async(s,t)=>{try{const e=await i.ReArchAPI(t.token,t.envName).post(_,{...s,token:t.token}),{data:n}=e||{};return Promise.resolve(n)}catch(e){return Promise.reject(e)}},j=async(s,t)=>{try{const e=await i.ReArchAPI(t.token,t.envName).put(h+"/"+s?.person_role_id,{...s}),{data:n}=e||{};return Promise.resolve(n)}catch(e){return console.log(e),Promise.reject(e)}},v=async(s,t)=>{try{const e=await i.hplxAPI(t.token,t.envName).post(f,s),{data:n}=e||{};return Promise.resolve(n)}catch(e){return console.log(e),Promise.reject(e)}},Y=async(s,t)=>{try{const e=await i.hplxAPI(t.token,t.envName).post(I,s),{data:n}=e||{};return Promise.resolve(n)}catch(e){return console.log(e),Promise.reject(e)}},C=async({callback:s,payload:t,token_env:e,isCallbackNeeded:n=!0})=>{try{const r=t;window?.partner_service_enabled==="1"&&(r.partner_service_enabled=!0);const o=await i.ReArchAPI(e.token,e.envName).post(l,{...r}),{data:a}=o||{},{error:c}=a||{};if(c)throw new Error(c);if(n)s(a);else return a}catch(r){console.log(r)}},G=async({doc_id:s="",doc_rid:t=""},e,n,r,o)=>{try{const a={branch_id:n,doctor_id:s||r,doctor_role_id:t||o},c=await i.hplxAPI(e.token,e.envName).post(d,a),{data:p}=c||{};return Promise.resolve(p)}catch(a){return console.error("Error fetching visitpad preference:",a),Promise.reject(a)}};exports.GET_PATIENT_DETAILS=l;exports.addPatientDetails=R;exports.addPatientImage=v;exports.deletePatientImage=Y;exports.getBranchPreferences=T;exports.getDoctorPreference=D;exports.getPatientDetails=C;exports.getPatientList=y;exports.getReferredByList=N;exports.getVisitpadPreference=G;exports.updatePatientDetails=j;
1
+ "use strict";const i=require("./common-utils-BuL9g3zT.cjs"),P=require("./dayjs.min-DXp74Ozx.cjs"),m="/preferences/doctor",d="/preferences/visitpad",E="/preferences/branch",u="patient/search",A="../api/modelGetAddPatientSuggestion.php",g="appointments/get",_="/v1/patient/add",h="/v1/patients",f="../api/modelSavePatientImage.php",I="../api/modelDeletePatientImage.php",l="/patient/detail",D=async(s="",t={},e,n,r)=>{const{doc_rid:o=""}=t;let a="";Array.isArray(s)?a=s.map(c=>`&fields_required=${encodeURIComponent(c)}`).join(""):s&&(a=`&fields_required=${encodeURIComponent(s)}`);try{const c=await i.hplxAPI(r?.token,r.envName).get(`${m}/${o||e}?branch_id=${n}`+a),{data:p}=c||{};return Promise.resolve(p)}catch(c){return console.error("Error fetching doctor preference:",c),Promise.reject(c)}},T=async(s="",t,e)=>{try{const n=await i.ReArchAPI(e.token,e.envName).get(`${E}/${t}?fields_required=${s}`),{data:r}=n||{};return Promise.resolve(r)}catch(n){return console.log(n),Promise.reject(n)}},w=async(s,t,e,n,r)=>{try{const o={appnt_date:s,doctor_role_id:t,doctor_id:n,org_branch_id:e},a=await i.ReArchAPI(r.token,r.envName).post(g,{...o}),{data:c}=a||{};return Promise.resolve(c)}catch(o){return o instanceof Error&&console.error("Error fetching appointments:",o.message),o?.response?.status===401&&i.handle401Status(),Promise.reject(o)}},y=async(s,t)=>{let e=[];const n=await w(P.dayjs().format("YYYY-MM-DD"),s.doctor_role_id,s.branch_id,s.doctor_id,t);n?.appointments?.length&&(e=n.appointments),window.filteredUpcomingAppts=[],e.length&&(s.term?.length?window.filteredUpcomingAppts=e.filter(r=>r.org_person_name.length&&r.org_person_name.toLowerCase().includes(s.term.toLowerCase())&&r.appnt_date>=P.dayjs(new Date).format("YYYY-MM-DD")&&(r.remote_appnt_status==="CONFIRMED"||r.appnt_status===0||r.appnt_status===3||r.appnt_status===5)):window.filteredUpcomingAppts=e.filter(r=>r.appnt_date>=P.dayjs(new Date).format("YYYY-MM-DD")&&(r.remote_appnt_status==="CONFIRMED"||r.appnt_status===0||r.appnt_status===3||r.appnt_status===5)));try{const r=await i.ReArchAPI(t.token,t.envName).post(u,s),{data:o}=r||{};return Promise.resolve(o)}catch(r){return console.log(r),null}},N=async s=>{try{const t=await i.hplxAPI(s.token,s.envName).post(A),{data:e}=t||{},{apiError:n}=e||{};if(n)throw new Error(n);return Promise.resolve(e)}catch(t){return t instanceof Error&&console.error("Error fetching referred by list:",t.message),t?.response?.status===401&&i.handle401Status(),Promise.reject(t)}},R=async(s,t)=>{try{const e=await i.ReArchAPI(t.token,t.envName).post(_,{...s,token:t.token}),{data:n}=e||{};return Promise.resolve(n)}catch(e){return Promise.reject(e)}},j=async(s,t)=>{try{const e=await i.ReArchAPI(t.token,t.envName).put(h+"/"+s?.person_role_id,{...s}),{data:n}=e||{};return Promise.resolve(n)}catch(e){return console.log(e),Promise.reject(e)}},v=async(s,t)=>{try{const e=await i.hplxAPI(t.token,t.envName).post(f,s),{data:n}=e||{};return Promise.resolve(n)}catch(e){return console.log(e),Promise.reject(e)}},Y=async(s,t)=>{try{const e=await i.hplxAPI(t.token,t.envName).post(I,s),{data:n}=e||{};return Promise.resolve(n)}catch(e){return console.log(e),Promise.reject(e)}},C=async({callback:s,payload:t,token_env:e,isCallbackNeeded:n=!0})=>{try{const r=t;window?.partner_service_enabled==="1"&&(r.partner_service_enabled=!0);const o=await i.ReArchAPI(e.token,e.envName).post(l,{...r}),{data:a}=o||{},{error:c}=a||{};if(c)throw new Error(c);if(n)s(a);else return a}catch(r){console.log(r)}},G=async({doc_id:s="",doc_rid:t=""},e,n,r,o)=>{try{const a={branch_id:n,doctor_id:s||r,doctor_role_id:t||o},c=await i.hplxAPI(e.token,e.envName).post(d,a),{data:p}=c||{};return Promise.resolve(p)}catch(a){return console.error("Error fetching visitpad preference:",a),Promise.reject(a)}};exports.GET_PATIENT_DETAILS=l;exports.addPatientDetails=R;exports.addPatientImage=v;exports.deletePatientImage=Y;exports.getBranchPreferences=T;exports.getDoctorPreference=D;exports.getPatientDetails=C;exports.getPatientList=y;exports.getReferredByList=N;exports.getVisitpadPreference=G;exports.updatePatientDetails=j;
@@ -1,4 +1,4 @@
1
- import { h as p, R as i, b as d } from "./common-utils-DOjdqsiU.js";
1
+ import { h as p, R as i, b as d } from "./common-utils-DvF5Rjeq.js";
2
2
  import { d as l } from "./dayjs.min-D52_GdfV.js";
3
3
  const P = "/preferences/doctor", E = "/preferences/visitpad", u = "/preferences/branch", f = "patient/search", _ = "../api/modelGetAddPatientSuggestion.php", g = "appointments/get", h = "/v1/patient/add", A = "/v1/patients", w = "../api/modelSavePatientImage.php", D = "../api/modelDeletePatientImage.php", T = "/patient/detail", R = async (s = "", t = {}, e, o, r) => {
4
4
  const { doc_rid: n = "" } = t;
@@ -1,4 +1,4 @@
1
- import { A as f } from "../Attachments-imJatd2A.js";
1
+ import { A as f } from "../Attachments-Dsb_1p7x.js";
2
2
  export {
3
3
  f as default
4
4
  };
@@ -183,4 +183,4 @@ For more info see: https://github.com/konvajs/react-konva/issues/256
183
183
  `,q9=`ReactKonva: You are using "zIndex" attribute for a Konva node.
184
184
  react-konva may get confused with ordering. Just define correct order of elements in your render function of a component.
185
185
  For more info see: https://github.com/konvajs/react-konva/issues/194
186
- `,Z9={};function l0(s,l,f=Z9){if(!By&&"zIndex"in l&&(console.warn(q9),By=!0),!Gy&&l.draggable){var v=l.x!==void 0||l.y!==void 0,S=l.onDragEnd||l.onDragMove;v&&!S&&(console.warn(J9),Gy=!0)}for(var y in f)if(!ky[y]){var h=y.slice(0,2)==="on",x=f[y]!==l[y];if(h&&x){var E=y.substr(2).toLowerCase();E.substr(0,7)==="content"&&(E="content"+E.substr(7,1).toUpperCase()+E.substr(8)),s.off(E,f[y])}var d=!l.hasOwnProperty(y);d&&s.setAttr(y,void 0)}var b=l._useStrictMode,P={},w=!1;const C={};for(var y in l)if(!ky[y]){var h=y.slice(0,2)==="on",A=f[y]!==l[y];if(h&&A){var E=y.substr(2).toLowerCase();E.substr(0,7)==="content"&&(E="content"+E.substr(7,1).toUpperCase()+E.substr(8)),l[y]&&(C[E]=l[y])}!h&&(l[y]!==f[y]||b&&l[y]!==s.getAttr(y))&&(w=!0,P[y]=l[y])}w&&(s.setAttrs(P),sl(s));for(var E in C)s.on(E+Em,C[E])}function sl(s){if(!W9.Konva.autoDrawEnabled){var l=s.getLayer()||s.getStage();l&&l.batchDraw()}}var rm=Sm();const D5={},Q9={};If.Node.prototype._applyProps=l0;function K9(s,l){if(typeof l=="string"){console.error(`Do not use plain text as child of Konva.Node. You are using text: ${l}`);return}s.add(l),sl(s)}function _9(s,l,f){let v=If[s];v||(console.error(`Konva has no node with the type ${s}. Group will be used instead. If you use minimal version of react-konva, just import required nodes into Konva: "import "konva/lib/shapes/${s}" If you want to render DOM elements as part of canvas tree take a look into this demo: https://konvajs.github.io/docs/react/DOM_Portal.html`),v=If.Group);const S={},y={};for(var h in l){var x=h.slice(0,2)==="on";x?y[h]=l[h]:S[h]=l[h]}const E=new v(S);return l0(E,y),E}function $9(s,l,f){console.error(`Text components are not supported for now in ReactKonva. Your text is: "${s}"`)}function eS(s,l,f){return!1}function tS(s){return s}function nS(){return null}function rS(){return null}function aS(s,l,f,v){return Q9}function iS(){}function sS(s){}function lS(s,l){return!1}function oS(){return D5}function uS(){return D5}const cS=setTimeout,fS=clearTimeout,dS=-1;function hS(s,l){return!1}const pS=!1,vS=!0,mS=!0;function gS(s,l){l.parent===s?l.moveToTop():s.add(l),sl(s)}function yS(s,l){l.parent===s?l.moveToTop():s.add(l),sl(s)}function P5(s,l,f){l._remove(),s.add(l),l.setZIndex(f.getZIndex()),sl(s)}function xS(s,l,f){P5(s,l,f)}function SS(s,l){l.destroy(),l.off(Em),sl(s)}function ES(s,l){l.destroy(),l.off(Em),sl(s)}function CS(s,l,f){console.error(`Text components are not yet supported in ReactKonva. You text is: "${f}"`)}function bS(s,l,f){}function AS(s,l,f,v,S){l0(s,S,v)}function wS(s){s.hide(),sl(s)}function RS(s){}function TS(s,l){(l.visible==null||l.visible)&&s.show()}function DS(s,l){}function PS(s){}function NS(){}const OS=()=>T5.DefaultEventPriority,MS=Object.freeze(Object.defineProperty({__proto__:null,appendChild:gS,appendChildToContainer:yS,appendInitialChild:K9,cancelTimeout:fS,clearContainer:PS,commitMount:bS,commitTextUpdate:CS,commitUpdate:AS,createInstance:_9,createTextInstance:$9,detachDeletedInstance:NS,finalizeInitialChildren:eS,getChildHostContext:uS,getCurrentEventPriority:OS,getPublicInstance:tS,getRootHostContext:oS,hideInstance:wS,hideTextInstance:RS,idlePriority:rm.unstable_IdlePriority,insertBefore:P5,insertInContainerBefore:xS,isPrimaryRenderer:pS,noTimeout:dS,now:rm.unstable_now,prepareForCommit:nS,preparePortalMount:rS,prepareUpdate:aS,removeChild:SS,removeChildFromContainer:ES,resetAfterCommit:iS,resetTextContent:sS,run:rm.unstable_runWithPriority,scheduleTimeout:cS,shouldDeprioritizeSubtree:lS,shouldSetTextContent:hS,supportsMutation:mS,unhideInstance:TS,unhideTextInstance:DS,warnsIfNotActing:vS},Symbol.toStringTag,{value:"Module"}));var jS=Object.defineProperty,LS=Object.defineProperties,zS=Object.getOwnPropertyDescriptors,Uy=Object.getOwnPropertySymbols,FS=Object.prototype.hasOwnProperty,HS=Object.prototype.propertyIsEnumerable,Vy=(s,l,f)=>l in s?jS(s,l,{enumerable:!0,configurable:!0,writable:!0,value:f}):s[l]=f,Xy=(s,l)=>{for(var f in l||(l={}))FS.call(l,f)&&Vy(s,f,l[f]);if(Uy)for(var f of Uy(l))HS.call(l,f)&&Vy(s,f,l[f]);return s},kS=(s,l)=>LS(s,zS(l)),Yy,Iy;typeof window<"u"&&((Yy=window.document)!=null&&Yy.createElement||((Iy=window.navigator)==null?void 0:Iy.product)==="ReactNative")?ia.useLayoutEffect:ia.useEffect;function N5(s,l,f){if(!s)return;if(f(s)===!0)return s;let v=s.child;for(;v;){const S=N5(v,l,f);if(S)return S;v=v.sibling}}function O5(s){try{return Object.defineProperties(s,{_currentRenderer:{get(){return null},set(){}},_currentRenderer2:{get(){return null},set(){}}})}catch{return s}}const Wy=console.error;console.error=function(){const s=[...arguments].join("");if(s?.startsWith("Warning:")&&s.includes("useContext")){console.error=Wy;return}return Wy.apply(this,arguments)};const Cm=O5(ia.createContext(null));class M5 extends ia.Component{render(){return ia.createElement(Cm.Provider,{value:this._reactInternals},this.props.children)}}function BS(){const s=ia.useContext(Cm);if(s===null)throw new Error("its-fine: useFiber must be called within a <FiberProvider />!");const l=ia.useId();return ia.useMemo(()=>{for(const v of[s,s?.alternate]){if(!v)continue;const S=N5(v,!1,y=>{let h=y.memoizedState;for(;h;){if(h.memoizedState===l)return!0;h=h.next}});if(S)return S}},[s,l])}function GS(){const s=BS(),[l]=ia.useState(()=>new Map);l.clear();let f=s;for(;f;){if(f.type&&typeof f.type=="object"){const S=f.type._context===void 0&&f.type.Provider===f.type?f.type:f.type._context;S&&S!==Cm&&!l.has(S)&&l.set(S,ia.useContext(O5(S)))}f=f.return}return l}function US(){const s=GS();return ia.useMemo(()=>Array.from(s.keys()).reduce((l,f)=>v=>ia.createElement(l,null,ia.createElement(f.Provider,kS(Xy({},v),{value:s.get(f)}))),l=>ia.createElement(M5,Xy({},l))),[s])}function VS(s){const l=ae.useRef({});return ae.useLayoutEffect(()=>{l.current=s}),ae.useLayoutEffect(()=>()=>{l.current={}},[]),l.current}const XS=s=>{const l=ae.useRef(),f=ae.useRef(),v=ae.useRef(),S=VS(s),y=US(),h=x=>{const{forwardedRef:E}=s;E&&(typeof E=="function"?E(x):E.current=x)};return ae.useLayoutEffect(()=>(f.current=new If.Stage({width:s.width,height:s.height,container:l.current}),h(f.current),v.current=Uf.createContainer(f.current,T5.LegacyRoot,!1,null),Uf.updateContainer(ae.createElement(y,{},s.children),v.current),()=>{If.isBrowser&&(h(null),Uf.updateContainer(null,v.current,null),f.current.destroy())}),[]),ae.useLayoutEffect(()=>{h(f.current),l0(f.current,s,S),Uf.updateContainer(ae.createElement(y,{},s.children),v.current,null)}),ae.createElement("div",{ref:l,id:s.id,accessKey:s.accessKey,className:s.className,role:s.role,style:s.style,tabIndex:s.tabIndex,title:s.title})},YS="Layer",Jy="Rect",qy="Circle",IS="Line",WS="Image",Uf=V9(MS);Uf.injectIntoDevTools({findHostInstanceByFiber:()=>null,bundleType:process.env.NODE_ENV!=="production"?1:0,version:ae.version,rendererPackageName:"react-konva"});const JS=ae.forwardRef((s,l)=>ae.createElement(M5,{},ae.createElement(XS,{...s,forwardedRef:l}))),qS=10,ZS=2.5,j5=({imageUrl:s,customClassName:l="",containerRef:f})=>{const{showPenTool:v,penColor:S,penTool:y,strokeWidth:h}=Jf(),[x,E]=ae.useState(null),[d,b]=ae.useState({width:0,height:0}),[P,w]=ae.useState({scale:1,x:0,y:0}),[C,A]=ae.useState(!1),[N,B]=ae.useState([]),[G,R]=ae.useState([]),[g,M]=ae.useState(null),[j,U]=ae.useState(!1),[Z,L]=ae.useState({scale:1,x:0,y:0}),H=ae.useRef(null),k=ae.useRef(null),J=ae.useRef(null);ae.useEffect(()=>{const O=new window.Image;O.onload=()=>{E(O)},O.src=s},[s]);const _=()=>{if(v)return;const O=H.current;if(O)if(j)w(Z),U(!1);else{const Y=O.getPointerPosition();if(!Y)return;const V={x:(Y.x-O.x())/O.scaleX(),y:(Y.y-O.y())/O.scaleY()},q=Math.min(O.scaleX()*ZS,qS);w({scale:q,x:Y.x-V.x*q,y:Y.y-V.y*q}),U(!0)}},ee=O=>{w(Y=>({...Y,x:O.target.x(),y:O.target.y()}))},re=O=>O?O.getRelativePointerPosition():null,$=ae.useCallback(O=>{if(!v||!x)return;const Y=re(O.target.getStage());Y&&(A(!0),y===Ye.E_CANVAS_TOOLS.PEN?B([...N,{points:[{x:Y.x,y:Y.y}],color:S,width:h}]):(y===Ye.E_CANVAS_TOOLS.RECT||y===Ye.E_CANVAS_TOOLS.CIRCLE)&&M({points:[{x:Y.x,y:Y.y}]}))},[v,x,y,N,S,h]),pe=ae.useCallback(O=>{if(!v||!C||!x)return;const Y=re(O.target.getStage());if(Y)if(y===Ye.E_CANVAS_TOOLS.PEN){const V=N[N.length-1];V&&(V.points.push({x:Y.x,y:Y.y}),N.splice(N.length-1,1,V),B([...N]))}else g&&(y===Ye.E_CANVAS_TOOLS.RECT||y===Ye.E_CANVAS_TOOLS.CIRCLE)&&M({points:[g.points[0],{x:Y.x,y:Y.y}]})},[v,C,x,y,N,g]),z=ae.useCallback(O=>{!v||!x||(O?.evt.type.startsWith("touch")&&O.evt.preventDefault(),A(!1),g&&(y===Ye.E_CANVAS_TOOLS.RECT||y===Ye.E_CANVAS_TOOLS.CIRCLE)&&(g.points.length===2&&R([...G,{...g,tool:y,color:S,width:h}]),M(null)))},[v,x,g,y,G,S,h]);return ae.useEffect(()=>{const O=()=>f?document.getElementById(f):J.current,Y=()=>{const V=O();if(V&&x){const{clientWidth:q,clientHeight:se}=V;b({width:q,height:se});const ne=Math.min(q/x.width,se/x.height,1),ge={scale:ne,x:(q-x.width*ne)/2,y:(se-x.height*ne)/2};w(ge),L(ge),U(!1)}};return Y(),window.addEventListener("resize",Y),()=>window.removeEventListener("resize",Y)},[f,x]),ae.useEffect(()=>{const O=H.current;if(!O)return;const Y=O.container();v?Y.style.cursor="crosshair":Y.style.cursor=j?"zoom-out":"zoom-in"},[v,j]),ae.useEffect(()=>{const O=Y=>{C&&v&&Y.preventDefault()};return document.addEventListener("touchstart",O,{passive:!1}),document.addEventListener("touchmove",O,{passive:!1}),document.addEventListener("touchend",O,{passive:!1}),()=>{document.removeEventListener("touchstart",O),document.removeEventListener("touchmove",O),document.removeEventListener("touchend",O)}},[C,v]),x?I.jsxRuntimeExports.jsx("div",{ref:J,style:{width:"100%",height:"100%",touchAction:"none",WebkitUserSelect:"none",userSelect:"none"},className:l,children:I.jsxRuntimeExports.jsx(JS,{ref:H,width:d.width,height:d.height,onMouseDown:$,onMouseMove:pe,onMouseUp:z,onTouchStart:$,onTouchMove:pe,onTouchEnd:z,onClick:_,onTap:_,onDragEnd:ee,scaleX:P.scale,scaleY:P.scale,x:P.x,y:P.y,draggable:!v,children:I.jsxRuntimeExports.jsxs(YS,{children:[I.jsxRuntimeExports.jsx(WS,{ref:k,image:x,width:x.width,height:x.height}),N.map((O,Y)=>I.jsxRuntimeExports.jsx(IS,{points:O.points.flatMap(V=>[V.x,V.y]),stroke:O.color,strokeWidth:O.width,tension:.5,lineCap:"round",lineJoin:"round",globalCompositeOperation:"source-over"},`line-${Y}`)),G.map((O,Y)=>{if(O.tool===Ye.E_CANVAS_TOOLS.RECT&&O.points.length===2){const[V,q]=O.points;return I.jsxRuntimeExports.jsx(Jy,{x:V.x,y:V.y,width:q.x-V.x,height:q.y-V.y,stroke:O.color,strokeWidth:O.width,fill:"transparent"},`rect-${Y}`)}else if(O.tool===Ye.E_CANVAS_TOOLS.CIRCLE&&O.points.length===2){const[V,q]=O.points,se=Math.sqrt(Math.pow(q.x-V.x,2)+Math.pow(q.y-V.y,2));return I.jsxRuntimeExports.jsx(qy,{x:V.x,y:V.y,radius:se,stroke:O.color,strokeWidth:O.width,fill:"transparent"},`circle-${Y}`)}return null}),g&&g.points.length===2&&I.jsxRuntimeExports.jsxs(I.jsxRuntimeExports.Fragment,{children:[y===Ye.E_CANVAS_TOOLS.RECT&&I.jsxRuntimeExports.jsx(Jy,{x:g.points[0].x,y:g.points[0].y,width:g.points[1].x-g.points[0].x,height:g.points[1].y-g.points[0].y,stroke:S,strokeWidth:h,fill:"transparent",dash:[5,5]}),y===Ye.E_CANVAS_TOOLS.CIRCLE&&I.jsxRuntimeExports.jsx(qy,{x:g.points[0].x,y:g.points[0].y,radius:Math.sqrt(Math.pow(g.points[1].x-g.points[0].x,2)+Math.pow(g.points[1].y-g.points[0].y,2)),stroke:S,strokeWidth:h,fill:"transparent",dash:[5,5]})]})]})})}):I.jsxRuntimeExports.jsx("div",{style:{position:"relative"},children:I.jsxRuntimeExports.jsx("div",{style:{width:600,height:400,background:"#f0f0f0",display:"flex",alignItems:"center",justifyContent:"center"},children:"Loading image..."})})};function QS(s){const{containerHeight:l,containerWidth:f}=s,{groupDocuments:v}=q6(),{parentRef:S}=Ea(),y=ae.useRef(null);let h=1,x=v.length;(v.length===3||v.length===4)&&(h=2,x=2);const E=l/h,d=f/x;return ae.useEffect(()=>{y.current&&(y.current.style.height=`${l}px`,y.current.style.width=`${f}px`)},[l,f,S]),I.jsxRuntimeExports.jsx("div",{ref:y,className:"hfl-bg-Gray-400 hfl-py-2",style:{display:v.length>1?"grid":"flex",gridTemplateColumns:v.length>1?`repeat(${x}, 1fr)`:void 0,gridTemplateRows:v.length>2?`repeat(${h}, 1fr)`:void 0,gap:"8px",height:`${l}px`,width:`${f}px`,justifyContent:v.length===1?"center":void 0,alignItems:"center"},children:v.map((b,P)=>I.jsxRuntimeExports.jsx("div",{style:{width:`${d}px`,height:`${E}px`,display:"flex",alignItems:"center",justifyContent:P%2===0?"flex-end":"flex-start"},id:`compare-${b.id}`,children:I.jsxRuntimeExports.jsx(j5,{imageUrl:b.filePath,containerRef:`compare-${b.id}`})},`compare-${b.id}`))})}const KS="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M5.75%203H18.25C19.7688%203%2021%204.23122%2021%205.75V18.25C21%2019.7688%2019.7688%2021%2018.25%2021H5.75C4.23122%2021%203%2019.7688%203%2018.25V5.75C3%204.23122%204.23122%203%205.75%203ZM5.75%204.5C5.05964%204.5%204.5%205.05964%204.5%205.75V18.25C4.5%2018.9404%205.05964%2019.5%205.75%2019.5H18.25C18.9404%2019.5%2019.5%2018.9404%2019.5%2018.25V5.75C19.5%205.05964%2018.9404%204.5%2018.25%204.5H5.75Z'%20fill='%237C8897'/%3e%3c/svg%3e",_S="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAADxSURBVHgB7ZI9DoIwGIa/0gt4IRk0TnIR44IjEUNJiIbJDeI9ZJNEceE6HABqqwvy169MDDxJk6Yt7wP0BZiZHKcwst0w9kAT+dzxHNnNdaN1sqQAHJiOxA1vHufkSghfNPdocyFL77m5toiYMnNjQfZIXqpw4BUTww+cPVMKfpLkiZGownsFGAkmfFAwJMGGSwggcC8xEyc9Mdi3F8hwtOBPIkGGSwzAYhi8c66AYg7V/7n4aHkPqAqjBM0LxVYYJehri46E6obrSuiYcB0JHRveJVmutsU7TfL6fqumpISCV/yA7bkkcHbihcCHmUnyAbVr1q3eVypyAAAAAElFTkSuQmCC",$S="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M21.0302%202.96967C22.4276%204.36713%2022.4276%206.63286%2021.0302%208.03033L9.06186%2019.9987C8.78498%2020.2755%208.44064%2020.4754%208.06288%2020.5784L2.94719%2021.9736C2.38732%2022.1263%201.87359%2021.6125%202.02628%2021.0527L3.42147%2015.937C3.52449%2015.5592%203.72432%2015.2149%204.0012%2014.938L15.9695%202.96967C17.367%201.5722%2019.6327%201.5722%2021.0302%202.96967ZM15%206.06057L5.06186%2015.9987C4.96956%2016.0909%204.90296%2016.2057%204.86861%2016.3316L3.81877%2020.1811L7.6682%2019.1312C7.79412%2019.0969%207.9089%2019.0303%208.0012%2018.938L17.939%208.99957L15%206.06057ZM17.0302%204.03033L16.06%204.99957L18.999%207.93957L19.9695%206.96967C20.7812%206.15799%2020.7812%204.842%2019.9695%204.03033C19.1578%203.21865%2017.8419%203.21865%2017.0302%204.03033Z'%20fill='%237C8897'/%3e%3c/svg%3e",eE="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M12%202C17.5228%202%2022%206.47715%2022%2012C22%2017.5228%2017.5228%2022%2012%2022C6.47715%2022%202%2017.5228%202%2012C2%206.47715%206.47715%202%2012%202ZM12%203.5C7.30558%203.5%203.5%207.30558%203.5%2012C3.5%2016.6944%207.30558%2020.5%2012%2020.5C16.6944%2020.5%2020.5%2016.6944%2020.5%2012C20.5%207.30558%2016.6944%203.5%2012%203.5Z'%20fill='%237C8897'/%3e%3c/svg%3e";function tE(){const{setShowPenTool:s,setPenTool:l}=Jf(),f=ae.useMemo(()=>[{image:_S,onClick:()=>s(!1),label:"Close icon"},{image:eE,onClick:()=>l(Ye.E_CANVAS_TOOLS.CIRCLE),label:"Circle icon"},{image:KS,onClick:()=>l(Ye.E_CANVAS_TOOLS.RECT),label:"Checkbox icon"},{image:$S,onClick:()=>l(Ye.E_CANVAS_TOOLS.PEN),label:"Edit icon"}],[l,s]);return I.jsxRuntimeExports.jsx("div",{className:"hfl-rounded-md hfl-p-2 hfl-bg-White hfl-flex hfl-flex-col hfl-gap-2 hfl-items-center",children:f.map(v=>I.jsxRuntimeExports.jsx("img",{src:v.image,onClick:v.onClick,width:24,height:24,className:"hfl-cursor-pointer"},v.label))})}function nE(){const{setPenColor:s,penColor:l}=Jf();return I.jsxRuntimeExports.jsx("div",{className:"hfl-rounded-md hfl-p-2 hfl-bg-White hfl-flex hfl-flex-col hfl-gap-2 hfl-items-center",children:li.C_PEN_TOOL_COLORS.map(f=>l===f?I.jsxRuntimeExports.jsx("div",{className:"hfl-border-Primary-600 hfl-w-[26px] hfl-h-[26px] hfl-rounded-full hfl-flex hfl-justify-center hfl-items-center hfl-border-2",children:I.jsxRuntimeExports.jsx("div",{className:"hfl-rounded-full hfl-w-[24px] hfl-h-[24px] ",style:{backgroundColor:f},onClick:()=>s(f)})},f):I.jsxRuntimeExports.jsx("div",{className:"hfl-rounded-full hfl-w-[24px] hfl-h-[24px] ",style:{backgroundColor:f},onClick:()=>s(f)},f))})}function L5(){const s=ae.useRef(null),{parentRef:l}=Ea(),{showPenTool:f}=Jf();return ae.useEffect(()=>{if(f&&l.current&&s.current){const v=l.current.getBoundingClientRect(),S=v.width,y=v.height,h=v.top+y*.1,x=v.left+S*.9;s.current.style.position="fixed",s.current.style.top=`${h}px`,s.current.style.left=`${x}px`}},[l,f]),f?I.jsxRuntimeExports.jsxs("div",{className:"hfl-fixed hfl-z-99999999 hfl-flex hfl-flex-col hfl-gap-2",ref:s,children:[I.jsxRuntimeExports.jsx(tE,{}),I.jsxRuntimeExports.jsx(nE,{})]}):null}function rE(){const{clearSelectedDocuments:s,setSelectedGroup:l,selectedGroup:f,selectedDocuments:v,addDocument:S,setShowSaveGroupPreview:y,updateDocument:h}=sa(),[x,E]=ae.useState(!1),d=ae.useRef(null),{onSaveComparision:b,setCompareMode:P,setShowPreview:w,setError:C}=Ea(),[A,N]=ae.useState(f?.label||""),B=ae.useCallback(()=>{w(!1),P(!1),l(null),s(),y(!1)},[s,P,l,w,y]),G=ae.useCallback(async()=>{if(!A){C&&C("Group Name is required");return}try{E(!0);const g=await b(f?.id||"",A,v.map(M=>M.id));g.status&&g.data&&(f?.id?h(g.data):S(g.data))}catch(g){console.error("Error saving comparison:",g)}finally{E(!1),B()}},[S,B,b,v,f?.id,A,C,h]),R=ae.useCallback(()=>{y(!1)},[y]);return I.jsxRuntimeExports.jsxs("div",{className:"hfl-absolute hfl-top-1/2 hfl-left-1/2 hfl-p-4 hfl-bg-white hfl-rounded-lg hfl-shadow-lg hfl-z-[9999999999] hfl-flex hfl-flex-col hfl-gap-2 hfl-transform hfl--translate-x-1/2 hfl--translate-y-1/2",ref:d,children:[I.jsxRuntimeExports.jsx("div",{className:`hfl-w-[400px] hfl-h-[400px] ${v.length<2?"hfl-flex ":"hfl-grid hfl-grid-cols-2"} hfl-border-1 hfl-border-Gray-900 hfl-rounded-lg`,children:v.map((g,M)=>I.jsxRuntimeExports.jsx("img",{src:g.filePath,className:`hfl-object-contain ${v.length<2?"":M%2===0?"hfl-flex hfl-justify-end":"hfl-flex hfl-justify-start"} `,width:200,style:{height:Math.floor(400/Math.round(v.length/2)-2)}},`${g.id}-save`))}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Medium",type:"Text lg",className:"hfl-text-gray-900",children:"Save Comparision Group"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Regular",type:"Text sm",className:"hfl-text-gray-500",children:"Save the details of the comparison group"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Regular",type:"Text sm",className:"hfl-text-gray-900",children:"Group Name"}),I.jsxRuntimeExports.jsx(I.Ps,{inputProps:{value:A,onChange:g=>N(g.target.value),placeholder:"Name"}}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-w-full hfl-flex hfl-justify-between hfl-mt-1 hfl-gap-2",children:[I.jsxRuntimeExports.jsx(I.Ku,{hierarchy:"Secondary",size:"md",textField:"Cancel",onClick:R,className:"hfl-w-full hfl-flex hfl-justify-center"}),I.jsxRuntimeExports.jsx(I.Ku,{hierarchy:"Primary",className:"hfl-bg-Primary-600 hfl-w-full hfl-flex hfl-justify-center",size:"md",textField:"Save",onClick:G,disabled:x})]})]})}function aE(){const{parentRef:s}=Ea(),{selectedDocuments:l,selectedGroup:f,showSaveGroupPreview:v}=sa(),S=ae.useRef(null),[y,h]=ae.useState(void 0),[x,E]=ae.useState([]),[d,b]=ae.useState(0),[P,w]=ae.useState(0);return ae.useEffect(()=>{s.current&&S.current&&(S.current.style.height=`${s.current.clientHeight}px`,S.current.style.width=`${s.current.clientWidth}px`,S.current.style.top=s.current.getBoundingClientRect().top+"px",S.current.style.left=s.current.getBoundingClientRect().left+"px")},[s]),ae.useEffect(()=>{f?(E(f.documents),h(f.id)):(E(l),h(void 0))},[l,f]),ae.useEffect(()=>{if(s.current){const C=s.current.clientHeight;b(C-P)}},[P,s]),I.jsxRuntimeExports.jsx(Ky.Provider,{value:{groupDocuments:x,setGroupDocuments:E,groupId:y,setGroupId:h},children:I.jsxRuntimeExports.jsxs("div",{ref:S,className:"hfl-fixed hfl-z-99999",children:[I.jsxRuntimeExports.jsx(S5,{setHeaderHeight:w}),I.jsxRuntimeExports.jsx(QS,{containerHeight:d,containerWidth:S.current?.clientWidth||0}),I.jsxRuntimeExports.jsx(L5,{}),v&&I.jsxRuntimeExports.jsx(rE,{})]})})}function iE(s){const{allDocuments:l}=s,{selectedIndex:f,setSelectedIndex:v}=sa();return I.jsxRuntimeExports.jsx("div",{className:`hfl-flex hfl-bg-Gray-600 hfl-p-2 hfl-flex-col hfl-gap-2 hfl-h-full hfl-overflow-y-auto ${l.length<2?"hfl-hidden":""}`,children:l.map((S,y)=>{const h=l5(S),x=!S.thumbnail;return I.jsxRuntimeExports.jsx("div",{className:`hfl-w-[118px] hfl-h-[146px] hfl-flex-shrink-0 hfl-cursor-pointer hfl-border-2 hfl-rounded-md hfl-overflow-hidden ${f===y?"hfl-border-Blue-500":"hfl-border-transparent"}`,onClick:()=>v(y),children:I.jsxRuntimeExports.jsx("img",{src:h,alt:S.label,className:`hfl-w-full hfl-h-full ${x?"hfl-object-contain hfl-bg-Gray-700 hfl-p-4":"hfl-object-cover"}`})},`${S.id}-document-preview`)})})}const sE=ae.memo(iE),lE="data:image/svg+xml,%3csvg%20width='9'%20height='16'%20viewBox='0%200%209%2016'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M8.03033%2015.2803C8.32322%2014.9874%208.32322%2014.5126%208.03033%2014.2197L1.81066%208L8.03033%201.78033C8.32322%201.48744%208.32322%201.01256%208.03033%200.71967C7.73744%200.426777%207.26256%200.426777%206.96967%200.71967L0.219671%207.46967C-0.0732224%207.76256%20-0.0732225%208.23744%200.219671%208.53033L6.96967%2015.2803C7.26256%2015.5732%207.73744%2015.5732%208.03033%2015.2803Z'%20fill='%23101828'/%3e%3c/svg%3e",oE="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M8.96967%204.71967C8.67678%205.01256%208.67678%205.48744%208.96967%205.78033L15.1893%2012L8.96967%2018.2197C8.67678%2018.5126%208.67678%2018.9874%208.96967%2019.2803C9.26256%2019.5732%209.73744%2019.5732%2010.0303%2019.2803L16.7803%2012.5303C17.0732%2012.2374%2017.0732%2011.7626%2016.7803%2011.4697L10.0303%204.71967C9.73744%204.42678%209.26256%204.42678%208.96967%204.71967Z'%20fill='%23101828'/%3e%3c/svg%3e",uE=({file_data:s})=>{const[l,f]=ae.useState(!1),v=ae.useRef(null),S=[{src:s,type:"video/mp4"}],y=h=>{h.currentTarget.remove(),v.current&&v.current.children.length===0&&f(!0)};return I.jsxRuntimeExports.jsx("div",{className:"hfl-flex hfl-justify-center hfl-items-center hfl-w-full hfl-max-w-[800px] hfl-mx-auto",children:l?I.jsxRuntimeExports.jsx("div",{className:"hfl-flex hfl-flex-col hfl-justify-center hfl-items-center hfl-gap-2 hfl-h-[300px] hfl-p-2",children:I.jsxRuntimeExports.jsx(I.bs,{variant:"Medium",type:"Text md",className:"xxxs:max-sm:hfl-text-[10px]",children:"Live preview is not supported for this video. Please download it to watch."})}):I.jsxRuntimeExports.jsxs("video",{ref:v,controls:!0,autoPlay:!0,className:"hfl-flex hfl-justify-center hfl-items-center hfl-w-full hfl-max-w-[800px] hfl-mx-auto hfl-h-[350px]",children:[S.map(({src:h,type:x})=>I.jsxRuntimeExports.jsx("source",{src:h,type:x,onError:y},x)),"Your browser does not support the video tag."]})})};function cE({document:s}){const{parentRef:l}=Ea(),{clearSelectedDocuments:f}=sa(),{setShowPreview:v}=Ea(),S=ae.useCallback(()=>{v(!1),f()},[f,v]),y=ae.useCallback(()=>l?.current&&l.current.clientWidth<=1180,[l]);if(ae.useEffect(()=>{s.mimeType===Ye.E_DOCUMENT_FORMAT.PDF&&y()&&(window.open(s.filePath,"_blank"),S())},[s,y,S]),s.mimeType===Ye.E_DOCUMENT_FORMAT.PDF&&y())return I.jsxRuntimeExports.jsx(I.bs,{type:"Text lg",variant:"Bold",children:"Opening PDF in a new tab..."});switch(s.mimeType){case Ye.E_DOCUMENT_FORMAT.MP4:return I.jsxRuntimeExports.jsx(uE,{file_data:s.filePath});case Ye.E_DOCUMENT_FORMAT.PDF:return I.jsxRuntimeExports.jsx("div",{className:"hfl-bg-white hfl-h-full hfl-w-full",children:I.jsxRuntimeExports.jsx("iframe",{src:s.filePath,width:"100%",height:"100%",style:{border:"none"},children:"Your browser does not support PDFs. Please download the PDF to view it."})});default:return I.jsxRuntimeExports.jsxs("div",{children:["Unsupported file type: ",s.mimeType]})}}function fE(s){const{document:l}=s,f=`konva-container-${l.id}`;return I.jsxRuntimeExports.jsx("div",{id:f,className:"hfl-w-full hfl-h-full hfl-relative",children:I.jsxRuntimeExports.jsx(j5,{imageUrl:l.filePath,containerRef:f},l.id)})}function dE(){const{parentRef:s}=Ea(),l=ae.useRef(null),[f,v]=ae.useState(0),S=ae.useRef(null),{document:y,selectedIndex:h,setSelectedIndex:x}=sa(),E=ae.useMemo(()=>y.filter(rl),[y]),d=E.length,b=E[h];ae.useEffect(()=>{s.current&&l.current&&(l.current.style.height=`${s.current.clientHeight}px`,l.current.style.width=`${s.current.clientWidth}px`,l.current.style.top=`${s.current.getBoundingClientRect().top}px`,l.current.style.left=`${s.current.getBoundingClientRect().left}px`)},[s]),ae.useEffect(()=>{if(s.current&&S.current){const C=s.current.clientHeight;S.current.style.height=`${C-f}px`}},[f,s]);const P=ae.useCallback(C=>{if(d<=1)return;const A=C==="next"?(h+1)%d:(h-1+d)%d;x(A)},[h,d,x]);ae.useEffect(()=>{const C=A=>{A.key==="ArrowRight"?P("next"):A.key==="ArrowLeft"&&P("prev")};return window.addEventListener("keydown",C),()=>{window.removeEventListener("keydown",C)}},[P]);const w=b&&g2(b);return I.jsxRuntimeExports.jsxs("div",{className:"hfl-z-99999 hfl-fixed",ref:l,children:[I.jsxRuntimeExports.jsx(S5,{setHeaderHeight:v,isPreview:!0}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-bg-Gray-400 hfl-flex hfl-w-full",ref:S,children:[I.jsxRuntimeExports.jsx(sE,{allDocuments:E}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex-1 hfl-relative hfl-flex hfl-justify-center hfl-items-center hfl-p-4 hfl-overflow-hidden",children:[b&&g2(b)?I.jsxRuntimeExports.jsx(fE,{document:b}):b&&I.jsxRuntimeExports.jsx(cE,{document:b}),d>1&&I.jsxRuntimeExports.jsxs(I.jsxRuntimeExports.Fragment,{children:[I.jsxRuntimeExports.jsx("button",{onClick:()=>P("prev"),className:"hfl-absolute hfl-left-4 hfl-top-1/2 -hfl-translate-y-1/2 hfl-w-12 hfl-h-12 hfl-rounded-full hfl-bg-Gray-100/40 hover:hfl-bg-Gray-900/60 hfl-flex hfl-justify-center hfl-items-center hfl-z-10",children:I.jsxRuntimeExports.jsx("img",{src:lE,alt:"Previous"})}),I.jsxRuntimeExports.jsx("button",{onClick:()=>P("next"),className:"hfl-absolute hfl-right-4 hfl-top-1/2 -hfl-translate-y-1/2 hfl-w-12 hfl-h-12 hfl-rounded-full hfl-bg-Gray-100/40 hover:hfl-bg-Gray-900/60 hfl-flex hfl-justify-center hfl-items-center hfl-z-10",children:I.jsxRuntimeExports.jsx("img",{src:oE,alt:"Next"})})]})]})]}),w&&I.jsxRuntimeExports.jsx(L5,{})]})}const hE=[{label:"Unspecified",value:Ye.E_DOCUMENT_TYPE.REPORT_TYPE_UNSPECIFIED},...Object.values(Ye.E_DOCUMENT_TYPE).filter(s=>s!==Ye.E_DOCUMENT_TYPE.REPORT_TYPE_UNSPECIFIED).map(s=>({label:s.charAt(0).toUpperCase()+s.slice(1).replace(/_/g," "),value:s}))];function pE({isOpen:s,document:l,onClose:f,onSave:v}){const[S,y]=ae.useState(""),[h,x]=ae.useState(""),[E,d]=ae.useState(!1),[b,P]=ae.useState(""),[w,C]=ae.useState("");ae.useEffect(()=>{if(l){const N=l.label,B=N.lastIndexOf(".");B!==-1?(P(N.substring(0,B)),C(N.substring(B))):(P(N),C("")),y(l.reportType||Ye.E_DOCUMENT_TYPE.REPORT_TYPE_UNSPECIFIED),x(new Date(l.createdAt).toISOString().split("T")[0])}},[l]);const A=async()=>{if(l){d(!0);try{const N={id:l.id,label:`${b}${w}`,reportType:S===Ye.E_DOCUMENT_TYPE.REPORT_TYPE_UNSPECIFIED?"":S,createdAt:new Date(h).toISOString(),filePath:l.filePath,mimeType:l.mimeType,downloadPath:l.downloadPath,fileName:l.fileName};await v(N),f()}catch(N){console.error("Failed to save document:",N)}finally{d(!1)}}};return!s||!l?null:I.jsxRuntimeExports.jsx("div",{className:"hfl-fixed hfl-inset-0 hfl-bg-black hfl-bg-opacity-50 hfl-flex hfl-items-center hfl-justify-center hfl-z-50",children:I.jsxRuntimeExports.jsxs("div",{className:"hfl-bg-white hfl-rounded-lg hfl-p-8 hfl-w-full hfl-max-w-md hfl-flex hfl-flex-col hfl-gap-6",children:[I.jsxRuntimeExports.jsx("div",{className:"hfl-w-full hfl-h-48 hfl-bg-Gray-100 hfl-rounded-lg hfl-overflow-hidden",children:I.jsxRuntimeExports.jsx(o5,{documents:l})}),I.jsxRuntimeExports.jsxs("div",{children:[I.jsxRuntimeExports.jsx(I.bs,{variant:"Semibold",type:"Text xl",className:"hfl-text-Gray-900",children:"Edit Document"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Regular",type:"Text sm",className:"hfl-text-Gray-500",children:"Edit the details of the document."})]}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex hfl-flex-col hfl-gap-4",children:[I.jsxRuntimeExports.jsxs("div",{children:[I.jsxRuntimeExports.jsx("label",{htmlFor:"documentName",className:"hfl-block hfl-text-sm hfl-font-medium hfl-text-Gray-700 hfl-mb-1",children:"Document Name"}),I.jsxRuntimeExports.jsx("input",{id:"documentName",value:b,onChange:N=>P(N.target.value),placeholder:"Enter document name",className:"hfl-w-full hfl-border hfl-border-Gray-300 hfl-rounded-md hfl-px-3 hfl-py-2 focus:hfl-outline-none focus:hfl-ring-2 focus:hfl-ring-Primary-500"})]}),I.jsxRuntimeExports.jsxs("div",{children:[I.jsxRuntimeExports.jsx("label",{className:"hfl-block hfl-text-sm hfl-font-medium hfl-text-Gray-700 hfl-mb-1",children:"Type"}),I.jsxRuntimeExports.jsx("select",{value:S,onChange:N=>y(N.target.value),className:"hfl-w-full hfl-border hfl-border-Gray-300 hfl-rounded-md hfl-px-3 hfl-py-2 focus:hfl-outline-none focus:hfl-ring-2 focus:hfl-ring-Primary-500",children:hE.map(N=>I.jsxRuntimeExports.jsx("option",{value:N.value,children:N.label},N.value))})]}),I.jsxRuntimeExports.jsxs("div",{children:[I.jsxRuntimeExports.jsx("label",{className:"hfl-block hfl-text-sm hfl-font-medium hfl-text-Gray-700 hfl-mb-1",children:"Creation Date"}),I.jsxRuntimeExports.jsx("input",{type:"date",value:h,onChange:N=>x(N.target.value),className:"hfl-w-full hfl-border hfl-border-Gray-300 hfl-rounded-md hfl-px-3 hfl-py-2 focus:hfl-outline-none focus:hfl-ring-2 focus:hfl-ring-Primary-500"})]})]}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex hfl-justify-end hfl-gap-3 hfl-mt-4",children:[I.jsxRuntimeExports.jsx(I.Ku,{textField:"Cancel",hierarchy:"Secondary",onClick:f,disabled:E,size:"sm"}),I.jsxRuntimeExports.jsx(I.Ku,{textField:E?"Saving...":"Save",hierarchy:"Primary",onClick:A,disabled:E,size:"sm"})]})]})})}function vE({isOpen:s,onClose:l,onCapture:f}){const v=ae.useRef(null),S=ae.useRef(null),y=ae.useRef(null),[h,x]=ae.useState(!1),[E,d]=ae.useState(null),[b,P]=ae.useState(!1),[w,C]=ae.useState(!1),[A,N]=ae.useState([]),[B,G]=ae.useState(null),R=async()=>{try{const L=(await navigator.mediaDevices.enumerateDevices()).filter(H=>H.kind==="videoinput");console.log("Available video devices:",L),N(L)}catch(Z){console.error("Error enumerating devices:",Z)}};ae.useEffect(()=>{s&&R()},[s]);const g=async()=>{console.log("inside startCamera"),console.log("videoRef.current at start:",v.current),console.log("videoRef.current?.readyState:",v.current?.readyState);try{x(!0),d(null),console.log("before getUserMedia");const Z=await navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280},height:{ideal:720},facingMode:"environment"},audio:!1});console.log("after getUserMedia, stream:",Z),console.log("stream.getTracks():",Z.getTracks()),y.current=Z,console.log("videoRef.current after getUserMedia:",v.current),console.log("videoRef.current?.readyState after getUserMedia:",v.current?.readyState),G(Z),C(!0),console.log("after setHasPermission")}catch(Z){console.error("Error accessing camera:",Z),Z instanceof Error?Z.name==="NotAllowedError"?d("Camera access denied. Please grant permission to use the camera."):Z.name==="NotFoundError"?d("No camera found on this device."):Z.name==="NotSupportedError"?d("Camera is not supported on this device."):d("Failed to access camera. Please try again."):d("Failed to access camera. Please try again.")}finally{x(!1),console.log("startCamera finally block - isLoading set to false")}};ae.useEffect(()=>{B&&v.current&&w&&(v.current.srcObject=B,v.current.play().catch(Z=>{console.error("Error playing video:",Z)}))},[B,w]);const M=()=>{console.log("stopCamera called"),y.current&&(console.log("Stopping stream tracks:",y.current.getTracks().length),y.current.getTracks().forEach(Z=>{console.log("Stopping track:",Z.kind,Z.readyState),Z.stop()}),y.current=null),v.current&&(console.log("Clearing video srcObject"),v.current.srcObject=null),C(!1),console.log("stopCamera completed")},j=async()=>{if(!(!v.current||!S.current)){P(!0);try{const Z=v.current,L=S.current,H=L.getContext("2d");if(!H)throw new Error("Unable to get canvas context");L.width=Z.videoWidth,L.height=Z.videoHeight,H.drawImage(Z,0,0,L.width,L.height);const k=await new Promise((ee,re)=>{L.toBlob($=>{$?ee($):re(new Error("Failed to create image blob"))},"image/jpeg",.8)}),J=new Date().toISOString().replace(/[:.]/g,"-"),_=new File([k],`captured-image-${J}.jpg`,{type:"image/jpeg"});await f(_),l()}catch(Z){console.error("Error capturing photo:",Z),d("Failed to capture photo. Please try again.")}finally{P(!1)}}},U=async()=>{if(!y.current)return;const L=y.current.getVideoTracks()[0].getSettings().facingMode;M();try{const H=L==="environment"?"user":"environment",k=await navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280},height:{ideal:720},facingMode:H},audio:!1});y.current=k,v.current&&(v.current.srcObject=k,v.current.play())}catch(H){console.error("Error switching camera:",H),d("Failed to switch camera. Using default camera."),g()}};return ae.useEffect(()=>(console.log("useEffect triggered with isOpen:",s),s?(console.log("Calling startCamera from useEffect"),R(),g()):(console.log("Calling stopCamera from useEffect"),M(),d(null)),()=>{console.log("useEffect cleanup - calling stopCamera"),M()}),[s]),s?I.jsxRuntimeExports.jsx("div",{className:"hfl-fixed hfl-inset-0 hfl-bg-black hfl-bg-opacity-75 hfl-flex hfl-items-center hfl-justify-center hfl-z-50",children:I.jsxRuntimeExports.jsxs("div",{className:"hfl-bg-white hfl-rounded-lg hfl-p-6 hfl-w-full hfl-max-w-2xl hfl-max-h-[90vh] hfl-overflow-hidden",children:[I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex hfl-items-center hfl-justify-between hfl-mb-4",children:[I.jsxRuntimeExports.jsx(I.bs,{variant:"Semibold",type:"Text lg",className:"hfl-text-Gray-900",children:"Capture Photo"}),I.jsxRuntimeExports.jsx("button",{onClick:l,className:"hfl-text-Gray-500 hfl-hover:text-Gray-700 hfl-p-1 hfl-h-4 hfl-w-4",children:I.jsxRuntimeExports.jsx("i",{className:"hx_close hfl-text-xl"})})]}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-relative hfl-bg-black hfl-rounded-lg hfl-overflow-hidden hfl-mb-4",children:[h&&I.jsxRuntimeExports.jsx("div",{className:"hfl-flex hfl-items-center hfl-justify-center hfl-h-64",children:I.jsxRuntimeExports.jsx(I.bs,{variant:"Regular",type:"Text sm",className:"hfl-text-white",children:"Loading camera..."})}),E&&I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex hfl-flex-col hfl-items-center hfl-justify-center hfl-h-64 hfl-p-4",children:[I.jsxRuntimeExports.jsx("i",{className:"hx_camera hfl-text-4xl hfl-text-Gray-400 hfl-mb-2"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Regular",type:"Text sm",className:"hfl-text-Gray-600 hfl-text-center",children:E}),I.jsxRuntimeExports.jsx("button",{onClick:g,className:"hfl-mt-3 hfl-px-4 hfl-py-2 hfl-bg-Blue-600 hfl-text-white hfl-rounded-lg hfl-hover:bg-Blue-700",children:"Try Again"})]}),w&&!E&&I.jsxRuntimeExports.jsx("video",{ref:v,className:"hfl-w-full hfl-h-auto hfl-max-h-96",onLoadedMetadata:()=>console.log("Video onLoadedMetadata"),onCanPlay:()=>console.log("Video onCanPlay"),onPlaying:()=>console.log("Video onPlaying"),onWaiting:()=>console.log("Video onWaiting"),onError:Z=>console.log("Video onError:",Z),onLoadStart:()=>console.log("Video onLoadStart"),autoPlay:!0,playsInline:!0,muted:!0}),I.jsxRuntimeExports.jsx("canvas",{ref:S,className:"hfl-hidden"})]}),w&&!E&&I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex hfl-items-center hfl-justify-center hfl-gap-4",children:[A.length>1&&I.jsxRuntimeExports.jsxs("button",{onClick:U,className:"hfl-flex hfl-items-center hfl-gap-2 hfl-px-4 hfl-py-2 hfl-text-sm hfl-text-Gray-700 hfl-border hfl-border-Gray-300 hfl-rounded-lg hfl-hover:bg-Gray-50",children:[I.jsxRuntimeExports.jsx("i",{className:"hx_refresh hfl-text-base"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Medium",type:"Text sm",children:"Switch Camera"})]}),I.jsxRuntimeExports.jsxs("button",{onClick:j,disabled:b,className:`hfl-flex hfl-items-center hfl-gap-2 hfl-px-6 hfl-py-3 hfl-text-sm hfl-text-white hfl-rounded-lg hfl-transition-colors ${b?"hfl-bg-Gray-400 hfl-cursor-not-allowed":"hfl-bg-Blue-600 hfl-hover:bg-Blue-700"}`,children:[I.jsxRuntimeExports.jsx("i",{className:"hx_camera hfl-text-base"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Medium",type:"Text sm",className:"hfl-text-white",children:b?"Capturing...":"Capture Photo"})]})]})]})}):null}function mE({containerRef:s,setPage:l,hasData:f,shouldScroll:v,setNextDate:S,cursor:y,query_type:h}){const x=ae.useRef(v),E=ae.useRef(0),d=ae.useRef(!1);ae.useEffect(()=>{x.current=v},[v]),ae.useEffect(()=>{if(!s||!s.current)return;console.log("Inside scroll event",f);const b=s.current;if(!b)return;const P=()=>{if(!x.current||!f)return;const{scrollTop:w,scrollHeight:C,clientHeight:A}=b;d.current=w>E.current,E.current=w,d.current&&w+A>=C-10&&(h===Ye.E_ATTACHMENT_QUERY_TYPE.VIEW_GRID?l(N=>N+1):S(y))};return b.addEventListener("scroll",P),()=>{b.removeEventListener("scroll",P)}},[s,l,f,h,S,y])}function gE(s){const{isUploading:l}=s;return l?I.jsxRuntimeExports.jsxs("div",{className:"hfl-absolute hfl-flex hfl-gap-2 hfl-items-center hfl-left-[90%] hfl-top-[80%] hfl-p-3 hfl-rounded-md hfl-border-l-2 hfl-border-b-2 hfl-border-l-Success-600 hfl-border-b-Success-600 hfl-bg-White hfl-shadow-upload hfl-translate-x-[-80%] hfl-translate-y-[-90%] hfl-min-w-[375px] ",children:[I.jsxRuntimeExports.jsx("div",{className:"hfl-h-[32px] hfl-min-w-[32px] hfl-flex hfl-justify-center hfl-items-center hfl-rounded-md hfl-bg-Success-600",children:I.jsxRuntimeExports.jsx("i",{className:"hx_checkmark hfl-text-White "})}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Medium",type:"Text sm",className:"hfl-text-Blue_gray-800",children:"Your file(s) are being uploaded. Do not refresh or close the page."})]}):null}const yE=ae.memo(gE);function xE(s){const{parentRef:l,fetchAttachments:f,uploadFiles:v,onDocumentPreview:S,onDocumentDownload:y,onDocumentUpdate:h,setError:x,showHeaderBackButton:E,patient_id:d="",patient_role_id:b="",doctor_id:P="",doctor_role_id:w="",branch_id:C="",onDeleteAttachments:A,onSaveComparision:N,onHeaderBackClick:B}=s,[G,R]=ae.useState(!1),[g,M]=ae.useState(!1),[j,U]=ae.useState(""),[Z,L]=ae.useState(!0),[H,k]=ae.useState([]),[J,_]=ae.useState({startDate:null,endDate:null}),[ee,re]=ae.useState(1),[$,pe]=ae.useState(""),[z,O]=ae.useState(""),Y=ae.useRef(null),[V,q]=ae.useState(Ye.E_ATTACHMENT_QUERY_TYPE.VIEW_GRID),{documentView:se,setDocument:ne,addDocuments:ge,selectedDocuments:Re,addDocument:oe,updateDocument:Q}=sa(),ue=ae.useMemo(()=>se===Ye.E_DOCUMENT_VIEW_TYPE.GRID_VIEW?20:3,[se]),[Te,De]=ae.useState(null),[Me,qe]=ae.useState(!1),[xe,Le]=ae.useState(!1),je=ae.useMemo(()=>!G&&!g,[G,g]),{isLoading:Ke}=X6(`attachments?page=${ee}&page_size=${ue}&query_type=${V}&search=${j}&types=${H.join(",")}&start_date=${J.startDate}&end_date=${J.endDate}&next_date=${$}&patient_id=${d}&patient_role_id=${b}&doctor_id=${P}&doctor_role_id=${w}&branch_id=${C}`,()=>f(ee,j,H,ue,V,J,$),{revalidateOnFocus:!1,onSuccess:rt=>{rt.data&&(ee===1&&V===Ye.E_ATTACHMENT_QUERY_TYPE.VIEW_GRID?ne(rt.data):$&&V===Ye.E_ATTACHMENT_QUERY_TYPE.VIEW_DATE?ge(rt.data):V===Ye.E_ATTACHMENT_QUERY_TYPE.VIEW_DATE?ne(rt.data):ge(rt.data),(rt.data.length===0||rt.data.length<ue)&&L(!1),O(rt.next_date||""))},onError:rt=>x?.(`Failed to fetch documents: ${rt.message}`)});ae.useEffect(()=>{l.current&&Y.current&&(Y.current.style.height=`${l.current.clientHeight}px`)},[l]);const _e=async rt=>{Le(!0);try{const{validFiles:Vt,errors:fn}=s5(rt);if(fn.length>0&&fn.forEach(sn=>x?.(sn)),Vt.length>0){const sn=await v({files:Vt});let Pe=!0;console.log("Upload response for a file1: ",sn.data),sn.data.forEach(Ue=>{console.log("Upload response for a file: ",Ue),Ue.success&&Ue.data?(console.log("Adding document: ",Ue.data),oe(Ue.data)):Pe=!1}),Pe||x?.("Failed to upload all files")}}catch(Vt){x?.(`Failed to upload files. Please try again. ${Vt}`)}finally{Le(!1)}},gt=async rt=>{await _e([rt])},Dt=rt=>{De(rt)},dt=rt=>{S&&S(rt)},yt=rt=>{y&&y(rt)},St=()=>{De(null)},cn=async rt=>{try{const Vt=await h(rt);Vt.success&&Vt.data?Q(Vt.data):x?.("Failed to update document.")}catch(Vt){x?.("An unexpected error occurred while updating the document."),console.error(Vt)}},nn=()=>qe(!0),Ut=()=>qe(!1);return mE({containerRef:Y,setPage:re,hasData:Z,shouldScroll:!Ke,cursor:z,setNextDate:pe,query_type:V}),I.jsxRuntimeExports.jsxs(Qy.Provider,{value:{page:ee,setPage:re,hasData:Z,queryType:V,setQueryType:q,setShowPreview:R,showPreview:G,compareMode:g,setCompareMode:M,parentRef:l,search:j,setSearch:U,types:H,setTypes:k,dates:J,setDates:_,setHasData:L,onSaveComparision:N,onDeleteAttachments:A,setError:x},children:[I.jsxRuntimeExports.jsxs("div",{ref:Y,className:`hfl-w-full hfl-relative hfl-overflow-scroll ${Me?"hfl-overflow-hidden":""}`,children:[je&&I.jsxRuntimeExports.jsx(J6,{showBackButton:E&&!G&&!g,onFileUpload:_e,setNextDate:pe,setCursor:O,onCaptureClick:nn,isUploading:xe,setIsUploading:Le,onHeaderBackClickCb:E&&B?B:void 0}),se===Ye.E_DOCUMENT_VIEW_TYPE.GRID_VIEW?I.jsxRuntimeExports.jsx(c6,{onFileUpload:_e,onEdit:Dt,onPreview:dt,onDownload:yt}):I.jsxRuntimeExports.jsx(d6,{onFileUpload:_e,onEdit:Dt,onPreview:dt,onDownload:yt}),Re.length>0&&!G&&!g&&I.jsxRuntimeExports.jsx(I6,{})]}),g&&I.jsxRuntimeExports.jsx(aE,{}),G&&I.jsxRuntimeExports.jsx(dE,{}),Te&&I.jsxRuntimeExports.jsx(pE,{isOpen:!!Te,document:Te,onClose:St,onSave:cn}),I.jsxRuntimeExports.jsx(vE,{isOpen:Me,onClose:Ut,onCapture:gt}),I.jsxRuntimeExports.jsx(yE,{isUploading:xe})]})}exports.Attachments=xE;
186
+ `,Z9={};function l0(s,l,f=Z9){if(!By&&"zIndex"in l&&(console.warn(q9),By=!0),!Gy&&l.draggable){var v=l.x!==void 0||l.y!==void 0,S=l.onDragEnd||l.onDragMove;v&&!S&&(console.warn(J9),Gy=!0)}for(var y in f)if(!ky[y]){var h=y.slice(0,2)==="on",x=f[y]!==l[y];if(h&&x){var E=y.substr(2).toLowerCase();E.substr(0,7)==="content"&&(E="content"+E.substr(7,1).toUpperCase()+E.substr(8)),s.off(E,f[y])}var d=!l.hasOwnProperty(y);d&&s.setAttr(y,void 0)}var b=l._useStrictMode,P={},w=!1;const C={};for(var y in l)if(!ky[y]){var h=y.slice(0,2)==="on",A=f[y]!==l[y];if(h&&A){var E=y.substr(2).toLowerCase();E.substr(0,7)==="content"&&(E="content"+E.substr(7,1).toUpperCase()+E.substr(8)),l[y]&&(C[E]=l[y])}!h&&(l[y]!==f[y]||b&&l[y]!==s.getAttr(y))&&(w=!0,P[y]=l[y])}w&&(s.setAttrs(P),sl(s));for(var E in C)s.on(E+Em,C[E])}function sl(s){if(!W9.Konva.autoDrawEnabled){var l=s.getLayer()||s.getStage();l&&l.batchDraw()}}var rm=Sm();const D5={},Q9={};If.Node.prototype._applyProps=l0;function K9(s,l){if(typeof l=="string"){console.error(`Do not use plain text as child of Konva.Node. You are using text: ${l}`);return}s.add(l),sl(s)}function _9(s,l,f){let v=If[s];v||(console.error(`Konva has no node with the type ${s}. Group will be used instead. If you use minimal version of react-konva, just import required nodes into Konva: "import "konva/lib/shapes/${s}" If you want to render DOM elements as part of canvas tree take a look into this demo: https://konvajs.github.io/docs/react/DOM_Portal.html`),v=If.Group);const S={},y={};for(var h in l){var x=h.slice(0,2)==="on";x?y[h]=l[h]:S[h]=l[h]}const E=new v(S);return l0(E,y),E}function $9(s,l,f){console.error(`Text components are not supported for now in ReactKonva. Your text is: "${s}"`)}function eS(s,l,f){return!1}function tS(s){return s}function nS(){return null}function rS(){return null}function aS(s,l,f,v){return Q9}function iS(){}function sS(s){}function lS(s,l){return!1}function oS(){return D5}function uS(){return D5}const cS=setTimeout,fS=clearTimeout,dS=-1;function hS(s,l){return!1}const pS=!1,vS=!0,mS=!0;function gS(s,l){l.parent===s?l.moveToTop():s.add(l),sl(s)}function yS(s,l){l.parent===s?l.moveToTop():s.add(l),sl(s)}function P5(s,l,f){l._remove(),s.add(l),l.setZIndex(f.getZIndex()),sl(s)}function xS(s,l,f){P5(s,l,f)}function SS(s,l){l.destroy(),l.off(Em),sl(s)}function ES(s,l){l.destroy(),l.off(Em),sl(s)}function CS(s,l,f){console.error(`Text components are not yet supported in ReactKonva. You text is: "${f}"`)}function bS(s,l,f){}function AS(s,l,f,v,S){l0(s,S,v)}function wS(s){s.hide(),sl(s)}function RS(s){}function TS(s,l){(l.visible==null||l.visible)&&s.show()}function DS(s,l){}function PS(s){}function NS(){}const OS=()=>T5.DefaultEventPriority,MS=Object.freeze(Object.defineProperty({__proto__:null,appendChild:gS,appendChildToContainer:yS,appendInitialChild:K9,cancelTimeout:fS,clearContainer:PS,commitMount:bS,commitTextUpdate:CS,commitUpdate:AS,createInstance:_9,createTextInstance:$9,detachDeletedInstance:NS,finalizeInitialChildren:eS,getChildHostContext:uS,getCurrentEventPriority:OS,getPublicInstance:tS,getRootHostContext:oS,hideInstance:wS,hideTextInstance:RS,idlePriority:rm.unstable_IdlePriority,insertBefore:P5,insertInContainerBefore:xS,isPrimaryRenderer:pS,noTimeout:dS,now:rm.unstable_now,prepareForCommit:nS,preparePortalMount:rS,prepareUpdate:aS,removeChild:SS,removeChildFromContainer:ES,resetAfterCommit:iS,resetTextContent:sS,run:rm.unstable_runWithPriority,scheduleTimeout:cS,shouldDeprioritizeSubtree:lS,shouldSetTextContent:hS,supportsMutation:mS,unhideInstance:TS,unhideTextInstance:DS,warnsIfNotActing:vS},Symbol.toStringTag,{value:"Module"}));var jS=Object.defineProperty,LS=Object.defineProperties,zS=Object.getOwnPropertyDescriptors,Uy=Object.getOwnPropertySymbols,FS=Object.prototype.hasOwnProperty,HS=Object.prototype.propertyIsEnumerable,Vy=(s,l,f)=>l in s?jS(s,l,{enumerable:!0,configurable:!0,writable:!0,value:f}):s[l]=f,Xy=(s,l)=>{for(var f in l||(l={}))FS.call(l,f)&&Vy(s,f,l[f]);if(Uy)for(var f of Uy(l))HS.call(l,f)&&Vy(s,f,l[f]);return s},kS=(s,l)=>LS(s,zS(l)),Yy,Iy;typeof window<"u"&&((Yy=window.document)!=null&&Yy.createElement||((Iy=window.navigator)==null?void 0:Iy.product)==="ReactNative")?ia.useLayoutEffect:ia.useEffect;function N5(s,l,f){if(!s)return;if(f(s)===!0)return s;let v=s.child;for(;v;){const S=N5(v,l,f);if(S)return S;v=v.sibling}}function O5(s){try{return Object.defineProperties(s,{_currentRenderer:{get(){return null},set(){}},_currentRenderer2:{get(){return null},set(){}}})}catch{return s}}const Wy=console.error;console.error=function(){const s=[...arguments].join("");if(s?.startsWith("Warning:")&&s.includes("useContext")){console.error=Wy;return}return Wy.apply(this,arguments)};const Cm=O5(ia.createContext(null));class M5 extends ia.Component{render(){return ia.createElement(Cm.Provider,{value:this._reactInternals},this.props.children)}}function BS(){const s=ia.useContext(Cm);if(s===null)throw new Error("its-fine: useFiber must be called within a <FiberProvider />!");const l=ia.useId();return ia.useMemo(()=>{for(const v of[s,s?.alternate]){if(!v)continue;const S=N5(v,!1,y=>{let h=y.memoizedState;for(;h;){if(h.memoizedState===l)return!0;h=h.next}});if(S)return S}},[s,l])}function GS(){const s=BS(),[l]=ia.useState(()=>new Map);l.clear();let f=s;for(;f;){if(f.type&&typeof f.type=="object"){const S=f.type._context===void 0&&f.type.Provider===f.type?f.type:f.type._context;S&&S!==Cm&&!l.has(S)&&l.set(S,ia.useContext(O5(S)))}f=f.return}return l}function US(){const s=GS();return ia.useMemo(()=>Array.from(s.keys()).reduce((l,f)=>v=>ia.createElement(l,null,ia.createElement(f.Provider,kS(Xy({},v),{value:s.get(f)}))),l=>ia.createElement(M5,Xy({},l))),[s])}function VS(s){const l=ae.useRef({});return ae.useLayoutEffect(()=>{l.current=s}),ae.useLayoutEffect(()=>()=>{l.current={}},[]),l.current}const XS=s=>{const l=ae.useRef(),f=ae.useRef(),v=ae.useRef(),S=VS(s),y=US(),h=x=>{const{forwardedRef:E}=s;E&&(typeof E=="function"?E(x):E.current=x)};return ae.useLayoutEffect(()=>(f.current=new If.Stage({width:s.width,height:s.height,container:l.current}),h(f.current),v.current=Uf.createContainer(f.current,T5.LegacyRoot,!1,null),Uf.updateContainer(ae.createElement(y,{},s.children),v.current),()=>{If.isBrowser&&(h(null),Uf.updateContainer(null,v.current,null),f.current.destroy())}),[]),ae.useLayoutEffect(()=>{h(f.current),l0(f.current,s,S),Uf.updateContainer(ae.createElement(y,{},s.children),v.current,null)}),ae.createElement("div",{ref:l,id:s.id,accessKey:s.accessKey,className:s.className,role:s.role,style:s.style,tabIndex:s.tabIndex,title:s.title})},YS="Layer",Jy="Rect",qy="Circle",IS="Line",WS="Image",Uf=V9(MS);Uf.injectIntoDevTools({findHostInstanceByFiber:()=>null,bundleType:process.env.NODE_ENV!=="production"?1:0,version:ae.version,rendererPackageName:"react-konva"});const JS=ae.forwardRef((s,l)=>ae.createElement(M5,{},ae.createElement(XS,{...s,forwardedRef:l}))),qS=10,ZS=2.5,j5=({imageUrl:s,customClassName:l="",containerRef:f})=>{const{showPenTool:v,penColor:S,penTool:y,strokeWidth:h}=Jf(),[x,E]=ae.useState(null),[d,b]=ae.useState({width:0,height:0}),[P,w]=ae.useState({scale:1,x:0,y:0}),[C,A]=ae.useState(!1),[N,B]=ae.useState([]),[G,R]=ae.useState([]),[g,M]=ae.useState(null),[j,U]=ae.useState(!1),[Z,L]=ae.useState({scale:1,x:0,y:0}),H=ae.useRef(null),k=ae.useRef(null),J=ae.useRef(null);ae.useEffect(()=>{const O=new window.Image;O.onload=()=>{E(O)},O.src=s},[s]);const _=()=>{if(v)return;const O=H.current;if(O)if(j)w(Z),U(!1);else{const Y=O.getPointerPosition();if(!Y)return;const V={x:(Y.x-O.x())/O.scaleX(),y:(Y.y-O.y())/O.scaleY()},q=Math.min(O.scaleX()*ZS,qS);w({scale:q,x:Y.x-V.x*q,y:Y.y-V.y*q}),U(!0)}},ee=O=>{w(Y=>({...Y,x:O.target.x(),y:O.target.y()}))},re=O=>O?O.getRelativePointerPosition():null,$=ae.useCallback(O=>{if(!v||!x)return;const Y=re(O.target.getStage());Y&&(A(!0),y===Ye.E_CANVAS_TOOLS.PEN?B([...N,{points:[{x:Y.x,y:Y.y}],color:S,width:h}]):(y===Ye.E_CANVAS_TOOLS.RECT||y===Ye.E_CANVAS_TOOLS.CIRCLE)&&M({points:[{x:Y.x,y:Y.y}]}))},[v,x,y,N,S,h]),pe=ae.useCallback(O=>{if(!v||!C||!x)return;const Y=re(O.target.getStage());if(Y)if(y===Ye.E_CANVAS_TOOLS.PEN){const V=N[N.length-1];V&&(V.points.push({x:Y.x,y:Y.y}),N.splice(N.length-1,1,V),B([...N]))}else g&&(y===Ye.E_CANVAS_TOOLS.RECT||y===Ye.E_CANVAS_TOOLS.CIRCLE)&&M({points:[g.points[0],{x:Y.x,y:Y.y}]})},[v,C,x,y,N,g]),z=ae.useCallback(O=>{!v||!x||(O?.evt.type.startsWith("touch")&&O.evt.preventDefault(),A(!1),g&&(y===Ye.E_CANVAS_TOOLS.RECT||y===Ye.E_CANVAS_TOOLS.CIRCLE)&&(g.points.length===2&&R([...G,{...g,tool:y,color:S,width:h}]),M(null)))},[v,x,g,y,G,S,h]);return ae.useEffect(()=>{const O=()=>f?document.getElementById(f):J.current,Y=()=>{const V=O();if(V&&x){const{clientWidth:q,clientHeight:se}=V;b({width:q,height:se});const ne=Math.min(q/x.width,se/x.height,1),ge={scale:ne,x:(q-x.width*ne)/2,y:(se-x.height*ne)/2};w(ge),L(ge),U(!1)}};return Y(),window.addEventListener("resize",Y),()=>window.removeEventListener("resize",Y)},[f,x]),ae.useEffect(()=>{const O=H.current;if(!O)return;const Y=O.container();v?Y.style.cursor="crosshair":Y.style.cursor=j?"zoom-out":"zoom-in"},[v,j]),ae.useEffect(()=>{const O=Y=>{C&&v&&Y.preventDefault()};return document.addEventListener("touchstart",O,{passive:!1}),document.addEventListener("touchmove",O,{passive:!1}),document.addEventListener("touchend",O,{passive:!1}),()=>{document.removeEventListener("touchstart",O),document.removeEventListener("touchmove",O),document.removeEventListener("touchend",O)}},[C,v]),x?I.jsxRuntimeExports.jsx("div",{ref:J,style:{width:"100%",height:"100%",touchAction:"none",WebkitUserSelect:"none",userSelect:"none"},className:l,children:I.jsxRuntimeExports.jsx(JS,{ref:H,width:d.width,height:d.height,onMouseDown:$,onMouseMove:pe,onMouseUp:z,onTouchStart:$,onTouchMove:pe,onTouchEnd:z,onClick:_,onTap:_,onDragEnd:ee,scaleX:P.scale,scaleY:P.scale,x:P.x,y:P.y,draggable:!v,children:I.jsxRuntimeExports.jsxs(YS,{children:[I.jsxRuntimeExports.jsx(WS,{ref:k,image:x,width:x.width,height:x.height}),N.map((O,Y)=>I.jsxRuntimeExports.jsx(IS,{points:O.points.flatMap(V=>[V.x,V.y]),stroke:O.color,strokeWidth:O.width,tension:.5,lineCap:"round",lineJoin:"round",globalCompositeOperation:"source-over"},`line-${Y}`)),G.map((O,Y)=>{if(O.tool===Ye.E_CANVAS_TOOLS.RECT&&O.points.length===2){const[V,q]=O.points;return I.jsxRuntimeExports.jsx(Jy,{x:V.x,y:V.y,width:q.x-V.x,height:q.y-V.y,stroke:O.color,strokeWidth:O.width,fill:"transparent"},`rect-${Y}`)}else if(O.tool===Ye.E_CANVAS_TOOLS.CIRCLE&&O.points.length===2){const[V,q]=O.points,se=Math.sqrt(Math.pow(q.x-V.x,2)+Math.pow(q.y-V.y,2));return I.jsxRuntimeExports.jsx(qy,{x:V.x,y:V.y,radius:se,stroke:O.color,strokeWidth:O.width,fill:"transparent"},`circle-${Y}`)}return null}),g&&g.points.length===2&&I.jsxRuntimeExports.jsxs(I.jsxRuntimeExports.Fragment,{children:[y===Ye.E_CANVAS_TOOLS.RECT&&I.jsxRuntimeExports.jsx(Jy,{x:g.points[0].x,y:g.points[0].y,width:g.points[1].x-g.points[0].x,height:g.points[1].y-g.points[0].y,stroke:S,strokeWidth:h,fill:"transparent",dash:[5,5]}),y===Ye.E_CANVAS_TOOLS.CIRCLE&&I.jsxRuntimeExports.jsx(qy,{x:g.points[0].x,y:g.points[0].y,radius:Math.sqrt(Math.pow(g.points[1].x-g.points[0].x,2)+Math.pow(g.points[1].y-g.points[0].y,2)),stroke:S,strokeWidth:h,fill:"transparent",dash:[5,5]})]})]})})}):I.jsxRuntimeExports.jsx("div",{style:{position:"relative"},children:I.jsxRuntimeExports.jsx("div",{style:{width:600,height:400,background:"#f0f0f0",display:"flex",alignItems:"center",justifyContent:"center"},children:"Loading image..."})})};function QS(s){const{containerHeight:l,containerWidth:f}=s,{groupDocuments:v}=q6(),{parentRef:S}=Ea(),y=ae.useRef(null);let h=1,x=v.length;(v.length===3||v.length===4)&&(h=2,x=2);const E=l/h,d=f/x;return ae.useEffect(()=>{y.current&&(y.current.style.height=`${l}px`,y.current.style.width=`${f}px`)},[l,f,S]),I.jsxRuntimeExports.jsx("div",{ref:y,className:"hfl-bg-Gray-400 hfl-py-2",style:{display:v.length>1?"grid":"flex",gridTemplateColumns:v.length>1?`repeat(${x}, 1fr)`:void 0,gridTemplateRows:v.length>2?`repeat(${h}, 1fr)`:void 0,gap:"8px",height:`${l}px`,width:`${f}px`,justifyContent:v.length===1?"center":void 0,alignItems:"center"},children:v.map((b,P)=>I.jsxRuntimeExports.jsx("div",{style:{width:`${d}px`,height:`${E}px`,display:"flex",alignItems:"center",justifyContent:P%2===0?"flex-end":"flex-start"},id:`compare-${b.id}`,children:I.jsxRuntimeExports.jsx(j5,{imageUrl:b.filePath,containerRef:`compare-${b.id}`})},`compare-${b.id}`))})}const KS="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M5.75%203H18.25C19.7688%203%2021%204.23122%2021%205.75V18.25C21%2019.7688%2019.7688%2021%2018.25%2021H5.75C4.23122%2021%203%2019.7688%203%2018.25V5.75C3%204.23122%204.23122%203%205.75%203ZM5.75%204.5C5.05964%204.5%204.5%205.05964%204.5%205.75V18.25C4.5%2018.9404%205.05964%2019.5%205.75%2019.5H18.25C18.9404%2019.5%2019.5%2018.9404%2019.5%2018.25V5.75C19.5%205.05964%2018.9404%204.5%2018.25%204.5H5.75Z'%20fill='%237C8897'/%3e%3c/svg%3e",_S="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAADxSURBVHgB7ZI9DoIwGIa/0gt4IRk0TnIR44IjEUNJiIbJDeI9ZJNEceE6HABqqwvy169MDDxJk6Yt7wP0BZiZHKcwst0w9kAT+dzxHNnNdaN1sqQAHJiOxA1vHufkSghfNPdocyFL77m5toiYMnNjQfZIXqpw4BUTww+cPVMKfpLkiZGownsFGAkmfFAwJMGGSwggcC8xEyc9Mdi3F8hwtOBPIkGGSwzAYhi8c66AYg7V/7n4aHkPqAqjBM0LxVYYJehri46E6obrSuiYcB0JHRveJVmutsU7TfL6fqumpISCV/yA7bkkcHbihcCHmUnyAbVr1q3eVypyAAAAAElFTkSuQmCC",$S="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M21.0302%202.96967C22.4276%204.36713%2022.4276%206.63286%2021.0302%208.03033L9.06186%2019.9987C8.78498%2020.2755%208.44064%2020.4754%208.06288%2020.5784L2.94719%2021.9736C2.38732%2022.1263%201.87359%2021.6125%202.02628%2021.0527L3.42147%2015.937C3.52449%2015.5592%203.72432%2015.2149%204.0012%2014.938L15.9695%202.96967C17.367%201.5722%2019.6327%201.5722%2021.0302%202.96967ZM15%206.06057L5.06186%2015.9987C4.96956%2016.0909%204.90296%2016.2057%204.86861%2016.3316L3.81877%2020.1811L7.6682%2019.1312C7.79412%2019.0969%207.9089%2019.0303%208.0012%2018.938L17.939%208.99957L15%206.06057ZM17.0302%204.03033L16.06%204.99957L18.999%207.93957L19.9695%206.96967C20.7812%206.15799%2020.7812%204.842%2019.9695%204.03033C19.1578%203.21865%2017.8419%203.21865%2017.0302%204.03033Z'%20fill='%237C8897'/%3e%3c/svg%3e",eE="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M12%202C17.5228%202%2022%206.47715%2022%2012C22%2017.5228%2017.5228%2022%2012%2022C6.47715%2022%202%2017.5228%202%2012C2%206.47715%206.47715%202%2012%202ZM12%203.5C7.30558%203.5%203.5%207.30558%203.5%2012C3.5%2016.6944%207.30558%2020.5%2012%2020.5C16.6944%2020.5%2020.5%2016.6944%2020.5%2012C20.5%207.30558%2016.6944%203.5%2012%203.5Z'%20fill='%237C8897'/%3e%3c/svg%3e";function tE(){const{setShowPenTool:s,setPenTool:l}=Jf(),f=ae.useMemo(()=>[{image:_S,onClick:()=>s(!1),label:"Close icon"},{image:eE,onClick:()=>l(Ye.E_CANVAS_TOOLS.CIRCLE),label:"Circle icon"},{image:KS,onClick:()=>l(Ye.E_CANVAS_TOOLS.RECT),label:"Checkbox icon"},{image:$S,onClick:()=>l(Ye.E_CANVAS_TOOLS.PEN),label:"Edit icon"}],[l,s]);return I.jsxRuntimeExports.jsx("div",{className:"hfl-rounded-md hfl-p-2 hfl-bg-White hfl-flex hfl-flex-col hfl-gap-2 hfl-items-center",children:f.map(v=>I.jsxRuntimeExports.jsx("img",{src:v.image,onClick:v.onClick,width:24,height:24,className:"hfl-cursor-pointer"},v.label))})}function nE(){const{setPenColor:s,penColor:l}=Jf();return I.jsxRuntimeExports.jsx("div",{className:"hfl-rounded-md hfl-p-2 hfl-bg-White hfl-flex hfl-flex-col hfl-gap-2 hfl-items-center",children:li.C_PEN_TOOL_COLORS.map(f=>l===f?I.jsxRuntimeExports.jsx("div",{className:"hfl-border-Primary-600 hfl-w-[26px] hfl-h-[26px] hfl-rounded-full hfl-flex hfl-justify-center hfl-items-center hfl-border-2",children:I.jsxRuntimeExports.jsx("div",{className:"hfl-rounded-full hfl-w-[24px] hfl-h-[24px] ",style:{backgroundColor:f},onClick:()=>s(f)})},f):I.jsxRuntimeExports.jsx("div",{className:"hfl-rounded-full hfl-w-[24px] hfl-h-[24px] ",style:{backgroundColor:f},onClick:()=>s(f)},f))})}function L5(){const s=ae.useRef(null),{parentRef:l}=Ea(),{showPenTool:f}=Jf();return ae.useEffect(()=>{if(f&&l.current&&s.current){const v=l.current.getBoundingClientRect(),S=v.width,y=v.height,h=v.top+y*.1,x=v.left+S*.9;s.current.style.position="fixed",s.current.style.top=`${h}px`,s.current.style.left=`${x}px`}},[l,f]),f?I.jsxRuntimeExports.jsxs("div",{className:"hfl-fixed hfl-z-99999999 hfl-flex hfl-flex-col hfl-gap-2",ref:s,children:[I.jsxRuntimeExports.jsx(tE,{}),I.jsxRuntimeExports.jsx(nE,{})]}):null}function rE(){const{clearSelectedDocuments:s,setSelectedGroup:l,selectedGroup:f,selectedDocuments:v,addDocument:S,setShowSaveGroupPreview:y,updateDocument:h}=sa(),[x,E]=ae.useState(!1),d=ae.useRef(null),{onSaveComparision:b,setCompareMode:P,setShowPreview:w,setError:C}=Ea(),[A,N]=ae.useState(f?.label||""),B=ae.useCallback(()=>{w(!1),P(!1),l(null),s(),y(!1)},[s,P,l,w,y]),G=ae.useCallback(async()=>{if(!A){C&&C("Group Name is required");return}try{E(!0);const g=await b(f?.id||"",A,v.map(M=>M.id));g.status&&g.data&&(f?.id?h(g.data):S(g.data))}catch(g){console.error("Error saving comparison:",g)}finally{E(!1),B()}},[S,B,b,v,f?.id,A,C,h]),R=ae.useCallback(()=>{y(!1)},[y]);return I.jsxRuntimeExports.jsxs("div",{className:"hfl-absolute hfl-top-1/2 hfl-left-1/2 hfl-p-4 hfl-bg-white hfl-rounded-lg hfl-shadow-lg hfl-z-[9999999999] hfl-flex hfl-flex-col hfl-gap-2 hfl-transform hfl--translate-x-1/2 hfl--translate-y-1/2",ref:d,children:[I.jsxRuntimeExports.jsx("div",{className:`hfl-w-[400px] hfl-h-[400px] ${v.length<2?"hfl-flex ":"hfl-grid hfl-grid-cols-2"} hfl-border-1 hfl-border-Gray-900 hfl-rounded-lg`,children:v.map((g,M)=>I.jsxRuntimeExports.jsx("img",{src:g.filePath,className:`hfl-object-contain ${v.length<2?"":M%2===0?"hfl-flex hfl-justify-end":"hfl-flex hfl-justify-start"} `,width:200,style:{height:Math.floor(400/Math.round(v.length/2)-2)}},`${g.id}-save`))}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Medium",type:"Text lg",className:"hfl-text-gray-900",children:"Save Comparision Group"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Regular",type:"Text sm",className:"hfl-text-gray-500",children:"Save the details of the comparison group"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Regular",type:"Text sm",className:"hfl-text-gray-900",children:"Group Name"}),I.jsxRuntimeExports.jsx(I.Ps,{inputProps:{value:A,onChange:g=>N(g.target.value),placeholder:"Name"}}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-w-full hfl-flex hfl-justify-between hfl-mt-1 hfl-gap-2",children:[I.jsxRuntimeExports.jsx(I.Ku,{hierarchy:"Secondary",size:"md",textField:"Cancel",onClick:R,className:"hfl-w-full hfl-flex hfl-justify-center"}),I.jsxRuntimeExports.jsx(I.Ku,{hierarchy:"Primary",className:"hfl-bg-Primary-600 hfl-w-full hfl-flex hfl-justify-center",size:"md",textField:"Save",onClick:G,disabled:x})]})]})}function aE(){const{parentRef:s}=Ea(),{selectedDocuments:l,selectedGroup:f,showSaveGroupPreview:v}=sa(),S=ae.useRef(null),[y,h]=ae.useState(void 0),[x,E]=ae.useState([]),[d,b]=ae.useState(0),[P,w]=ae.useState(0);return ae.useEffect(()=>{s.current&&S.current&&(S.current.style.height=`${s.current.clientHeight}px`,S.current.style.width=`${s.current.clientWidth}px`,S.current.style.top=s.current.getBoundingClientRect().top+"px",S.current.style.left=s.current.getBoundingClientRect().left+"px")},[s]),ae.useEffect(()=>{f?(E(f.documents),h(f.id)):(E(l),h(void 0))},[l,f]),ae.useEffect(()=>{if(s.current){const C=s.current.clientHeight;b(C-P)}},[P,s]),I.jsxRuntimeExports.jsx(Ky.Provider,{value:{groupDocuments:x,setGroupDocuments:E,groupId:y,setGroupId:h},children:I.jsxRuntimeExports.jsxs("div",{ref:S,className:"hfl-fixed hfl-z-99999",children:[I.jsxRuntimeExports.jsx(S5,{setHeaderHeight:w}),I.jsxRuntimeExports.jsx(QS,{containerHeight:d,containerWidth:S.current?.clientWidth||0}),I.jsxRuntimeExports.jsx(L5,{}),v&&I.jsxRuntimeExports.jsx(rE,{})]})})}function iE(s){const{allDocuments:l}=s,{selectedIndex:f,setSelectedIndex:v}=sa();return I.jsxRuntimeExports.jsx("div",{className:`hfl-flex hfl-bg-Gray-600 hfl-p-2 hfl-flex-col hfl-gap-2 hfl-h-full hfl-overflow-y-auto ${l.length<2?"hfl-hidden":""}`,children:l.map((S,y)=>{const h=l5(S),x=!S.thumbnail;return I.jsxRuntimeExports.jsx("div",{className:`hfl-w-[118px] hfl-h-[146px] hfl-flex-shrink-0 hfl-cursor-pointer hfl-border-2 hfl-rounded-md hfl-overflow-hidden ${f===y?"hfl-border-Blue-500":"hfl-border-transparent"}`,onClick:()=>v(y),children:I.jsxRuntimeExports.jsx("img",{src:h,alt:S.label,className:`hfl-w-full hfl-h-full ${x?"hfl-object-contain hfl-bg-Gray-700 hfl-p-4":"hfl-object-cover"}`})},`${S.id}-document-preview`)})})}const sE=ae.memo(iE),lE="data:image/svg+xml,%3csvg%20width='9'%20height='16'%20viewBox='0%200%209%2016'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M8.03033%2015.2803C8.32322%2014.9874%208.32322%2014.5126%208.03033%2014.2197L1.81066%208L8.03033%201.78033C8.32322%201.48744%208.32322%201.01256%208.03033%200.71967C7.73744%200.426777%207.26256%200.426777%206.96967%200.71967L0.219671%207.46967C-0.0732224%207.76256%20-0.0732225%208.23744%200.219671%208.53033L6.96967%2015.2803C7.26256%2015.5732%207.73744%2015.5732%208.03033%2015.2803Z'%20fill='%23101828'/%3e%3c/svg%3e",oE="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M8.96967%204.71967C8.67678%205.01256%208.67678%205.48744%208.96967%205.78033L15.1893%2012L8.96967%2018.2197C8.67678%2018.5126%208.67678%2018.9874%208.96967%2019.2803C9.26256%2019.5732%209.73744%2019.5732%2010.0303%2019.2803L16.7803%2012.5303C17.0732%2012.2374%2017.0732%2011.7626%2016.7803%2011.4697L10.0303%204.71967C9.73744%204.42678%209.26256%204.42678%208.96967%204.71967Z'%20fill='%23101828'/%3e%3c/svg%3e",uE=({file_data:s})=>{const[l,f]=ae.useState(!1),v=ae.useRef(null),S=[{src:s,type:"video/mp4"}],y=h=>{h.currentTarget.remove(),v.current&&v.current.children.length===0&&f(!0)};return I.jsxRuntimeExports.jsx("div",{className:"hfl-flex hfl-justify-center hfl-items-center hfl-w-full hfl-max-w-[800px] hfl-mx-auto",children:l?I.jsxRuntimeExports.jsx("div",{className:"hfl-flex hfl-flex-col hfl-justify-center hfl-items-center hfl-gap-2 hfl-h-[300px] hfl-p-2",children:I.jsxRuntimeExports.jsx(I.bs,{variant:"Medium",type:"Text md",className:"xxxs:max-sm:hfl-text-[10px]",children:"Live preview is not supported for this video. Please download it to watch."})}):I.jsxRuntimeExports.jsxs("video",{ref:v,controls:!0,autoPlay:!0,className:"hfl-flex hfl-justify-center hfl-items-center hfl-w-full hfl-max-w-[800px] hfl-mx-auto hfl-h-[350px]",children:[S.map(({src:h,type:x})=>I.jsxRuntimeExports.jsx("source",{src:h,type:x,onError:y},x)),"Your browser does not support the video tag."]})})};function cE({document:s}){const{parentRef:l}=Ea(),{clearSelectedDocuments:f}=sa(),{setShowPreview:v}=Ea(),S=ae.useCallback(()=>{v(!1),f()},[f,v]),y=ae.useCallback(()=>l?.current&&l.current.clientWidth<=1180,[l]);if(ae.useEffect(()=>{s.mimeType===Ye.E_DOCUMENT_FORMAT.PDF&&y()&&(window.open(s.filePath,"_blank"),S())},[s,y,S]),s.mimeType===Ye.E_DOCUMENT_FORMAT.PDF&&y())return I.jsxRuntimeExports.jsx(I.bs,{type:"Text lg",variant:"Bold",children:"Opening PDF in a new tab..."});const x=`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(s.filePath)}`;switch(s.mimeType){case Ye.E_DOCUMENT_FORMAT.MP4:return I.jsxRuntimeExports.jsx(uE,{file_data:s.filePath});case Ye.E_DOCUMENT_FORMAT.PDF:return I.jsxRuntimeExports.jsx("div",{className:"hfl-bg-white hfl-h-full hfl-w-full",children:I.jsxRuntimeExports.jsx("iframe",{src:s.filePath,width:"100%",height:"100%",style:{border:"none"},children:"Your browser does not support PDFs. Please download the PDF to view it."})});case Ye.E_DOCUMENT_FORMAT.DOC:case Ye.E_DOCUMENT_FORMAT.DOCX:return I.jsxRuntimeExports.jsx("div",{className:"hfl-bg-white hfl-h-full hfl-w-full",children:I.jsxRuntimeExports.jsx("iframe",{src:x,width:"100%",height:"100%",style:{border:"none"},children:"Preview is not available for this document. Please check the file URL."})});default:return I.jsxRuntimeExports.jsxs("div",{children:["Unsupported file type: ",s.mimeType]})}}function fE(s){const{document:l}=s,f=`konva-container-${l.id}`;return I.jsxRuntimeExports.jsx("div",{id:f,className:"hfl-w-full hfl-h-full hfl-relative",children:I.jsxRuntimeExports.jsx(j5,{imageUrl:l.filePath,containerRef:f},l.id)})}function dE(){const{parentRef:s}=Ea(),l=ae.useRef(null),[f,v]=ae.useState(0),S=ae.useRef(null),{document:y,selectedIndex:h,setSelectedIndex:x}=sa(),E=ae.useMemo(()=>y.filter(rl),[y]),d=E.length,b=E[h];ae.useEffect(()=>{s.current&&l.current&&(l.current.style.height=`${s.current.clientHeight}px`,l.current.style.width=`${s.current.clientWidth}px`,l.current.style.top=`${s.current.getBoundingClientRect().top}px`,l.current.style.left=`${s.current.getBoundingClientRect().left}px`)},[s]),ae.useEffect(()=>{if(s.current&&S.current){const C=s.current.clientHeight;S.current.style.height=`${C-f}px`}},[f,s]);const P=ae.useCallback(C=>{if(d<=1)return;const A=C==="next"?(h+1)%d:(h-1+d)%d;x(A)},[h,d,x]);ae.useEffect(()=>{const C=A=>{A.key==="ArrowRight"?P("next"):A.key==="ArrowLeft"&&P("prev")};return window.addEventListener("keydown",C),()=>{window.removeEventListener("keydown",C)}},[P]);const w=b&&g2(b);return I.jsxRuntimeExports.jsxs("div",{className:"hfl-z-99999 hfl-fixed",ref:l,children:[I.jsxRuntimeExports.jsx(S5,{setHeaderHeight:v,isPreview:!0}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-bg-Gray-400 hfl-flex hfl-w-full",ref:S,children:[I.jsxRuntimeExports.jsx(sE,{allDocuments:E}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex-1 hfl-relative hfl-flex hfl-justify-center hfl-items-center hfl-p-4 hfl-overflow-hidden",children:[b&&g2(b)?I.jsxRuntimeExports.jsx(fE,{document:b}):b&&I.jsxRuntimeExports.jsx(cE,{document:b}),d>1&&I.jsxRuntimeExports.jsxs(I.jsxRuntimeExports.Fragment,{children:[I.jsxRuntimeExports.jsx("button",{onClick:()=>P("prev"),className:"hfl-absolute hfl-left-4 hfl-top-1/2 -hfl-translate-y-1/2 hfl-w-12 hfl-h-12 hfl-rounded-full hfl-bg-Gray-100/40 hover:hfl-bg-Gray-900/60 hfl-flex hfl-justify-center hfl-items-center hfl-z-10",children:I.jsxRuntimeExports.jsx("img",{src:lE,alt:"Previous"})}),I.jsxRuntimeExports.jsx("button",{onClick:()=>P("next"),className:"hfl-absolute hfl-right-4 hfl-top-1/2 -hfl-translate-y-1/2 hfl-w-12 hfl-h-12 hfl-rounded-full hfl-bg-Gray-100/40 hover:hfl-bg-Gray-900/60 hfl-flex hfl-justify-center hfl-items-center hfl-z-10",children:I.jsxRuntimeExports.jsx("img",{src:oE,alt:"Next"})})]})]})]}),w&&I.jsxRuntimeExports.jsx(L5,{})]})}const hE=[{label:"Unspecified",value:Ye.E_DOCUMENT_TYPE.REPORT_TYPE_UNSPECIFIED},...Object.values(Ye.E_DOCUMENT_TYPE).filter(s=>s!==Ye.E_DOCUMENT_TYPE.REPORT_TYPE_UNSPECIFIED).map(s=>({label:s.charAt(0).toUpperCase()+s.slice(1).replace(/_/g," "),value:s}))];function pE({isOpen:s,document:l,onClose:f,onSave:v}){const[S,y]=ae.useState(""),[h,x]=ae.useState(""),[E,d]=ae.useState(!1),[b,P]=ae.useState(""),[w,C]=ae.useState("");ae.useEffect(()=>{if(l){const N=l.label,B=N.lastIndexOf(".");B!==-1?(P(N.substring(0,B)),C(N.substring(B))):(P(N),C("")),y(l.reportType||Ye.E_DOCUMENT_TYPE.REPORT_TYPE_UNSPECIFIED),x(new Date(l.createdAt).toISOString().split("T")[0])}},[l]);const A=async()=>{if(l){d(!0);try{const N={id:l.id,label:`${b}${w}`,reportType:S===Ye.E_DOCUMENT_TYPE.REPORT_TYPE_UNSPECIFIED?"":S,createdAt:new Date(h).toISOString(),filePath:l.filePath,mimeType:l.mimeType,downloadPath:l.downloadPath,fileName:l.fileName};await v(N),f()}catch(N){console.error("Failed to save document:",N)}finally{d(!1)}}};return!s||!l?null:I.jsxRuntimeExports.jsx("div",{className:"hfl-fixed hfl-inset-0 hfl-bg-black hfl-bg-opacity-50 hfl-flex hfl-items-center hfl-justify-center hfl-z-50",children:I.jsxRuntimeExports.jsxs("div",{className:"hfl-bg-white hfl-rounded-lg hfl-p-8 hfl-w-full hfl-max-w-md hfl-flex hfl-flex-col hfl-gap-6",children:[I.jsxRuntimeExports.jsx("div",{className:"hfl-w-full hfl-h-48 hfl-bg-Gray-100 hfl-rounded-lg hfl-overflow-hidden",children:I.jsxRuntimeExports.jsx(o5,{documents:l})}),I.jsxRuntimeExports.jsxs("div",{children:[I.jsxRuntimeExports.jsx(I.bs,{variant:"Semibold",type:"Text xl",className:"hfl-text-Gray-900",children:"Edit Document"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Regular",type:"Text sm",className:"hfl-text-Gray-500",children:"Edit the details of the document."})]}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex hfl-flex-col hfl-gap-4",children:[I.jsxRuntimeExports.jsxs("div",{children:[I.jsxRuntimeExports.jsx("label",{htmlFor:"documentName",className:"hfl-block hfl-text-sm hfl-font-medium hfl-text-Gray-700 hfl-mb-1",children:"Document Name"}),I.jsxRuntimeExports.jsx("input",{id:"documentName",value:b,onChange:N=>P(N.target.value),placeholder:"Enter document name",className:"hfl-w-full hfl-border hfl-border-Gray-300 hfl-rounded-md hfl-px-3 hfl-py-2 focus:hfl-outline-none focus:hfl-ring-2 focus:hfl-ring-Primary-500"})]}),I.jsxRuntimeExports.jsxs("div",{children:[I.jsxRuntimeExports.jsx("label",{className:"hfl-block hfl-text-sm hfl-font-medium hfl-text-Gray-700 hfl-mb-1",children:"Type"}),I.jsxRuntimeExports.jsx("select",{value:S,onChange:N=>y(N.target.value),className:"hfl-w-full hfl-border hfl-border-Gray-300 hfl-rounded-md hfl-px-3 hfl-py-2 focus:hfl-outline-none focus:hfl-ring-2 focus:hfl-ring-Primary-500",children:hE.map(N=>I.jsxRuntimeExports.jsx("option",{value:N.value,children:N.label},N.value))})]}),I.jsxRuntimeExports.jsxs("div",{children:[I.jsxRuntimeExports.jsx("label",{className:"hfl-block hfl-text-sm hfl-font-medium hfl-text-Gray-700 hfl-mb-1",children:"Creation Date"}),I.jsxRuntimeExports.jsx("input",{type:"date",value:h,onChange:N=>x(N.target.value),className:"hfl-w-full hfl-border hfl-border-Gray-300 hfl-rounded-md hfl-px-3 hfl-py-2 focus:hfl-outline-none focus:hfl-ring-2 focus:hfl-ring-Primary-500"})]})]}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex hfl-justify-end hfl-gap-3 hfl-mt-4",children:[I.jsxRuntimeExports.jsx(I.Ku,{textField:"Cancel",hierarchy:"Secondary",onClick:f,disabled:E,size:"sm"}),I.jsxRuntimeExports.jsx(I.Ku,{textField:E?"Saving...":"Save",hierarchy:"Primary",onClick:A,disabled:E,size:"sm"})]})]})})}function vE({isOpen:s,onClose:l,onCapture:f}){const v=ae.useRef(null),S=ae.useRef(null),y=ae.useRef(null),[h,x]=ae.useState(!1),[E,d]=ae.useState(null),[b,P]=ae.useState(!1),[w,C]=ae.useState(!1),[A,N]=ae.useState([]),[B,G]=ae.useState(null),R=async()=>{try{const L=(await navigator.mediaDevices.enumerateDevices()).filter(H=>H.kind==="videoinput");console.log("Available video devices:",L),N(L)}catch(Z){console.error("Error enumerating devices:",Z)}};ae.useEffect(()=>{s&&R()},[s]);const g=async()=>{console.log("inside startCamera"),console.log("videoRef.current at start:",v.current),console.log("videoRef.current?.readyState:",v.current?.readyState);try{x(!0),d(null),console.log("before getUserMedia");const Z=await navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280},height:{ideal:720},facingMode:"environment"},audio:!1});console.log("after getUserMedia, stream:",Z),console.log("stream.getTracks():",Z.getTracks()),y.current=Z,console.log("videoRef.current after getUserMedia:",v.current),console.log("videoRef.current?.readyState after getUserMedia:",v.current?.readyState),G(Z),C(!0),console.log("after setHasPermission")}catch(Z){console.error("Error accessing camera:",Z),Z instanceof Error?Z.name==="NotAllowedError"?d("Camera access denied. Please grant permission to use the camera."):Z.name==="NotFoundError"?d("No camera found on this device."):Z.name==="NotSupportedError"?d("Camera is not supported on this device."):d("Failed to access camera. Please try again."):d("Failed to access camera. Please try again.")}finally{x(!1),console.log("startCamera finally block - isLoading set to false")}};ae.useEffect(()=>{B&&v.current&&w&&(v.current.srcObject=B,v.current.play().catch(Z=>{console.error("Error playing video:",Z)}))},[B,w]);const M=()=>{console.log("stopCamera called"),y.current&&(console.log("Stopping stream tracks:",y.current.getTracks().length),y.current.getTracks().forEach(Z=>{console.log("Stopping track:",Z.kind,Z.readyState),Z.stop()}),y.current=null),v.current&&(console.log("Clearing video srcObject"),v.current.srcObject=null),C(!1),console.log("stopCamera completed")},j=async()=>{if(!(!v.current||!S.current)){P(!0);try{const Z=v.current,L=S.current,H=L.getContext("2d");if(!H)throw new Error("Unable to get canvas context");L.width=Z.videoWidth,L.height=Z.videoHeight,H.drawImage(Z,0,0,L.width,L.height);const k=await new Promise((ee,re)=>{L.toBlob($=>{$?ee($):re(new Error("Failed to create image blob"))},"image/jpeg",.8)}),J=new Date().toISOString().replace(/[:.]/g,"-"),_=new File([k],`captured-image-${J}.jpg`,{type:"image/jpeg"});await f(_),l()}catch(Z){console.error("Error capturing photo:",Z),d("Failed to capture photo. Please try again.")}finally{P(!1)}}},U=async()=>{if(!y.current)return;const L=y.current.getVideoTracks()[0].getSettings().facingMode;M();try{const H=L==="environment"?"user":"environment",k=await navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280},height:{ideal:720},facingMode:H},audio:!1});y.current=k,v.current&&(v.current.srcObject=k,v.current.play())}catch(H){console.error("Error switching camera:",H),d("Failed to switch camera. Using default camera."),g()}};return ae.useEffect(()=>(console.log("useEffect triggered with isOpen:",s),s?(console.log("Calling startCamera from useEffect"),R(),g()):(console.log("Calling stopCamera from useEffect"),M(),d(null)),()=>{console.log("useEffect cleanup - calling stopCamera"),M()}),[s]),s?I.jsxRuntimeExports.jsx("div",{className:"hfl-fixed hfl-inset-0 hfl-bg-black hfl-bg-opacity-75 hfl-flex hfl-items-center hfl-justify-center hfl-z-50",children:I.jsxRuntimeExports.jsxs("div",{className:"hfl-bg-white hfl-rounded-lg hfl-p-6 hfl-w-full hfl-max-w-2xl hfl-max-h-[90vh] hfl-overflow-hidden",children:[I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex hfl-items-center hfl-justify-between hfl-mb-4",children:[I.jsxRuntimeExports.jsx(I.bs,{variant:"Semibold",type:"Text lg",className:"hfl-text-Gray-900",children:"Capture Photo"}),I.jsxRuntimeExports.jsx("button",{onClick:l,className:"hfl-text-Gray-500 hfl-hover:text-Gray-700 hfl-p-1 hfl-h-4 hfl-w-4",children:I.jsxRuntimeExports.jsx("i",{className:"hx_close hfl-text-xl"})})]}),I.jsxRuntimeExports.jsxs("div",{className:"hfl-relative hfl-bg-black hfl-rounded-lg hfl-overflow-hidden hfl-mb-4",children:[h&&I.jsxRuntimeExports.jsx("div",{className:"hfl-flex hfl-items-center hfl-justify-center hfl-h-64",children:I.jsxRuntimeExports.jsx(I.bs,{variant:"Regular",type:"Text sm",className:"hfl-text-white",children:"Loading camera..."})}),E&&I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex hfl-flex-col hfl-items-center hfl-justify-center hfl-h-64 hfl-p-4",children:[I.jsxRuntimeExports.jsx("i",{className:"hx_camera hfl-text-4xl hfl-text-Gray-400 hfl-mb-2"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Regular",type:"Text sm",className:"hfl-text-Gray-600 hfl-text-center",children:E}),I.jsxRuntimeExports.jsx("button",{onClick:g,className:"hfl-mt-3 hfl-px-4 hfl-py-2 hfl-bg-Blue-600 hfl-text-white hfl-rounded-lg hfl-hover:bg-Blue-700",children:"Try Again"})]}),w&&!E&&I.jsxRuntimeExports.jsx("video",{ref:v,className:"hfl-w-full hfl-h-auto hfl-max-h-96",onLoadedMetadata:()=>console.log("Video onLoadedMetadata"),onCanPlay:()=>console.log("Video onCanPlay"),onPlaying:()=>console.log("Video onPlaying"),onWaiting:()=>console.log("Video onWaiting"),onError:Z=>console.log("Video onError:",Z),onLoadStart:()=>console.log("Video onLoadStart"),autoPlay:!0,playsInline:!0,muted:!0}),I.jsxRuntimeExports.jsx("canvas",{ref:S,className:"hfl-hidden"})]}),w&&!E&&I.jsxRuntimeExports.jsxs("div",{className:"hfl-flex hfl-items-center hfl-justify-center hfl-gap-4",children:[A.length>1&&I.jsxRuntimeExports.jsxs("button",{onClick:U,className:"hfl-flex hfl-items-center hfl-gap-2 hfl-px-4 hfl-py-2 hfl-text-sm hfl-text-Gray-700 hfl-border hfl-border-Gray-300 hfl-rounded-lg hfl-hover:bg-Gray-50",children:[I.jsxRuntimeExports.jsx("i",{className:"hx_refresh hfl-text-base"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Medium",type:"Text sm",children:"Switch Camera"})]}),I.jsxRuntimeExports.jsxs("button",{onClick:j,disabled:b,className:`hfl-flex hfl-items-center hfl-gap-2 hfl-px-6 hfl-py-3 hfl-text-sm hfl-text-white hfl-rounded-lg hfl-transition-colors ${b?"hfl-bg-Gray-400 hfl-cursor-not-allowed":"hfl-bg-Blue-600 hfl-hover:bg-Blue-700"}`,children:[I.jsxRuntimeExports.jsx("i",{className:"hx_camera hfl-text-base"}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Medium",type:"Text sm",className:"hfl-text-white",children:b?"Capturing...":"Capture Photo"})]})]})]})}):null}function mE({containerRef:s,setPage:l,hasData:f,shouldScroll:v,setNextDate:S,cursor:y,query_type:h}){const x=ae.useRef(v),E=ae.useRef(0),d=ae.useRef(!1);ae.useEffect(()=>{x.current=v},[v]),ae.useEffect(()=>{if(!s||!s.current)return;console.log("Inside scroll event",f);const b=s.current;if(!b)return;const P=()=>{if(!x.current||!f)return;const{scrollTop:w,scrollHeight:C,clientHeight:A}=b;d.current=w>E.current,E.current=w,d.current&&w+A>=C-10&&(h===Ye.E_ATTACHMENT_QUERY_TYPE.VIEW_GRID?l(N=>N+1):S(y))};return b.addEventListener("scroll",P),()=>{b.removeEventListener("scroll",P)}},[s,l,f,h,S,y])}function gE(s){const{isUploading:l}=s;return l?I.jsxRuntimeExports.jsxs("div",{className:"hfl-absolute hfl-flex hfl-gap-2 hfl-items-center hfl-left-[90%] hfl-top-[80%] hfl-p-3 hfl-rounded-md hfl-border-l-2 hfl-border-b-2 hfl-border-l-Success-600 hfl-border-b-Success-600 hfl-bg-White hfl-shadow-upload hfl-translate-x-[-80%] hfl-translate-y-[-90%] hfl-min-w-[375px] ",children:[I.jsxRuntimeExports.jsx("div",{className:"hfl-h-[32px] hfl-min-w-[32px] hfl-flex hfl-justify-center hfl-items-center hfl-rounded-md hfl-bg-Success-600",children:I.jsxRuntimeExports.jsx("i",{className:"hx_checkmark hfl-text-White "})}),I.jsxRuntimeExports.jsx(I.bs,{variant:"Medium",type:"Text sm",className:"hfl-text-Blue_gray-800",children:"Your file(s) are being uploaded. Do not refresh or close the page."})]}):null}const yE=ae.memo(gE);function xE(s){const{parentRef:l,fetchAttachments:f,uploadFiles:v,onDocumentPreview:S,onDocumentDownload:y,onDocumentUpdate:h,setError:x,showHeaderBackButton:E,patient_id:d="",patient_role_id:b="",doctor_id:P="",doctor_role_id:w="",branch_id:C="",onDeleteAttachments:A,onSaveComparision:N,onHeaderBackClick:B}=s,[G,R]=ae.useState(!1),[g,M]=ae.useState(!1),[j,U]=ae.useState(""),[Z,L]=ae.useState(!0),[H,k]=ae.useState([]),[J,_]=ae.useState({startDate:null,endDate:null}),[ee,re]=ae.useState(1),[$,pe]=ae.useState(""),[z,O]=ae.useState(""),Y=ae.useRef(null),[V,q]=ae.useState(Ye.E_ATTACHMENT_QUERY_TYPE.VIEW_GRID),{documentView:se,setDocument:ne,addDocuments:ge,selectedDocuments:Re,addDocument:oe,updateDocument:Q}=sa(),ue=ae.useMemo(()=>se===Ye.E_DOCUMENT_VIEW_TYPE.GRID_VIEW?20:3,[se]),[Te,De]=ae.useState(null),[Me,qe]=ae.useState(!1),[xe,Le]=ae.useState(!1),je=ae.useMemo(()=>!G&&!g,[G,g]),{isLoading:Ke}=X6(`attachments?page=${ee}&page_size=${ue}&query_type=${V}&search=${j}&types=${H.join(",")}&start_date=${J.startDate}&end_date=${J.endDate}&next_date=${$}&patient_id=${d}&patient_role_id=${b}&doctor_id=${P}&doctor_role_id=${w}&branch_id=${C}`,()=>f(ee,j,H,ue,V,J,$),{revalidateOnFocus:!1,onSuccess:rt=>{rt.data&&(ee===1&&V===Ye.E_ATTACHMENT_QUERY_TYPE.VIEW_GRID?ne(rt.data):$&&V===Ye.E_ATTACHMENT_QUERY_TYPE.VIEW_DATE?ge(rt.data):V===Ye.E_ATTACHMENT_QUERY_TYPE.VIEW_DATE?ne(rt.data):ge(rt.data),(rt.data.length===0||rt.data.length<ue)&&L(!1),O(rt.next_date||""))},onError:rt=>x?.(`Failed to fetch documents: ${rt.message}`)});ae.useEffect(()=>{l.current&&Y.current&&(Y.current.style.height=`${l.current.clientHeight}px`)},[l]);const _e=async rt=>{Le(!0);try{const{validFiles:Vt,errors:fn}=s5(rt);if(fn.length>0&&fn.forEach(sn=>x?.(sn)),Vt.length>0){const sn=await v({files:Vt});let Pe=!0;console.log("Upload response for a file1: ",sn.data),sn.data.forEach(Ue=>{console.log("Upload response for a file: ",Ue),Ue.success&&Ue.data?(console.log("Adding document: ",Ue.data),oe(Ue.data)):Pe=!1}),Pe||x?.("Failed to upload all files")}}catch(Vt){x?.(`Failed to upload files. Please try again. ${Vt}`)}finally{Le(!1)}},gt=async rt=>{await _e([rt])},Dt=rt=>{De(rt)},dt=rt=>{S&&S(rt)},yt=rt=>{y&&y(rt)},St=()=>{De(null)},cn=async rt=>{try{const Vt=await h(rt);Vt.success&&Vt.data?Q(Vt.data):x?.("Failed to update document.")}catch(Vt){x?.("An unexpected error occurred while updating the document."),console.error(Vt)}},nn=()=>qe(!0),Ut=()=>qe(!1);return mE({containerRef:Y,setPage:re,hasData:Z,shouldScroll:!Ke,cursor:z,setNextDate:pe,query_type:V}),I.jsxRuntimeExports.jsxs(Qy.Provider,{value:{page:ee,setPage:re,hasData:Z,queryType:V,setQueryType:q,setShowPreview:R,showPreview:G,compareMode:g,setCompareMode:M,parentRef:l,search:j,setSearch:U,types:H,setTypes:k,dates:J,setDates:_,setHasData:L,onSaveComparision:N,onDeleteAttachments:A,setError:x},children:[I.jsxRuntimeExports.jsxs("div",{ref:Y,className:`hfl-w-full hfl-relative hfl-overflow-scroll ${Me?"hfl-overflow-hidden":""}`,children:[je&&I.jsxRuntimeExports.jsx(J6,{showBackButton:E&&!G&&!g,onFileUpload:_e,setNextDate:pe,setCursor:O,onCaptureClick:nn,isUploading:xe,setIsUploading:Le,onHeaderBackClickCb:E&&B?B:void 0}),se===Ye.E_DOCUMENT_VIEW_TYPE.GRID_VIEW?I.jsxRuntimeExports.jsx(c6,{onFileUpload:_e,onEdit:Dt,onPreview:dt,onDownload:yt}):I.jsxRuntimeExports.jsx(d6,{onFileUpload:_e,onEdit:Dt,onPreview:dt,onDownload:yt}),Re.length>0&&!G&&!g&&I.jsxRuntimeExports.jsx(I6,{})]}),g&&I.jsxRuntimeExports.jsx(aE,{}),G&&I.jsxRuntimeExports.jsx(dE,{}),Te&&I.jsxRuntimeExports.jsx(pE,{isOpen:!!Te,document:Te,onClose:St,onSave:cn}),I.jsxRuntimeExports.jsx(vE,{isOpen:Me,onClose:Ut,onCapture:gt}),I.jsxRuntimeExports.jsx(yE,{isUploading:xe})]})}exports.Attachments=xE;