{"version":3,"file":"PatientScopeSwitch.CL_qtzGP.mjs","names":["useId","useMemo","useState","__esmMin","ie","init_ssg_sandbox_shims","_e","pe","p","ce","init_npm_react_18_3_1","window","init_framer_CKT6jEEQ","useIsStaticRenderer","init_menoMaps","tokens","init_menoUi","ui","callDoctorRpc","init_menoSupabase","PatientScopeSwitch","isStatic","id","client","config","session","setSession","key","mode","showMine","result","setResult","reset","value","enabled","controller","inFlight","stopped","assignments","onInvited","load","counts","assignment","response","read","index","error","refresh","timer","events","event","refreshKey","choices","css","label","count","pending","description","number","active","onChange","init_PatientScopeSwitch","init_jsx_runtime"],"sources":["https:/framerusercontent.com/modules/9h1nWDGPOTx80Wt0gKUK/4519ZUlaqacLxdKjQHhE/PatientScopeSwitch.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useId,useMemo,useState}from\"react\";import{useIsStaticRenderer}from\"framer\";import{callDoctorRpc}from\"https://framerusercontent.com/modules/KGFBZr5wsBdeI4S5ZDdN/rErYkPc7NppdRCIfNqaV/menoSupabase.js\";import{tokens}from\"https://framerusercontent.com/modules/tVCqDSXfHsd06f23WSmv/tFSEtuEyMXpbOjIK8QT9/menoMaps.js\";import{ui}from\"https://framerusercontent.com/modules/HbJgAhUddkuvwT0INTir/uwbAnNIayiRJRzLwEvod/menoUi.js\";const number=new Intl.NumberFormat(\"he-IL\");const css=`\n.patient-scope-switch{display:flex;gap:8px;flex-wrap:wrap;container:patient-scopes/inline-size}\n.patient-scope-switch button{white-space:nowrap;gap:10px;min-height:44px;font-size:14px;padding:10px 16px}\n.patient-scope-switch .patient-scope-count{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;min-width:26px;height:24px;padding-inline:7px;border-radius:999px;font-size:12px;font-weight:600;line-height:1;font-variant-numeric:tabular-nums;color:${tokens.tobaccoText};background:${tokens.navSelected}}\n.patient-scope-switch button[aria-pressed=\"true\"] .patient-scope-count{background:${tokens.bone}}\n.patient-scope-switch .patient-scope-count[data-pending=\"true\"]{opacity:.65}\n@container patient-scopes (max-width:520px){.patient-scope-switch button{flex:1 0 auto;padding:10px 12px;font-size:13px;gap:7px}}\n.patient-scope-short{display:none}\n@media(max-width:767px){\n .patient-scope-switch{padding:10px 12px 0!important;gap:4px;flex-wrap:nowrap}\n .patient-scope-switch button{flex:1 1 0;min-width:0;min-height:46px;font-size:13px;padding:8px 6px;gap:5px;box-shadow:none!important}\n .patient-scope-long{display:none}.patient-scope-short{display:inline}\n .patient-scope-switch .patient-scope-count{min-width:20px;height:20px;padding-inline:4px;font-size:11px}\n}\n`;/** Patient totals for the two existing, permission-scoped directory views.\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function PatientScopeSwitch({config={supabaseUrl:\"\",supabaseAnonKey:\"\"},active=\"mine\",onChange=()=>{},mode=\"directory\",enabled=false,showMine=true,onInvited,refreshKey=0,style}){const isStatic=useIsStaticRenderer();const id=useId();const client=useMemo(()=>config,[config.supabaseUrl,config.supabaseAnonKey]);const[session,setSession]=useState(0);const key=JSON.stringify([client,mode,showMine,session]);const[result,setResult]=useState({key:\"\"});useEffect(()=>{const reset=()=>setSession(value=>value+1);window.addEventListener(\"meno-doctor-session-change\",reset);window.addEventListener(\"meno-patient-directory-invalidated\",reset);return()=>{window.removeEventListener(\"meno-doctor-session-change\",reset);window.removeEventListener(\"meno-patient-directory-invalidated\",reset);};},[]);useEffect(()=>{if(!enabled||isStatic)return;const controller=new AbortController;let inFlight=false,stopped=false;const assignments=showMine?[\"all\",\"mine\"]:[\"all\"];if(mode===\"directory\"&&onInvited)assignments.push(\"invited\");async function load(){if(inFlight||stopped||controller.signal.aborted||document.visibilityState===\"hidden\")return;inFlight=true;const counts={key};try{const reads=mode===\"directory\"?await callDoctorRpc(client,\"formidable_clinic_patient_directory_counts\",{},{signal:controller.signal,timeoutMs:15e3}).then(counts=>assignments.map(assignment=>{const value=counts[assignment];if(!Number.isSafeInteger(value)||value===null||value<0)throw new Error(\"invalid_response\");return{status:\"fulfilled\",value};})):await Promise.allSettled(assignments.map(async assignment=>{const response=await callDoctorRpc(client,\"clinic_expiring_patients\",{p_assignment:assignment,p_query:null,p_offset:0},{signal:controller.signal});if(!Number.isSafeInteger(response?.total_count)||response.total_count<0)throw new Error(\"invalid_response\");return response.total_count;}));reads.forEach((read,index)=>{if(read.status===\"fulfilled\")counts[assignments[index]]=read.value;else{counts.failed=true;const error=read.reason;if(error.status===401||error.status===403||/clinic_access_denied|session_inactive/.test(error.message||\"\"))stopped=true;}});if(!controller.signal.aborted)setResult(counts);}catch{if(!controller.signal.aborted)setResult({key,failed:true});}finally{inFlight=false;}}setResult({key});void load();const refresh=()=>void load(),timer=window.setInterval(refresh,3e4);const events=[\"focus\",\"online\",\"meno:crm-changed\",\"meno-clinic-care-change\",\"meno-clinic-prescriptions-change\"];events.forEach(event=>window.addEventListener(event,refresh));document.addEventListener(\"visibilitychange\",refresh);return()=>{controller.abort();window.clearInterval(timer);events.forEach(event=>window.removeEventListener(event,refresh));document.removeEventListener(\"visibilitychange\",refresh);};},[key,enabled,isStatic,refreshKey]);const counts=enabled&&!isStatic&&result.key===key?result:undefined;const choices=showMine?[\"all\",\"mine\"]:[\"all\"];if(mode===\"directory\"&&onInvited)choices.push(\"invited\");return /*#__PURE__*/_jsxs(\"div\",{dir:\"rtl\",className:\"patient-scope-switch\",role:\"group\",\"aria-label\":mode===\"directory\"?\"מטופלים אישיים ומטופלי המרפאה\":\"שיוך המטופלים\",style:style,children:[/*#__PURE__*/_jsx(\"style\",{children:css}),choices.map(assignment=>{const label=assignment===\"invited\"?\"הזמנות ממתינות\":assignment===\"mine\"?\"המטופלים שלי\":\"כל מטופלי המרפאה\",count=counts?.[assignment];const pending=count===undefined&&!counts?.failed;const description=count===undefined?pending?\"טוענים את מספר המטופלים\":\"מספר המטופלים אינו זמין כרגע\":`${number.format(count)} מטופלים`;return /*#__PURE__*/_jsxs(\"button\",{type:\"button\",\"aria-label\":label,\"aria-describedby\":id+assignment,\"aria-pressed\":active===assignment,style:{...active===assignment?ui.primaryButton:ui.secondaryButton,fontSize:undefined,padding:undefined,gap:undefined,minHeight:undefined},onClick:()=>assignment===\"invited\"?onInvited?.():onChange(assignment),children:[/*#__PURE__*/_jsx(\"span\",{className:\"patient-scope-long\",children:label}),/*#__PURE__*/_jsx(\"span\",{className:\"patient-scope-short\",\"aria-hidden\":\"true\",children:assignment===\"all\"?\"המרפאה\":assignment===\"mine\"?\"שלי\":\"ממתינים\"}),/*#__PURE__*/_jsx(\"span\",{id:id+assignment,className:\"patient-scope-count\",\"aria-label\":description,\"data-pending\":pending,title:description,children:/*#__PURE__*/_jsx(\"bdi\",{\"aria-hidden\":\"true\",children:count===undefined?pending?\"…\":\"—\":number.format(count)})})]},assignment);})]});}\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"PatientScopeSwitch\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"A,6RAiBG,SAAwBoB,EAAmB,CAAC,SAAO,CAAC,YAAY,GAAG,gBAAgB,EAAE,EAAE,SAAO,OAAO,eAAa,CAAC,EAAE,OAAK,YAAY,UAAQ,GAAM,WAAS,GAAK,YAAU,aAAW,EAAE,SAAO,CAAC,IAAMC,EAASR,EAAoB,EAAQS,EAAGtB,EAAM,EAAQuB,EAAOtB,MAAYuB,EAAO,CAACA,EAAO,YAAYA,EAAO,eAAe,CAAC,EAAO,CAACC,EAAQC,GAAYxB,EAAS,CAAC,EAAQyB,EAAI,KAAK,UAAU,CAACJ,EAAOK,EAAKC,EAASJ,CAAO,CAAC,EAAO,CAACK,EAAOC,GAAW7B,EAAS,CAAC,IAAI,EAAE,CAAC,EAAEO,MAAc,CAAC,IAAMuB,MAAUN,EAAW,GAAOO,EAAM,CAAC,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