1import{c as le,e as j,s as R,j as e,k as F,B as H,b as ce,u as Oe,d as ve,m as Zs,F as Ce,X as jt,S as De,C as Ze,h as et,i as de,f as tt,g as ne,n as ns,o as is,p as os,a as er}from"./index-BoPK12rZ.js";import{D as ls,a as cs,b as ds,c as tr,d as Bt,e as pe,M as sr}from"./MobileHeader-CqvUywPA.js";import{f as ge}from"./format-Mfnei9oz.js";import{B as ue}from"./badge-Dzgcftu_.js";import{A as rr}from"./arrow-left-Bm3n84ZD.js";import{A as us}from"./arrow-right-Blw5VId1.js";import{S as ar}from"./switch-BKo3y5a4.js";import{U as vt}from"./user-BOOKI8Fb.js";import{S as je}from"./stethoscope-BHnL3bfQ.js";import{D as nr}from"./dna-FOYyeFo0.js";import{F as ir}from"./flask-conical-CCmJ33kr.js";import{S as or}from"./shopping-bag-fcG6Crkn.js";import{M as ut}from"./moon-B1YbfDdn.js";import{L as lr}from"./log-out-B0yE91Jf.js";import{C as ms}from"./chevron-left-ApOVVF0y.js";import{C as xs}from"./chevron-right-DhPYa9x5.js";import{S as fs,a as hs,b as ps,c as gs}from"./sheet-cWIgBlZN.js";import{M as Se}from"./mic-mMHz3pNt.js";import{C as ze}from"./calendar-CRUjAu6G.js";import{S as me}from"./square-check-big-MfaNS_-G.js";import{D as Nt,a as cr,b as wt,c as kt,d as St}from"./dialog-By_dUouJ.js";import{U as dr}from"./users-DpKGh2ZL.js";import{H as Ie}from"./heart-BibdQAhM.js";import{T as ur}from"./target-BMINKRby.js";import{S as Te}from"./sparkles-BRTES-oi.js";import{R as mr}from"./radio-o0KlLwdI.js";import{C as ie}from"./clock-DupAsq6s.js";import{T as xr,a as fr,b as Kt,c as Vt}from"./tabs-DWQ6x32b.js";import{u as _e}from"./useMutation-CQ66tvoD.js";import{U as mt}from"./upload-C8ESeIAY.js";import{C as qe}from"./circle-check-BHOaP-8t.js";import{S as hr}from"./send-BepDDYBj.js";import{C as _t}from"./circle-alert-ChnZ4M4N.js";import{A as bs,a as ys,b as js,c as vs,d as Ns,e as ws,f as ks,g as Ss,h as _s}from"./alert-dialog-fxcYzu1A.js";import{r as pr}from"./smadarAgents-DJoJ-q7J.js";import{F as Cs}from"./folder-open-C_qrhCxL.js";import{C as Ct}from"./chevron-up-BRs2jkXF.js";import{C as Dt}from"./chevron-down-BAeWndFz.js";import{E as xt}from"./external-link-B11tOvEC.js";import{D as gr}from"./download-hT9-cBzw.js";import{T as Ds}from"./trash-2-C45zYdX5.js";import{I as br}from"./image-Dxl47uOh.js";import{F as yr,E as jr}from"./file-B9hXm8Ut.js";import{C as vr}from"./circle-help-B-shSThO.js";import{T as Tt}from"./triangle-alert-Dyay52l3.js";import{I as ye}from"./input-B7jnFymG.js";import{L as ae}from"./label-CCd9oABz.js";import{S as ct}from"./separator-CZZGhig_.js";import{S as ft,a as ht,b as pt,c as gt,d as ke}from"./select-B6XUQb0n.js";import{D as Ts}from"./database-DX2pm16R.js";import{S as Nr}from"./slider-Dy9QdG3l.js";import{C as wr}from"./calendar-C9Cmfj0s.js";import{P as Ms,a as As,b as Es}from"./popover-BMAGgRds.js";import{A as Me}from"./activity-CT9PJwf8.js";import{D as Wt}from"./droplets-BQpdZSpW.js";import{C as Ge}from"./calendar-days-Ghlhkcyw.js";import{P as Rs}from"./plus-DvgK6Rve.js";import{T as kr}from"./trending-up-CjqgoF2p.js";import{P as oe}from"./pill-DyW1TgDo.js";import{L as Ps}from"./leaf-D6FAbpCJ.js";import{F as Sr,M as _r}from"./meh-DUhkFhs4.js";import{S as Cr}from"./smile-C0Lf5usD.js";import{h as Fe}from"./he-Jgw9chNc.js";import{p as Dr}from"./dateUtils-BU0ZLEbi.js";import{Q as Tr,i as dt,R as Mr}from"./RiskAlertsPanel-BxMQpxa1.js";import{S as Qt}from"./search-DSwtWRUA.js";import{T as Ae}from"./test-tube-7vicV7wn.js";import{M as Ls}from"./map-pin-BAbW9TMd.js";import{B as Ye}from"./bell-B5LDbczd.js";import{S as Ar}from"./sun-BEIew4v3.js";import{T as Er}from"./textarea-D9g-r6Bx.js";import{D as Rr}from"./DiagnosisDialog-CAkS69mq.js";import{P as Pr}from"./progress-B2ndVF8r.js";import{C as Lr}from"./circle-CiqXIsD8.js";import{M as qr}from"./message-circle-ZpEgKGux.js";import{S as Fr}from"./SmadarChat--ZxJiGwP.js";import{u as Or}from"./usePageAudit-C1C3kbpQ.js";import"./index-DuY6vpjC.js";import"./index-Bu4KJFpo.js";import"./index-DR_KIw6N.js";import"./avatar-CP49ZCZe.js";import"./ShareAccessButton-Cpy7wsA0.js";import"./share-2-C8elsqEp.js";import"./settings-3KW-LxmR.js";import"./en-US-BsB0DKe1.js";import"./index-BAk_bO_9.js";import"./subDays-dkkdDXrN.js";import"./endOfMonth-BSQE6Amk.js";import"./refresh-cw-DOixBuok.js";import"./info-BMh2YgBd.js";import"./save-BlQGp2m0.js";import"./ButterflyIcon-Dp_wm40A.js";import"./index-BTMZPHgP.js";import"./mic-off-BP77eSKT.js";import"./useAuditLog-CYpjb-9d.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const zr=le("ArrowDownToLine",[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Hr=le("CheckCheck",[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const $r=le("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/** 17 * @license lucide-react v0.462.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const Gt=le("FileAudio",[["path",{d:"M17.5 22h.5a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"rslqgf"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 19a2 2 0 1 1 4 0v1a2 2 0 1 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 1 1-4 0v-1a2 2 0 1 1 4 0",key:"9f7x3i"}]]);/** 22 * @license lucide-react v0.462.0 - ISC 23 * 24 * This source code is licensed under the ISC license. 25 * See the LICENSE file in the root directory of this source tree. 26 */const Ur=le("HeartOff",[["line",{x1:"2",y1:"2",x2:"22",y2:"22",key:"1w4vcy"}],["path",{d:"M16.5 16.5 12 21l-7-7c-1.5-1.45-3-3.2-3-5.5a5.5 5.5 0 0 1 2.14-4.35",key:"3mpagl"}],["path",{d:"M8.76 3.1c1.15.22 2.13.78 3.24 1.9 1.5-1.5 2.74-2 4.5-2A5.5 5.5 0 0 1 22 8.5c0 2.12-1.3 3.78-2.67 5.17",key:"1gh3v3"}]]);/** 27 * @license lucide-react v0.462.0 - ISC 28 * 29 * This source code is licensed under the ISC license. 30 * See the LICENSE file in the root directory of this source tree. 31 */const Ir=le("ListTodo",[["rect",{x:"3",y:"5",width:"6",height:"6",rx:"1",key:"1defrl"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);/** 32 * @license lucide-react v0.462.0 - ISC 33 * 34 * This source code is licensed under the ISC license. 35 * See the LICENSE file in the root directory of this source tree. 36 */const Br=le("MessageCircleQuestion",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/** 37 * @license lucide-react v0.462.0 - ISC 38 * 39 * This source code is licensed under the ISC license. 40 * See the LICENSE file in the root directory of this source tree. 41 */const Kr=le("Server",[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]]);/** 42 * @license lucide-react v0.462.0 - ISC 43 * 44 * This source code is licensed under the ISC license. 45 * See the LICENSE file in the root directory of this source tree. 46 */const Vr=le("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",ke
vendor: 5,671 bytes, lines 46-66
46y:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);/** 47 * @license lucide-react v0.462.0 - ISC 48 * 49 * This source code is licensed under the ISC license. 50 * See the LICENSE file in the root directory of this source tree. 51 */const Wr=le("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/** 52 * @license lucide-react v0.462.0 - ISC 53 * 54 * This source code is licensed under the ISC license. 55 * See the LICENSE file in the root directory of this source tree. 56 */const Je=le("StickyNote",[["path",{d:"M16 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8Z",key:"qazsjp"}],["path",{d:"M15 3v4a2 2 0 0 0 2 2h4",key:"40519r"}]]);/** 57 * @license lucide-react v0.462.0 - ISC 58 * 59 * This source code is licensed under the ISC license. 60 * See the LICENSE file in the root directory of this source tree. 61 */const Qr=le("Sunrise",[["path",{d:"M12 2v8",key:"1q4o3n"}],["path",{d:"m4.93 10.93 1.41 1.41",key:"2a7f42"}],["path",{d:"M2 18h2",key:"j10viu"}],["path",{d:"M20 18h2",key:"wocana"}],["path",{d:"m19.07 10.93-1.41 1.41",key:"15zs5n"}],["path",{d:"M22 22H2",key:"19qnx5"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}],["path",{d:"M16 18a4 4 0 0 0-8 0",key:"1lzouq"}]]);/** 62 * @license lucide-react v0.462.0 - ISC 63 * 64 * This source code is licensed under the ISC license. 65 * See the LICENSE file in the root directory of this source tree. 66 */const qs=le("UserRound",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]),Gr=t=>{const[r,a]=j.useState({openTasks:0,todayAppointments:0,unreadNotifications:0}),[n,s]=j.useState(!0);return j.useEffect(()=>{if(!t){s(!1);return}const o=async()=>{try{const d=ge(new Date,"yyyy-MM-dd"),[i,g,u]=await Promise.all([R.from("tasks").select("id",{count:"exact",head:!0}).eq("patient_id",t).eq("type","task").eq("status","open"),R.from("tasks").select("id",{count:"exact",head:!0}).eq("patient_id",t).eq("type","appointment").eq("status","open").eq("due_date",d),R.from("notifications").select("id",{count:"exact",head:!0}).eq("patient_id",t).is("read_at",null)]);a({openTasks:i.count??0,todayAppointments:g.count??0,unreadNotifications:u.count??0})}catch(d){console.error("Error fetching nav badges:",d)}finally{s(!1)}};o();const l=R.channel("nav-badges-tasks").on("postgres_changes",{event:"*",schema:"public",table:"tasks",filter:`patient_id=eq.${t}`},()=>o()).subscribe(),c=R.channel("nav-badges-notifications").on("postgres_changes",{event:"*",schema:"public",table:"notifications",filter:`patient_id=eq.${t}`},()=>o()).subscribe();return()=>{R.removeChannel(l),R.removeChannel(c)}},[t]),{badges:r,isLoading:n}};function Yr(t){return Object.prototype.toString.call(t)==="[object Object]"}function Yt(t){return Yr(t)||Array.isArray(t)}function Jr(){return!!(typeof window<"u"&&window.document&&window.document.createElement)}function Mt(t,r){const a=Object.keys(t),n=Object.keys(r);if(a.length!==n.length)return!1;const s=JSON.stringify(Object.keys(t.breakpoints||{})),o=JSON.stringify(Object.keys(r.breakpoints||{}));return s!==o?!1:a.every(l=>{const c=t[l],d=r[l];return typeof c=="function"?`${c}`==`${d}`:!Yt(c)||!Yt(d)?c===d:Mt(c,d)})}function Jt(t){return t.concat().sort((r,a)=>r.name>a.name?1:-1).map(r=>r.options)}function Xr(t,r){if(t.length!==r.length)return!1;const a=Jt(t),n=Jt(r);return a.every((s,o)=>{const l=n[o];return Mt(s,l)})}function At(t){return typeof t=="number"}function bt(t){return typeof t=="string"}function st(t){return typeof t=="boolean"}function Xt(t){return Object.prototype.toString.call(t)==="[object Object]"}function Z(t){return Math.abs(t)}function Et(t){return Math.sign(t)}function Ue(t,r){return Z(t-r)}function Zr(t,r){if(t===0||r===0||Z(t)<=Z(r))return 0;const a=Ue(Z(t),Z(r));return Z(a/t)}function ea(t){return Math.round(t*100)/100}function Be(t){return Ke(t).map(Number)}function xe(t){return t[We(t)]}function We(t){return Math.max(0,t.length-1)}function Rt(t,r){return r===We(t)}function Zt(t,r=0){return Array.from(Array(t),(a,n)=>r+n)}function Ke(t){return Object.keys(t)}function Fs(t,r){return[t,r].reduce((a,n)=>(Ke(n).forEach(s=>{const o=a[s],l=n[s],c=Xt(o)&&Xt(l);a[s]=c?Fs(o,l):l}),a),{})}function yt(t,r){return typeof r.MouseEvent<"u"&&t instanceof r.MouseEvent}function ta(t,r){const a={start:n,center:s,end:o};function n(){return 0}function s(d){return o(d)/2}function o(d){return r-d}function l(d,i){return bt(t)?a[t](d):t(r,d,i)}return{measure:l}}function Ve(){let t=[];function r(s,o,l,c={passive:!0}){let d;if("addEventListener"in s)s.addEventListener(o,l,c),d=()=>s.removeEventListener(o,l,c);else{const i=s;i.addListener(l),d=()=>i.removeListener(l)}return t.push(d),n}function a(){t=t.filter(s=>s())}const n={add:r,clear:a};return n}function sa(t,r,a,n){const s=Ve(),o=1e3/60;let l=null,c=0,d=0;function i(){s.add(t,"visibilitychange",()=>{t.hidden&&y()})}function g(){h(),s.clear()}function u(p){if(!d)return;l||(l=p,a(),a());const b=p-l;for(l=p,c+=b;c>=o;)a(),c-=o;const w=c/o;n(w),d&&(d=r.requestAnimationFrame(u))}function f(){d||(d=r.requestAnimationFrame(u))}function h(){r.cancelAnimationFrame(d),l=null,c=0,d=0}function y(){l=null,c=0}return{init:i,destroy:g,start:f,stop:h,update:a,render:n}}function ra(t,r){const a=r==="rtl",n=t==="y",s=n?"y":"x",o=n?"x":"y",l=!n&&a?-1:1,c=g(),d=u();function i(y){const{height:x,width:p}=y;return n?x:p}function g(){return n?"top":a?"right":"left"}function u(){return n?"bottom":a?"left":"right"}function f(y){return y*l}return{scroll:s,cross:o,startEdge:c,endEdge:d,measureSize:i,direction:f}}function Ee(t=0,r=0){const a=Z(t-r);function n(i){return i<t}function s(i){return i>r}function o(i){return n(i)||s(i)}function l(i){return o(i)?n(i)?t:r:i}
vendor: 14,515 bytes, line 66
66function c(i){return a?i-a*Math.ceil((i-r)/a):i}return{length:a,max:r,min:t,constrain:l,reachedAny:o,reachedMax:s,reachedMin:n,removeOffset:c}}function Os(t,r,a){const{constrain:n}=Ee(0,t),s=t+1;let o=l(r);function l(f){return a?Z((s+f)%s):n(f)}function c(){return o}function d(f){return o=l(f),u}function i(f){return g().set(c()+f)}function g(){return Os(t,c(),a)}const u={get:c,set:d,add:i,clone:g};return u}function aa(t,r,a,n,s,o,l,c,d,i,g,u,f,h,y,x,p,b,w){const{cross:T,direction:k}=t,v=["INPUT","SELECT","TEXTAREA"],P={passive:!1},A=Ve(),M=Ve(),D=Ee(50,225).constrain(h.measure(20)),L={mouse:300,touch:400},m={mouse:500,touch:600},N=y?43:25;let E=!1,q=0,z=0,S=!1,U=!1,I=!1,se=!1;function _(O){if(!w)return;function W(Y){(st(w)||w(O,Y))&&G(Y)}const X=r;A.add(X,"dragstart",Y=>Y.preventDefault(),P).add(X,"touchmove",()=>{},P).add(X,"touchend",()=>{}).add(X,"touchstart",W).add(X,"mousedown",W).add(X,"touchcancel",V).add(X,"contextmenu",V).add(X,"click",re,!0)}function C(){A.clear(),M.clear()}function $(){const O=se?a:r;M.add(O,"touchmove",B,P).add(O,"touchend",V).add(O,"mousemove",B,P).add(O,"mouseup",V)}function Q(O){const W=O.nodeName||"";return v.includes(W)}function J(){return(y?m:L)[se?"mouse":"touch"]}function ee(O,W){const X=u.add(Et(O)*-1),Y=g.byDistance(O,!y).distance;return y||Z(O)<D?Y:p&&W?Y*.5:g.byIndex(X.get(),0).distance}function G(O){const W=yt(O,n);se=W,I=y&&W&&!O.buttons&&E,E=Ue(s.get(),l.get())>=2,!(W&&O.button!==0)&&(Q(O.target)||(S=!0,o.pointerDown(O),i.useFriction(0).useDuration(0),s.set(l),$(),q=o.readPoint(O),z=o.readPoint(O,T),f.emit("pointerDown")))}function B(O){if(!yt(O,n)&&O.touches.length>=2)return V(O);const X=o.readPoint(O),Y=o.readPoint(O,T),fe=Ue(X,q),he=Ue(Y,z);if(!U&&!se&&(!O.cancelable||(U=fe>he,!U)))return V(O);const Ne=o.pointerMove(O);fe>x&&(I=!0),i.useFriction(.3).useDuration(.75),c.start(),s.add(k(Ne)),O.preventDefault()}function V(O){const X=g.byDistance(0,!1).index!==u.get(),Y=o.pointerUp(O)*J(),fe=ee(k(Y),X),he=Zr(Y,fe),Ne=N-10*he,be=b+he/50;U=!1,S=!1,M.clear(),i.useDuration(Ne).useFriction(be),d.distance(fe,!y),se=!1,f.emit("pointerUp")}function re(O){I&&(O.stopPropagation(),O.preventDefault(),I=!1)}function te(){return S}return{init:_,destroy:C,pointerDown:te}}function na(t,r){let n,s;function o(u){return u.timeStamp}function l(u,f){const y=`client${(f||t.scroll)==="x"?"X":"Y"}`;return(yt(u,r)?u:u.touches[0])[y]}function c(u){return n=u,s=u,l(u)}function d(u){const f=l(u)-l(s),h=o(u)-o(n)>170;return s=u,h&&(n=u),f}function i(u){if(!n||!s)return 0;const f=l(s)-l(n),h=o(u)-o(n),y=o(u)-o(s)>170,x=f/h;return h&&!y&&Z(x)>.1?x:0}return{pointerDown:c,pointerMove:d,pointerUp:i,readPoint:l}}function ia(){function t(a){const{offsetTop:n,offsetLeft:s,offsetWidth:o,offsetHeight:l}=a;return{top:n,right:s+o,bottom:n+l,left:s,width:o,height:l}}return{measure:t}}function oa(t){function r(n){return t*(n/100)}return{measure:r}}function la(t,r,a,n,s,o,l){const c=[t].concat(n);let d,i,g=[],u=!1;function f(p){return s.measureSize(l.measure(p))}function h(p){if(!o)return;i=f(t),g=n.map(f);function b(w){for(const T of w){if(u)return;const k=T.target===t,v=n.indexOf(T.target),P=k?i:g[v],A=f(k?t:n[v]);if(Z(A-P)>=.5){p.reInit(),r.emit("resize");break}}}d=new ResizeObserver(w=>{(st(o)||o(p,w))&&b(w)}),a.requestAnimationFrame(()=>{c.forEach(w=>d.observe(w))})}function y(){u=!0,d&&d.disconnect()}return{init:h,destroy:y}}function ca(t,r,a,n,s,o){let l=0,c=0,d=s,i=o,g=t.get(),u=0;function f(){const P=n.get()-t.get(),A=!d;let M=0;return A?(l=0,a.set(n),t.set(n),M=P):(a.set(t),l+=P/d,l*=i,g+=l,t.add(l),M=g-u),c=Et(M),u=g,v}function h(){const P=n.get()-r.get();return Z(P)<.001}function y(){return d}function x(){return c}function p(){return l}function b(){return T(s)}function w(){return k(o)}function T(P){return d=P,v}function k(P){return i=P,v}const v={direction:x,duration:y,velocity:p,seek:f,settled:h,useBaseFriction:w,useBaseDuration:b,useFriction:k,useDuration:T};return v}function da(t,r,a,n,s){const o=s.measure(10),l=s.measure(50),c=Ee(.1,.99);let d=!1;function i(){return!(d||!t.reachedAny(a.get())||!t.reachedAny(r.get()))}function g(h){if(!i())return;const y=t.reachedMin(r.get())?"min":"max",x=Z(t[y]-r.get()),p=a.get()-r.get(),b=c.constrain(x/l);a.subtract(p*b),!h&&Z(p)<o&&(a.set(t.constrain(a.get())),n.useDuration(25).useBaseFriction())}function u(h){d=!h}return{shouldConstrain:i,constrain:g,toggleActive:u}}function ua(t,r,a,n,s){const o=Ee(-r+t,0),l=u(),c=g(),d=f();function i(y,x){return Ue(y,x)<=1}function g(){const y=l[0],x=xe(l),p=l.lastIndexOf(y),b=l.indexOf(x)+1;return Ee(p,b)}function u(){return a.map((y,x)=>{const{min:p,max:b}=o,w=o.constrain(y),T=!x,k=Rt(a,x);return T?b:k||i(p,w)?p:i(b,w)?b:w}).map(y=>parseFloat(y.toFixed(3)))}function f(){if(r<=t+s)return[o.max];if(n==="keepSnaps")return l;const{min:y,max:x}=c;return l.slice(y,x)}return{snapsContained:d,scrollContainLimit:c}}function ma(t,r,a){const n=r[0],s=a?n-t:xe(r);return{limit:Ee(s,n)}}function xa(t,r,a,n){const o=r.min+.1,l=r.max+.1,{reachedMin:c,reachedMax:d}=Ee(o,l);function i(f){return f===1?d(a.get()):f===-1?c(a.get()):!1}function g(f){if(!i(f))return;const h=t*(f*-1);n.forEach(y=>y.add(h))}return{loop:g}}function fa(t){const{max:r,length:a}=t;function n(o){const l=o-r;return a?l/-a:0}return{get:n}}function ha(t,r,a,n,s){const{startEdge:o,endEdge:l}=t,{groupSlides:c}=s,d=u().map(r.measure),i=f(),g=h();function u(){return c(n).map(x=>xe(x)[l]-x[0][o]).map(Z)}function f(){return n.map(x=>a[o]-x[o]).map(x=>-Z(x))}function h(){return c(i).map(x=>x[0]).map((x,p)=>x+d[p])}return{snaps:i,snapsAligned:g}}function pa(t,r,a,n,s,o){const{groupSlides:l}=s,{min:c,max:d}=n,i=g();function g(){const f=l(o),h=!t||r==="keepSnaps";return a.length===1?[o]:h?f:f.slice(c,d).map((y,x,p)=>{const b=!x,w=Rt(p,x);if(b){const T=xe(p[0])+1;return Zt(T)}if(w){const T=We(o)-xe(p)[0]+1;return Zt(T,xe(p)[0])}return y})}return{slideRegistry:i}}function ga(t,r,a,n,s){const{reachedAny:o,removeOffset:l,constrain:c}=n;function d(y){return y.concat().sort((x,p)=>Z(x)-Z(p))[0]}function i(y){const x=t?l(y):c(y),p=r.map((w,T)=>({diff:g(w-x,0),index:T})).sort((w,T)=>Z(w.diff)-Z(T.diff)),{index:b}=p[0];return{index:b,distance:x}}function g(y,x){const p=[y,y+a,y-a];if(!t)return y;if(!x)return d(p);const b=p.filter(w=>Et(w)===x);return b.length?d(b):xe(p)-a}function u(y,x){const p=r[y]-s.get(),b=g(p,x);return{index:y,distance:b}}function f(y,x){const p=s.get()+y,{index:b,distance:w}=i(p),T=!t&&o(p);if(!x||T)return{index:b,distance:y};const k=r[b]-w,v=y+g(k,0);return{index:b,distance:v}}return{byDistance:f,byIndex:u,shortcut:g}}function ba(t,r,a,n,s,o,l){function c(u){const f=u.distance,h=u.index!==r.get();o.add(f),f&&(n.duration()?t.start():(t.update(),t.render(1),t.update())),h&&(a.set(r.get()),r.set(u.index),l.emit("select"))}function d(u,f){const h=s.byDistance(u,f);c(h)}function i(u,f){const h=r.clone().set(u),y=s.byIndex(h.get(),f);c(y)}return{distance:d,index:i}}function ya(t,r,a,n,s,o,l,c){const d={passive:!0,capture:!0};let i=0;function g(h){if(!c)return;function y(x){if(new Date().getTime()-i>10)return;l.emit("slideFocusStart"),t.scrollLeft=0;const w=a.findIndex(T=>T.includes(x));At(w)&&(s.useDuration(0),n.index(w,0),l.emit("slideFocus"))}o.add(document,"keydown",u,!1),r.forEach((x,p)=>{o.add(x,"focus",b=>{(st(c)||c(h,b))&&y(p)},d)})}function u(h){h.code==="Tab"&&(i=new Date().getTime())}return{init:g}}function $e(t){let r=t;function a(){return r}function n(d){r=l(d)}function s(d){r+=l(d)}function o(d){r-=l(d)}function l(d){return At(d)?d:d.get()}return{get:a,set:n,add:s,subtract:o}}function zs(t,r){const a=t.scroll==="x"?l:c,n=r.style;let s=null,o=!1;function l(f){return`translate3d(${f}px,0px,0px)`}function c(f){return`translate3d(0px,${f}px,0px)`}function d(f){if(o)return;const h=ea(t.direction(f));h!==s&&(n.transform=a(h),s=h)}function i(f){o=!f}function g(){o||(n.transform="",r.getAttribute("style")||r.removeAttribute("style"))}return{clear:g,to:d,toggleActive:i}}function ja(t,r,a,n,s,o,l,c,d){const g=Be(s),u=Be(s).reverse(),f=b().concat(w());function h(A,M){return A.reduce((D,L)=>D-s[L],M)}function y(A,M){return A.reduce((D,L)=>h(D,M)>0?D.concat([L]):D,[])}function x(A){return o.map((M,D)=>({start:M-n[D]+.5+A,end:M+r-.5+A}))}function p(A,M,D){const L=x(M);return A.map(m=>{const N=D?0:-a,E=D?a:0,q=D?"end":"start",z=L[m][q];return{index:m,loopPoint:z,slideLocation:$e(-1),translate:zs(t,d[m]),target:()=>c.get()>z?N:E}})}function b(){const A=l[0],M=y(u,A);return p(M,a,!1)}function w(){const A=r-l[0]-1,M=y(g,A);return p(M,-a,!0)}function T(){return f.every(({index:A})=>{const M=g.filter(D=>D!==A);return h(M,r)<=.1})}function k(){f.forEach(A=>{const{target:M,translate:D,slideLocation:L}=A,m=M();m!==L.get()&&(D.to(m),L.set(m))})}function v(){f.forEach(A=>A.translate.clear())}return{canLoop:T,clear:v,loop:k,loopPoints:f}}function va(t,r,a){let n,s=!1;function o(d){if(!a)return;function i(g){for(const u of g)if(u.type==="childList"){d.reInit(),r.emit("slidesChanged");break}}n=new MutationObserver(g=>{s||(st(a)||a(d,g))&&i(g)}),n.observe(t,{childList:!0})}function l(){n&&n.disconnect(),s=!0}return{init:o,destroy:l}}function Na(t,r,a,n){const s={};let o=null,l=null,c,d=!1;function i(){c=new IntersectionObserver(y=>{d||(y.forEach(x=>{const p=r.indexOf(x.target);s[p]=x}),o=null,l=null,a.emit("slidesInView"))},{root:t.parentElement,threshold:n}),r.forEach(y=>c.observe(y))}function g(){c&&c.disconnect(),d=!0}function u(y){return Ke(s).reduce((x,p)=>{const b=parseInt(p),{isIntersecting:w}=s[b];return(y&&w||!y&&!w)&&x.push(b),x},[])}function f(y=!0){if(y&&o)return o;if(!y&&l)return l;const x=u(y);return y&&(o=x),y||(l=x),x}return{init:i,destroy:g,get:f}}function wa(t,r,a,n,s,o){const{measureSize:l,startEdge:c,endEdge:d}=t,i=a[0]&&s,g=y(),u=x(),f=a.map(l),h=p();function y(){if(!i)return 0;const w=a[0];return Z(r[c]-w[c])}function x(){if(!i)return 0;const w=o.getComputedStyle(xe(n));return parseFloat(w.getPropertyValue(`margin-${d}`))}function p(){return a.map((w,T,k)=>{const v=!T,P=Rt(k,T);return v?f[T]+g:P?f[T]+u:k[T+1][c]-w[c]}).map(Z)}return{slideSizes:f,slideSizesWithGaps:h,startGap:g,endGap:u}}function ka(t,r,a,n,s,o,l,c,d){const{startEdge:i,endEdge:g,direction:u}=t,f=At(a);function h(b,w){return Be(b).filter(T=>T%w===0).map(T=>b.slice(T,T+w))}function y(b){return b.length?Be(b).reduce((w,T,k)=>{const v=xe(w)||0,P=v===0,A=T===We(b),M=s[i]-o[v][i],D=s[i]-o[T][g],L=!n&&P?u(l):0,m=!n&&A?u(c):0,N=Z(D-m-(M+L));return k&&N>r+d&&w.push(T),A&&w.push(b.length),w},[]).map((w,T,k)=>{const v=Math.max(k[T-1]||0);return b.slice(v,w)}):[]}function x(b){return f?h(b,a):y(b)}return{groupSlides:x}}function Sa(t,r,a,n,s,o,l){const{align:c,axis:d,direction:i,startIndex:g,loop:u,duration:f,dragFree:h,dragThreshold:y,inViewThreshold:x,slidesToScroll:p,skipSnaps:b,containScroll:w,watchResize:T,watchSlides:k,watchDrag:v,watchFocus:P}=o,A=2,M=ia(),D=M.measure(r),L=a.map(M.measure),m=ra(d,i),N=m.measureSize(D),E=oa(N),q=ta(c,N),z=!u&&!!w,S=u||!!w,{slideSizes:U,slideSizesWithGaps:I,startGap:se,endGap:_}=wa(m,D,L,a,S,s),C=ka(m,N,p,u,D,L,se,_,A),{snaps:$,snapsAligned:Q}=ha(m,q,D,L,C),J=-xe($)+xe(I),{snapsContained:ee,scrollContainLimit:G}=ua(N,J,Q,w,A),B=z?ee:Q,{limit:V}=ma(J,B,u),re=Os(We(B),g,u),te=re.clone(),K=Be(a),O=({dragHandler:Re,scrollBody:ot,scrollBounds:lt,options:{loop:Qe}})=>{Qe||lt.constrain(Re.pointerDown()),ot.seek()},W=({scrollBody:Re,translate:ot,location:lt,offsetLocation:Qe,previousLocation:Ks,scrollLooper:Vs,slideLooper:Ws,dragHandler:Qs,animation:Gs,eventHandler:Ot,scrollBounds:Ys,options:{loop:zt}},Ht)=>{const $t=Re.settled(),Js=!Ys.shouldConstrain(),Ut=zt?$t:$t&&Js,It=Ut&&!Qs.pointerDown();It&&Gs.stop();const Xs=lt.get()*Ht+Ks.get()*(1-Ht);Qe.set(Xs),zt&&(Vs.loop(Re.direction()),Ws.loop()),ot.to(Qe.get()),It&&Ot.emit("settle"),Ut||Ot.emit("scroll")},X=sa(n,s,()=>O(it),Re=>W(it,Re)),Y=.68,fe=B[re.get()],he=$e(fe),Ne=$e(fe),be=$e(fe),we=$e(fe),He=ca(he,be,Ne,we,f,Y),at=ga(u,B,J,V,we),nt=ba(X,re,te,He,at,we,l),Lt=fa(V),qt=Ve(),Is=Na(r,a,l,x),{slideRegistry:Ft}=pa(z,w,B,G,C,K),Bs=ya(t,a,Ft,nt,He,qt,l,P),it={ownerDocument:n,ownerWindow:s,eventHandler:l,containerRect:D,slideRects:L,animation:X,axis:m,dragHandler:aa(m,t,n,s,we,na(m,s),he,X,nt,He,at,re,l,E,h,y,b,Y,v),eventStore:qt,percentOfView:E,index:re,indexPrevious:te,limit:V,location:he,offsetLocation:be,previousLocation:Ne,options:o,resizeHandler:la(r,l,s,a,m,T,M),scrollBody:He,scrollBounds:da(V,be,we,He,E),scrollLooper:xa(J,V,be,[he,be,Ne,we]),scrollProgress:Lt,scrollSnapList:B.map(Lt.get),scrollSnaps:B,scrollTarget:at,scrollTo:nt,slideLooper:ja(m,N,J,U,I,$,B,be,a),slideFocus:Bs,slidesHandler:va(r,l,k),slidesInView:Is,slideIndexes:K,slideRegistry:Ft,slidesToScroll:C,target:we,translate:zs(m,r)};return it}function _a(){let t={},r;function a(i){r=i}function n(i){return t[i]||[]}function s(i){return n(i).forEach(g=>g(r,i)),d}function o(i,g){return t[i]=n(i).concat([g]),d}function l(i,g){return t[i]=n(i).filter(u=>u!==g),d}function c(){t={}}const d={init:a,emit:s,off:l,on:o,clear:c};return d}const Ca={align:"center",axis:"x",container:null,slides:null,containScroll:"trimSnaps",direction:"ltr",slidesToScroll:1,inViewThreshold:0,breakpoints:{},dragFree:!1,dragThreshold:10,loop:!1,skipSnaps:!1,duration:25,startIndex:0,active:!0,watchDrag:!0,watchResize:!0,watchSlides:!0,watchFocus:!0};function Da(t){function r(o,l){return Fs(o,l||{})}function a(o){const l=o.breakpoints||{},c=Ke(l).filter(d=>t.matchMedia(d).matches).map(d=>l[d]).reduce((d,i)=>r(d,i),{});return r(o,c)}function n(o){return o.map(l=>Ke(l.breakpoints||{})).reduce((l,c)=>l.concat(c),[]).map(t.matchMedia)}return{mergeOptions:r,optionsAtMedia:a,optionsMediaQueries:n}}function Ta(t){let r=[];function a(o,l){return r=l.filter(({options:c})=>t.optionsAtMedia(c).active!==!1),r.forEach(c=>c.init(o,t)),l.reduce((c,d)=>Object.assign(c,{[d.name]:d}),{})}function n(){r=r.filter(o=>o.destroy())}return{init:a,destroy:n}}function Xe(t,r,a){const n=t.ownerDocument,s=n.defaultView,o=Da(s),l=Ta(o),c=Ve(),d=_a(),{mergeOptions:i,optionsAtMedia:g,optionsMediaQueries:u}=o,{on:f,off:h,emit:y}=d,x=m;let p=!1,b,w=i(Ca,Xe.globalOptions),T=i(w),k=[],v,P,A;function M(){const{container:K,slides:O}=T;P=(bt(K)?t.querySelector(K):K)||t.children[0];const X=bt(O)?P.querySelectorAll(O):O;A=[].slice.call(X||P.children)}function D(K){const O=Sa(t,P,A,n,s,K,d);if(K.loop&&!O.slideLooper.canLoop()){const W=Object.assign({},K,{loop:!1});return D(W)}return O}function L(K,O){p||(w=i(w,K),T=g(w),k=O||k,M(),b=D(T),u([w,...k.map(({options:W})=>
66W)]).forEach(W=>c.add(W,"change",m)),T.active&&(b.translate.to(b.location.get()),b.animation.init(),b.slidesInView.init(),b.slideFocus.init(te),b.eventHandler.init(te),b.resizeHandler.init(te),b.slidesHandler.init(te),b.options.loop&&b.slideLooper.loop(),P.offsetParent&&A.length&&b.dragHandler.init(te),v=l.init(te,k)))}function m(K,O){const W=C();N(),L(i({startIndex:W},K),O),d.emit("reInit")}function N(){b.dragHandler.destroy(),b.eventStore.clear(),b.translate.clear(),b.slideLooper.clear(),b.resizeHandler.destroy(),b.slidesHandler.destroy(),b.slidesInView.destroy(),b.animation.destroy(),l.destroy(),c.clear()}function E(){p||(p=!0,c.clear(),N(),d.emit("destroy"),d.clear())}function q(K,O,W){!T.active||p||(b.scrollBody.useBaseFriction().useDuration(O===!0?0:T.duration),b.scrollTo.index(K,W||0))}function z(K){const O=b.index.add(1).get();q(O,K,-1)}function S(K){const O=b.index.add(-1).get();q(O,K,1)}function U(){return b.index.add(1).get()!==C()}function I(){return b.index.add(-1).get()!==C()}function se(){return b.scrollSnapList}function _(){return b.scrollProgress.get(b.offsetLocation.get())}function C(){return b.index.get()}function $(){return b.indexPrevious.get()}function Q(){return b.slidesInView.get()}function J(){return b.slidesInView.get(!1)}function ee(){return v}function G(){return b}function B(){return t}function V(){return P}function re(){return A}const te={canScrollNext:U,canScrollPrev:I,containerNode:V,internalEngine:G,destroy:E,off:h,on:f,emit:y,plugins:ee,previousScrollSnap:$,reInit:x,rootNode:B,scrollNext:z,scrollPrev:S,scrollProgress:_,scrollSnapList:se,scrollTo:q,selectedScrollSnap:C,slideNodes:re,slidesInView:Q,slidesNotInView:J};return L(r,a),setTimeout(()=>d.emit("init"),0),te}Xe.globalOptions=void 0;function Pt(t={},r=[]){const a=j.useRef(t),n=j.useRef(r),[s,o]=j.useState(),[l,c]=j.useState(),d=j.useCallback(()=>{s&&s.reInit(a.current,n.current)},[s]);return j.useEffect(()=>{Mt(a.current,t)||(a.current=t,d())},[t,d]),j.useEffect(()=>{Xr(n.current,r)||(n.current=r,d())},[r,d]),j.useEffect(()=>{if(Jr()&&l){Xe.globalOptions=Pt.globalOptions;const i=Xe(l,a.current,n.current);return o(i),()=>i.destroy()}else o(void 0)},[l,o]),[c,s]}Pt.globalOptions=void 0;const Hs=j.createContext(null);function rt(){const t=j.useContext(Hs);if(!t)throw new Error("useCarousel must be used within a <Carousel />");return t}const $s=j.forwardRef(({orientation:t="horizontal",opts:r,setApi:a,plugins:n,className:s,children:o,...l},c)=>{const[d,i]=Pt({...r,axis:t==="horizontal"?"x":"y"},n),[g,u]=j.useState(!1),[f,h]=j.useState(!1),y=j.useCallback(w=>{w&&(u(w.canScrollPrev()),h(w.canScrollNext()))},[]),x=j.useCallback(()=>{i==null||i.scrollPrev()},[i]),p=j.useCallback(()=>{i==null||i.scrollNext()},[i]),b=j.useCallback(w=>{w.key==="ArrowLeft"?(w.preventDefault(),x()):w.key==="ArrowRight"&&(w.preventDefault(),p())},[x,p]);return j.useEffect(()=>{!i||!a||a(i)},[i,a]),j.useEffect(()=>{if(i)return y(i),i.on("reInit",y),i.on("select",y),()=>{i==null||i.off("select",y)}},[i,y]),e.jsx(Hs.Provider,{value:{carouselRef:d,api:i,opts:r,orientation:t||((r==null?void 0:r.axis)==="y"?"vertical":"horizontal"),scrollPrev:x,scrollNext:p,canScrollPrev:g,canScrollNext:f},children:e.jsx("div",{ref:c,onKeyDownCapture:b,className:F("relative",s),role:"region","aria-roledescription":"carousel",...l,children:o})})});$s.displayName="Carousel";const Us=j.forwardRef(({className:t,...r},a)=>{const{carouselRef:n,orientation:s}=rt();return e.jsx("div",{ref:n,className:"overflow-hidden",children:e.jsx("div",{ref:a,className:F("flex",s==="horizontal"?"-ml-4":"-mt-4 flex-col",t),...r})})});Us.displayName="CarouselContent";const Le=j.forwardRef(({className:t,...r},a)=>{const{orientation:n}=rt();return e.jsx("div",{ref:a,role:"group","aria-roledescription":"slide",className:F("min-w-0 shrink-0 grow-0 basis-full",n==="horizontal"?"pl-4":"pt-4",t),...r})});Le.displayName="CarouselItem";const Ma=j.forwardRef(({className:t,variant:r="outline",size:a="icon",...n},s)=>{const{orientation:o,scrollPrev:l,canScrollPrev:c}=rt();return e.jsxs(H,{ref:s,variant:r,size:a,className:F("absolute h-8 w-8 rounded-full",o==="horizontal"?"-left-12 top-1/2 -translate-y-1/2":"-top-12 left-1/2 -translate-x-1/2 rotate-90",t),disabled:!c,onClick:l,...n,children:[e.jsx(rr,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Previous slide"})]})});
66Ma.displayName="CarouselPrevious";const Aa=j.forwardRef(({className:t,variant:r="outline",size:a="icon",...n},s)=>{const{orientation:o,scrollNext:l,canScrollNext:c}=rt();return e.jsxs(H,{ref:s,variant:r,size:a,className:F("absolute h-8 w-8 rounded-full",o==="horizontal"?"-right-12 top-1/2 -translate-y-1/2":"-bottom-12 left-1/2 -translate-x-1/2 rotate-90",t),disabled:!c,onClick:l,...n,children:[e.jsx(us,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Next slide"})]})});Aa.displayName="CarouselNext";const Ea=({onDiagnosisClick:t,onNavigateToDocuments:r})=>{const{language:a,t:n}=ce(),s=Oe(),{toast:o}=ve(),[l,c]=j.useState(!1),d=a==="he";j.useEffect(()=>{const h=document.documentElement.classList.contains("dark");c(h)},[]);const i=h=>{c(h),h?(document.documentElement.classList.add("dark"),localStorage.setItem("theme","dark")):(document.documentElement.classList.remove("dark"),localStorage.setItem("theme","light"))},g=async()=>{try{await R.auth.signOut(),s("/"),o({title:n("××תר××ת!","Goodbye!"),description:n("××ª× ×ª×§×ª ××צ×××","You have been signed out")})}catch(h){console.error("Logout error:",h)}},u=[{id:"profile",label:n("×¢×××× ×¤×¨×××","Update Details"),description:n("ש×, ×××, ×××ר ×××ר××","Name, age, region"),icon:vt,onClick:()=>{s("/onboarding")}},{id:"diagnosis",label:n("×¢×××× ×××× ×","Update Diagnosis"),description:n("פר×× ××××× × ×©××","Your diagnosis details"),icon:je,onClick:()=>{t==null||t()}},{id:"personalized-medicine",label:n("רפ××× ××ת××ת ××ש×ת","Personalized Medicine"),description:n("× ×ת×× ×¡×××× ×× ×ת××× ×ת ×× ×××ת","Risk analysis & genetic insights"),icon:nr,onClick:()=>{s("/personalized-medicine")}},{id:"lab-results",label:n("ת×צ××ת ××¢×××","Lab Results"),description:n("××× × ×××¢×§× ××ר ××××§×ת ××","Enter and track blood tests"),icon:ir,onClick:()=>{s("/lab-results")}},{id:"privacy",label:n("×××ר×ת פר×××ת","Privacy Settings"),description:n("× ×××× ×ס×××ת ×××××¢ ××ש×","Manage consents and personal data"),icon:Zs,onClick:()=>{s("/privacy-settings")}},{id:"marketplace",label:n("×× ×ת Wellness ðï¸","Wellness Shop ðï¸"),description:n("××צר×× × ××ר×× ×תק×פת ×××פ××××","Curated products for treatment support"),icon:or,onClick:()=>{s("/marketplace")}}],f=d?ms:xs;return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"px-6 py-4 border-b",children:[e.jsx("h2",{className:"text-xl font-semibold",children:n("×¢××","More")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("×××ר×ת ×פע×××ת × ×ספ×ת","Settings and more actions")})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-6 py-4 space-y-2",children:[u.map(h=>{const y=h.icon;return e.jsxs("button",{onClick:h.onClick,className:"w-full flex items-center gap-4 p-4 rounded-2xl bg-muted/50 hover:bg-muted border border-transparent hover:border-border/50 transition-all duration-200 active:scale-[0.98] text-start",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(y,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-foreground",children:h.label}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:h.description})]}),e.jsx(f,{className:"h-5 w-5 text-muted-foreground"})]},h.id)}),e.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-2xl bg-muted/50",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(ut,{className:"h-5 w-5 text-primary"})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"font-medium text-foreground",children:n("××¦× ×××","Dark Mode")})}),e.jsx(ar,{checked:l,onCheckedChange:i})]}),e.jsxs("button",{onClick:g,className:"w-full flex items-center gap-4 p-4 rounded-2xl bg-destructive/10 hover:bg-destructive/20 border border-transparent hover:border-destructive/30 transition-all duration-200 active:scale-[0.98] text-start",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-destructive/20 flex items-center justify-center shrink-0",children:e.jsx(lr,{className:"h-5 w-5 text-destructive"})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"font-medium text-destructive",children:n("××ª× ×ª×§×ת","Sign Out")})})]})]}),e.jsx("div",{className:"px-6 py-3 border-t",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:n("××ער×ת ×× ×××©× ××××¢ ××ת×× ××ש×ת ×××× × ×××××¤× ×¨××¤× ×× ×××¢××¥ רפ×××","The system provides personalized information and does not replace a doctor or medical advice")})})]})},Ra=({open:t,onOpenChange:r,onAction:a})=>{const{t:n}=ce(),s=[{id:"recording",label:n("××¢××ת ××§×××","Upload Recording"),description:n("××¢×× ××§××× ×פ×××©× ×¢× ×¨×פ×","Upload a re
66cording from a doctor visit"),icon:Se,gradientClass:"bg-gradient-purple"},{id:"appointment",label:n("××ספת ת×ר","Add Appointment"),description:n("ת××× × ×ª×ר ××ש ×××××","Schedule a new appointment"),icon:ze,gradientClass:"bg-gradient-blue"},{id:"task",label:n("××ספת ×ש×××","Add Task"),description:n("×¦×¨× ×ש××× ×××©× ×××צ××¢","Create a new task"),icon:me,gradientClass:"bg-gradient-green"},{id:"document",label:n("××¢××ת ×ס××","Upload Document"),description:n("××¢×× ×ס×× ×¨×¤××× ××ש","Upload a new medical document"),icon:Ce,gradientClass:"bg-gradient-orange"},{id:"diagnosis",label:n("×¢×××× ×××× ×","Update Diagnosis"),description:n("×¢××× × ×ת פר×× ××××× × ×©××","Update your diagnosis details"),icon:je,gradientClass:"bg-gradient-brand"}],o=l=>{a(l),r(!1)};return e.jsx(fs,{open:t,onOpenChange:r,children:e.jsxs(hs,{side:"bottom",className:"rounded-t-3xl max-h-[85vh] px-6 pb-10",children:[e.jsx(ps,{className:"pb-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(gs,{className:"text-xl font-semibold",children:n("פע××× ×××ר×","Quick Action")}),e.jsx(H,{variant:"ghost",size:"icon",className:"rounded-full",onClick:()=>r(!1),"aria-label":n("ס××ר","Close"),children:e.jsx(jt,{className:"h-5 w-5"})})]})}),e.jsx("div",{className:"space-y-3 pt-2",children:s.map(l=>{const c=l.icon;return e.jsxs("button",{onClick:()=>o(l.id),className:"w-full flex items-center gap-4 p-4 rounded-2xl bg-muted/50 hover:bg-muted border border-transparent hover:border-border/50 transition-all duration-200 active:scale-[0.98] text-start",children:[e.jsx("div",{className:`w-12 h-12 rounded-xl ${l.gradientClass} flex items-center justify-center shrink-0`,children:e.jsx(c,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-foreground",children:l.label}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:l.description})]})]},l.id)})}),e.jsx("div",{className:"absolute top-3 left-1/2 -translate-x-1/2 w-10 h-1 bg-muted-foreground/30 rounded-full"})]})})},Pa={breast:["breast","ש×"],lung:["lung","ר×××"],colorectal:["colon","×§××××","××¢×"],prostate:["prostate","ער××× ×ת"],pancreatic:["pancreatic","××××"],ovarian:["ovarian","ש×××ת"],lymphoma:["blood","×××פ×××","××"],leukemia:["blood","×××§×××","××"],melanoma:["skin","××× ×××","×¢×ר"],brain:["brain","×××"],stomach:["stomach","×§×××"],liver:["liver","×××"],kidney:["kidney","××××"],bladder:["bladder","ש×פ×××ת"],thyroid:["thyroid","תר×ס"]},La=t=>{if(!t)return null;const r=t.toLowerCase(),a={"סר×× ×©×":"breast","סר×× ×¨×××":"lung","סר×× ×××¢× ××ס":"colorectal","סר×× ×¢×¨××× ×ת":"prostate","סר×× ××××":"pancreatic","סר×× ×©×××ת":"ovarian",×××פ×××:"lymphoma",×××§×××:"leukemia",××× ×××:"melanoma","סר×× ×××":"brain","סר×× ×§×××":"stomach","סר×× ×××":"liver","סר×× ××××":"kidney","סר×× ×©×פ×××ת":"bladder","סר×× ××××ת ×תר×ס":"thyroid"};for(const[s,o]of Object.entries(a))if(t.includes(s))return o;const n={"breast cancer":"breast","lung cancer":"lung","colorectal cancer":"colorectal","prostate cancer":"prostate","pancreatic cancer":"pancreatic","ovarian cancer":"ovarian",lymphoma:"lymphoma",leukemia:"leukemia",melanoma:"melanoma","brain cancer":"brain","stomach cancer":"stomach","liver cancer":"liver","kidney cancer":"kidney","bladder cancer":"bladder","thyroid cancer":"thyroid"};for(const[s,o]of Object.entries(n))if(r.includes(s))return o;return null},es=(t,r)=>{if(!t||!r)return!1;const a=Pa[r];if(!a)return!1;const n=t.toLowerCase();return a.some(s=>n.includes(s.toLowerCase()))},qa=({patientId:t,patientRegion:r,diagnosisText:a,language:n})=>{const{toast:s}=ve(),[o,l]=j.useState([]),[c,d]=j.useState(new Set),[i,g]=j.useState(!0),[u,f]=j.useState(null),[h,y]=j.useState(!1),[x,p]=j.useState(!1),b=n==="he",w=La(a),T={title:b?"ר×פ××× ××××צ×× ×¢××ר×":"Doctors Recommended For You",myDoctors:b?"×ר×פ××× ×©××":"My Doctors",save:b?"ש××ר×":"Save",remove:b?"×סר×":"Remove",saved:b?"× ×©×ר":"Saved",experience:b?"×©× ×ת × ×ס×××":"years experience",noResults:b?"×× × ×צ×× ×¨×פ××× ×ת××××× ××××× × ×©××. ×××× ×©××× ×ª ×ת ס×× ×סר×× ×פר×× ××××× ×.":"No matching doctors found for your diagnosis. Make sure you've entered your cancer type in the diagnosis details.",noDiagnosis:b?"××× ×ר××ת ר×פ××× ××××צ××, ×ש ××××× ×§××× ×ת פר×× ××××× × ×©××.":"To see recommended doctors, please enter your diagnosis details first.",noSaved:b?"×¢×××× ×× ×©×רת ר×פ×××. ×××¦× ×¢× ×פת×ר ×ש×××¨× ××× ×ר××¤× ×©×ת××× ××.":"You haven't saved any doctors yet. Click save next to a doctor that suits you.",whyFit:b?"××× ×ת××× ××":"Why they fit you",perfectMatch:b?"×ת××× ××××":"Perfect Match",specializes:b?"×ת××× ×":"Specializes in",inYourArea:b?"××××ר ש××":"In your area",showAll:b?"××¦× ×ת ××××":"Show All",showRelevant:b?"××¦× ×ת×××××":"Show Relevant"};j.useEffect(()=>{(async()=>{g(!0);try{const{data:D,error:L}=await R.from("doctors").select("*").order("experience_years",{ascending:!1});if(L)throw L;if(l(D||[]),t){const{data:m,error:N}=await R.from("saved_doctors").select("doctor_id").eq("patient_id",t);if(N)throw N;d(new Set((m==null?void 0:m.map(E=>
66E.doctor_id))||[]))}}catch(D){console.error("Error fetching doctors:",D)}finally{g(!1)}})()},[t]);const k=j.useMemo(()=>x?o.map(L=>{const m=es(L.cancer_focus,w),N=r?L.region===r:!1;let E=0;return m&&(E+=10),N&&(E+=5),E+=Math.min(L.experience_years/5,5),{...L,score:E,matchesFocus:m,matchesRegion:N}}).sort((L,m)=>m.score-L.score):!w&&!r?[]:o.map(L=>{const m=es(L.cancer_focus,w),N=r?L.region===r:!1;let E=0;return m&&(E+=10),N&&(E+=5),E+=Math.min(L.experience_years/5,5),{...L,score:E,matchesFocus:m,matchesRegion:N}}).filter(L=>w?L.matchesFocus:L.matchesRegion).sort((L,m)=>m.score-L.score).slice(0,8),[o,r,w,x]),v=j.useMemo(()=>o.filter(M=>c.has(M.id)),[o,c]),P=async M=>{if(!t){s({title:b?"ש××××":"Error",description:b?"×ש ××צ×ר ת××§ ××××¤× ×§×××":"Please create a patient file first",variant:"destructive"});return}f(M);const D=c.has(M);try{if(D){const{error:L}=await R.from("saved_doctors").delete().eq("patient_id",t).eq("doctor_id",M);if(L)throw L;d(m=>{const N=new Set(m);return N.delete(M),N})}else{const{error:L}=await R.from("saved_doctors").insert({patient_id:t,doctor_id:M});if(L)throw L;d(m=>new Set([...m,M]))}}catch(L){console.error("Error toggling save:",L),s({title:b?"ש××××":"Error",description:L.message,variant:"destructive"})}finally{f(null)}},A=({doctor:M,compact:D=!1})=>{const L=c.has(M.id),m=M.matchesFocus&&M.matchesRegion;return e.jsxs("div",{className:` 67 group relative flex items-center gap-3 p-3 rounded-xl transition-all duration-200 68 ${m?"bg-primary/5 border border-primary/20":"bg-muted/30 border border-transparent hover:border-border/50"} 69 `,children:[e.jsxs("div",{className:` 70 relative shrink-0 w-10 h-10 rounded-xl flex items-center justify-center 71 ${m?"bg-gradient-brand shadow-sm":"bg-primary/10"} 72 `,children:[e.jsx(qs,{className:`h-5 w-5 ${m?"text-white":"text-primary"}`}),m&&e.jsx("div",{className:"absolute -top-1 -end-1 w-4 h-4 bg-accent rounded-full flex items-center justify-center border-2 border-background",children:e.jsx(Te,{className:"h-2 w-2 text-accent-foreground"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("h4",{className:"font-semibold text-sm text-foreground truncate",children:M.full_name})}),e.jsx("p",{className:"text-xs text-primary/80 font-medium",children:M.specialty}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"truncate",children:M.hospital}),e.jsx("span",{children:"â¢"}),e.jsx("span",{children:M.region})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1.5 shrink-0",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground font-medium",children:[M.experience_years," ",b?"×©× ××":"yrs"]}),e.jsx(H,{variant:L?"secondary":"default",size:"sm",onClick:()=>P(M.id),disabled:u===M.id,className:` 73 h-7 px-3 text-xs font-medium rounded-lg 74 ${L?"bg-muted text-muted-foreground":"bg-gradient-brand text-white shadow-sm"} 75 `,children:L?e.jsx(Ur,{className:"h-3 w-3"}):e.jsx(Ie,{className:"h-3 w-3"})})]})]})};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:T.title}),e.jsxs(Nt,{open:h,onOpenChange:y,children:[e.jsx(cr,{asChild:!0,children:e.jsxs(H,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs gap-1.5 text-muted-foreground",children:[e.jsx(dr,{className:"h-3.5 w-3.5"}),T.myDoctors,v.length>0&&e.jsx(ue,{variant:"secondary",className:"h-4 min-w-4 px-1 text-[10px]",children:v.length})]})}),e.jsxs(wt,{className:"max-w-sm",children:[e.jsx(kt,{children:e.jsxs(St,{className:"flex items-center gap-2 text-base",children:[e.jsx(Ie,{className:"h-4 w-4 text-primary"}),T.myDoctors]})}),e.jsx(De,{className:"max-h-[50vh]",children:v.length===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-6",children:T.noSaved}):e.jsx("div",{className:"space-y-2 pr-2",children:v.map(M=>e.jsx(A,{doctor:M,compact:!0},M.id))})})]})]})]}),i?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx("div",{className:"h-5 w-5 border-2 border-primary border-t-transparent roun
75ded-full animate-spin"})}):k.length===0&&!x?e.jsxs("div",{className:"text-center py-6 px-4",children:[e.jsx(ur,{className:"h-8 w-8 text-muted-foreground/40 mx-auto mb-2"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:w?T.noResults:T.noDiagnosis}),e.jsx(H,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>p(!0),children:T.showAll})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-2",children:k.slice(0,3).map(M=>e.jsx(A,{doctor:M},M.id))}),e.jsx(H,{variant:"ghost",size:"sm",onClick:()=>p(!x),className:"w-full h-8 text-xs text-muted-foreground hover:text-foreground",children:x?T.showRelevant:T.showAll})]})]})},Fa=({patientId:t,language:r,onRecordingComplete:a})=>{const{toast:n}=ve(),[s,o]=j.useState(!1),[l,c]=j.useState(!1),[d,i]=j.useState(0),g=j.useRef(null),u=j.useRef([]),f=j.useRef(null),h=r==="he",y=60*60,x=j.useMemo(()=>({startRecording:h?"×ת×× ××§×××":"Start Recording",stopRecording:h?"עצ×ר":"Stop",recording:h?"××§×××...":"Recording...",processing:h?"××¢×× ×ת ×××§×××...":"Processing recording...",success:h?"×××§××× × ×©××¨× ×××¢×××ת":"Recording saved and processing",error:h?"ש×××× ×××§×××":"Recording error",noMic:h?"××× ×××©× ×××קר×פ××":"No microphone access",liveMeeting:h?"פ×××©× ×¨×¤×××ת":"Medical Meeting",tapToRecord:h?"××§×××× ×ת ×פ×××©× ×¢× ×ר×פ×":"Record your doctor visit",maxDuration:h?"×××§××× ×××¤×¡×§× (×קס×××× 60 ××§×ת)":"Recording stopped (60 min max)"}),[h]);j.useEffect(()=>()=>{f.current&&clearInterval(f.current)},[]),j.useEffect(()=>{d>=y&&s&&(w(),n({title:x.maxDuration}))},[d,s]);const p=k=>{const v=Math.floor(k/60),P=k%60;return`${v.toString().padStart(2,"0")}:${P.toString().padStart(2,"0")}`},b=async()=>{try{const k=await navigator.mediaDevices.getUserMedia({audio:!0}),v=MediaRecorder.isTypeSupported("audio/webm;codecs=opus")?"audio/webm;codecs=opus":MediaRecorder.isTypeSupported("audio/mp4")?"audio/mp4":"",P=new MediaRecorder(k,v?{mimeType:v}:void 0);g.current=P,u.current=[],P.ondataavailable=A=>{A.data.size>0&&u.current.push(A.data)},P.onstop=async()=>{const A=v||"audio/webm",M=new Blob(u.current,{type:A});k.getTracks().forEach(D=>D.stop()),f.current&&clearInterval(f.current),await T(M)},P.start(1e3),o(!0),i(0),f.current=setInterval(()=>{i(A=>A+1)},1e3)}catch(k){console.error("Microphone access error:",k),n({title:x.noMic,variant:"destructive"})}},w=()=>{g.current&&s&&(g.current.stop(),o(!1))},T=async k=>{if(t){c(!0);try{const{data:{session:v}}=await R.auth.getSession();if(!(v!=null&&v.user))throw new Error("Not authenticated");const P=v.user.id,A=new Date().toISOString().replace(/[:.]/g,"-"),M=k.type.includes("mp4")?"mp4":"webm",D=`meeting_${A}.${M}`,L=`${P}/${D}`,{error:m}=await R.storage.from("recordings").upload(L,k);if(m)throw m;const{data:N,error:E}=await R.from("recordings").insert({patient_id:t,file_name:D,file_path:L,status:"pending",duration_seconds:d}).select("id").single();if(E)throw E;await R.functions.invoke("process-recording",{body:{recording_id:N.id}}),n({title:x.success}),a==null||a()}catch(v){console.error("Upload error:",v),n({title:x.error,description:v instanceof Error?v.message:"Unknown error",variant:"destructive"})}finally{c(!1),i(0)}}};return e.jsx(Ze,{className:F("border-2 transition-all duration-300 overflow-hidden",s?"border-red-500/50 bg-gradient-to-br from-red-50/50 to-orange-50/50 dark:from-red-950/20 dark:to-orange-950/20":"border-primary/20 bg-gradient-to-br from-primary/5 to-purple-500/5"),children:e.jsx(et,{className:"p-4",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:F("relative w-12 h-12 sm:w-14 sm:h-14 rounded-xl flex items-center justify-center shrink-0 transition-all",s?"bg-red-500 animate-pulse":l?"bg-muted":"bg-gradient-purple"),children:l?e.jsx(de,{className:"h-5 w-5 sm:h-6 sm:w-6 text-muted-foreground animate-spin"}):s?e.jsxs(e.Fragment,{children:[e.jsx(mr,{className:"h-5 w-5 sm:h-6 sm:w-6 text-white"}),e.jsx("span",{className:"absolute -top-1 -end-1 w-3 h-3 bg-red-500 rounded-full animate-ping"}),e.jsx("span",{className:"absolute -top-1 -end-1 w-3 h-3 bg-red-600 rounded-full"})]}):e.jsx(Se,{className:"h-5 w-5 sm:h-6 sm:w-6 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"font-semibold text-foreground text-sm sm:text-base",children:x.liveMeeting}),s&&e.jsxs(ue,{variant:"destructive",className:"animate-pulse gap-1 text-xs",children:[e.jsx("span",{className:"w-1.5 h-1.5 bg-white rounded-full"}),h?"××§×××":"REC"]})]}),s?e.jsxs("div",{className:"flex items-center gap-2 text-red-600 dark:text-red-400 mt-0.5",children:[e.jsx(ie,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"font-mono text-base sm:text-lg font-medium",children:p(d)})]}):l?e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-0.5",children:x.processing}):e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-0.5",children:x.tapToRecord})]})]}),!l&&e.jsx(H,{size:"lg",variant:s?"destructive":"default",className:F("w-full rounded-xl h-11 sm:h-12 gap-2 transition-all text-sm sm:text-base",!s&&"bg-gradient-brand hover:opacity-90"),onClick:s?w:b,disabled:!t,children:s?e.jsxs(e.Fragment,{children:[e.jsx(Wr,{className:"h-4 w-4 fill-current"}),x.stopRecording]}):e.jsxs(e.Fragment,{children:[e.jsx(Se,{className:"h-4 w-4"}),x.startRecording]})})]})})})},Oa=({patientId:t,language:r})=>{const{toast:a}=ve(),n=tt(),s=j.useRef(null),[o,l]=j.useState(!1),[c,d]=j.useState(null),[i,g]=j.useState(!1),[u,f]=j.useState(!1),[h,y]=j.useState(!1),x=r==="he",p=j.useMemo(()=>({title:x?"ס××××× ×¤××ש×ת":"Meeting Summaries",upload:x?"××¢××ת ××§×××":"Upload Recording",uploading:x?"××¢××...":"Uploading...",processing:x?"××¢××...":"Processing...",completed:x?"××ש××":"Completed",pending:x?"××ת××":"Pending",openSummary:x?"×¤×ª× ×¡××××":"Open Summary",emptyState:x?"××× ×¢×××× ××§×××ת. ××¢×× ××§××× ××× ××§×× ×¡×××× ×××××××.":"No recordings yet. Upload a re
75cording to get an automatic summary.",summaryTitle:x?"ס×××× ×¤××ש×":"Meeting Summary",actionItems:x?"×ש×××ת ×××צ××¢":"Action Items",keyTerms:x?"××× ××× ×ר×××××":"Key Terms",uploadSuccess:x?"×××§××× ×××¢××ª× ××צ××× ×××¢×××ת":"Recording uploaded successfully and being processed",uploadError:x?"ש×××× ×××¢××ת ××§×××":"Error uploading recording",processingError:x?"ש×××× ××¢×××× ×××§×××":"Error processing recording",fileTypes:x?"×§××¦× ×©××¢ × ×ª××××: MP3, WAV, M4A, WebM":"Supported audio files: MP3, WAV, M4A, WebM",tabSummary:x?"ס××××":"Summary",tabTranscript:x?"ת×××× ×××":"Full Transcript",noTranscript:x?"××× ×ª×××× ××××":"No transcript available",shareWithDoctor:x?"שתף ×¢× ×ר×פ×":"Share with Doctor",sharing:x?"ש×××...":"Sharing...",shareSuccess:x?"×ס×××× × ×©×× ×ר××¤× ××צ×××":"Summary shared with doctor successfully",shareError:x?"ש×××× ×ש×××ת ×ס××××":"Error sharing summary",noDoctor:x?"×× × ××¦× ×¨××¤× ×ש×××. ×©×ª×¤× ×××©× ×¢× ×¨××¤× ×ª××××.":"No linked doctor found. Share access with a doctor first.",shared:x?"× ×©×× â":"Sent â"}),[x]),{data:b=[],isLoading:w}=ne({queryKey:["recordings",t],queryFn:async()=>{if(!t)return[];const{data:m,error:N}=await R.from("recordings").select("id, file_name, status, uploaded_at, duration_seconds").eq("patient_id",t).order("uploaded_at",{ascending:!1});if(N)throw N;return m},enabled:!!t,refetchInterval:5e3}),T=_e({mutationFn:async m=>{if(!t)throw new Error("No patient ID");const{data:{session:N}}=await R.auth.getSession();if(!(N!=null&&N.user))throw new Error("Not authenticated");const E=N.user.id,q=`${Date.now()}_${m.name}`,z=`${E}/${q}`,{error:S}=await R.storage.from("recordings").upload(z,m);if(S)throw S;const{data:U,error:I}=await R.from("recordings").insert({patient_id:t,file_name:m.name,file_path:z,status:"pending"}).select("id").single();if(I)throw I;const{error:se}=await R.functions.invoke("process-recording",{body:{recording_id:U.id}});return se&&console.error("Processing error:",se),U},onSuccess:()=>{n.invalidateQueries({queryKey:["recordings",t]}),a({title:p.uploadSuccess})},onError:m=>{console.error("Upload error:",m),a({title:p.uploadError,description:m.message,variant:"destructive"})}}),k=async m=>{var q;const N=(q=m.target.files)==null?void 0:q[0];if(!N)return;if(!["audio/mpeg","audio/wav","audio/m4a","audio/webm","audio/mp3"].includes(N.type)&&!N.name.match(/\.(mp3|wav|m4a|webm)$/i)){a({title:x?"ס×× ×§×××¥ ×× × ×ª××":"Unsupported file type",description:p.fileTypes,variant:"destructive"});return}l(!0);try{await T.mutateAsync(N)}finally{l(!1),s.current&&(s.current.value="")}},v=async m=>{var z;const[N,E]=await Promise.all([R.from("summaries").select("*").eq("recording_id",m).single(),R.from("transcripts").select("transcript_text").eq("recording_id",m).single()]);if(N.error)throw N.error;const q=N.data;return{id:q.id,summary_text:q.summary_text,key_terms:q.key_terms,action_items:q.action_items,created_at:q.created_at,transcript_text:((z=E.data)==null?void 0:z.transcript_text)||void 0}},P=async m=>{try{const N=await v(m);d(N),y(!1),g(!0)}catch(N){console.error("Error fetching summary:",N),a({title:x?"ש×××× ×××¢×× ×ª ×ס××××":"Error loading summary",variant:"destructive"})}},A=async()=>{var m,N;if(!(!c||!t)){f(!0),y(!1);try{const{data:{session:E}}=await R.auth.getSession();if(!(E!=null&&E.user))throw new Error("Not authenticated");const{data:q,error:z}=await R.from("patient_shares").select("shared_with_user_id").eq("patient_id",t).eq("status","accepted").in("role",["physician","doctor"]);if(z)throw z;const S=(q||[]).map(_=>_.shared_with_user_id).filter(Boolean);if(S.length===0){a({title:p.noDoctor,variant:"destructive"});return}let U=`ð ${p.summaryTitle} 76 77${c.summary_text}`;(m=c.action_items)!=null&&m.length&&(U+=` 78 79${p.actionItems}: 80`+c.action_items.map((_,C)=>`${C+1}. ${_.task}${_.due?` (${_.due})`:""}`).join(` 81`)),(N=c.key_terms)!=null&&N.length&&(U+=` 82 83${p.keyTerms}: ${c.key_terms.join(", ")}`);const I=S.map(_=>({physician_id:_,patient_id:t,content:U})),{error:se}=await R.from("physician_messages").insert(I);if(se)throw se;y(!0),a({title:p.shareSuccess})}catch(E){console.error("Share error:",E),a({title:p.shareError,variant:"destructive"})}finally{f(!1)}}},M=m=>{switch(m){case"completed":return e.jsx(qe,{className:"h-3 w-3 text-primary"});case"processing":return e.jsx(de,{className:"h-3 w-3 text-accent-foreground animate-spin"});case"error":return e.jsx(_t,{className:"h-3 w-3 text-destructive"});default:return e.jsx(ie,{className:"h-3 w-3 text-muted-foreground"})}},D=m=>{switch(m){case"completed":return p.completed;case"processing":return p.processing;default:return p.pending}},L=m=>new Date(m).toLocaleDateString(x?"he-IL":"en-US",{day:"numeric",month:"short",year:"numeric"});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(Se,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:p.title}),b.length>0&&e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[b.length," ",x?"××§×××ת":"recordings"]})]})]}
83),e.jsx("input",{ref:s,type:"file",accept:"audio/*,.mp3,.wav,.m4a,.webm",onChange:k,className:"hidden"}),e.jsxs(H,{variant:"outline",size:"sm",onClick:()=>{var m;return(m=s.current)==null?void 0:m.click()},disabled:o||!t,className:"h-8 gap-1.5 text-xs rounded-lg",children:[o?e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(mt,{className:"h-3.5 w-3.5"}),x?"××¢×××":"Upload"]})]}),w?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(de,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):b.length===0?e.jsxs("div",{className:"text-center py-8 px-4 rounded-xl bg-muted/30 border border-dashed border-border/50",children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-3 rounded-full bg-muted flex items-center justify-center",children:e.jsx(Gt,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:p.emptyState}),e.jsx("p",{className:"text-[10px] text-muted-foreground/60",children:p.fileTypes})]}):e.jsx("div",{className:"space-y-2",children:b.map(m=>e.jsxs("div",{className:"group relative flex items-center gap-3 p-3 rounded-xl bg-muted/30 border border-transparent hover:border-primary/20 hover:bg-muted/50 transition-all",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-primary/20 to-accent/20 flex items-center justify-center shrink-0",children:e.jsx(Gt,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate text-foreground",children:m.file_name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground flex items-center gap-1",children:[e.jsx(ze,{className:"h-3 w-3"}),L(m.uploaded_at)]}),e.jsxs("span",{className:"text-[10px] flex items-center gap-1",children:[M(m.status),e.jsx("span",{className:m.status==="completed"?"text-primary":"text-muted-foreground",children:D(m.status)})]})]})]}),m.status==="completed"&&e.jsx(H,{variant:"default",size:"sm",onClick:()=>P(m.id),className:"shrink-0 h-8 px-3 text-xs rounded-lg bg-gradient-brand text-white shadow-sm",children:p.openSummary}),m.status==="processing"&&e.jsxs("div",{className:"shrink-0 px-3 py-1.5 rounded-lg bg-accent/50 text-accent-foreground text-xs font-medium flex items-center gap-1.5",children:[e.jsx(de,{className:"h-3 w-3 animate-spin"}),p.processing]})]},m.id))})]}),e.jsx(Nt,{open:i,onOpenChange:g,children:e.jsxs(wt,{className:"max-w-2xl max-h-[80vh]",children:[e.jsx(kt,{children:e.jsxs(St,{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-5 w-5"}),p.summaryTitle]})}),e.jsxs(xr,{defaultValue:"summary",className:"w-full",children:[e.jsxs(fr,{className:"w-full mb-4",children:[e.jsxs(Kt,{value:"summary",className:"flex-1 gap-1.5",children:[e.jsx(Se,{className:"h-3.5 w-3.5"}),p.tabSummary]}),e.jsxs(Kt,{value:"transcript",className:"flex-1 gap-1.5",children:[e.jsx(Ce,{className:"h-3.5 w-3.5"}),p.tabTranscript]})]}),e.jsx(Vt,{value:"summary",children:e.jsx(De,{className:"max-h-[55vh] pr-4",children:c&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"prose prose-sm max-w-none dark:prose-invert",children:e.jsx("div",{className:"whitespace-pre-wrap text-sm leading-relaxed",children:c.summary_text})}),c.action_items&&c.action_items.length>0&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[e.jsx(qe,{className:"h-4 w-4 text-primary"}),p.actionItems]}),e.jsx("ul",{className:"space-y-2",children:c.action_items.map((m,N)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm p-2 rounded-lg bg-muted/50",children:[e.jsx("span",{className:"w-5 h-5 rounded-full bg-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:N+1}),e.jsxs("div",{children:[e.jsx("span",{children:m.task}),m.due&&e.jsxs("span",{className:"text-xs text-muted-foreground ms-2",children:["(",m.due,")"]})]})]},N))})]}),c.key_terms&&c.key_terms.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-2",children:p.keyTerms}),e.jsx("div",{className:"flex flex-wrap gap-2",children:c.key_terms.map((m,
83N)=>e.jsx("span",{className:"px-2 py-1 text-xs rounded-full bg-primary/10 text-primary",children:m},N))})]})]})})}),e.jsx(Vt,{value:"transcript",children:e.jsx(De,{className:"max-h-[55vh] pr-4",children:c!=null&&c.transcript_text?e.jsx("div",{className:"prose prose-sm max-w-none dark:prose-invert",children:e.jsx("div",{className:"whitespace-pre-wrap text-sm leading-relaxed",dir:"auto",children:c.transcript_text})}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground text-sm",children:[e.jsx(Ce,{className:"h-8 w-8 mx-auto mb-2 opacity-40"}),p.noTranscript]})})})]}),c&&e.jsx("div",{className:"mt-4 pt-4 border-t border-border",children:e.jsxs(H,{onClick:A,disabled:u||h,variant:h?"secondary":"default",className:"w-full gap-2",children:[u?e.jsx(de,{className:"h-4 w-4 animate-spin"}):h?e.jsx(qe,{className:"h-4 w-4"}):e.jsx(hr,{className:"h-4 w-4"}),u?p.sharing:h?p.shared:p.shareWithDoctor]})})]})})]})},za=({patientId:t,persona:r="patient"})=>{const{t:a}=ce(),{toast:n}=ve(),s=tt(),[o,l]=j.useState(!1),[c,d]=j.useState(!1),[i,g]=j.useState(null),[u,f]=j.useState(new Set),[h,y]=j.useState({}),x=j.useMemo(()=>({title:a("××ס×××× ×©××","My Documents"),subtitle:a("×ס×××× ×¨×¤××××× ×ת×צ××ת ××××§×ת","Medical documents and test results"),empty:a("××× ×ס×××× ×¢××××","No documents yet"),emptyDesc:a("××¢×× ×ס×××× ×¨×¤×××××, ת×צ××ת ××××§×ת ××¢××","Upload medical documents, test results and more"),upload:a("××¢××ת ×ס××","Upload Document"),uploading:a("××¢××...","Uploading..."),download:a("××ר××","Download"),open:a("פת×××","Open"),analyze:a("× ×ª× ×ס××","Analyze Document"),analyzing:a("×× ×ª×...","Analyzing..."),analyzed:a("× ×ת×","Analyzed"),showSummary:a("××¦× ×¡××××","Show Summary"),hideSummary:a("×סתר ס××××","Hide Summary"),keyPoints:a("× ×§×××ת ×פת×","Key Points"),questionsForDoctor:a("ש×××ת ×ר×פ×","Questions for Doctor"),redFlags:a("××××× ××××××","Red Flags"),nextSteps:a("צע××× ×××××","Next Steps"),whenToCall:a("××ª× ××¤× ×ת ×ר×פ×","When to Call Doctor"),deleteAnalysis:a("×××§ × ×ת××","Delete Analysis"),deleteAnalysisConfirm:a("××× ×××××§ ×ת ×× ×ת××?","Delete this analysis?"),deleteAnalysisDesc:a("×× ×ת×× ×××××§ ×צ××ת×ת. × ××ª× ×× ×ª× ×©×× ××××ר ××תר.","The analysis will be permanently deleted. You can re-analyze later."),cancel:a("×××××","Cancel"),delete:a("×××§","Delete")}),[a]),{data:p=[],isLoading:b}=ne({queryKey:["documents-content",t],queryFn:async()=>{if(!t)return[];const{data:_,error:C}=await R.from("documents").select("id, file_name, storage_path, doc_type, created_at").eq("patient_id",t).order("created_at",{ascending:!1});if(C)throw C;return _},enabled:!!t}),{data:w=[]}=ne({queryKey:["document-summaries",t],queryFn:async()=>{if(!t)return[];const _=p.map(Q=>Q.id);if(_.length===0)return[];const{data:C,error:$}=await R.from("document_summaries").select("id, document_id, summary_text, key_points, created_at").in("document_id",_);if($)throw $;return C},enabled:!!t&&p.length>0}),T=new Map(w.map(_=>[_.document_id,_])),k=_e({mutationFn:async _=>{var V;if(!t)throw new Error("No patient ID");const{data:{session:C}}=await R.auth.getSession();if(!(C!=null&&C.user))throw new Error("Not authenticated");const $=C.user.id,Q=((V=_.name.split(".").pop())==null?void 0:V.replace(/[^a-zA-Z0-9]/g,""))||"bin",J=`${$}/${Date.now()}.${Q}`,{error:ee}=await R.storage.from("documents").upload(J,_);if(ee)throw ee;const{data:G,error:B}=await R.from("documents").insert({patient_id:t,file_name:_.name,storage_path:J,doc_type:_.type.startsWith("image/")?"image":"document"}).select("id").single();if(B)throw await R.storage.from("documents").remove([J]),B;G!=null&&G.id&&R.functions.invoke("process-medical-documents",{body:{document_id:G.id,storage_path:J}}).then(({data:re,error:te})=>{var O,W,X;if(te){const Y=typeof te=="object"&&(te!=null&&te.message)?te.message:String(te);Y.includes("credit")||Y.includes("402")?n({title:a("ש×ר×ת ×-AI ××× × ×××× ×ר××¢","AI service currently unavailable"),description:a("××ס×× ×××¢×× ×× ×× × ×ת×. × ×¡× ×× ×ª× ×©×× ××××ר ××תר.","Document uploaded but not analyzed. Try anal
83yzing again later."),variant:"destructive"}):console.warn("Auto-extraction failed:",te);return}const K=re==null?void 0:re.auto_extracted;if(K){const Y=[];(O=K.appointments)!=null&&O.length&&Y.push(`${K.appointments.length} ${a("פ××ש×ת","appointments")}`),(W=K.medications)!=null&&W.length&&Y.push(`${K.medications.length} ${a("תר×פ×ת","medications")}`),(X=K.recommendations)!=null&&X.length&&Y.push(`${K.recommendations.length} ${a("× ×§×××ת ×××ר×ר","points to clarify")}`),Y.length>0&&n({title:a("××××¦× ×¤×¨×××× ×××ס××","Items extracted from document"),description:Y.join(", ")})}s.invalidateQueries({queryKey:["documents-content",t]}),s.invalidateQueries({queryKey:["document-summaries",t]})})},onSuccess:()=>{s.invalidateQueries({queryKey:["documents-content",t]}),n({title:a("××§×××¥ ×××¢×× ××צ×××","File uploaded successfully"),description:a("× ×ת×× AI רץ ×רקע â תק×× ×תר×× ×ש×סת×××","AI analysis running in background â you'll be notified when done")})},onError:_=>{n({title:a("ש×××× ×××¢×××","Upload failed"),description:_.message,variant:"destructive"})}}),v=_e({mutationFn:async _=>{if(!t)throw new Error("No patient ID");const{data:C}=await R.storage.from("documents").createSignedUrl(_.storage_path,3600);if(!(C!=null&&C.signedUrl))throw new Error("Could not get document URL");const $=_.doc_type==="image"?"imaging":"lab";let Q="";try{const{data:ee,error:G}=await R.functions.invoke("invoke-ai",{body:{prompt:`Extract and summarize ALL text content from this medical document. Include all dates, names, values, diagnoses, medications, and recommendations. Document name: ${_.file_name}`,file_urls:[C.signedUrl]}});if(G)throw console.error("AI extraction error:",G),new Error(typeof G=="object"&&(G!=null&&G.message)?G.message:"AI extraction failed");if(!(ee!=null&&ee.response))throw new Error("Empty AI response");Q=ee.response}catch(ee){throw console.error("Document text extraction failed:",ee),new Error(a("×× ×צ××× × ×קר×× ×ת ת××× ××ס××. × ×¡× ×©××.","Could not read document content. Please try again."))}return await pr(Q,r,$,void 0,_.id)},onSuccess:(_,C)=>{y($=>({...$,[C.id]:_})),s.invalidateQueries({queryKey:["document-summaries",t]}),n({title:a("××ס×× × ××ª× ××צ×××","Document analyzed successfully")})},onError:_=>{console.error("Analysis error:",_);const C=(_==null?void 0:_.message)||"",$=C.includes("credit")||C.includes("402");n({title:$?a("ש×ר×ת ×-AI ××× × ×××× ×ר××¢","AI service currently unavailable"):a("ש×××× ×× ×ת×× ××ס××","Analysis failed"),description:$?a("× ×××¨× ×קר××××× ×©× ×©×ר×ת ×-AI. × ×¡× ×©×× ××××ר ××תר.","AI service credits exhausted. Please try again later."):void 0,variant:"destructive"})}}),P=_e({mutationFn:async _=>{const{error:C}=await R.from("document_summaries").delete().eq("document_id",_);if(C)throw C},onSuccess:(_,C)=>{y($=>{const Q={...$};return delete Q[C],Q}),f($=>{const Q=new Set($);return Q.delete(C),Q}),s.invalidateQueries({queryKey:["document-summaries",t]}),n({title:a("×× ×ת×× × ×××§","Analysis deleted")})},onError:()=>{n({title:a("ש×××× ×××××§×","Delete failed"),variant:"destructive"})}}),A=["application/pdf","image/jpeg","image/png","image/gif","image/webp","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],M=/\.(pdf|jpg|jpeg|png|gif|webp|doc|docx)$/i,D=async _=>{if(!A.includes(_.type)&&!M.test(_.name)){n({title:a("ס×× ×§×××¥ ×× × ×ª××","Unsupported file type"),description:a("×§×צ×× × ×ª××××: PDF, JPG, PNG, DOC","Supported: PDF, JPG, PNG, DOC"),variant:"destructive"});return}if(_.size>50*1024*1024){n({title:a("××§×××¥ ×××× ×××","File too large"),description:a("×××× ×קס××××: 50MB","Maximum size: 50MB"),variant:"destructive"});return}l(!0);try{await k.mutateAsync(_)}finally{l(!1)}},L=async _=>{var $;const C=($=_.target.files)==null?void 0:$[0];C&&await D(C)},m=_=>{_.preventDefault(),_.stopPropagation(),d(!0)},N=_=>{_.preventDefault(),_.stopPropagation(),d(!1)},E=async _=>{var $;_.preventDefault(),_.stopPropagation(),d(!1);const C=($=_.dataTransfer.files)==null?void 0:$[0];C&&await D(C)},q=async _=>{g(_.id);try{await v.mutateAsync(_)}finally{g(null)}},z=_=>{f(C=>
83{const $=new Set(C);return $.has(_)?$.delete(_):$.add(_),$})},S=async _=>{const{data:C}=await R.storage.from("documents").createSignedUrl(_.storage_path,3600);C!=null&&C.signedUrl&&window.open(C.signedUrl,"_blank")},U=async _=>{const{data:C}=await R.storage.from("documents").createSignedUrl(_.storage_path,3600);if(C!=null&&C.signedUrl){const $=document.createElement("a");$.href=C.signedUrl,$.download=_.file_name,$.click()}},I=(_,C)=>_==="image"||C.match(/\.(jpg|jpeg|png|gif|webp)$/i)?br:yr,se=_=>{var $,Q,J,ee,G;const C=h[_];return C?r==="patient"?e.jsxs("div",{className:"space-y-3",children:[C.headline&&e.jsx("p",{className:"font-medium text-sm",children:C.headline}),C.plain_summary&&e.jsx("p",{className:"text-sm leading-relaxed text-muted-foreground",children:C.plain_summary}),C.what_it_means&&e.jsx("div",{className:"bg-primary/5 rounded-lg p-3",children:e.jsx("p",{className:"text-sm",children:C.what_it_means})}),(($=C.questions_for_doctor)==null?void 0:$.length)>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(vr,{className:"w-3.5 h-3.5 text-primary"}),e.jsxs("p",{className:"text-xs font-medium text-primary",children:[x.questionsForDoctor,":"]})]}),e.jsx("ul",{className:"space-y-1",children:C.questions_for_doctor.map((B,V)=>e.jsxs("li",{className:"text-xs flex items-start gap-2",children:[e.jsx("span",{className:"text-primary mt-0.5",children:"â¢"}),e.jsx("span",{children:B})]},V))})]}),C.dont_worry_about&&e.jsxs("p",{className:"text-xs text-muted-foreground italic",children:["ð ",C.dont_worry_about]}),C.disclaimer&&e.jsx("p",{className:"text-[10px] text-muted-foreground/60 mt-2",children:C.disclaimer})]}):r==="physician"?e.jsxs("div",{className:"space-y-3",children:[((Q=C.findings_summary)==null?void 0:Q.length)>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-medium mb-1.5",children:[e.jsx(je,{className:"w-3 h-3 inline mr-1"}),"Findings:"]}),e.jsx("ul",{className:"space-y-1",children:C.findings_summary.map((B,V)=>e.jsxs("li",{className:"text-xs",children:["⢠",B]},V))})]}),((J=C.abnormal_values)==null?void 0:J.length)>0&&e.jsxs("div",{className:"bg-destructive/5 rounded-lg p-2",children:[e.jsx("p",{className:"text-xs font-medium text-destructive mb-1",children:"Abnormal Values:"}),C.abnormal_values.map((B,V)=>e.jsxs("p",{className:"text-xs",children:[B.test,": ",B.value," (ref: ",B.ref,") ",B.delta]},V))]}),((ee=C.red_flags)==null?void 0:ee.length)>0&&e.jsxs("div",{className:"bg-destructive/10 rounded-lg p-2",children:[e.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[e.jsx(Tt,{className:"w-3 h-3 text-destructive"}),e.jsxs("p",{className:"text-xs font-medium text-destructive",children:[x.redFlags,":"]})]}),C.red_flags.map((B,V)=>e.jsxs("p",{className:"text-xs text-destructive",children:["ð´ ",B]},V))]}),C.clinical_correlation&&e.jsx("p",{className:"text-xs text-muted-foreground",children:C.clinical_correlation})]}):e.jsxs("div",{className:"space-y-3",children:[C.simple_summary&&e.jsx("p",{className:"text-sm font-medium",children:C.simple_summary}),C.what_to_know&&e.jsx("p",{className:"text-sm text-muted-foreground",children:C.what_to_know}),((G=C.next_steps)==null?void 0:G.length)>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-medium mb-1",children:[x.nextSteps,":"]}),e.jsx("ul",{className:"space-y-1",children:C.next_steps.map((B,V)=>e.jsxs("li",{className:"text-xs",children:["â
",B]},V))})]}),C.when_to_call_doctor&&e.jsx("div",{className:"bg-amber-50 dark:bg-amber-950/20 rounded-lg p-2",children:e.jsxs("p",{className:"text-xs",children:["ð ",C.when_to_call_doctor]})})]}):null};return e.jsxs("div",{className:"flex flex-col h-full relative",onDragOver:m,onDragLeave:N,onDrop:E,children:[c&&e.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-primary/10 backdrop-blur-sm border-2 border-dashed border-primary rounded-xl m-2 pointer-events-none",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(mt,{className:"w-10 h-10 text-primary animate-bounce"}),e.jsx("p",{className:"text-sm font-medium text-primary",children:a("ש×רר ××× ×××¢××ת","Drop to upload")})]})}),e.jsx("div",{className:"px-6 py-4 border-b",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(Ce,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:x.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:x.subtitle})]})]})}),e.jsx("div",{className:"flex-1 overflow-auto",children:b?e.jsx("div",{className:"flex-1 flex items-center justify-center py-12",children:e.jsx(de,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):p.length===0?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-6 text-center py-12",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-muted flex items-center justify-center mb-4",children:e.jsx(Cs,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("h3",{className:"font-medium text-lg mb-1",children:x.empty}),e.jsx("p",{className:"text-sm text-muted-foreground mb-6",children:x.emptyDesc})]}):e.jsx(De,{className:"flex-1 px-4",children:e.jsx("div",{className:"space-y-3 py-4",children:p.map(_=>{const C=I(_.doc_type,_.file_name),$=T.get(_.id),Q=h[_.id],J=$||Q,ee=i===_.id,G=u.has(_.id);return e.jsxs("div",{className:"rounded-xl bg-muted/50 hover:bg-muted transition-colors overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(C,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-medium text-sm truncate",children:_.file_name}),J&&e.jsxs(ue,{variant:"secondary",className:"text-xs shrink-0",children:[e.jsx(Te,{className:"w-3 h-3 mr-1"}),x.analyzed]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ge(new Date(_.created_at),"dd/MM/yyyy")})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[!J&&e.jsxs(H,{variant:"ghost",size:"sm",className:"h-8 gap-1 text-primary hover:text-primary",onClick:()=>q(_),disabled:ee,children:[ee?e.jsx(de,{className:"w-4 h-4 animate-spin"}):e.jsx(Te,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:ee?x.analyzing:x.analyze})]}),J&&e.jsxs(H,{variant:"ghost",size:"sm",className:"h-8 gap-1",onClick:()=>z(_.id),children:[G?e.jsx(Ct,{className:"w-4 h-4"}):e.jsx(Dt,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:G?x.hideSummary:x.showSummary})]}),e.jsx(H,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>S(_),children:e.jsx(xt,{className:"w-4 h-4"})}),e.jsx(H,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>U(_),children:e.jsx(gr,{className:"w-4 h-4"})})]})]}),J&&G&&e.jsxs("div",{className:"px-4 pb-4 pt-1 border-t border-border/50",children:[e.jsx("div",{className:"bg-background/50 rounded-lg p-3",children:Q?se(_.id):$?e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm leading-relaxed",children:$.summary_text}),$.key_points&&$.key_points.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:[x.keyPoints,":"]}),e.jsx("ul",{className:"space-y-1",children:$.key_points.map((B,V)=>e.jsxs("li",{className:"text-xs flex items-start gap-2",children:[e.jsx("span",{className:"text-primary mt-0.5",children:"â¢"}),e.jsx("span",{children:B})]},V))})]})]}):null}),e.jsx("div",{className:"flex justify-end mt-2",children:e.jsxs(bs,{children:[e.jsx(ys,{asChild:!0,children:e.jsxs(H,{variant:"ghost",size:"sm",className:"h-7 gap-1 text-destructive hover:text-destructive hover:bg-destructive/10",children:[e.jsx(Ds,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"text-xs",children:x.deleteAnalysis})]})}),e.jsxs(js,{children:[e.jsxs(vs,{children:[e.jsx(Ns,{children:x.deleteAnalysisConfirm}),e.jsx(ws,{children:x.deleteAnalysisDesc})]}),e.jsxs(ks,{children:[e.jsx(Ss,{children:x.cancel}),e.jsx(_s,{onClick:()=>P.mutate(_.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:x.delete})]})]})]})})]})]},_.id)})})})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsx(H,{className:"w-full",disabled:o||!t,asChild:!0,children:e.jsxs("label",{className:"cursor-pointer flex items-center justify-center gap-2",children:[o?e.jsx(de,{className:"w-4 h-4 animate-spin"}):e.jsx(mt,{className:"w-4 h-4"}),o?x.uploading:x.upload,e.jsx("input",{type:"file",className:"hidden",onChange:L,accept:"image/*,.pdf,.doc,.docx",disabled:o||!t})]})})})]})},ts=[{id:"epic_sandbox",name:"Epic (Sandbox)",url:"https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4"},{id:"epic_prod",name:"Epic (Production)",url:"https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4"},{id:"cerner_sandbox",name:"Cerner / Oracle Health (Sandbox)",url:"https://fhir-open.cerner.com/r4/ec2458f2-1e24-41c8-b71b-0e701af7583d"},{id:"cerner_prod",name:"Cerner / Oracle Health",url:"https://fhir.cerner.com/r4"},{id:"clalit",name:"××××ת (Clalit)",url:"https://fhir.clalit.org.il/api/FHIR/R4"},{id:"maccabi",name:"×××× (Maccabi)",url:"https://fhir.maccabi.co.il/api/FHIR/R4"},{id:"meuhedet",name:"×××××ת (Meuhedet)",url:"https://fhir.meuhedet.co.il/api/FHIR/R4"},{id:"leumit",name:"×××××ת (Leumit)",url:"https://fhir.leumit.co.il/api/FHIR/R4"}
83,{id:"custom",name:"Custom / ××ר",url:""}],ss=[{id:"Condition",he:"×××× ×ת",en:"Conditions"},{id:"MedicationRequest",he:"×רש×××",en:"Medications"},{id:"Observation",he:"××××§×ת ××¢×××",en:"Lab Results"},{id:"DiagnosticReport",he:"××××ת ×××××",en:"Diagnostic Reports"},{id:"Procedure",he:"פר×צ××ר×ת",en:"Procedures"}],Ha=()=>{const{t,language:r}=ce(),{toast:a}=ve(),n=r==="he",[s,o]=j.useState("custom"),[l,c]=j.useState(""),[d,i]=j.useState(""),[g,u]=j.useState(""),[f,h]=j.useState(ss.map(v=>v.id)),[y,x]=j.useState(!1),[p,b]=j.useState(null),w=v=>{o(v);const P=ts.find(A=>A.id===v);P&&P.url&&c(P.url)},T=v=>{h(P=>P.includes(v)?P.filter(A=>A!==v):[...P,v])},k=async()=>{var v,P;if(!l||!d){a({title:t("ש××××","Error"),description:t("×ש ×××× ×ת××ת שרת ××××× ×××פ×","Server URL and Patient ID are required"),variant:"destructive"});return}x(!0),b(null);try{const{data:A,error:M}=await R.functions.invoke("fhir-sync",{body:{fhir_server_url:l,patient_id:d,access_token:g||void 0,resource_types:f}});if(M)throw M;b(A),a({title:t("××¡× ×ר×× ××ש××","Sync completed"),description:t(`${((v=A.sync_results)==null?void 0:v.total_synced)||0} רש×××ת ××××× ××צ×××`,`${((P=A.sync_results)==null?void 0:P.total_synced)||0} records imported successfully`)})}catch(A){b({success:!1,error:A.message}),a({title:t("ש×××ת ×¡× ×ר××","Sync Error"),description:A.message,variant:"destructive"})}finally{x(!1)}};return e.jsxs(Ze,{className:"border-primary/20",children:[e.jsxs(ns,{className:"pb-3",children:[e.jsxs(is,{className:"flex items-center gap-2 text-base",children:[e.jsx(Ts,{className:"h-5 w-5 text-primary"}),t("××××× ××××¢ רפ××× (FHIR)","Import Medical Data (FHIR)")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("××××× × ×ª×× ×× ××ער×ת רפ×××ת ××צ×× ×ת ××ª×§× FHIR (Epic, Cerner ××¢××)","Import data from external EHR systems via FHIR (Epic, Cerner, etc.)")})]}),e.jsxs(et,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(ae,{className:"text-sm flex items-center gap-1.5",children:[e.jsx(Kr,{className:"h-3.5 w-3.5"}),t("××ר ×ער×ת רפ×××ת","Select EHR System")]}),e.jsxs(ft,{value:s,onValueChange:w,children:[e.jsx(ht,{className:"text-sm",children:e.jsx(pt,{placeholder:t("××ר שרת...","Select server...")})}),e.jsx(gt,{children:ts.map(v=>e.jsx(ke,{value:v.id,children:v.name},v.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ae,{className:"text-sm",children:t("×ת××ת שרת FHIR","FHIR Server URL")}),e.jsx(ye,{placeholder:"https://fhir.hospital.org/api/FHIR/R4",value:l,onChange:v=>{c(v.target.value),o("custom")},dir:"ltr",className:"font-mono text-sm",readOnly:s!=="custom"}),s!=="custom"&&e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("××ת××ת × ×§××¢× ×××××××ת ××××××¨× ×××¢××","URL auto-filled from selection above")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ae,{className:"text-sm",children:t("×××× ××××¤× (Patient ID)","Patient ID")}),e.jsx(ye,{placeholder:"e.g. abc-123-def",value:d,onChange:v=>i(v.target.value),dir:"ltr",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(ae,{className:"text-sm flex items-center gap-1.5",children:[e.jsx(Vr,{className:"h-3.5 w-3.5"}),t("×××§× ×××©× (××פצ××× ××)","Access Token (optional)")]}),e.jsx(ye,{type:"password",placeholder:"Bearer token...",value:g,onChange:v=>u(v.target.value),dir:"ltr",className:"font-mono text-sm"})]}),e.jsx(ct,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ae,{className:"text-sm",children:t("ס××× ××××¢ ××××××","Resource Types to Import")}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:ss.map(v=>e.jsxs("label",{className:"flex items-center gap-2.5 p-2 rounded-lg hover:bg-muted/50 cursor-pointer transition-colors",children:[e.jsx(os,{checked:f.includes(v.id),onCheckedChange:()=>T(v.id)}),e.jsx("span",{className:"text-sm",children:n?v.he:v.en}),e.jsx(ue,{variant:"outline",className:"text-[10px] ms-auto font-mono",children:v.id})]},v.id))})]}),e.jsx(ct,{}
83),e.jsxs(bs,{children:[e.jsx(ys,{asChild:!0,children:e.jsxs(H,{className:"w-full",disabled:y||!l||!d||f.length===0,children:[y?e.jsx(de,{className:"h-4 w-4 animate-spin me-2"}):e.jsx(zr,{className:"h-4 w-4 me-2"}),y?t("××××× × ×ª×× ××...","Importing data..."):t("×ת×× ×××××","Start Import")]})}),e.jsxs(js,{dir:n?"rtl":"ltr",children:[e.jsxs(vs,{children:[e.jsx(Ns,{children:t("××××× × ×ª×× × FHIR?","Import FHIR Data?")}),e.jsx(ws,{children:t(`פע××× ×× ×ª×××× ${f.length} ס××× ××××¢ ××שרת. ×× ×ª×× ×× ××ש××¨× ××ער×ת SMADAR ש××.`,`This will import ${f.length} resource types from the server. Data will be saved to your SMADAR records.`)})]}),e.jsxs(ks,{children:[e.jsx(Ss,{children:t("×××××","Cancel")}),e.jsx(_s,{onClick:k,children:t("××××","Import")})]})]})]}),p&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx(ct,{}),e.jsxs("h4",{className:"text-sm font-semibold flex items-center gap-1.5",children:[p.success?e.jsx(qe,{className:"h-4 w-4 text-green-500"}):e.jsx(Tt,{className:"h-4 w-4 text-destructive"}),t("ת×צ××ת ××××××","Import Results")]}),p.error&&e.jsx("p",{className:"text-xs text-destructive bg-destructive/10 p-2 rounded-md",children:p.error}),p.sync_results&&e.jsx(De,{className:"max-h-48",children:e.jsxs("div",{className:"space-y-1.5",children:[p.sync_results.success.map((v,P)=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-2 bg-muted/50 rounded-md",children:[e.jsx("span",{className:"font-medium",children:v.resource_type}),e.jsxs(ue,{variant:v.count>0?"default":"secondary",className:"text-[10px]",children:[v.count," ",t("רש×××ת","records")]})]},P)),p.sync_results.errors.map((v,P)=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-2 bg-destructive/10 rounded-md",children:[e.jsx("span",{className:"font-medium",children:v.resource_type}),e.jsx("span",{className:"text-destructive truncate max-w-[60%]",children:v.error})]},`err-${P}`))]})}),p.sync_results&&e.jsxs("p",{className:"text-xs text-muted-foreground text-center",children:[t("ס××´×:","Total:")," ",p.sync_results.total_synced," ",t("רש×××ת ×××××","records imported")]})]})]})]})},$a=({patientId:t,patientRegion:r,diagnosisText:a,language:n,onRecordingComplete:s,activeTab:o})=>{const l=n==="he",c=j.useMemo(()=>({title:l?"×ר×× ×¨×¤×××":"Medical Hub",subtitle:l?"×× ×× ×©×§×©×ר ×××פ×× ×××§×× ×××":"Everything related to your care in one place"}),[l]);return e.jsxs("div",{className:"flex flex-col h-full pb-24",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 pb-2",children:[e.jsx("div",{className:"p-2.5 rounded-2xl bg-gradient-brand text-primary-foreground shadow-lg shadow-primary/25",children:e.jsx(je,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-foreground",children:c.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c.subtitle})]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4",children:[e.jsx("div",{className:F("transition-all duration-300 ease-out",o?"opacity-100":"opacity-0"),children:o&&e.jsxs("div",{className:"py-4 animate-fade-in",children:[o==="doctors"&&e.jsx(qa,{patientId:t,patientRegion:r,diagnosisText:a,language:n}),o==="recording"&&e.jsx(Fa,{patientId:t,language:n,onRecordingComplete:s}),o==="summaries"&&e.jsx(Oa,{patientId:t,language:n}),o==="documents"&&e.jsx(za,{patientId:t}),o==="fhir"&&e.jsx(Ha,{})]})}),!o&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center animate-fade-in",children:[e.jsx("div",{className:"p-4 rounded-full bg-primary/10 mb-4",children:e.jsx(je,{className:"w-10 h-10 text-primary"})}),e.jsx("p",{className:"text-muted-foreground text-sm",children:l?"××ר ×פשר×ת ×××××":"Select an option below"})]})]})]})},Ua=({language:t})=>{const r=t==="he",[a,n]=j.useState(null),[s,o]=j.useState(!1),[l,c]=j.useState({from:void 0,to:void 0}),[d,i]=j.useState([{id:"pain",name:"×××",nameEn:"Pain",icon:e.jsx(Me,{className:"h-4 w-4"}),level:3,lastUpdated:new Date},{id:"fatigue",name:"×¢××פ×ת",nameEn:"Fatigue",icon:e.jsx(ut,{className:"h-4 w-4"}),level:5,lastUpdated:new Date}
83,{id:"nausea",name:"×××××",nameEn:"Nausea",icon:e.jsx(Wt,{className:"h-4 w-4"}),level:2,lastUpdated:new Date}]),[g,u]=j.useState("neutral"),f=j.useMemo(()=>({title:r?"ר×××× ×ת××××":"Wellness & Support",subtitle:r?"××¢×§× ××××":"Daily tracking",symptoms:r?"תס××× ××":"Symptoms",mood:r?"××¦× ×¨××":"Mood",tips:r?"× ×§×××ת ×××ר×ר":"Points to Clarify",supplements:r?"ת××¡×¤× ×ª××× ×":"Supplements",viewAll:r?"××¦× ×××":"View All",level:r?"ר××":"Level",low:r?"× ×××":"Low",high:r?"××××":"High",trackSymptom:r?"×¢×§×× ×××¨× ×ª×¡×××":"Track Symptom",howAreYou:r?"××× ×ת ×ר×××©× ××××?":"How are you feeling today?",clinicalTrials:r?"× ×ס×××× ×§××× ×××":"Clinical Trials",findTrials:r?"×צ×× × ×ס×××× ×ת×××××":"Find matching trials",supportiveCare:r?"××פ×××× ×ª×××××":"Supportive Care",iHerbDiscount:r?"×× ×× ×××××ת":"Special Discount",startTracking:r?"×ת×× ××¢×§× ×ª×¡××× ××":"Start Symptom Tracking",trackingActive:r?"××¢×§× ×¤×¢××":"Tracking Active",selectPeriod:r?"××ר תק×פת ××¢×§×":"Select tracking period",until:r?"×¢×":"until",stopTracking:r?"עצ×ר ××¢×§×":"Stop Tracking",daysLeft:r?"×××× × ×תר×":"days left"}),[r]),h=()=>{l.from&&l.to&&(n({startDate:l.from,endDate:l.to,isActive:!0}),o(!0))},y=()=>{n(null),o(!1),c({from:void 0,to:void 0})},x=()=>{if(!a)return 0;const k=new Date,v=a.endDate.getTime()-k.getTime();return Math.max(0,Math.ceil(v/(1e3*60*60*24)))},p=[{id:"ginger",title:r?"×'×× ×'ר ××××××":"Ginger for Nausea",de
83scription:r?"×ª× ×'×× ×'ר ×××× ××¢××ר ×¢× ×××××ת":"Ginger tea can help with nausea",icon:e.jsx(Ps,{className:"h-4 w-4"}),category:r?"×××¢×":"Natural"},{id:"rest",title:r?"×× ××× ××××ת×ת":"Quality Rest",description:r?"ש×× × ×©× 7-8 שע×ת ×שפרת ×ת××שש×ת":"7-8 hours of sleep improves recovery",icon:e.jsx(ut,{className:"h-4 w-4"}),category:r?"ש×× ×":"Sleep"},{id:"hydration",title:r?"שת××× ×ר×××":"Stay Hydrated",description:r?"×©×ª× ×פ××ת 8 ××ס×ת ××× ××××":"Drink at least 8 glasses of water daily",icon:e.jsx(Wt,{className:"h-4 w-4"}),category:r?"ת××× ×":"Nutrition"}],b=(k,v)=>{i(P=>P.map(A=>A.id===k?{...A,level:v,lastUpdated:new Date}:A))},w=k=>{switch(k){case"good":return e.jsx(Cr,{className:"h-6 w-6"});case"neutral":return e.jsx(_r,{className:"h-6 w-6"});case"bad":return e.jsx(Sr,{className:"h-6 w-6"})}},T=k=>k<=3?"text-green-500":k<=6?"text-amber-500":"text-red-500";return e.jsxs(Ze,{className:"border-border/50 overflow-hidden",children:[e.jsx(ns,{className:"pb-3",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-pink-500 to-rose-500 rounded-xl flex items-center justify-center",children:e.jsx(Ie,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsxs(is,{className:"text-lg font-medium flex items-center gap-2",children:[f.title,e.jsx(Te,{className:"h-4 w-4 text-pink-500"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:f.subtitle})]})]})})}),e.jsxs(et,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm font-medium",children:f.howAreYou}),e.jsx("div",{className:"flex items-center justify-center gap-4",children:["bad","neutral","good"].map(k=>e.jsx("button",{onClick:()=>u(k),className:F("w-14 h-14 rounded-full flex items-center justify-center transition-all",g===k?k==="good"?"bg-green-100 text-green-600 ring-2 ring-green-500 dark:bg-green-950":k==="neutral"?"bg-amber-100 text-amber-600 ring-2 ring-amber-500 dark:bg-amber-950":"bg-red-100 text-red-600 ring-2 ring-red-500 dark:bg-red-950":"bg-muted hover:bg-muted/80 text-muted-foreground"),children:w(k)},k))})]}),e.jsx("div",{className:"space-y-3",children:a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ue,{className:"bg-green-500/20 text-green-600 dark:text-green-400 gap-1",children:[e.jsx(ie,{className:"h-3 w-3"}),f.trackingActive]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[x()," ",f.daysLeft]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(H,{variant:"ghost",size:"sm",className:"h-7 text-xs text-destructive hover:text-destructive",onClick:y,children:f.stopTracking}),e.jsx(H,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>o(!s),children:s?e.jsx(Ct,{className:"h-4 w-4"}):e.jsx(Dt,{className:"h-4 w-4"})})]})]}),s&&e.jsx("div",{className:"space-y-4 animate-fade-in",children:d.map(k=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:F("p-1.5 rounded-lg bg-muted",T(k.level)),children:k.icon}),e.jsx("span",{className:"text-sm font-medium",children:r?k.name:k.nameEn})]}),e.jsxs(ue,{variant:"outline",className:F("text-xs",T(k.level)),children:[k.level,"/10"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground w-10",children:f.low}),e.jsx(Nr,{value:[k.level],onValueChange:([v])=>b(k.id,v),max:10,min:1,step:1,className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground w-10 text-end",children:f.high})]})]},k.id))})]}):e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-primary/5 to-accent/5 border border-primary/20",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center",children:e.jsx(Me,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:f.symptoms}),e.jsx("p",{className:"text-xs text-muted-foreground",children:f.selectPeriod})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Ms,{children:[e.jsx(As,{asChild:!0,children:e.jsxs(H,{variant:"outline",size:"sm",className:"flex-1 justify-start gap-2 text-xs",children:[e.jsx(Ge,{className:"h-4 w-4"}),l.from?l.to?e.jsxs(e.Fragment,{children:[ge(l.from,"dd/MM",{locale:r?Fe:void 0})," - ",ge(l.to,"dd/MM",{locale:r?Fe:void 0})]}):ge(l.from,"dd/MM/yyyy",{locale:r?Fe:void 0}):r?"××ר ת×ר××××":"Select dates"]})}),e.jsx(Es,{className:"w-auto p-0",align:"start",children:e.jsx(wr,{mode:"range",selected:l,onSelect:k=>c({from:k==null?void 0:k.from,to:k==null?void 0:k.to}),numberOfMonths:1,disabled:k=>k<new Date,className:"p-3 pointer-events-auto"})})]}),e.jsxs(H,{size:"sm",onClick:h,disabled:!l.from||!l.to,className:"gap-1",children:[e.jsx(Rs,{className:"h-3 w-3"}),r?"×ת××":"Start"]})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm font-medium",children:f.supportiveCare}),e.jsx(H,{variant:"link",size:"sm",className:"h-auto p-0 text-xs",children:f.viewAll})]}),e.jsx(De,{className:"h-[120px]",children:e.jsx("div",{className:"space-y-2",children:p.map(k=>e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-xl bg-muted/30 border border-transparent hover:border-border/50 transition-all",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center shrink-0 text-primary",children:k.icon}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:k.title}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-1",children:k.description})]}),e.jsx(ue,{variant:"secondary",className:"text-xs shrink-0",children:k.category})]},k.id))})})]}),e.jsx("div",{className:"p-4 rounded-xl bg-gradient-to-br from-purple-50 to-indigo-50 dark:from-purple-950/30 dark:to-indigo-950/30 border border-purple-200/50 dark:border-purple-800/30",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-purple-100 dar
83k:bg-purple-900 flex items-center justify-center shrink-0",children:e.jsx(kr,{className:"h-5 w-5 text-purple-600 dark:text-purple-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:f.clinicalTrials}),e.jsx("p",{className:"text-xs text-muted-foreground",children:f.findTrials})]}),e.jsxs(H,{size:"sm",variant:"secondary",className:"shrink-0 gap-1",children:[e.jsx(xt,{className:"h-3 w-3"}),r?"×פש×":"Search"]})]})}),e.jsx("div",{className:"p-4 rounded-xl bg-gradient-to-br from-green-50 to-emerald-50 dark:from-green-950/30 dark:to-emerald-950/30 border border-green-200/50 dark:border-green-800/30",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-green-100 dark:bg-green-900 flex items-center justify-center shrink-0",children:e.jsx(oe,{className:"h-5 w-5 text-green-600 dark:text-green-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium",children:f.supplements}),e.jsx(ue,{className:"bg-green-600 text-white text-xs",children:f.iHerbDiscount})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r?"×§××× ×× ×× ×¢× ×ª××¡×¤× ×ª××× × ××××צ××":"Get discounts on recommended supplements"})]}),e.jsxs(H,{size:"sm",variant:"outline",className:"shrink-0 gap-1 border-green-300 dark:border-green-700",children:[e.jsx(xt,{className:"h-3 w-3"}),"iHerb"]})]})})]})]})},Ia=({language:t,stats:r,filter:a,onFilterChange:n,onAddItem:s,searchQuery:o,onSearchChange:l,texts:c})=>{const d=t==="he",[i,g]=j.useState(!1);return e.jsxs("div",{className:"shrink-0 px-4 pt-4 pb-3 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-gradient-to-br from-primary via-primary/80 to-pink-500 flex items-center justify-center shadow-lg shadow-primary/20",children:e.jsx(Ge,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-xl font-bold text-foreground flex items-center gap-2",children:[c.title,e.jsx(Te,{className:"h-4 w-4 text-primary"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c.subtitle})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{variant:"ghost",size:"icon",className:"h-10 w-10 rounded-full",onClick:()=>{g(!i),i&&l("")},children:i?e.jsx(jt,{className:"h-5 w-5"}):e.jsx(Qt,{className:"h-5 w-5"})}),e.jsxs(ls,{children:[e.jsx(cs,{asChild:!0,children:e.jsx(H,{size:"icon",className:"h-11 w-11 rounded-full bg-gradient-to-br from-primary to-pink-500 shadow-lg shadow-primary/30 hover:shadow-primary/40 transition-all hover:scale-105",children:e.jsx(Rs,{className:"h-5 w-5"})})}),e.jsxs(ds,{align:d?"start":"end",className:"w-52",children:[e.jsx(tr,{className:"text-xs text-muted-foreground",children:d?"××סף ××ש":"Add New"}),e.jsx(Bt,{}),e.jsxs(pe,{onClick:()=>s("task"),className:"gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-emerald-100 dark:bg-emerald-900/30 flex items-center justify-center",children:e.jsx(me,{className:"h-4 w-4 text-emerald-600 dark:text-emerald-400"})}),e.jsx("span",{children:c.task})]}),e.jsxs(pe,{onClick:()=>s("appointment"),className:"gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center",children:e.jsx(ie,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"})}),e.jsx("span",{children:c.appointment})]}),e.jsx(Bt,{}),e.jsxs(pe,{onClick:()=>s("medication"),className:"gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center",children:e.jsx(oe,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"})}),e.jsx("span",{children:c.medication})]}),e.jsxs(pe,{onClick:()=>s("test"),className:"gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center",children:e.jsx(Ae,{className:"h-4 w-4 text-amber-600 dar
83k:text-amber-400"})}),e.jsx("span",{children:c.test})]}),e.jsxs(pe,{onClick:()=>s("symptom"),className:"gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-rose-100 dark:bg-rose-900/30 flex items-center justify-center",children:e.jsx(Me,{className:"h-4 w-4 text-rose-600 dark:text-rose-400"})}),e.jsx("span",{children:c.symptom})]}),e.jsxs(pe,{onClick:()=>s("note"),className:"gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-slate-100 dark:bg-slate-800/30 flex items-center justify-center",children:e.jsx(Je,{className:"h-4 w-4 text-slate-600 dark:text-slate-400"})}),e.jsx("span",{children:c.note})]})]})]})]})]}),i&&e.jsxs("div",{className:"relative animate-fade-in",children:[e.jsx(Qt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ye,{value:o,onChange:u=>l(u.target.value),placeholder:c.search,className:"h-10 pl-10 rounded-xl bg-muted/50",autoFocus:!0})]}),e.jsxs("div",{className:"flex gap-2 overflow-x-auto pb-1 scrollbar-hide",children:[e.jsxs("div",{className:F("flex items-center gap-2 px-3 py-2 rounded-xl border transition-all shrink-0",r.today>0?"bg-primary/5 border-primary/20":"bg-muted/50 border-transparent"),children:[e.jsx("div",{className:F("w-7 h-7 rounded-lg flex items-center justify-center",r.today>0?"bg-primary/10":"bg-muted"),children:e.jsx(Ge,{className:F("h-3.5 w-3.5",r.today>0?"text-primary":"text-muted-foreground")})}),e.jsxs("div",{children:[e.jsx("p",{className:F("text-base font-bold leading-none",r.today>0?"text-primary":"text-muted-foreground"),children:r.today}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:c.today})]})]}),r.overdue>0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-destructive/5 border border-destructive/20 shrink-0 animate-pulse",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-destructive/10 flex items-center justify-center",children:e.jsx(_t,{className:"h-3.5 w-3.5 text-destructive"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-bold leading-none text-destructive",children:r.overdue}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:c.overdue})]})]}),r.medications>0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-purple-50/50 dark:bg-purple-950/20 border border-purple-200/30 dark:border-purple-800/30 shrink-0",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-purple-100 dark:bg-purple-900/50 flex items-center justify-center",children:e.jsx(oe,{className:"h-3.5 w-3.5 text-purple-600 dark:text-purple-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-bold leading-none text-purple-600 dark:text-purple-400",children:r.medications}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:c.medications})]})]}),r.appointments>0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-blue-50/50 dark:bg-blue-950/20 border border-blue-200/30 dark:border-blue-800/30 shrink-0",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-blue-100 dark:bg-blue-900/50 flex items-center justify-center",children:e.jsx(ie,{className:"h-3.5 w-3.5 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-bold leading-none text-blue-600 dark:text-blue-400",children:r.appointments}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:c.appointments})]})]}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-emerald-50/50 dark:bg-emerald-950/20 border border-emerald-200/30 dark:border-emerald-800/30 shrink-0",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-emerald-100 dark:bg-emerald-900/50 flex items-center justify-center",children:e.jsx(me,{className:"h-3.5 w-3.5 text-emerald-600 dark:text-emerald-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-bold leading-none text-emerald-600 dark:text-emerald-400",children:r.completed}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:c.completed})]})]})]}),e.jsxs("div",{className:"flex gap-2 overflow-x-auto scrollbar-hide pb-1",children:[e.jsx(H,{variant:a==="all"?"default":"outline",size:"sm",onClick:()=>n("all"),className:F("rounded-full text-xs h-8 px-4 shrink-0",a==="all"&&"bg-primary"),children:c.all}),e.jsxs(H,{variant:a==="tasks"?"default":"outline",size:"sm",onClick:()=>n("tasks"),className:F("rounded-full text-xs h-8 px-4 gap-1.5 shrink-0",a==="tasks"&&"bg-emerald-600 hover:bg-emerald-700"),children:[e.jsx(me,{className:"h-3 w-3"}),c.tasks]}),e.jsxs(H,{variant:a==="appointments"?"default":"outline",size:"sm",onClick:()=>n("appointments"),className:F("rounded-full text-xs h-8 px-4 gap-1.5 shrink-0",a==="appointments"&&"bg-blue-600 hover:bg-blue-700"),
83children:[e.jsx(ie,{className:"h-3 w-3"}),c.appointments]}),e.jsxs(H,{variant:a==="medications"?"default":"outline",size:"sm",onClick:()=>n("medications"),className:F("rounded-full text-xs h-8 px-4 gap-1.5 shrink-0",a==="medications"&&"bg-purple-600 hover:bg-purple-700"),children:[e.jsx(oe,{className:"h-3 w-3"}),c.medications]}),e.jsxs(H,{variant:a==="tests"?"default":"outline",size:"sm",onClick:()=>n("tests"),className:F("rounded-full text-xs h-8 px-4 gap-1.5 shrink-0",a==="tests"&&"bg-amber-600 hover:bg-amber-700"),children:[e.jsx(Ae,{className:"h-3 w-3"}),c.tests]})]})]})},Ba=t=>{if(t.type==="appointment")return{icon:ie,bgColor:"bg-blue-100 dark:bg-blue-900/40",textColor:"text-blue-600 dark:text-blue-400",badgeBg:"bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300",cardBg:"bg-blue-50/50 dark:bg-blue-950/20 border-blue-200/50 dark:border-blue-800/30 hover:border-blue-300 dark:hover:border-blue-700",label:{he:"ת×ר",en:"Apt"}};switch(t.category){case"medication":return{icon:oe,bgColor:"bg-purple-100 dark:bg-purple-900/40",textColor:"text-purple-600 dark:text-purple-400",badgeBg:"bg-purple-100 text-purple-700 dark:bg-purple-900/50 dark:text-purple-300",cardBg:"bg-purple-50/50 dark:bg-purple-950/20 border-purple-200/50 dark:border-purple-800/30 hover:border-purple-300 dark:hover:border-purple-700",label:{he:"תר×פ×",en:"Med"}};case"test":return{icon:Ae,bgColor:"bg-amber-100 dark:bg-amber-900/40",textColor:"text-amber-600 dark:text-amber-400",badgeBg:"bg-amber-100 text-amber-700 dark:bg-amber-900/50 dark:text-amber-300",cardBg:"bg-amber-50/50 dark:bg-amber-950/20 border-amber-200/50 dark:border-amber-800/30 hover:border-amber-300 dark:hover:border-amber-700",label:{he:"××××§×",en:"Test"}};case"symptom":return{icon:Me,bgColor:"bg-rose-100 dark:bg-rose-900/40",textColor:"text-rose-600 dar
83k:text-rose-400",badgeBg:"bg-rose-100 text-rose-700 dark:bg-rose-900/50 dark:text-rose-300",cardBg:"bg-rose-50/50 dark:bg-rose-950/20 border-rose-200/50 dark:border-rose-800/30 hover:border-rose-300 dark:hover:border-rose-700",label:{he:"תס×××",en:"Symp"}};case"note":return{icon:Je,bgColor:"bg-slate-100 dark:bg-slate-800/40",textColor:"text-slate-600 dark:text-slate-400",badgeBg:"bg-slate-100 text-slate-700 dark:bg-slate-800/50 dark:text-slate-300",cardBg:"bg-slate-50/50 dark:bg-slate-950/20 border-slate-200/50 dark:border-slate-800/30 hover:border-slate-300 dark:hover:border-slate-700",label:{he:"×ער×",en:"Note"}};default:return{icon:me,bgColor:"bg-emerald-100 dark:bg-emerald-900/40",textColor:"text-emerald-600 dark:text-emerald-400",badgeBg:"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/50 dark:text-emerald-300",cardBg:"bg-background border-border/50 hover:border-border hover:shadow-sm",label:{he:"×ש×××",en:"Task"}}}},Ka=({item:t,language:r,onToggle:a,onDelete:n,isUrgent:s=!1,animationDelay:o=0})=>{const[l,c]=j.useState(!1),d=r==="he",i=t.status==="done",g=t.type==="appointment",u=Ba(t),f=u.icon,h=p=>p?new Date(p).toLocaleDateString(d?"he-IL":"en-US",{day:"numeric",month:"short"}):null,y=p=>{if(!p)return null;const[b,w]=p.split(":");return`${b}:${w}`},x=t.due_time||t.location||t.doctor||t.notes||t.reminder_minutes;return e.jsxs("div",{className:F("group relative flex flex-col gap-2 p-3 rounded-xl border transition-all duration-200","animate-fade-in",i?"bg-muted/30 border-transparent opacity-60":s?"bg-destructive/5 border-destructive/30 hover:border-destructive/50":u.cardBg),style:{animationDelay:`${o}s`},onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"shrink-0",children:g||t.category?e.jsx("div",{className:F("w-10 h-10 rounded-xl flex items-center justify-center transition-colors",i?"bg-muted":u.bgColor),children:e.jsx(f,{className:F("h-5 w-5",i?"text-muted-foreground":u.textColor)})}):e.jsx(os,{checked:i,onCheckedChange:a,className:F("h-6 w-6 rounded-lg border-2 transition-all",i?"data-[state=checked]:bg-emerald-500 data-[state=checked]:border-emerald-500":s?"border-destructive/50":"border-muted-foreground/30")})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:F("text-sm font-medium truncate transition-all",i&&"line-through text-muted-foreground"),children:t.title}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[t.due_time&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ie,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:F("text-xs font-medium",s&&!i?"text-destructive":"text-muted-foreground"),children:y(t.due_time)})]}),t.due_date&&!t.due_time&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ze,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:F("text-xs",s&&!i?"text-destructive":"text-muted-foreground"),children:h(t.due_date)})]}),t.location&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ls,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground truncate max-w-[120px]",children:t.location})]}),t.reminder_minutes&&e.jsx("div",{className:"flex items-center gap-1",children:e.jsx(Ye,{className:"h-3 w-3 text-primary"})})]})]}),e.jsx("div",{className:F("shrink-0 px-2.5 py-1 rounded-full text-[10px] font-medium uppercase tracking-wider",i?"bg-muted text-muted-foreground":u.badgeBg),children:d?u.label.he:u.label.en}),e.jsx("div",{className:F("shrink-0 transition-opacity duration-200",l||i?"opacity-100":"opacity-0"),children:e.jsxs(ls,{children:[e.jsx(cs,{asChild:!0,children:e.jsx(H,{variant:"ghost",size:"icon",className:"h-8 w-8",children:e.jsx(jr,{className:"h-4 w-4"})})}),e.jsxs(ds,{align:d?"start":"end",children:[(g||t.category)&&!i&&e.jsxs(pe,{onClick:a,children:[e.jsx(me,{className:"h-4 w-4 me-2"}),d?"ס×× ×××צע":"Mark as done"]}),!g&&!t.category&&i&&e.jsxs(pe,{onClick:a,children:[e.jsx(me,{className:"h-4 w-4 me-2"}),d?"ס×× ××× ××צע":"Mark as open"]}),e.jsxs(pe,{onClick:n,className:"text-destructive focus:text-destructive",children:[e.jsx(Ds,{className:"h-4 w-4 me-2"}),d?"×××§":"Delete"]})]})]})})]}),x&&!i&&e.jsxs("div",{className:F("flex flex-col gap-1.5 pt-2 border-t border-border/30",d?"mr-13":"ml-13"),style:{marginLeft:d?0:52,marginRight:d?52:0},children:[t.doctor&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(vt,{className:"h-3 w-3"}),e.jsx("span",{className:"font-medium",children:t.doctor.full_name}),e.jsx("span",{children:"·"}),e.jsx("span",{children:t.doctor.specialty}),t.doctor.hospital&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("span",{className:"truncate",children:t.doctor.hospital})]})]}),t.notes&&e.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx(Ce,{className:"h-3 w-3 mt-0.5 shrink-0"}),e.jsx("span",{className:"line-clamp-2",children:t.notes})]}),t.reminder_minutes&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-primary",children:[e.jsx(Ye,{className:"h-3 w-3"}),e.jsx("span",{children:d?`ת×××רת ${t.reminder_minutes} ××§×ת ××¤× ×`:`Reminder ${t.reminder_minutes} min before`})]})]}),s&&!i&&e.jsxs("div",{className:"absolute -top-1 -right-1 w-3 h-3",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full rounded-full bg-destructive opacity-75 animate-ping"}),e.jsx("span",{className:"relative inline-flex rounded-full h-3 w-3 bg-destructive"})]}),t.priority==="urgent"&&!s&&!i&&e.jsx("div",{className:"absolute -top-1 -left-1 w-3 h-3",children:e.jsx("span",{className:"relative inline-flex rounded-full h-3 w-3 bg-orange-500"})}),t.priority==="high"&&!i&&e.jsx("div",{className:"absolute -top-1 -left-1 w-2 h-2",children:e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-amber-500"})})]})}
83,Pe=({title:t,icon:r,items:a,language:n,onToggleItem:s,onDeleteItem:o,variant:l="default",collapsible:c=!1,defaultCollapsed:d=!1})=>{const[i,g]=j.useState(d),u=n==="he";if(a.length===0)return null;const h={default:{line:"bg-border",dot:"bg-muted-foreground/20 border-muted-foreground/40",icon:"text-muted-foreground",title:"text-muted-foreground"},urgent:{line:"bg-gradient-to-b from-destructive/50 to-destructive/20",dot:"bg-destructive/20 border-destructive animate-pulse",icon:"text-destructive",title:"text-destructive font-semibold"},highlight:{line:"bg-gradient-to-b from-primary/50 to-primary/20",dot:"bg-primary/20 border-primary",icon:"text-primary",title:"text-primary font-semibold"},success:{line:"bg-gradient-to-b from-emerald-500/30 to-emerald-500/10",dot:"bg-emerald-100 border-emerald-500 dark:bg-emerald-900/30",icon:"text-emerald-600 dark:text-emerald-400",title:"text-emerald-600 dark:text-emerald-400"}}[l],y=a.filter(p=>p.category==="medication").length,x=a.filter(p=>p.category==="test").length;return a.filter(p=>p.type==="appointment").length,e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:F("absolute w-0.5 top-10 bottom-0 rounded-full",u?"right-[19px]":"left-[19px]",h.line)}),e.jsxs("div",{className:F("flex items-center gap-3 mb-3 relative z-10",c&&"cursor-pointer hover:opacity-80 transition-opacity"),onClick:()=>c&&g(!i),children:[e.jsx("div",{className:F("w-10 h-10 rounded-full border-2 flex items-center justify-center bg-background",h.dot),children:e.jsx(r,{className:F("h-4 w-4",h.icon)})}),e.jsxs("div",{className:"flex-1 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("h3",{className:F("text-sm",h.title),children:[t,e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ms-2",children:["(",a.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[y>0&&e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-purple-100 dark:bg-purple-900/30",children:[e.jsx(oe,{className:"h-2.5 w-2.5 text-purple-600 dark:text-purple-400"}),e.jsx("span",{className:"text-[9px] font-medium text-purple-600 dark:text-purple-400",children:y})]}),x>0&&e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-amber-100 dark:bg-amber-900/30",children:[e.jsx(Ae,{className:"h-2.5 w-2.5 text-amber-600 dark:text-amber-400"}),e.jsx("span",{className:"text-[9px] font-medium text-amber-600 dark:text-amber-400",children:x})]})]})]}),c&&e.jsx(H,{variant:"ghost",size:"icon",className:"h-6 w-6",children:i?e.jsx(Dt,{className:"h-4 w-4"}):e.jsx(Ct,{className:"h-4 w-4"})})]})]}),!i&&e.jsx("div",{className:F("space-y-2 pb-6",u?"pr-14":"pl-14"),children:a.map((p,b)=>e.jsx(Ka,{item:p,language:n,onToggle:()=>s(p.id,p.status),onDelete:()=>o(p.id),isUrgent:l==="urgent",animationDelay:b*.05},p.id))})]})},Va=({groups:t,language:r,texts:a,onToggleItem:n,onDeleteItem:s})=>e.jsxs("div",{className:"px-4 py-2",children:[e.jsx(Pe,{title:a.overdue,icon:_t,items:t.overdue,language:r,onToggleItem:n,onDeleteItem:s,variant:"urgent"}),e.jsx(Pe,{title:a.today,icon:Ar,items:t.today,language:r,onToggleItem:n,onDeleteItem:s,variant:"highlight"}),e.jsx(Pe,{title:a.tomorrow,icon:Qr,items:t.tomorrow,language:r,onToggleItem:n,onDeleteItem:s}),e.jsx(Pe,{title:a.thisWeek,icon:ze,items:t.thisWeek,language:r,onToggleItem:n,onDeleteItem:s}),e.jsx(Pe,{title:a.upcoming,icon:us,items:t.upcoming,language:r,onToggleItem:n,onDeleteItem:s,collapsible:!0,defaultCollapsed:t.upcoming.length>5}),e.jsx(Pe,{title:a.completed,icon:qe,items:t.completed,language:r,onToggleItem:n,onDeleteItem:s,variant:"success",collapsible:!0,defaultCollapsed:!0})]}),Wa=({open:t,onOpenChange:r,type:a,onTypeChange:n,language:s,patientId:o,onSubmit:l,isLoading:c,texts:d})=>{const[i,g]=j.useState(""),[u,f]=j.useState(""),[h,y]=j.useState(""),[x,p]=j.useState(""),[b,w]=j.useState(""),[T,k]=j.useState(""),[v,P]=j.useState("medium"),[A,M]=j.useState(""),D=s==="he",{data:L=[]}=ne({queryKey:["saved-doctors",o],queryFn:async()=>{if(!o)return[];const{data:S,error:U}=await R.from("saved_doctors").select(` 84 doctor_id, 85 doctors:doctor_id (id, full_name, specialty, hospital) 86 `).eq("patient_id",o);if(U)throw U;return(S==null?void 0:S.map(I=>
86I.doctors).filter(Boolean))||[]},enabled:!!o&&(a==="appointment"||a==="test")});j.useEffect(()=>{t&&(g(""),f(""),y(""),p(""),w(""),k(""),P("medium"),M(""))},[t,a]);const m=S=>{S.preventDefault(),i.trim()&&l({title:i.trim(),due_date:u||void 0,due_time:h||void 0,type:a,notes:x.trim()||void 0,location:b.trim()||void 0,doctor_id:T||void 0,priority:v,reminder_minutes:A?parseInt(A):void 0})},N={task:{icon:me,color:"emerald",bgColor:"bg-emerald-100 dark:bg-emerald-900/40",textColor:"text-emerald-600 dark:text-emerald-400",title:D?"×ש××× ××ש×":"New Task",placeholder:D?"×× ×¦×¨×× ×עש×ת?":"What needs to be done?",showTime:!1,showLocation:!1,showDoctor:!1,showReminder:!1,showPriority:!0},appointment:{icon:ie,color:"blue",bgColor:"bg-blue-100 dark:bg-blue-900/40",textColor:"text-blue-600 dark:text-blue-400",title:D?"ת×ר ××ש":"New Appointment",placeholder:D?"××ש×: ×״ר ××× - ××× ×§××××××":"e.g., Dr. Smith - Oncology",showTime:!0,showLocation:!0,showDoctor:!0,showReminder:!0,showPriority:!1},medication:{icon:oe,color:"purple",bgColor:"bg-purple-100 dark:bg-purple-900/40",textColor:"text-purple-600 dark:text-purple-400",title:D?"תר××¤× ××ש×":"New Medication",placeholder:D?"×©× ×תר××¤× ×××× ××":"Medication name and dosage",showTime:!0,showLocation:!1,showDoctor:!1,showReminder:!0,showPriority:!1},test:{icon:Ae,color:"amber",bgColor:"bg-amber-100 dark:bg-amber-900/40",textColor:"text-amber-600 dark:text-amber-400",title:D?"××××§× ××ש×":"New Test",placeholder:D?"ס×× ×××××§× (CT, MRI, ××...)":"Test type (CT, MRI, Blood...)",showTime:!0,showLocation:!0,showDoctor:!0,showReminder:!0,showPriority:!1},symptom:{icon:Me,color:"rose",bgColor:"bg-rose-100 dark:bg-rose-900/40",textColor:"text-rose-600 dar
86k:text-rose-400",title:D?"תס××× ××ש":"New Symptom",placeholder:D?"ת×ר/× ×ת ×תס×××":"Describe the symptom",showTime:!1,showLocation:!1,showDoctor:!1,showReminder:!1,showPriority:!1},note:{icon:Je,color:"slate",bgColor:"bg-slate-100 dark:bg-slate-800/40",textColor:"text-slate-600 dark:text-slate-400",title:D?"××¢×¨× ××ש×":"New Note",placeholder:D?"×× ×ר××¤× ××ר? ×× ×ר×שת×?":"What did the doctor say? How did I feel?",showTime:!1,showLocation:!1,showDoctor:!1,showReminder:!1,showPriority:!1}},E=N[a],q=E.icon,z=[{type:"task",icon:me,label:d.task},{type:"appointment",icon:ie,label:d.appointment},{type:"medication",icon:oe,label:d.medication},{type:"test",icon:Ae,label:d.test},{type:"symptom",icon:Me,label:d.symptom},{type:"note",icon:Je,label:d.note}];return e.jsx(fs,{open:t,onOpenChange:r,children:e.jsxs(hs,{side:"bottom",className:"rounded-t-3xl px-6 pt-6 pb-8 max-h-[85vh] overflow-y-auto",children:[e.jsx(ps,{className:"pb-4",children:e.jsxs(gs,{className:"flex items-center gap-3 justify-center",children:[e.jsx("div",{className:F("w-10 h-10 rounded-xl flex items-center justify-center",E.bgColor),children:e.jsx(q,{className:F("h-5 w-5",E.textColor)})}),e.jsx("span",{children:E.title}),e.jsx(Te,{className:"h-4 w-4 text-primary"})]})}),e.jsx("div",{className:"flex gap-1.5 overflow-x-auto pb-4 scrollbar-hide",children:z.map(S=>{const U=S.icon,I=a===S.type;return e.jsxs(H,{type:"button",variant:I?"default":"outline",size:"sm",onClick:()=>n(S.type),className:F("rounded-full text-xs h-8 px-3 gap-1.5 shrink-0 transition-all",I&&N[S.type].color==="emerald"&&"bg-emerald-600 hover:bg-emerald-700",I&&N[S.type].color==="blue"&&"bg-blue-600 hover:bg-blue-700",I&&N[S.type].color==="purple"&&"bg-purple-600 hover:bg-purple-700",I&&N[S.type].color==="amber"&&"bg-amber-600 hover:bg-amber-700",I&&N[S.type].color==="rose"&&"bg-rose-600 hover:bg-rose-700",I&&N[S.type].color==="slate"&&"bg-slate-600 hover:bg-slate-700"),children:[e.jsx(U,{className:"h-3 w-3"}),S.label]},S.type)})}),e.jsxs("form",{onSubmit:m,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ae,{className:"text-sm text-muted-foreground",children:D?"××תרת":"Title"}),e.jsx(ye,{value:i,onChange:S=>g(S.target.value),placeholder:E.placeholder,className:"h-12 rounded-xl text-base",autoFocus:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ae,{className:"text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4"}),D?"ת×ר××":"Date"]}),e.jsx(ye,{type:"date",value:u,onChange:S=>f(S.target.value),className:"h-12 rounded-xl"})]}),E.showTime&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ae,{className:"text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx(ie,{className:"h-4 w-4"}),D?"שע×":"Time"]}),e.jsx(ye,{type:"time",value:h,onChange:S=>y(S.target.value),className:"h-12 rounded-xl"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(H,{type:"button",variant:"outline",size:"sm",className:"rounded-full flex-1",onClick:()=>{const S=new Date().toISOString().split("T")[0];f(S)},children:D?"××××":"Today"}),e.jsx(H,{type:"button",variant:"outline",size:"sm",className:"rounded-full flex-1",onClick:()=>{const S=new Date;S.setDate(S.getDate()+1),f(S.toISOString().split("T")[0])},children:D?"××ר":"Tomorrow"}),e.jsx(H,{type:"button",variant:"outline",size:"sm",className:"rounded-full flex-1",onClick:()=>{const S=new Date;S.setDate(S.getDate()+7),f(S.toISOString().split("T")[0])},children:D?"×¢×× ×©×××¢":"Next week"})]}),E.showLocation&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ae,{className:"text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx(Ls,{className:"h-4 w-4"}),D?"×××§××":"Location"]}),e.jsx(ye,{value:b,onChange:S=>w(S.target.value),placeholder:D?"××ת ×××××, ××××§×, ××ר...":"Hospital, department, room...",className:"h-12 rounded-xl"})]}),E.showDoctor&&L.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ae,{className:"text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx(vt,{className:"h-4 w-4"}),D?"ר×פ×":"Doctor"]}),e.jsxs(ft,{value:T,onValueChange:k,children:[e.jsx(ht,{className:"h-12 rounded-xl",children:e.jsx(pt,{placeholder:D?"××ר ר××¤× (××פצ××× ××)":"Select doctor (optional)"})}),e.jsx(gt,{children:L.map(S=>e.jsxs(ke,{value:S.id,children:[S.full_name," - ",S.specialty]},S.id))})]})]}),E.showPriority&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ae,{className:"text-sm text-muted-foreground",children:D?"×¢××פ×ת":"Priority"}),e.jsx("div",{className:"flex gap-2",children:["low","medium","high","urgent"].map(S=>e.jsx(H,{type:"button",variant:v===S?"default":"outline",size:"sm",onClick:()=>P(S),className:F("rounded-full flex-1 text-xs",v===S&&S==="low"&&"bg-slate-500",v===S&&S==="medium"&&"bg-blue-500",v===S&&S==="high"&&"bg-amber-500",v===S&&S==="urgent"&&"bg-destructive"),children:D?{low:"× ××××",medium:"××× ×× ×ת",high:"×××××",urgent:"××××£"}[S]:{low:"Low",medium:"Medium",high:"High",urgent:"Urgent"}[S]},S))})]}),E.showReminder&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ae,{className:"text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx(Ye,{className:"h-4 w-4"}),D?"ת×××רת":"Reminder"]}),e.jsxs(ft,{value:A,onValueChange:M,children:[e.jsx(ht,{className:"h-12 rounded-xl",children:e.jsx(pt,{placeholder:D?"××× ×ª×××רת":"No reminder"})}),e.jsxs(gt,{children:[e.jsx(ke,{value:"15",children:D?"15 ××§×ת ××¤× ×":"15 minutes before"}),e.jsx(ke,{value:"30",children:D?"30 ××§×ת ××¤× ×":"30 minutes before"}),e.jsx(ke,{value:"60",children:D?"×©×¢× ××¤× ×":"1 hour before"}),e.jsx(ke,{value:"120",children:D?"שעת××× ××¤× ×":"2 hours before"}),e.jsx(ke,{value:"1440",children:D?"××× ××¤× ×":"1 day before"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ae,{className:"text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx(Ce,{className:"h-4 w-4"}),D?"×ער×ת":"Notes"]}),e.jsx(Er,{value:x,onChange:S=>p(S.target.value),placeholder:D?"×ער×ת × ×ספ×ת...":"Additional notes...",className:"min-h-[80px] rounded-xl resize-none"})]}),e.jsx(H,{type:"submit",disabled:!i.trim()||c,className:F("w-full h-12 rounded-xl text-base gap-2",a==="appointment"&&"bg-blue-600 hover:bg-blue-700",a==="task"&&"bg-emerald-600 hover:bg-emerald-700",a==="medication"&&"bg-purple-600 hover:bg-purple-700",a==="test"&&"bg-amber-600 hover:bg-amber-700",a==="symptom"&&"bg-rose-600 hover:bg-rose-700",a==="note"&&"bg-slate-600 hover:bg-slate-700"),
86children:c?e.jsx(de,{className:"h-5 w-5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-5 w-5"}),D?"××סף":"Add"]})})]})]})})},Qa=({language:t,onAddItem:r,texts:a})=>{const n=t==="he";return e.jsxs("div",{className:"flex flex-col items-center justify-center px-6 py-12 text-center",children:[e.jsxs("div",{className:"relative mb-8",children:[e.jsx("div",{className:"w-32 h-32 rounded-full bg-gradient-to-br from-primary/10 via-pink-500/10 to-purple-500/10 flex items-center justify-center",children:e.jsx("div",{className:"w-24 h-24 rounded-full bg-gradient-to-br from-primary/20 via-pink-500/20 to-purple-500/20 flex items-center justify-center animate-pulse",children:e.jsx(Ge,{className:"h-12 w-12 text-primary/60"})})}),e.jsx("div",{className:"absolute -top-2 -right-2 w-8 h-8 rounded-lg bg-blue-100 dark:bg-blue-900/40 flex items-center justify-center animate-bounce",style:{animationDelay:"0.1s"},children:e.jsx(ie,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"})}),e.jsx("div",{className:"absolute -bottom-2 -left-2 w-8 h-8 rounded-lg bg-emerald-100 dark:bg-emerald-900/40 flex items-center justify-center animate-bounce",style:{animationDelay:"0.3s"},children:e.jsx(me,{className:"h-4 w-4 text-emerald-600 dark:text-emerald-400"})}),e.jsx("div",{className:"absolute top-1/2 -right-6 w-6 h-6 rounded-full bg-purple-100 dark:bg-purple-900/40 flex items-center justify-center animate-bounce",style:{animationDelay:"0.5s"},children:e.jsx(oe,{className:"h-3 w-3 text-purple-600 dark:text-purple-400"})}),e.jsx("div",{className:"absolute top-1/4 -left-4 w-6 h-6 rounded-full bg-amber-100 dark:bg-amber-900/40 flex items-center justify-center animate-bounce",style:{animationDelay:"0.7s"},children:e.jsx(Ae,{className:"h-3 w-3 text-amber-600 dark:text-amber-400"})})]}),e.jsxs("h2",{className:"text-xl font-bold text-foreground mb-2 flex items-center gap-2",children:[a.noItems,e.jsx(Te,{className:"h-5 w-5 text-primary"})]}),e.jsx("p",{className:"text-muted-foreground mb-8 max-w-xs",children:n?"××××× ×©×× ××ת×× ××. ××ס××¤× ×ª×ר××, תר×פ×ת, ××××§×ת ××ש×××ת ×× ×××× ××× ××תר ×©× ×××פ××.":"Your diary awaits. Add appointments, medications, tests and tasks to better manage your care."}),e.jsxs("div",{className:"flex flex-wrap gap-2 justify-center",children:[e.jsxs(H,{onClick:()=>r("appointment"),className:"gap-2 bg-blue-600 hover:bg-blue-700 rounded-xl px-4",children:[e.jsx(ie,{className:"h-4 w-4"}),a.appointment]}),e.jsxs(H,{onClick:()=>r("medication"),className:"gap-2 bg-purple-600 hover:bg-purple-700 rounded-xl px-4",children:[e.jsx(oe,{className:"h-4 w-4"}),a.medication]}),e.jsxs(H,{onClick:()=>r("task"),variant:"outline",className:"gap-2 rounded-xl px-4",children:[e.jsx(me,{className:"h-4 w-4"}),a.task]})]})]})},Ga=({patientId:t,language:r,className:a})=>{const{toast:n}=ve(),s=tt();j.useState("timeline"),j.useState(new Date);const[o,l]=j.useState(!1),[c,d]=j.useState("task"),[i,g]=j.useState("all"),[u,f]=j.useState(""),h=r==="he",y=j.useMemo(()=>({title:h?"××××× ×©××":"My Diary",subtitle:h?"××× ×××§×× ×××":"Everything in one place",today:h?"××××":"Today",tomorrow:h?"××ר":"Tomorrow",thisWeek:h?"×ש×××¢":"This Week",upcoming:h?"קר××":"Upcoming",overdue:h?"×××××ר":"Overdue",completed:h?"××ש××":"Completed",noItems:h?"××××× ×¨××§":"Diary is empty",addFirst:h?"××ס××¤× ×ת ×פר×× ×ר×ש××":"Add your first item",task:h?"×ש×××":"Task",appointment:h?"ת×ר":"Appointment",medication:h?"תר×פ×":"Medication",test:h?"××××§×":"Test",symptom:h?"תס×××":"Symptom",note:h?"×ער×":"Note",all:h?"×××":"All",tasks:h?"×ש×××ת":"Tasks",appointments:h?"ת×ר××":"Appointments",medications:h?"תר×פ×ת":"Medications",tests:h?"××××§×ת":"Tests",itemAdded:h?"× ×סף ××צ×××":"Added successfully",itemUpdated:h?"×¢×××× ××צ×××":"Updated successfully",itemDeleted:h?"× ×××§":"Deleted",search:h?"××פ×ש...":"Search...",at:h?"×-":"at"}),[h]),{data:x=[],isLoading:p}=ne({queryKey:Tr.diaryItems(t),queryFn:async()=>
86{if(!t)return[];const{data:m,error:N}=await R.from("tasks").select(` 87 id, title, due_date, due_time, status, type, 88 priority, category, notes, location, doctor_id, 89 reminder_minutes, created_at, 90 doctors:doctor_id (full_name, specialty, hospital) 91 `).eq("patient_id",t).order("due_date",{ascending:!0,nullsFirst:!1});if(N)throw N;return(m||[]).map(E=>({...E,doctor:E.doctors}))},enabled:!!t}),b=_e({mutationFn:async({id:m,currentStatus:N})=>{const E=N==="open"?"done":"open",{error:q}=await R.from("tasks").update({status:E}).eq("id",m);if(q)throw q},onSuccess:()=>{dt(s,t)}}),w=_e({mutationFn:async m=>{const{error:N}=await R.from("tasks").delete().eq("id",m);if(N)throw N},onSuccess:()=>{dt(s,t),n({title:y.itemDeleted})}}),T=_e({mutationFn:async m=>{if(!t)return;let N="task",E=null;m.type==="appointment"?N="appointment":m.type==="medication"?(N="task",E="medication"):m.type==="test"?(N="task",E="test"):m.type==="symptom"?(N="task",E="symptom"):m.type==="note"&&(N="task",E="note");const{error:q}=await R.from("tasks").insert({patient_id:t,title:m.title,due_date:m.due_date||null,due_time:m.due_time||null,type:N,category:m.category||E,notes:m.notes||null,location:m.location||null,doctor_id:m.doctor_id||null,priority:m.priority||"medium",reminder_minutes:m.reminder_minutes||null});if(q)throw q},onSuccess:()=>{dt(s,t),l(!1),n({title:y.itemAdded})}}),k=j.useMemo(()=>x.filter(m=>{var N,E,q;if(i==="tasks"&&(m.type!=="task"||m.category)||i==="appointments"&&m.type!=="appointment"||i==="medications"&&m.category!=="medication"||i==="tests"&&m.category!=="test")return!1;if(u){const z=u.toLowerCase(),S=m.title.toLowerCase().includes(z),U=(N=m.notes)==null?void 0:N.toLowerCase().includes(z),I=(E=m.location)==null?void 0:E.toLowerCase().includes(z),se=(q=m.doctor)==null?void 0:q.full_name.toLowerCase().includes(z);return S||U||I||se}return!0}),[x,i,u]),v=j.useMemo(()=>{const m=new Date;m.setHours(0,0,0,0);const N=new Date(m);N.setDate(N.getDate()+1);const E=new Date(m);E.setDate(E.getDate()+7);const q={overdue:[],today:[],tomorrow:[],thisWeek:[],upcoming:[],completed:[]};k.forEach(S=>{if(S.status==="done"){q.completed.push(S);return}if(!S.due_date){q.upcoming.push(S);return}const U=Dr(S.due_date);U.setHours(0,0,0,0),U<m?q.overdue.push(S):U.getTime()===m.getTime()?q.today.push(S):U.getTime()===N.getTime()?q.tomorrow.push(S):U<=E?q.thisWeek.push(S):q.upcoming.push(S)});const z=(S,U)=>!S.due_time&&!U.due_time?0:S.due_time?U.due_time?S.due_time.localeCompare(U.due_time):-1:1;return q.today.sort(z),q.tomorrow.sort(z),q.thisWeek.sort(z),q},[k]),P=m=>{d(m),l(!0)},A=(m,N)=>{b.mutate({id:m,currentStatus:N})},M=m=>{w.mutate(m)},D=m=>{T.mutate(m)},L=j.useMemo(()=>{const m=x.filter(N=>N.status==="open");return{total:m.length,overdue:v.overdue.length,today:v.today.length,completed:v.completed.length,medications:m.filter(N=>N.category==="medication").length,appointments:m.filter(N=>N.type==="appointment").length,tests:m.filter(N=>N.category==="test").length}},[x,v]);return p?e.jsx("div",{className:F("flex items-center justify-center min-h-[400px]",a),children:e.jsx(de,{className:"h-8 w-8 animate-spin text-primary/50"})}):e.jsxs("div",{className:F("flex flex-col h-full bg-background",a),dir:h?"rtl":"ltr",children:[e.jsx(Ia,{language:r,stats:L,filter:i,onFilterChange:g,onAddItem:P,searchQuery:u,onSearchChange:f,texts:y}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsx("div",{className:"px-4 pt-3",children:e.jsx(Mr,{patientId:t,trigger:"page_load",compact:!0})}),x.length===0?e.jsx(Qa,{language:r,onAddItem:P,texts:y}):k.length===0?e.jsx("div",{className:"flex flex-col items-center justify-center py-12 px-4 text-center",children:e.jsx("p",{className:"text-muted-foreground",children:h?"×× × ×צ×× ×ª×צ××ת":"No results found"})}):e.jsx(Va,{groups:v,language:r,texts:y,onToggleItem:A,onDeleteItem:M})]}),e.jsx(Wa,{open:o,onOpenChange:l,type:c,onTypeChange:d,language:r,patientId:t,onSubmit:D,isLoading:T.isPending,texts:y})]})},Ya=({className:t})=>e.jsx("img",{src:"/smadar-logo.jpg",alt:"Smadar",className:F("rounded-full object-cover",t)}),Ja=({patientId:t,currentStage:r,language:a,patientRegion:n,diagnosisText:s,onDiagnosisClick:o,onRecordingComplete:l,onQuickAction:c,children:d})=>{const i=er();Oe();const{t:g}=ce(),{badges:u}=Gr(t),[f,h]=j.useState(),[y,x]=j.useState(2),[p,b]=j.useState(!1),[w,T]=j.useState(null),{data:k=0}=ne({queryKey:["recordings-count",t],queryFn:async()=>
91{if(!t)return 0;const{count:m}=await R.from("recordings").select("id",{count:"exact",head:!0}).eq("patient_id",t).eq("status","completed");return m||0},enabled:!!t}),v=a==="he",P=i.pathname==="/auth";j.useEffect(()=>{if(!f)return;f.scrollTo(2,!0);const m=()=>{x(f.selectedScrollSnap())};return f.on("select",m),()=>{f.off("select",m)}},[f]);const A=j.useCallback(m=>{f&&f.scrollTo(m)},[f]),M=[{index:0,type:"slide",label:g("×ש×××ת","Tasks"),icon:Ir,badge:u.openTasks>0?u.openTasks:null},{index:1,type:"slide",label:g("רפ×××","Medical"),icon:je,badge:null},{index:2,type:"fab"},{index:3,type:"slide",label:g("×ר×××ת","Wellness"),icon:Ps,badge:null},{index:4,type:"slide",label:g("×¢××","More"),icon:$r,badge:null}],D=({activeTab:m,onTabClick:N,recordingsCount:E,isHebrew:q})=>{const z=[{id:"doctors",label:q?"ר×פ×××":"Doctors",icon:qs},{id:"recording",label:q?"××§×××":"Record",icon:Se},{id:"summaries",label:q?"ס××××××":"Summaries",icon:Ce,badge:E>0?E:null},{id:"documents",label:q?"×ס××××":"Docs",icon:Cs},{id:"fhir",label:"FHIR",icon:Ts}];return e.jsx("div",{className:"flex items-center justify-around",children:z.map(S=>{const U=S.icon,I=m===S.id;return e.jsxs("button",{onClick:()=>N(S.id),className:F("relative flex flex-col items-center gap-1 py-1.5 px-3 rounded-xl transition-all duration-200","active:scale-95",I?"text-primary":"text-muted-foreground hover:text-foreground"),children:[S.badge&&e.jsx(ue,{variant:"default",className:"absolute -top-1 -right-1 h-4 min-w-4 px-1 text-[9px] font-bold",children:S.badge}),e.jsx(U,{className:F("h-5 w-5",I&&"scale-110")}),e.jsx("span",{className:"text-[10px] font-medium",children:S.label})]},S.id)})})},L=m=>{c==null||c(m),b(!1)};return P?e.jsx(e.Fragment,{children:d}):e.jsxs("div",{className:"min-h-screen flex flex-col",children:[e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx($s,{opts:{align:"start",loop:!1,direction:v?"rtl":"ltr",watchDrag:!0},setApi:h,className:"w-full h-full",children:e.jsxs(Us,{className:"h-full -ml-0",children:[e.jsx(Le,{className:"pl-0 h-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-background pb-20",dir:v?"rtl":"ltr",children:e.jsx(Ga,{patientId:t,language:a,className:"h-full"})})}),e.jsx(Le,{className:"pl-0 h-full overflow-auto",children:e.jsx("div",{className:"h-full bg-background",dir:v?"rtl":"ltr",children:e.jsx($a,{patientId:t,patientRegion:n,diagnosisText:s,language:a,onRecordingComplete:l,activeTab:w})})}),e.jsx(Le,{className:"pl-0 h-full overflow-auto",children:d}),e.jsx(Le,{className:"pl-0 h-full overflow-auto",children:e.jsx("div",{className:"min-h-screen bg-background pb-24 p-4",dir:v?"rtl":"ltr",children:e.jsx(Ua,{language:a})})}),e.jsx(Le,{className:"pl-0 h-full overflow-auto",children:e.jsx("div",{className:"min-h-screen bg-background pb-24",dir:v?"rtl":"ltr",children:e.jsx(Ea,{onDiagnosisClick:o})})})]})})}),y===1&&e.jsx("div",{className:F("fixed left-1/2 -translate-x-1/2 z-50","bottom-[76px] w-full md:bottom-24 md:w-auto md:min-w-[400px] md:max-w-[500px]","bg-card/95 backdrop-blur-lg border-t md:border border-border/50 md:rounded-2xl md:shadow-2xl","px-2 py-2"),children:e.jsx(D,{activeTab:w,onTabClick:m=>T(w===m?null:m),recordingsCount:k,isHebrew:v})}),e.jsxs("nav",{role:"tablist","aria-label":g("× ×××× ×¨×ש×","Main Navigation"),className:F("fixed z-50 safe-area-bottom","bottom-0 left-0 right-0","md:bottom-6 md:left-1/2 md:-translate-x-1/2 md:right-auto","md:w-auto md:min-w-[420px] md:max-w-[500px]","bg-card/95 backdrop-blur-xl border-t md:border border-border/50","md:rounded-2xl md:shadow-2xl md:shadow-black/10"),children:[e.jsx("div",{className:"flex justify-center gap-1.5 pt-2 pb-1",children:[0,1,2,3,4].map(m=>e.jsx("div",{className:F("h-1 rounded-full transition-all duration-300",y===m?"w-4 bg-primary":"w-1 bg-muted-foreground/30")},m))}),e.jsx("div",{className:"flex items-center justify-around h-16 px-4",children:M.map((m,N)=>{if(m.type==="fab")return e.jsx("button",{onClick:()=>A(2),className:F("relative -top-5 w-16 h-16 rounded-full shadow-xl shadow-primary/20 flex items-center justify-center active:scale-95 transition-all duration-300 overflow-hidden","bg-card","border-4 border-card","ring-2 ring-primary/20",y===2&&"ring-4 ring-primary/40 scale-105"),"aria-label":g("××ת","Home"),children:e.jsx(Ya,{className:"w-12 h-12"})},"fab");if(m.type==="slide"){const E=m.icon,q=y===m.index;return e.jsxs("button",{onClick:()=>A(m.index),onKeyDown:z=>{(z.key==="Enter"||z.key===" ")&&(z.preventDefault(),A(m.index))},tabIndex:0,role:"tab","aria-selected":q,"aria-label":m.label,className:F("relative flex flex-col items-center justify-center py-2 px-4 roun
91ded-xl transition-all duration-200",q?"text-primary":"text-muted-foreground hover:text-foreground"),children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:F("p-1.5 rounded-lg transition-all duration-200",q&&"bg-primary/10"),children:e.jsx(E,{className:F("h-5 w-5",q&&"scale-110")})}),m.badge&&e.jsx(ue,{variant:"destructive",className:"absolute -top-2 -right-2 min-w-[18px] h-[18px] p-0 flex items-center justify-center text-[10px] badge-bounce",children:m.badge})]}),e.jsx("span",{className:"text-[10px] mt-0.5 font-medium",children:m.label})]},m.index)}return null})})]}),e.jsx(Ra,{open:p,onOpenChange:b,onAction:L})]})},Xa=({patientId:t,patientName:r})=>{const{t:a,language:n}=ce(),s=n==="he",{data:o}=ne({queryKey:["patient-profile",t],queryFn:async()=>{if(!t)return null;const{data:y}=await R.from("patients").select("cancer_type, cancer_stage").eq("id",t).maybeSingle();return y},enabled:!!t}),{data:l}=ne({queryKey:["treatments-timeline",t],queryFn:async()=>{if(!t)return[];const{data:y}=await R.from("treatments").select("*").eq("patient_id",t).eq("status","active").order("start_date",{ascending:!0});return y||[]},enabled:!!t}),{data:c}=ne({queryKey:["next-appointment",t],queryFn:async()=>{if(!t)return null;const y=new Date().toISOString().split("T")[0],{data:x}=await R.from("tasks").select("*").eq("patient_id",t).eq("type","appointment").neq("status","done").gte("due_date",y).order("due_date",{ascending:!0}).limit(1).maybeSingle();return x},enabled:!!t}),d=l==null?void 0:l[0];let i=0,g=12;if(d!=null&&d.start_date){const y=new Date(d.start_date),p=new Date().getTime()-y.getTime();if(i=Math.max(1,Math.ceil(p/(7*24*60*60*1e3))),d.end_date){const b=new Date(d.end_date);g=Math.max(1,Math.ceil((b.getTime()-y.getTime())/(7*24*60*60*1e3)))}}const u=d?Math.min(100,i/g*100):0,f=o!=null&&o.cancer_type?`${o.cancer_type}${o.cancer_stage?` â ${a("ש××","Stage")} ${o.cancer_stage}`:""}`:a("×× ××××ר ס××","Type not set"),h=c?`${ge(new Date(c.due_date),s?"dd/MM":"MMM dd",{locale:s?Fe:void 0})} â ${c.title}`:a("×× × ×§××¢ ××פ××","No treatment scheduled");return e.jsx(Ze,{className:"border-0 bg-gradient-to-br from-primary/10 via-secondary to-accent/20 shadow-md",children:e.jsxs(et,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/15",children:e.jsx(Me,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h2",{className:"text-lg font-bold text-foreground truncate",children:r||a("×××פ×","Patient")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:f})]})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-4 p-2.5 rounded-lg bg-card/60 backdrop-blur-sm",children:[e.jsx(ze,{className:"h-4 w-4 text-primary shrink-0"}),e.jsxs("span",{className:"text-sm font-medium text-foreground",children:[a("×××פ×× ×××:","Next treatment:")," ",h]})]}),d&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground mb-1.5",children:[e.jsx("span",{children:a("×תק×××ת ×פר××××§××","Protocol progress")}),e.jsx("span",{children:a(`ש×××¢ ${i} ×ת×× ${g}`,`Week ${i} of ${g}`)})]}),e.jsx(Pr,{value:u,className:"h-2.5 bg-muted"})]})]})})},Za=()=>{const{t}=ce(),r=Oe(),a=[{icon:je,label:t("××× ×××ª× ××××§×ר","Prep for visit"),emoji:"ð©º",path:"/visit-prep",color:"bg-primary/10 text-primary hover:bg-primary/20"},{icon:oe,label:t("×××× ×ª×פעת ×××××","Report side effect"),emoji:"ð",path:"/side-effects",color:"bg-accent text-accent-foreground hover:bg-accent/80"},{icon:Br,label:t("ש×× ×©××× ×¨×¤×××ת","Ask medical question"),emoji:"â",path:"/dashboard",color:"bg-secondary text-secondary-foreground hover:bg-secondary/80",action:"chat"}],n=s=>{if(s.action==="chat"){r("/dashboard");return}r(s.path)};return e.jsx("div",{className:"grid grid-cols-3 gap-2.5",children:a.map(s=>e.jsxs(H,{variant:"ghost",className:`flex flex-col items-center gap-1.5 h-auto py-4 px-2 rounded-xl border border-border/50 ${s.color} transition-all active:scale-95`,onClick:()=>n(s),children:[e.jsx("span",{className:"text-2xl",children:s.emoji}),e.jsx("span",{className:"text-xs font-medium leading-tight text-center",children:s.label})]},s.path+s.label))})},en=({patientName:t})=>{const{t:r}=ce(),a=Oe(),n=t||r("××§×ר×","your loved one"),s=[{emoji:"ð",label:r("×× ×¦×¨×× ×ס×ר ×ש×××¢","What to arrange this week"),path:"/caregiver",color:"bg-primary/10 text-primary hover:bg-primary/20"},{emoji:"ð",label:r("ת×××רת תר×פ×ת","Medication reminders"),path:"/medications",color:"bg-
91accent text-accent-foreground hover:bg-accent/80"},{emoji:"ð¥",label:r("×× ××§×ת ××××§×ר","What to bring to visit"),path:"/visit-prep",color:"bg-secondary text-secondary-foreground hover:bg-secondary/80"},{emoji:"ð§ ",label:r(`×ס×ר ×× ×¢× ×××פ×× ×©× ${n}`,`Explain ${n}'s treatment`),path:"/dashboard",action:"chat-caregiver",color:"bg-primary/5 text-primary hover:bg-primary/15"}];return e.jsx("div",{className:"grid grid-cols-2 gap-2.5",children:s.map(o=>e.jsxs(H,{variant:"ghost",className:`flex flex-col items-center gap-1.5 h-auto py-4 px-2 rounded-xl border border-border/50 ${o.color} transition-all active:scale-95`,onClick:()=>a(o.path),children:[e.jsx("span",{className:"text-2xl",children:o.emoji}),e.jsx("span",{className:"text-xs font-medium leading-tight text-center",children:o.label})]},o.label))})},tn=({patientId:t})=>{const{t:r,language:a}=ce(),n=Oe(),o=a==="he"?ms:xs,{data:l}=ne({queryKey:["smart-alert-appointment",t],queryFn:async()=>{if(!t)return null;const i=new Date,g=new Date(i.getTime()+72*60*60*1e3),{data:u}=await R.from("tasks").select("*").eq("patient_id",t).eq("type","appointment").neq("status","done").gte("due_date",i.toISOString().split("T")[0]).lte("due_date",g.toISOString().split("T")[0]).order("due_date",{ascending:!0}).limit(1).maybeSingle();return u},enabled:!!t}),{data:c}=ne({queryKey:["smart-alert-symptoms",t],queryFn:async()=>{if(!t)return null;const{data:i}=await R.from("symptoms").select("created_at").eq("patient_id",t).order("created_at",{ascending:!1}).limit(1).maybeSingle();return i},enabled:!!t}),d=[];if(l&&d.push({id:"visit-soon",icon:e.jsx(Tt,{className:"h-4 w-4 text-destructive"}),text:r("â ï¸ ××××§×ר ××ª×§×¨× â ר××¦× ××ת××× ×?","â ï¸ Visit coming up â want to prepare?"),action:r("×ת××× ×","Prepare"),path:"/visit-prep",variant:"warning"}),c){const i=new Date(c.created_at),g=new Date(Date.now()-3*24*60*60*1e3);i<g&&d.push({id:"no-symptoms",icon:e.jsx(oe,{className:"h-4 w-4 text-primary"}),text:r("ð ×× ×××××ת ×ש×××¢ â ××× ×ס×ר?","ð No report this week â feeling OK?"),action:r("××××","Report"),path:"/side-effects",variant:"info"})}else t&&d.push({id:"no-symptoms-ever",icon:e.jsx(oe,{className:"h-4 w-4 text-primary"}),text:r("ð ×× ×××××ת ×¢×××× â ××× ×ס×ר?","ð No reports yet â feeling OK?"),action:r("××××","Report"),path:"/side-effects",variant:"info"});return d.length===0?null:e.jsx("div",{className:"space-y-2",children:d.map(i=>e.jsxs("button",{onClick:()=>n(i.path),className:`w-full flex items-center gap-3 p-3.5 rounded-xl text-start transition-all active:scale-[0.98] ${i.variant==="warning"?"bg-destructive/10 border border-destructive/20":"bg-primary/5 border border-primary/15"}`,children:[i.icon,e.jsx("span",{className:"flex-1 text-sm font-medium text-foreground",children:i.text}),e.jsx(o,{className:"h-4 w-4 text-muted-foreground shrink-0"})]},i.id))})},sn=({patientId:t})=>{const{t:r,language:a}=ce(),n=a==="he",[s,o]=j.useState(null),{data:l}=ne({queryKey:["timeline-diagnosis",t],queryFn:async()=>{if(!t)return null;const{data:u}=await R.from("patient_state").select("diagnosis_text, diagnosis_status").eq("patient_id",t).maybeSingle();return u},enabled:!!t}),{data:c}=ne({queryKey:["timeline-treatments",t],queryFn:async()=>{if(!t)return[];const{data:u}=await R.from("treatments").select("*").eq("patient_id",t).order("start_date",{ascending:!0});return u||[]},enabled:!!t}),d=[],i=new Date;(l==null?void 0:l.diagnosis_status)==="known"&&d.push({id:"diagnosis",label:r("×××× ×","Diagnosis"),date:null,type:"diagnosis",details:l.diagnosis_text||void 0,status:"completed"}),c==null||c.forEach(u=>{const f=u.start_date?new Date(u.start_date):null,h=f&&f<i;d.push({id:u.id,label:u.name||u.type,date:u.start_date,type:h?"treatment":"future",details:u.notes||void 0,status:u.status})});const g=d.filter(u=>u.type!=="future").length;return d.splice(g,0,{id:"today",label:r("××××","Today"),date:i.toISOString().split("T")[0],type:"today",status:"current"}),d.length<=1?e.jsx("div",{className:"text-center py-6 text-sm text-muted-foreground",children:r("××× × ×ª×× × ××פ×× ×¢×××× â ××סף ××פ×××× ××¨× ×××××","No treatment data yet â add treatments via the diary")}):e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground mb-4",children:r("צ×ר ××פ××","Treatment Timeline")}),e.jsx("div",{className:"overflow-x-auto pb-2 -mx-1",children:e.jsx("div",{className:"flex items-center min-w-max px-1",children:d.map((u,f)=>e.jsxs("div",{className:"flex items-center",children:[e.jsxs("button",{onClick:()=>u.type!=="today"&&o(u),className:F("flex flex-col items-center gap-1.5 px-3 py-2 rounded-xl transition-all min-w-[72px]",u.type!=="today"&&"hover:bg-muted active:scale-95 cursor-pointer",u.type==="today"&&"cursor-default"),children:[e.jsx("div",{className:F("w-8 h-8 rounded-full flex items-center justify-center border-2 transition-all",u.type==="diagnosis"&&"bg-primary border-primary text-primary-foreground",u.type==="treatment"&&"bg-primary/80 border-primary/80 text-primary-foreground",u.type==="today"&&"bg-accent border-accent-foreground
91/30 text-accent-foreground ring-2 ring-accent-foreground/20 scale-110",u.type==="future"&&"bg-muted border-muted-foreground/30 text-muted-foreground"),children:u.type==="treatment"||u.type==="diagnosis"?e.jsx(qe,{className:"h-4 w-4"}):e.jsx(Lr,{className:"h-3 w-3 fill-current"})}),e.jsx("span",{className:F("text-[10px] leading-tight text-center max-w-[64px] truncate",u.type==="today"&&"font-bold text-accent-foreground",u.type==="future"&&"text-muted-foreground",(u.type==="treatment"||u.type==="diagnosis")&&"text-muted-foreground"),children:u.label}),u.date&&e.jsx("span",{className:"text-[9px] text-muted-foreground/70",children:ge(new Date(u.date),n?"dd/MM":"MMM dd",{locale:n?Fe:void 0})})]}),f<d.length-1&&e.jsx("div",{className:F("h-0.5 w-6 shrink-0",d[f+1].type==="future"||u.type==="today"?"bg-muted-foreground/20 border-dashed":"bg-primary/50")})]},u.id))})}),e.jsx(Nt,{open:!!s,onOpenChange:()=>o(null),children:e.jsxs(wt,{className:"max-w-sm",children:[e.jsx(kt,{children:e.jsx(St,{children:s==null?void 0:s.label})}),e.jsxs("div",{className:"space-y-2 text-sm",children:[(s==null?void 0:s.date)&&e.jsx("p",{className:"text-muted-foreground",children:ge(new Date(s.date),n?"dd/MM/yyyy":"MMM dd, yyyy",{locale:n?Fe:void 0})}),(s==null?void 0:s.details)&&e.jsx("p",{children:s.details}),e.jsxs("p",{className:"text-xs text-muted-foreground capitalize",children:[r("ס×××ס:","Status:")," ",s==null?void 0:s.status]})]})]})})]})},rs="smadar_burnout_dismissed",as=14,rn=()=>{const{t}=ce(),[r,a]=j.useState(!1);j.useEffect(()=>{const s=new Date().toISOString().split("T")[0],o=localStorage.getItem("smadar_caregiver_days"),l=o?JSON.parse(o):[];l.includes(s)||(l.push(s),localStorage.setItem("smadar_caregiver_days",JSON.stringify(l)));const c=localStorage.getItem(rs);if(c){const g=new Date(c),u=new Date(Date.now()-7*24*60*60*1e3);if(g>u)return}const d=new Date(Date.now()-as*24*60*60*1e3);l.filter(g=>new Date(g)>=d).length>=as&&a(!0)},[]);const n=()=>{localStorage.setItem(rs,new Date().toISOString()),a(!1)};return r?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-foreground
91/30 backdrop-blur-sm px-6",children:e.jsxs("div",{className:"bg-card rounded-2xl shadow-xl max-w-sm w-full p-6 space-y-4 animate-in fade-in zoom-in-95",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"p-4 rounded-full bg-accent",children:e.jsx(Ie,{className:"h-8 w-8 text-accent-foreground"})})}),e.jsx("h2",{className:"text-lg font-bold text-center text-foreground",children:t("×× ×ת/× ×ש××/× ð","You matter too ð")}),e.jsx("p",{className:"text-sm text-center text-muted-foreground leading-relaxed",children:t("××ר 14 ×××× ×©×ת/× ××××× ××××¤× ××××××× â ×× ×רש×× ××ש××¢×ת×. ××× ×ש×× ××××ר ×× ×ת עצ××. ×ש ×× ××ש×× ×××ר ××ת×?","You've been caregiving daily for 14 days â that's impressive and meaningful. But don't forget about yourself. Do you have someone to talk to?")}),e.jsxs("div",{className:"rounded-xl bg-secondary/50 p-3 text-xs text-secondary-foreground space-y-1",children:[e.jsx("p",{className:"font-medium",children:t("×§×××× ×ת××××:","Support lines:")}),e.jsxs("p",{children:["ð¢ ",t('×¢××תת ער"× â 1201',"ERAN â 1201")]}),e.jsxs("p",{children:["ð¢ ",t("×¢××תת ×ש××× ××××× â *8944","For Life Association â *8944")]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(H,{onClick:n,className:"flex-1",variant:"default",children:t("ת×××, ××× ×ª×","Thanks, got it")}),e.jsx(H,{onClick:n,variant:"ghost",size:"icon",className:"shrink-0",children:e.jsx(jt,{className:"h-4 w-4"})})]})]})}):null},an=t=>{const[r,a]=j.useState([]),[n,s]=j.useState(0),o=j.useCallback(async()=>{if(!t)return;const{data:i}=await R.from("notifications").select("*").eq("patient_id",t).order("created_at",{ascending:!1}).limit(20),g=i||[];a(g),s(g.filter(u=>!u.read_at).length)},[t]),l=j.useCallback(async i=>{await R.from("notifications").update({read_at:new Date().toISOString()}).eq("id",i),a(g=>g.map(u=>u.id===i?{...u,read_at:new Date().toISOString()}:u)),s(g=>Math.max(0,g-1))},[]),c=j.useCallback(async()=>{t&&(await R.from("notifications").update({read_at:new Date().toISOString()}).eq("patient_id",t).is("read_at",null),a(i=>i.map(g=>({...g,read_at:g.read_at||new Date().toISOString()}))),s(0))},[t]);j.useEffect(()=>{if(o(),!t)return;const i=R.channel(`notifications-${t}`).on("postgres_changes",{event:"INSERT",schema:"public",table:"notifications",filter:`patient_id=eq.${t}`},g=>{const u=g.new;a(f=>[u,...f]),s(f=>f+1),"Notification"in window&&Notification.permission==="granted"&&new Notification(u.title,{body:u.body})}).subscribe();return()=>{R.removeChannel(i)}},[t,o]);const d=j.useCallback(async()=>{"Notification"in window&&Notification.permission==="default"&&await Notification.requestPermission()},[]);return{notifications:r,unreadCount:n,markAsRead:l,markAllRead:c,requestPermission:d}},nn=({patientId:t})=>{const{t:r}=ce(),{notifications:a,unreadCount:n,markAsRead:s,markAllRead:o,requestPermission:l}=an(t);return e.jsxs(Ms,{onOpenChange:c=>{c&&l()},children:[e.jsx(As,{asChild:!0,children:e.jsxs(H,{variant:"ghost",size:"icon",className:"relative","aria-label":r("×תר××ת","Notifications"),children:[e.jsx(Ye,{className:"h-5 w-5"}),n>0&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 h-4 w-4 rounded-full bg-destructive text-[10px] text-destructive-foreground flex items-center justify-center font-bold",children:n>9?"9+":n})]})}),e.jsxs(Es,{className:"w-80 p-0",align:"end",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b",children:[e.jsx("h4",{className:"text-sm font-semibold",children:r("×תר××ת","Notifications")}),n>0&&e.jsxs(H,{variant:"ghost",size:"sm",className:"h-7 text-xs gap-1",onClick:o,children:[e.jsx(Hr,{className:"h-3 w-3"}),r("ס×× ××× ×× ×§×¨×","Mark all read")]})]}),e.jsx(De,{className:"max-h-72",children:a.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:r("××× ×תר××ת","No notifications")}):e.jsx("div",{className:"divide-y",children:a.map(c=>e.jsx("button",{onClick:()=>!c.read_at&&s(c.id),className:`w-full text-start p-3 hover:bg-muted/50 transition-colors ${c.read_at?"":"bg-primary/5"}`,children:e.jsxs("div",{className:"flex items-start gap-2",children:[!c.read_at&&e.jsx("span",{className:"h-2 w-2 rounded-full bg-primary mt-1.5 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:c.title}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:c.body}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:ge(new Date(c.created_at),"dd/MM HH:mm")}
91)]}),c.severity==="urgent"&&e.jsx(ue,{variant:"destructive",className:"text-[9px] shrink-0",children:r("××××£","Urgent")})]})},c.id))})})]})]})},on=({language:t,activeMode:r,onModeChange:a})=>{const n=t==="he",s=[{id:"patient",label:n?"×××פ×/ת":"Patient",icon:qr},{id:"physician",label:n?"ר×פ×/×":"Physician",icon:je},{id:"caregiver",label:n?"×××××":"Caregiver",icon:Ie}];return e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"inline-flex bg-muted/60 backdrop-blur-sm rounded-full p-1 gap-1 border border-border/30 shadow-sm",children:s.map(o=>{const l=o.icon;return e.jsxs("button",{onClick:()=>a(o.id),className:F("flex items-center gap-1.5 px-4 py-2 rounded-full text-sm font-medium transition-all duration-300",r===o.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[e.jsx(l,{className:F("h-4 w-4 transition-transform duration-300",r===o.id&&"scale-110")}),o.label]},o.id)})})})},ln=[{he:"×× ××¡× ××××ר×ת",en:"Entry & Intro"},{he:"×××× × ××××רת ר×פ×",en:"Diagnosis & Doctor"},{he:"פ××שת ר×פ×",en:"Doctor Meeting"},{he:"× ×××× ×©×××£",en:"Ongoing Management"},{he:"×ער×ת ××§××××ת",en:"Active System"}],cn=t=>{const[r,a]=j.useState(1),[n,s]=j.useState(!0);j.useEffect(()=>{(async()=>{if(!t){s(!1);return}try{const{data:d,error:i}=await R.from("patient_state").select("current_stage").eq("patient_id",t).maybeSingle();if(i)throw i;d!=null&&d.current_stage&&a(d.current_stage)}catch(d){console.error("Error fetching patient stage:",d)}finally{s(!1)}})()},[t]);const o=j.useCallback(async c=>{if(!(!t||c<1||c>5))try{const{error:d}=await R.from("patient_state").update({current_stage:c}).eq("patient_id",t);if(d)throw d;a(c)}catch(d){console.error("Error updating stage:",d)}},[t]),l=j.useCallback(async()=>{var c,d;if(t)try{if(r===1){const{data:i}=await R.from("patients").select("first_name, health_fund").eq("id",t).maybeSingle();if(i!=null&&i.first_name&&(i!=null&&i.health_fund)){await o(2);return}}if(r===2){const[i,g]=await Promise.all([R.from("patient_state").select("diagnosis_status").eq("patient_id",t).maybeSingle(),R.from("saved_doctors").select("id").eq("patient_id",t).limit(1)]),u=((c=i.data)==null?void 0:c.diagnosis_status)==="known",f=(((d=g.data)==null?void 0:d.length)??0)>0;if(u&&f){await o(3);return}}if(r===3){const{data:i}=await R.from("recordings").select("id").eq("patient_id",t).eq("status","processed").limit(1);if(((i==null?void 0:i.length)??0)>0){await o(4);return}}if(r===4){const{data:i}=await R.from("patients").select("created_at").eq("id",t).maybeSingle();if(i!=null&&i.created_at){const g=new Date(i.created_at),u=new Date;if(u.setDate(u.getDate()-14),g<u){await o(5);return}}}}catch(i){console.error("Error checking stage advancement:",i)}},[t,r,o]);return{currentStage:r,stageNames:ln,isLoading:n,updateStage:o,checkAndAdvanceStage:l}},dn=()=>{const[t,r]=j.useState({roleType:"patient",caregiverName:null,relationToPatient:null,patientName:null,isLoading:!0});return j.useEffect(()=>{(async()=>{try{const{data:{session:n}}=await R.auth.getSession();if(!(n!=null&&n.user))return;const s=n.user.id,{data:o}=await R.from("user_roles").select("role").eq("user_id",s);let l="patient";if(o&&o.length>0){const i=o.map(g=>g.role);i.includes("healthcare_provider")?l="healthcare_provider":i.includes("caregiver")?l="caregiver":l="patient"}else{const{data:i}=await R.from("profiles").select("role_type").eq("id",s).maybeSingle();l=(i==null?void 0:i.role_type)||"patient"}const{data:c}=await R.from("profiles").select("full_name, relationship_to_patient").eq("id",s).maybeSingle();let d=null;if(l==="caregiver"){const{data:i}=await R.from("patients").select("first_name").eq("user_id",s).maybeSingle();d=(i==null?void 0:i.first_name)||null}r({roleType:l,caregiverName:(c==null?void 0:c.full_name)||null,relationToPatient:(c==null?void 0:c.relationship_to_patient)||null,patientName:d,isLoading:!1})}catch(n){console.error("Error fetching user role:",n)}finally{r(n=>({...n,isLoading:!1}))}})()},[]),t},un=(t,r)=>{const a=j.useRef(!1),n=j.useCallback(async()=>{var s,o;
91if(!(!t||!r)&&!a.current)try{if(!("serviceWorker"in navigator)||!("PushManager"in window)){console.log("Push not supported in this browser");return}const l=void 0;if(!l){console.warn("VITE_VAPID_PUBLIC_KEY not set â skipping push registration");return}const c=await navigator.serviceWorker.register("/sw.js");await navigator.serviceWorker.ready;let d=await c.pushManager.getSubscription();if(!d){if(await Notification.requestPermission()!=="granted"){console.log("Push permission denied");return}d=await c.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:mn(l).buffer})}const i=d.toJSON(),g=d.endpoint,u=((s=i.keys)==null?void 0:s.p256dh)||"",f=((o=i.keys)==null?void 0:o.auth)||"",{error:h}=await R.from("push_subscriptions").upsert({user_id:t,patient_id:r,endpoint:g,p256dh:u,auth:f,updated_at:new Date().toISOString()},{onConflict:"endpoint"});h?console.error("Failed to save push subscription:",h):(a.current=!0,console.log("Push subscription registered"))}catch(l){console.error("Push subscription error:",l)}},[t,r]);return j.useEffect(()=>{n()},[n]),{subscribe:n}};function mn(t){const r="=".repeat((4-t.length%4)%4),a=(t+r).replace(/-/g,"+").replace(/_/g,"/"),n=window.atob(a),s=new Uint8Array(n.length);for(let o=0;o<n.length;++o)s[o]=n.charCodeAt(o);return s}const eo=()=>{const{language:t,t:r}=ce();Oe(),ve();const a=tt(),n=dn(),[s,o]=j.useState(null),[l,c]=j.useState(null),[d,i]=j.useState(!0),[g,u]=j.useState(!1),[f,h]=j.useState(!1),[y,x]=j.useState("patient"),[p,b]=j.useState(""),[w,T]=j.useState(null);un(w,(s==null?void 0:s.id)||null),Or("dashboard",s==null?void 0:s.id);const k=t==="he",v=n.roleType==="caregiver";j.useEffect(()=>{!n.isLoading&&v&&x("caregiver")},[n.isLoading,v]);const{currentStage:P,stageNames:A,checkAndAdvanceStage:M}=cn((s==null?void 0:s.id)||null);j.useEffect(()=>{s!=null&&s.id&&M()},[s==null?void 0:s.id,M]),j.useEffect(()=>{(async()=>{try{const{data:{session:z}}=await R.auth.getSession();if(!(z!=null&&z.user)){window.location.href="/auth";return}u(z.user.is_anonymous??!1),T(z.user.id);const{data:S}=await R.from("patients").select("id, first_name, region").eq("user_id",z.user.id).maybeSingle();if(S){o(S);const{data:U}=await R.from("patient_state").select("id, diagnosis_status, diagnosis_text").eq("patient_id",S.id).maybeSingle();U&&(c(U),b(U.diagnosis_text||""))}else{window.location.href="/onboarding";return}}catch(z){console.error("Error fetching data:",z)}finally{i(!1)}})()},[]);const D=(q,z)=>{b(z),l&&c({...l,diagnosis_status:q?"known":"unknown",diagnosis_text:z})},L=()=>{a.invalidateQueries({queryKey:["recordings",s==null?void 0:s.id]}),a.invalidateQueries({queryKey:["action-items",s==null?void 0:s.id]})},m=q=>{q==="diagnosis"&&h(!0)},N=v?r("××× ×××××","Caregiver Board"):r("×ת××§ ש××","My File"),E=v&&n.caregiverName||(s==null?void 0:s.first_name);return e.jsx(Ja,{patientId:(s==null?void 0:s.id)||null,currentStage:P,language:t,patientRegion:(s==null?void 0:s.region)||null,diagnosisText:p,onDiagnosisClick:()=>h(!0),onRecordingComplete:L,onQuickAction:m,children:e.jsxs("div",{className:"min-h-screen bg-background pb-24 md:pb-6",dir:k?"rtl":"ltr",children:[e.jsx(sr,{title:N,patientName:E,isAnonymous:g,patientId:(s==null?void 0:s.id)||null}),e.jsx("div",{className:"max-w-2xl mx-auto px-4 flex justify-end -mt-2",children:e.jsx(nn,{patientId:(s==null?void 0:s.id)||null})}),e.jsxs("main",{className:"flex flex-col max-w-2xl mx-auto",children:[v&&(s==null?void 0:s.first_name)&&e.jsx("div",{className:"px-4 pt-3",children:e.jsxs("div",{className:"flex items-center gap-2 p-2.5 rounded-xl bg-accent/40 border border-accent-foreground/10",children:[e.jsx("span",{className:"text-lg",children:"ð¤"}),e.jsx("span",{className:"text-sm font-medium text-accent-foreground",children:r(`××××× ×ת ${s.first_name} ${n.relationToPatient?`(${n.relationToPatient})`:""}`,`Caring for ${s.first_name} ${n.relationToPatient?`(${n.relationToPatient})`:""}`)})]})}),e.jsx("div",{className:"px-4 pt-4",children:e.jsx(Xa,{patientId:(s==null?void 0:s.id)||null,patientName:(s==null?void 0:s.first_name)||null})}),e.jsx("div",{className:"px-4 pt-4",children:v?e.jsx(en,{patientName:(s==null?void 0:s.first_name)||null}):e.jsx(Za,{})}),e.jsx("div",{className:"px-4 pt-4",children:e.jsx(tn,{patientId:(s==null?void 0:s.id)||null})}),e.jsx("div",{className:"px-4 pt-5",children:e.jsx(sn,{patientId:(s==null?void 0:s.id)||null})}),e.jsx("div",{className:"px-4 pt-5",children:e.jsx(on,{language:t,activeMode:y,onModeChange:x})}),e.jsx("div",{className:"h-[50vh] min-h-[300px] px-4 pt-2",children:e.jsx(Fr,{patientId:(s==null?void 0:s.id)||null,language:t,className:"h-full",persona:y,patientContext:{name:(s==null?void 0:s.first_name)||void 0,diagnosis:(l==null?void 0:l.diagnosis_text)||void 0}})})]}),(s==null?void 0:s.id)&&e.jsx(Rr,{patientId:s.id,onDiagnosisChange:D}),v&&e.jsx(rn,{})]})})};export{eo as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.