SCGR commited on
Commit
9579cfb
Β·
1 Parent(s): 33b2bfa

admin loading state

Browse files
frontend/src/pages/AdminPage/AdminPage.tsx CHANGED
@@ -549,14 +549,6 @@ Model "${newModelData.label}" added successfully!
549
  if (!isAuthenticated) {
550
  return (
551
  <PageContainer>
552
- {/* Login Loading State */}
553
- {isLoggingIn && (
554
- <div className={uploadStyles.loadingContainer}>
555
- <Spinner className="text-ifrcRed" />
556
- <p className={uploadStyles.loadingText}>Logging in...</p>
557
- </div>
558
- )}
559
-
560
  <div className="mx-auto max-w-md px-4 sm:px-6 lg:px-8 py-6 sm:py-10">
561
  <div className="text-center mb-8">
562
  <Heading level={2}>Admin Login</Heading>
@@ -576,6 +568,7 @@ Model "${newModelData.label}" added successfully!
576
  placeholder="Enter admin password"
577
  required
578
  className="w-full"
 
579
  />
580
  </div>
581
 
@@ -587,15 +580,21 @@ Model "${newModelData.label}" added successfully!
587
 
588
  <div className="flex justify-center">
589
  <Container withInternalPadding className="p-2">
590
- <Button
591
- name="login"
592
- type="submit"
593
- variant="primary"
594
- size={2}
595
- disabled={isLoggingIn}
596
- >
597
- Login
598
- </Button>
 
 
 
 
 
 
599
  </Container>
600
  </div>
601
  </form>
 
549
  if (!isAuthenticated) {
550
  return (
551
  <PageContainer>
 
 
 
 
 
 
 
 
552
  <div className="mx-auto max-w-md px-4 sm:px-6 lg:px-8 py-6 sm:py-10">
553
  <div className="text-center mb-8">
554
  <Heading level={2}>Admin Login</Heading>
 
568
  placeholder="Enter admin password"
569
  required
570
  className="w-full"
571
+ disabled={isLoggingIn}
572
  />
573
  </div>
574
 
 
580
 
581
  <div className="flex justify-center">
582
  <Container withInternalPadding className="p-2">
583
+ {isLoggingIn ? (
584
+ <div className={uploadStyles.loadingContainer}>
585
+ <Spinner className="text-ifrcRed" />
586
+ <p className={uploadStyles.loadingText}>Logging in...</p>
587
+ </div>
588
+ ) : (
589
+ <Button
590
+ name="login"
591
+ type="submit"
592
+ variant="primary"
593
+ size={2}
594
+ >
595
+ Login
596
+ </Button>
597
+ )}
598
  </Container>
599
  </div>
600
  </form>
py_backend/static/assets/{AdminPage-a1ONalH9.js β†’ AdminPage-QC43WsfP.js} RENAMED
@@ -1,4 +1,4 @@
1
- import{r as t,j as a,N as D,H as Z,_ as Ae,I as Ie,O as h,z as f,n as d,J as b}from"./index-BCz4bkWK.js";import{u as Pe}from"./useAdmin-LSEnRjVv.js";const $e="_adminContainer_j11pf_5",Le="_adminHeader_j11pf_13",Ee="_adminSection_j11pf_20",Be="_modelSelectionArea_j11pf_29",Oe="_modelSelectionRow_j11pf_36",De="_modelsTable_j11pf_89",Re="_promptSubsection_j11pf_97",Ue="_promptSubsectionTitle_j11pf_109",ze="_modelCode_j11pf_152",He="_modelId_j11pf_157",Je="_modelActions_j11pf_163",Ge="_addModelButtonContainer_j11pf_169",Ve="_addModelForm_j11pf_177",Ke="_addModelFormTitle_j11pf_185",We="_addModelFormGrid_j11pf_193",qe="_addModelFormField_j11pf_206",Ye="_addModelFormCheckbox_j11pf_250",Qe="_addModelFormActions_j11pf_268",Xe="_modalOverlay_j11pf_277",Ze="_modalContent_j11pf_291",ea="_modalBody_j11pf_302",aa="_modalTitle_j11pf_312",la="_modalText_j11pf_320",sa="_modalTextLeft_j11pf_332",oa="_modalButtons_j11pf_355",ta="_modalForm_j11pf_363",da="_formField_j11pf_372",ia="_formLabel_j11pf_376",na="_formInput_j11pf_385",ra="_textarea_j11pf_407",l={adminContainer:$e,adminHeader:Le,adminSection:Ee,modelSelectionArea:Be,modelSelectionRow:Oe,modelsTable:De,promptSubsection:Re,promptSubsectionTitle:Ue,modelCode:ze,modelId:He,modelActions:Je,addModelButtonContainer:Ge,addModelForm:Ve,addModelFormTitle:Ke,addModelFormGrid:We,addModelFormField:qe,addModelFormCheckbox:Ye,addModelFormActions:Qe,modalOverlay:Xe,modalContent:Ze,modalBody:ea,modalTitle:aa,modalText:la,modalTextLeft:sa,modalButtons:oa,modalForm:ta,formField:da,formLabel:ia,formInput:na,textarea:ra},k="selectedVlmModel";function ha(){const{isAuthenticated:w,isLoading:ee,login:ae,logout:le}=Pe(),[F,R]=t.useState(""),[U,j]=t.useState(""),[z,H]=t.useState(!1),[T,J]=t.useState([]),[se,y]=t.useState(""),[oe,A]=t.useState(""),[G,te]=t.useState([]),[de,ie]=t.useState([]),[ne,N]=t.useState(!1),[re,C]=t.useState(!1),[ce,I]=t.useState(null),[M,P]=t.useState(null),[n,r]=t.useState({p_code:"",label:"",metadata_instructions:"",image_type:"crisis_map",is_active:!1}),[V,$]=t.useState(!1),[me,L]=t.useState(!1),[E,B]=t.useState(null),[o,c]=t.useState({m_code:"",label:"",model_type:"custom",provider:"huggingface",model_id:"",is_available:!1,is_fallback:!1}),[he,S]=t.useState(!1),[pe,O]=t.useState(!1),[_e,p]=t.useState(!1),[K,W]=t.useState(""),[ue,je]=t.useState(""),[xe,_]=t.useState(""),[ve,x]=t.useState(""),u=t.useCallback(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{console.log("Models data received:",e),J(e.models||[]);const s=localStorage.getItem(k);if(e.models&&e.models.length>0)if(s==="random")y("random");else if(s&&e.models.find(i=>i.m_code===s&&i.is_available))y(s);else{const i=e.models.find(m=>m.is_available)||e.models[0];y(i.m_code),localStorage.setItem(k,i.m_code)}}).catch(()=>{}),fetch("/api/admin/fallback-model",{headers:{Authorization:`Bearer ${localStorage.getItem("adminToken")}`}}).then(e=>e.json()).then(e=>{console.log("Fallback model data received:",e),e.fallback_model?A(e.fallback_model.m_code):A("")}).catch(()=>{})},[]),v=t.useCallback(()=>{console.log("=== fetchPrompts called ==="),fetch("/api/prompts").then(e=>e.json()).then(e=>{console.log("Prompts data received:",e),te(e||[]),console.log("State update triggered with:",e||[])}).catch(e=>{console.error("Error fetching prompts:",e)})},[]),q=t.useCallback(()=>{fetch("/api/image-types").then(e=>e.json()).then(e=>{console.log("Image types data received:",e),ie(e||[])}).catch(()=>{})},[]);t.useEffect(()=>{w&&(u(),v(),q())},[w,u,v,q]);const Y=e=>{P(e),r({p_code:e.p_code,label:e.label||"",metadata_instructions:e.metadata_instructions||"",image_type:e.image_type||"crisis_map",is_active:e.is_active||!1}),N(!0)},ge=async()=>{try{if(!M){alert("No prompt selected for editing");return}const e=await fetch(`/api/prompts/${M.p_code}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:n.label,metadata_instructions:n.metadata_instructions,image_type:n.image_type,is_active:n.is_active})});if(e.ok)v(),N(!1),P(null),r({p_code:"",label:"",metadata_instructions:"",image_type:"crisis_map",is_active:!1});else{const s=await e.json();alert(`Failed to update prompt: ${s.error||"Unknown error"}`)}}catch{alert("Error updating prompt")}},Q=async(e,s)=>{try{const i=await fetch(`/api/prompts/${e}/toggle-active?image_type=${s}`,{method:"POST",headers:{"Content-Type":"application/json"}});if(i.ok)v();else{const m=await i.json();alert(`Failed to toggle prompt active status: ${m.detail||"Unknown error"}`)}}catch{alert("Error toggling prompt active status")}},X=e=>{I(e),r({p_code:"",label:"",metadata_instructions:"",image_type:e,is_active:!1}),C(!0)},fe=async()=>{try{const e=await fetch("/api/prompts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(e.ok)v(),C(!1),I(null),r({p_code:"",label:"",metadata_instructions:"",image_type:"crisis_map",is_active:!1});else{const s=await e.json();alert(`Failed to create prompt: ${s.detail||"Unknown error"}`)}}catch{alert("Error creating prompt")}},be=async(e,s)=>{try{const i=await fetch(`/api/models/${e}/toggle`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({is_available:!s})});if(i.ok)J(m=>m.map(g=>g.m_code===e?{...g,is_available:!s}:g));else{const m=await i.json();alert(`Failed to toggle model availability: ${m.error||"Unknown error"}`)}}catch{alert("Error toggling model availability")}},ye=e=>{y(e),e==="random"?localStorage.setItem(k,"random"):localStorage.setItem(k,e)},Ne=async e=>{try{const s=await fetch(`/api/admin/models/${e}`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("adminToken")}`},body:JSON.stringify({is_fallback:!0})});if(s.ok)A(e),u();else{const i=await s.json();alert(`Failed to set fallback model: ${i.detail||"Unknown error"}`)}}catch{alert("Error setting fallback model")}},Ce=async()=>{try{const e=await fetch("/api/admin/models",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("adminToken")}`},body:JSON.stringify(o)});if(e.ok){const s=`
2
  Model "${o.label}" added successfully!
3
 
4
  ⚠️ IMPORTANT: Model will NOT work until you complete these steps:
@@ -42,4 +42,4 @@ Raw data:
42
  ${JSON.stringify(e,null,2)}`:s=`Prompts Response:
43
 
44
  Unexpected data type: ${typeof e}
45
- Value: ${e}`,_(s),x(i),p(!0)}).catch(e=>{console.error("Schemas Error:",e);const s=`Failed to fetch prompts: ${e.message||"Unknown error"}`;_(s),x("Schemas Error"),p(!0)})},children:"View Schemas"})]})})]})]}),he&&a.jsx("div",{className:l.modalOverlay,onClick:()=>S(!1),children:a.jsx("div",{className:l.modalContent,onClick:e=>e.stopPropagation(),children:a.jsxs("div",{className:l.modalBody,children:[a.jsx("h3",{className:l.modalTitle,children:"Delete Model"}),a.jsxs("p",{className:l.modalText,children:["Are you sure you want to delete model ",a.jsx("span",{className:l.modelCode,children:K}),"? This action cannot be undone."]}),a.jsxs("div",{className:l.modalButtons,children:[a.jsx(d,{name:"cancel-delete",variant:"tertiary",onClick:()=>S(!1),children:"Cancel"}),a.jsx(d,{name:"confirm-delete",variant:"secondary",onClick:we,children:"Delete"})]})]})})}),pe&&a.jsx("div",{className:l.modalOverlay,onClick:()=>O(!1),children:a.jsx("div",{className:l.modalContent,onClick:e=>e.stopPropagation(),children:a.jsxs("div",{className:l.modalBody,children:[a.jsx("h3",{className:l.modalTitle,children:"Model Added Successfully!"}),a.jsx("div",{className:`${l.modalText} ${l.modalTextLeft}`,children:ue}),a.jsx("div",{className:l.modalButtons,children:a.jsx(d,{name:"close-setup-instructions",variant:"secondary",onClick:()=>O(!1),children:"Got it!"})})]})})}),_e&&a.jsx("div",{className:l.modalOverlay,onClick:()=>p(!1),children:a.jsx("div",{className:l.modalContent,onClick:e=>e.stopPropagation(),children:a.jsxs("div",{className:l.modalBody,children:[a.jsx("h3",{className:l.modalTitle,children:ve}),a.jsx("div",{className:`${l.modalText} ${l.modalTextLeft}`,children:a.jsx("div",{className:"whitespace-pre-wrap font-mono text-sm leading-relaxed",children:xe})}),a.jsx("div",{className:l.modalButtons,children:a.jsx(d,{name:"close-test-results",variant:"secondary",onClick:()=>p(!1),children:"Close"})})]})})}),ne&&a.jsx("div",{className:l.modalOverlay,onClick:()=>N(!1),children:a.jsx("div",{className:l.modalContent,onClick:e=>e.stopPropagation(),children:a.jsxs("div",{className:l.modalBody,children:[a.jsxs("h3",{className:l.modalTitle,children:["Edit Prompt: ",M?.p_code]}),a.jsxs("div",{className:l.modalForm,children:[a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Code:"}),a.jsx(h,{name:"prompt-code",value:M?.p_code,onChange:()=>{},disabled:!0,className:l.formInput})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Label:"}),a.jsx(h,{name:"prompt-label",value:n.label,onChange:e=>r(s=>({...s,label:e||""})),className:l.formInput})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Image Type:"}),a.jsx(b,{name:"prompt-image-type",value:n.image_type,onChange:e=>r(s=>({...s,image_type:e||"crisis_map"})),options:de,keySelector:e=>e.image_type,labelSelector:e=>e.label})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Active Status:"}),a.jsxs("div",{className:l.addModelFormCheckbox,children:[a.jsx("input",{type:"checkbox",checked:n.is_active,onChange:e=>r(s=>({...s,is_active:e.target.checked}))}),a.jsx("span",{children:"Active for this image type"})]})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Metadata Instructions:"}),a.jsx("textarea",{name:"prompt-instructions",value:n.metadata_instructions,onChange:e=>r(s=>({...s,metadata_instructions:e.target.value})),className:`${l.formInput} ${l.textarea}`,rows:8})]})]}),a.jsxs("div",{className:l.modalButtons,children:[a.jsx(d,{name:"cancel-edit-prompt",variant:"tertiary",onClick:()=>{N(!1),P(null),r({p_code:"",label:"",metadata_instructions:"",image_type:"crisis_map",is_active:!1})},children:"Cancel"}),a.jsx(d,{name:"save-prompt",variant:"primary",onClick:ge,children:"Save Changes"})]})]})})}),re&&a.jsx("div",{className:l.modalOverlay,onClick:()=>C(!1),children:a.jsx("div",{className:l.modalContent,onClick:e=>e.stopPropagation(),children:a.jsxs("div",{className:l.modalBody,children:[a.jsxs("h3",{className:l.modalTitle,children:["Add New ",ce==="crisis_map"?"Crisis Map":"Drone Image"," Prompt"]}),a.jsxs("div",{className:l.modalForm,children:[a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Code:"}),a.jsx(h,{name:"prompt-code",value:n.p_code,onChange:e=>r(s=>({...s,p_code:e||""})),placeholder:"e.g., CUSTOM_CRISIS_MAP_001",className:l.formInput})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Label:"}),a.jsx(h,{name:"prompt-label",value:n.label,onChange:e=>r(s=>({...s,label:e||""})),placeholder:"Enter prompt description...",className:l.formInput})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Image Type:"}),a.jsx(h,{name:"prompt-image-type",value:n.image_type,onChange:()=>{},disabled:!0,className:l.formInput})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Active Status:"}),a.jsxs("div",{className:l.addModelFormCheckbox,children:[a.jsx("input",{type:"checkbox",checked:n.is_active,onChange:e=>r(s=>({...s,is_active:e.target.checked}))}),a.jsx("span",{children:"Active for this image type"})]})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Metadata Instructions:"}),a.jsx("textarea",{name:"prompt-instructions",value:n.metadata_instructions,onChange:e=>r(s=>({...s,metadata_instructions:e.target.value})),placeholder:"Enter metadata extraction instructions...",className:`${l.formInput} ${l.textarea}`,rows:8})]})]}),a.jsxs("div",{className:l.modalButtons,children:[a.jsx(d,{name:"cancel-add-prompt",variant:"tertiary",onClick:()=>{C(!1),I(null),r({p_code:"",label:"",metadata_instructions:"",image_type:"crisis_map",is_active:!1})},children:"Cancel"}),a.jsx(d,{name:"save-new-prompt",variant:"primary",onClick:fe,disabled:!n.p_code||!n.label,children:"Create Prompt"})]})]})})})]}):a.jsxs(D,{children:[z&&a.jsxs("div",{className:Z.loadingContainer,children:[a.jsx(Ae,{className:"text-ifrcRed"}),a.jsx("p",{className:Z.loadingText,children:"Logging in..."})]}),a.jsxs("div",{className:"mx-auto max-w-md px-4 sm:px-6 lg:px-8 py-6 sm:py-10",children:[a.jsx("div",{className:"text-center mb-8",children:a.jsx(Ie,{level:2,children:"Admin Login"})}),a.jsxs("form",{onSubmit:Fe,className:"space-y-6",children:[a.jsxs("div",{children:[a.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-gray-700 mb-2",children:"Password"}),a.jsx(h,{id:"password",name:"password",type:"password",value:F,onChange:e=>R(e||""),placeholder:"Enter admin password",required:!0,className:"w-full"})]}),U&&a.jsx("div",{children:a.jsx("p",{className:"text-sm text-ifrcRed font-medium",children:U})}),a.jsx("div",{className:"flex justify-center",children:a.jsx(f,{withInternalPadding:!0,className:"p-2",children:a.jsx(d,{name:"login",type:"submit",variant:"primary",size:2,disabled:z,children:"Login"})})})]})]})]})}export{ha as default};
 
1
+ import{r as t,j as a,N as D,H as Ae,O as h,z as f,I as Z,_ as Ie,n as d,J as b}from"./index-RA4UIF3R.js";import{u as Pe}from"./useAdmin-k5gw6w_T.js";const $e="_adminContainer_j11pf_5",Le="_adminHeader_j11pf_13",Ee="_adminSection_j11pf_20",Be="_modelSelectionArea_j11pf_29",Oe="_modelSelectionRow_j11pf_36",De="_modelsTable_j11pf_89",Re="_promptSubsection_j11pf_97",Ue="_promptSubsectionTitle_j11pf_109",ze="_modelCode_j11pf_152",He="_modelId_j11pf_157",Je="_modelActions_j11pf_163",Ge="_addModelButtonContainer_j11pf_169",Ve="_addModelForm_j11pf_177",Ke="_addModelFormTitle_j11pf_185",We="_addModelFormGrid_j11pf_193",qe="_addModelFormField_j11pf_206",Ye="_addModelFormCheckbox_j11pf_250",Qe="_addModelFormActions_j11pf_268",Xe="_modalOverlay_j11pf_277",Ze="_modalContent_j11pf_291",ea="_modalBody_j11pf_302",aa="_modalTitle_j11pf_312",la="_modalText_j11pf_320",sa="_modalTextLeft_j11pf_332",oa="_modalButtons_j11pf_355",ta="_modalForm_j11pf_363",da="_formField_j11pf_372",ia="_formLabel_j11pf_376",na="_formInput_j11pf_385",ra="_textarea_j11pf_407",l={adminContainer:$e,adminHeader:Le,adminSection:Ee,modelSelectionArea:Be,modelSelectionRow:Oe,modelsTable:De,promptSubsection:Re,promptSubsectionTitle:Ue,modelCode:ze,modelId:He,modelActions:Je,addModelButtonContainer:Ge,addModelForm:Ve,addModelFormTitle:Ke,addModelFormGrid:We,addModelFormField:qe,addModelFormCheckbox:Ye,addModelFormActions:Qe,modalOverlay:Xe,modalContent:Ze,modalBody:ea,modalTitle:aa,modalText:la,modalTextLeft:sa,modalButtons:oa,modalForm:ta,formField:da,formLabel:ia,formInput:na,textarea:ra},k="selectedVlmModel";function ha(){const{isAuthenticated:w,isLoading:ee,login:ae,logout:le}=Pe(),[F,R]=t.useState(""),[U,j]=t.useState(""),[z,H]=t.useState(!1),[T,J]=t.useState([]),[se,y]=t.useState(""),[oe,A]=t.useState(""),[G,te]=t.useState([]),[de,ie]=t.useState([]),[ne,N]=t.useState(!1),[re,C]=t.useState(!1),[ce,I]=t.useState(null),[M,P]=t.useState(null),[n,r]=t.useState({p_code:"",label:"",metadata_instructions:"",image_type:"crisis_map",is_active:!1}),[V,$]=t.useState(!1),[me,L]=t.useState(!1),[E,B]=t.useState(null),[o,c]=t.useState({m_code:"",label:"",model_type:"custom",provider:"huggingface",model_id:"",is_available:!1,is_fallback:!1}),[he,S]=t.useState(!1),[pe,O]=t.useState(!1),[_e,p]=t.useState(!1),[K,W]=t.useState(""),[ue,je]=t.useState(""),[xe,_]=t.useState(""),[ve,x]=t.useState(""),u=t.useCallback(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{console.log("Models data received:",e),J(e.models||[]);const s=localStorage.getItem(k);if(e.models&&e.models.length>0)if(s==="random")y("random");else if(s&&e.models.find(i=>i.m_code===s&&i.is_available))y(s);else{const i=e.models.find(m=>m.is_available)||e.models[0];y(i.m_code),localStorage.setItem(k,i.m_code)}}).catch(()=>{}),fetch("/api/admin/fallback-model",{headers:{Authorization:`Bearer ${localStorage.getItem("adminToken")}`}}).then(e=>e.json()).then(e=>{console.log("Fallback model data received:",e),e.fallback_model?A(e.fallback_model.m_code):A("")}).catch(()=>{})},[]),v=t.useCallback(()=>{console.log("=== fetchPrompts called ==="),fetch("/api/prompts").then(e=>e.json()).then(e=>{console.log("Prompts data received:",e),te(e||[]),console.log("State update triggered with:",e||[])}).catch(e=>{console.error("Error fetching prompts:",e)})},[]),q=t.useCallback(()=>{fetch("/api/image-types").then(e=>e.json()).then(e=>{console.log("Image types data received:",e),ie(e||[])}).catch(()=>{})},[]);t.useEffect(()=>{w&&(u(),v(),q())},[w,u,v,q]);const Y=e=>{P(e),r({p_code:e.p_code,label:e.label||"",metadata_instructions:e.metadata_instructions||"",image_type:e.image_type||"crisis_map",is_active:e.is_active||!1}),N(!0)},ge=async()=>{try{if(!M){alert("No prompt selected for editing");return}const e=await fetch(`/api/prompts/${M.p_code}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:n.label,metadata_instructions:n.metadata_instructions,image_type:n.image_type,is_active:n.is_active})});if(e.ok)v(),N(!1),P(null),r({p_code:"",label:"",metadata_instructions:"",image_type:"crisis_map",is_active:!1});else{const s=await e.json();alert(`Failed to update prompt: ${s.error||"Unknown error"}`)}}catch{alert("Error updating prompt")}},Q=async(e,s)=>{try{const i=await fetch(`/api/prompts/${e}/toggle-active?image_type=${s}`,{method:"POST",headers:{"Content-Type":"application/json"}});if(i.ok)v();else{const m=await i.json();alert(`Failed to toggle prompt active status: ${m.detail||"Unknown error"}`)}}catch{alert("Error toggling prompt active status")}},X=e=>{I(e),r({p_code:"",label:"",metadata_instructions:"",image_type:e,is_active:!1}),C(!0)},fe=async()=>{try{const e=await fetch("/api/prompts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(e.ok)v(),C(!1),I(null),r({p_code:"",label:"",metadata_instructions:"",image_type:"crisis_map",is_active:!1});else{const s=await e.json();alert(`Failed to create prompt: ${s.detail||"Unknown error"}`)}}catch{alert("Error creating prompt")}},be=async(e,s)=>{try{const i=await fetch(`/api/models/${e}/toggle`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({is_available:!s})});if(i.ok)J(m=>m.map(g=>g.m_code===e?{...g,is_available:!s}:g));else{const m=await i.json();alert(`Failed to toggle model availability: ${m.error||"Unknown error"}`)}}catch{alert("Error toggling model availability")}},ye=e=>{y(e),e==="random"?localStorage.setItem(k,"random"):localStorage.setItem(k,e)},Ne=async e=>{try{const s=await fetch(`/api/admin/models/${e}`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("adminToken")}`},body:JSON.stringify({is_fallback:!0})});if(s.ok)A(e),u();else{const i=await s.json();alert(`Failed to set fallback model: ${i.detail||"Unknown error"}`)}}catch{alert("Error setting fallback model")}},Ce=async()=>{try{const e=await fetch("/api/admin/models",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("adminToken")}`},body:JSON.stringify(o)});if(e.ok){const s=`
2
  Model "${o.label}" added successfully!
3
 
4
  ⚠️ IMPORTANT: Model will NOT work until you complete these steps:
 
42
  ${JSON.stringify(e,null,2)}`:s=`Prompts Response:
43
 
44
  Unexpected data type: ${typeof e}
45
+ Value: ${e}`,_(s),x(i),p(!0)}).catch(e=>{console.error("Schemas Error:",e);const s=`Failed to fetch prompts: ${e.message||"Unknown error"}`;_(s),x("Schemas Error"),p(!0)})},children:"View Schemas"})]})})]})]}),he&&a.jsx("div",{className:l.modalOverlay,onClick:()=>S(!1),children:a.jsx("div",{className:l.modalContent,onClick:e=>e.stopPropagation(),children:a.jsxs("div",{className:l.modalBody,children:[a.jsx("h3",{className:l.modalTitle,children:"Delete Model"}),a.jsxs("p",{className:l.modalText,children:["Are you sure you want to delete model ",a.jsx("span",{className:l.modelCode,children:K}),"? This action cannot be undone."]}),a.jsxs("div",{className:l.modalButtons,children:[a.jsx(d,{name:"cancel-delete",variant:"tertiary",onClick:()=>S(!1),children:"Cancel"}),a.jsx(d,{name:"confirm-delete",variant:"secondary",onClick:we,children:"Delete"})]})]})})}),pe&&a.jsx("div",{className:l.modalOverlay,onClick:()=>O(!1),children:a.jsx("div",{className:l.modalContent,onClick:e=>e.stopPropagation(),children:a.jsxs("div",{className:l.modalBody,children:[a.jsx("h3",{className:l.modalTitle,children:"Model Added Successfully!"}),a.jsx("div",{className:`${l.modalText} ${l.modalTextLeft}`,children:ue}),a.jsx("div",{className:l.modalButtons,children:a.jsx(d,{name:"close-setup-instructions",variant:"secondary",onClick:()=>O(!1),children:"Got it!"})})]})})}),_e&&a.jsx("div",{className:l.modalOverlay,onClick:()=>p(!1),children:a.jsx("div",{className:l.modalContent,onClick:e=>e.stopPropagation(),children:a.jsxs("div",{className:l.modalBody,children:[a.jsx("h3",{className:l.modalTitle,children:ve}),a.jsx("div",{className:`${l.modalText} ${l.modalTextLeft}`,children:a.jsx("div",{className:"whitespace-pre-wrap font-mono text-sm leading-relaxed",children:xe})}),a.jsx("div",{className:l.modalButtons,children:a.jsx(d,{name:"close-test-results",variant:"secondary",onClick:()=>p(!1),children:"Close"})})]})})}),ne&&a.jsx("div",{className:l.modalOverlay,onClick:()=>N(!1),children:a.jsx("div",{className:l.modalContent,onClick:e=>e.stopPropagation(),children:a.jsxs("div",{className:l.modalBody,children:[a.jsxs("h3",{className:l.modalTitle,children:["Edit Prompt: ",M?.p_code]}),a.jsxs("div",{className:l.modalForm,children:[a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Code:"}),a.jsx(h,{name:"prompt-code",value:M?.p_code,onChange:()=>{},disabled:!0,className:l.formInput})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Label:"}),a.jsx(h,{name:"prompt-label",value:n.label,onChange:e=>r(s=>({...s,label:e||""})),className:l.formInput})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Image Type:"}),a.jsx(b,{name:"prompt-image-type",value:n.image_type,onChange:e=>r(s=>({...s,image_type:e||"crisis_map"})),options:de,keySelector:e=>e.image_type,labelSelector:e=>e.label})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Active Status:"}),a.jsxs("div",{className:l.addModelFormCheckbox,children:[a.jsx("input",{type:"checkbox",checked:n.is_active,onChange:e=>r(s=>({...s,is_active:e.target.checked}))}),a.jsx("span",{children:"Active for this image type"})]})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Metadata Instructions:"}),a.jsx("textarea",{name:"prompt-instructions",value:n.metadata_instructions,onChange:e=>r(s=>({...s,metadata_instructions:e.target.value})),className:`${l.formInput} ${l.textarea}`,rows:8})]})]}),a.jsxs("div",{className:l.modalButtons,children:[a.jsx(d,{name:"cancel-edit-prompt",variant:"tertiary",onClick:()=>{N(!1),P(null),r({p_code:"",label:"",metadata_instructions:"",image_type:"crisis_map",is_active:!1})},children:"Cancel"}),a.jsx(d,{name:"save-prompt",variant:"primary",onClick:ge,children:"Save Changes"})]})]})})}),re&&a.jsx("div",{className:l.modalOverlay,onClick:()=>C(!1),children:a.jsx("div",{className:l.modalContent,onClick:e=>e.stopPropagation(),children:a.jsxs("div",{className:l.modalBody,children:[a.jsxs("h3",{className:l.modalTitle,children:["Add New ",ce==="crisis_map"?"Crisis Map":"Drone Image"," Prompt"]}),a.jsxs("div",{className:l.modalForm,children:[a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Code:"}),a.jsx(h,{name:"prompt-code",value:n.p_code,onChange:e=>r(s=>({...s,p_code:e||""})),placeholder:"e.g., CUSTOM_CRISIS_MAP_001",className:l.formInput})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Label:"}),a.jsx(h,{name:"prompt-label",value:n.label,onChange:e=>r(s=>({...s,label:e||""})),placeholder:"Enter prompt description...",className:l.formInput})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Image Type:"}),a.jsx(h,{name:"prompt-image-type",value:n.image_type,onChange:()=>{},disabled:!0,className:l.formInput})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Active Status:"}),a.jsxs("div",{className:l.addModelFormCheckbox,children:[a.jsx("input",{type:"checkbox",checked:n.is_active,onChange:e=>r(s=>({...s,is_active:e.target.checked}))}),a.jsx("span",{children:"Active for this image type"})]})]}),a.jsxs("div",{className:l.formField,children:[a.jsx("label",{className:l.formLabel,children:"Metadata Instructions:"}),a.jsx("textarea",{name:"prompt-instructions",value:n.metadata_instructions,onChange:e=>r(s=>({...s,metadata_instructions:e.target.value})),placeholder:"Enter metadata extraction instructions...",className:`${l.formInput} ${l.textarea}`,rows:8})]})]}),a.jsxs("div",{className:l.modalButtons,children:[a.jsx(d,{name:"cancel-add-prompt",variant:"tertiary",onClick:()=>{C(!1),I(null),r({p_code:"",label:"",metadata_instructions:"",image_type:"crisis_map",is_active:!1})},children:"Cancel"}),a.jsx(d,{name:"save-new-prompt",variant:"primary",onClick:fe,disabled:!n.p_code||!n.label,children:"Create Prompt"})]})]})})})]}):a.jsx(D,{children:a.jsxs("div",{className:"mx-auto max-w-md px-4 sm:px-6 lg:px-8 py-6 sm:py-10",children:[a.jsx("div",{className:"text-center mb-8",children:a.jsx(Ae,{level:2,children:"Admin Login"})}),a.jsxs("form",{onSubmit:Fe,className:"space-y-6",children:[a.jsxs("div",{children:[a.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-gray-700 mb-2",children:"Password"}),a.jsx(h,{id:"password",name:"password",type:"password",value:F,onChange:e=>R(e||""),placeholder:"Enter admin password",required:!0,className:"w-full",disabled:z})]}),U&&a.jsx("div",{children:a.jsx("p",{className:"text-sm text-ifrcRed font-medium",children:U})}),a.jsx("div",{className:"flex justify-center",children:a.jsx(f,{withInternalPadding:!0,className:"p-2",children:z?a.jsxs("div",{className:Z.loadingContainer,children:[a.jsx(Ie,{className:"text-ifrcRed"}),a.jsx("p",{className:Z.loadingText,children:"Logging in..."})]}):a.jsx(d,{name:"login",type:"submit",variant:"primary",size:2,children:"Login"})})})]})]})})}export{ha as default};
py_backend/static/assets/{ExportModal-Qf6Y7VAO.js β†’ ExportModal-DWGvhKT1.js} RENAMED
@@ -1 +1 @@
1
- import{r as n,j as e,P as V,S as A,o as O,T as H,D as q,z as b,n as v,O as D,J as F,V as G,_ as B,L as R}from"./index-BCz4bkWK.js";const $=({title:c,titleId:i,...r})=>n.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":i},r),c?n.createElement("title",{id:i},c):null,n.createElement("g",{clipPath:"url(#checkbox-indeterminate-line_svg__a)"},n.createElement("path",{d:"M4 3h16a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Zm1 2v14h14V5H5Zm2 6h10v2H7v-2Z"})),n.createElement("defs",null,n.createElement("clipPath",{id:"checkbox-indeterminate-line_svg__a"},n.createElement("path",{d:"M0 0h24v24H0z"})))),U=({title:c,titleId:i,...r})=>n.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":i},r),c?n.createElement("title",{id:i},c):null,n.createElement("g",{clipPath:"url(#filter-line_svg__a)"},n.createElement("path",{d:"M9 13.5 4 6H3V4h18v2h-1l-5 7.5V22H9v-8.5ZM6.404 6 11 12.894V20h2v-7.106L17.596 6H6.404Z"})),n.createElement("defs",null,n.createElement("clipPath",{id:"filter-line_svg__a"},n.createElement("path",{d:"M0 0h24v24H0z"}))));function Z(c){const{className:i,indeterminate:r,value:j}=c;return e.jsxs(e.Fragment,{children:[r&&e.jsx($,{className:i}),j&&!r&&e.jsx(V,{className:i}),!j&&!r&&e.jsx(A,{className:i})]})}const Y="_checkbox_12g7n_1",J="_with-background_12g7n_7",K="_checkmark-container_12g7n_12",Q="_input_12g7n_18",X="_content_12g7n_33",L="_description_12g7n_40",ee="_checked_12g7n_45",ae="_checkmark_12g7n_12",le="_disabled-checkbox_12g7n_58",h={checkbox:Y,withBackground:J,checkmarkContainer:K,input:Q,content:X,description:L,checked:ee,checkmark:ae,disabledCheckbox:le};function P(c){const{className:i,checkmark:r=Z,checkmarkClassName:j,checkmarkContainerClassName:z,disabled:s,error:x,indeterminate:k,inputClassName:I,invertedLogic:p=!1,label:_,labelContainerClassName:f,name:E,onChange:C,readOnly:u,tooltip:S,value:N,description:g,withBackground:T,...w}=c,M=n.useCallback(t=>{const o=t.currentTarget.checked;C(p?!o:o,E)},[E,C,p]),y=p?!N:N,m=O(h.checkbox,i,!k&&y&&h.checked,T&&h.withBackground,s&&h.disabledCheckbox,u&&h.readOnly);return e.jsxs("label",{className:m,title:S,children:[e.jsxs("div",{className:O(h.checkmarkContainer,z),children:[e.jsx("input",{onChange:M,className:O(h.input,I),type:"checkbox",checked:y??!1,disabled:s||u,readOnly:u,...w}),e.jsx(r,{className:O(h.checkmark,j),value:y??!1,indeterminate:k,"aria-hidden":"true"})]}),(_||g)&&e.jsxs("div",{className:h.content,children:[_&&e.jsx("div",{className:f,children:_}),g&&e.jsx("div",{className:h.description,children:g})]}),x&&e.jsx(H,{children:x})]})}function Ce({sources:c,types:i,regions:r,countries:j,imageTypes:z,isLoadingFilters:s=!1}){const[x,k]=n.useState(!1),[I,p]=n.useState(""),{search:_,setSearch:f,srcFilter:E,setSrcFilter:C,catFilter:u,setCatFilter:S,regionFilter:N,setRegionFilter:g,countryFilter:T,setCountryFilter:w,imageTypeFilter:M,setImageTypeFilter:y,uploadTypeFilter:m,setUploadTypeFilter:t,showReferenceExamples:o,setShowReferenceExamples:d,clearAllFilters:W}=q();return n.useEffect(()=>{p(_)},[_]),e.jsxs("div",{className:"mb-6 space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[e.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:e.jsx(v,{name:"toggle-filters",variant:"secondary",onClick:()=>k(!x),className:"whitespace-nowrap",title:x?"Hide Filters":"Show Filters",children:e.jsx(U,{className:"w-4 h-4"})})}),e.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2 flex-1 min-w-[300px]",children:e.jsx(D,{name:"search",placeholder:"Search",value:I,onChange:a=>p(a||""),onKeyDown:a=>{a.key==="Enter"&&f(I)}})}),e.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:e.jsx(v,{name:"clear-filters",variant:"secondary",onClick:W,children:"Clear Filters"})})]}),x&&e.jsx("div",{className:"bg-white/20 backdrop-blur-sm rounded-md p-4",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(F,{name:"source",placeholder:s?"Loading...":"All Sources",options:c,value:E||null,onChange:a=>C(a||""),keySelector:a=>a.s_code,labelSelector:a=>a.label,required:!1,disabled:s})}),e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(F,{name:"category",placeholder:s?"Loading...":"All Categories",options:i,value:u||null,onChange:a=>S(a||""),keySelector:a=>a.t_code,labelSelector:a=>a.label,required:!1,disabled:s})}),e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(F,{name:"region",placeholder:s?"Loading...":"All Regions",options:r,value:N||null,onChange:a=>g(a||""),keySelector:a=>a.r_code,labelSelector:a=>a.label,required:!1,disabled:s})}),e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(G,{name:"country",placeholder:s?"Loading...":"All Countries",options:j,value:T?[T]:[],onChange:a=>w(a[0]||""),keySelector:a=>a.c_code,labelSelector:a=>a.label,disabled:s})}),e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(F,{name:"imageType",placeholder:s?"Loading...":"All Image Types",options:z,value:M||null,onChange:a=>y(a||""),keySelector:a=>a.image_type,labelSelector:a=>a.label,required:!1,disabled:s})}),e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(F,{name:"uploadType",placeholder:"All Upload Types",options:[{key:"single",label:"Single Upload"},{key:"multiple",label:"Multiple Upload"}],value:m||null,onChange:a=>t(a||""),keySelector:a=>a.key,labelSelector:a=>a.label,required:!1,disabled:!1})})]})})]})}const te="_fullSizeModalOverlay_cyz3b_1",se="_fullSizeModalContent_cyz3b_29",ne="_ratingWarningContent_cyz3b_53",ie="_ratingWarningTitle_cyz3b_65",re="_exportModeSection_cyz3b_133",ce="_splitConfigSection_cyz3b_143",oe="_splitConfigTitle_cyz3b_153",de="_splitInputsContainer_cyz3b_167",pe="_splitInputGroup_cyz3b_183",me="_splitInputLabel_cyz3b_197",he="_splitInput_cyz3b_167",xe="_splitTotal_cyz3b_247",ue="_splitTotalError_cyz3b_261",ge="_checkboxesContainer_cyz3b_271",be="_ratingWarningButtons_cyz3b_289",ve="_singleExportMessage_cyz3b_309",je="_navigateButtonContainer_cyz3b_333",_e="_loadingOverlay_cyz3b_349",l={fullSizeModalOverlay:te,fullSizeModalContent:se,ratingWarningContent:ne,ratingWarningTitle:ie,exportModeSection:re,splitConfigSection:ce,splitConfigTitle:oe,splitInputsContainer:de,splitInputGroup:pe,splitInputLabel:me,splitInput:he,splitTotal:xe,splitTotalError:ue,checkboxesContainer:ge,ratingWarningButtons:be,singleExportMessage:ve,navigateButtonContainer:je,loadingOverlay:_e};function Ne({isOpen:c,onClose:i,onExport:r,crisisMapsCount:j,droneImagesCount:z,isLoading:s=!1,exportSuccess:x=!1,variant:k="bulk",onNavigateAndExport:I}){const[p,_]=n.useState("standard"),[f,E]=n.useState(80),[C,u]=n.useState(10),[S,N]=n.useState(10),[g,T]=n.useState(!0),[w,M]=n.useState(!0),y=()=>{if(k==="single"){r(p,["crisis_map","drone_image"]);return}if(!g&&!w){alert("Please select at least one image type to export.");return}const t=[];g&&t.push("crisis_map"),w&&t.push("drone_image"),r(p,t)},m=()=>{i()};return c?k==="single"?e.jsx("div",{className:l.fullSizeModalOverlay,onClick:m,children:e.jsxs("div",{className:l.fullSizeModalContent,onClick:t=>t.stopPropagation(),children:[s&&e.jsx("div",{className:l.loadingOverlay,children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(B,{className:"text-ifrcRed"}),e.jsx("div",{className:"text-lg font-medium",children:"Exporting..."}),e.jsx("div",{className:"text-sm text-gray-600",children:"This might take a few seconds"})]})}),x&&e.jsx("div",{className:l.loadingOverlay,children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"text-lg font-medium",children:"Export Successful!"}),e.jsx("div",{className:"text-sm text-gray-600",children:"Your dataset has been downloaded"}),e.jsx(v,{name:"close-export-success",onClick:m,className:"mt-4",children:"Close"})]})}),e.jsxs("div",{className:l.ratingWarningContent,children:[e.jsx("h3",{className:l.ratingWarningTitle,children:"Export Single Item"}),e.jsxs("div",{className:l.singleExportMessage,children:[e.jsx("p",{children:"This only exports the 1 item currently on display."}),e.jsx("p",{children:'You may export the entire dataset from the "list view" here:'})]}),e.jsx("div",{className:l.navigateButtonContainer,children:e.jsx(v,{name:"navigate-to-list",variant:"secondary",onClick:I,children:"Navigate to List View"})}),e.jsxs("div",{className:l.ratingWarningButtons,children:[e.jsx(v,{name:"continue-export",onClick:y,disabled:s,children:s?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"text-white"}),"Exporting..."]}):"Continue"}),e.jsx(v,{name:"cancel-export",variant:"tertiary",onClick:m,disabled:s,children:"Cancel"})]})]})]})}):e.jsx("div",{className:l.fullSizeModalOverlay,onClick:m,children:e.jsxs("div",{className:l.fullSizeModalContent,onClick:t=>t.stopPropagation(),children:[s&&e.jsx("div",{className:l.loadingOverlay,children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(B,{className:"text-ifrcRed"}),e.jsx("div",{className:"text-lg font-medium",children:"Exporting..."}),e.jsx("div",{className:"text-sm text-gray-600",children:"This might take a few seconds"})]})}),x&&e.jsx("div",{className:l.loadingOverlay,children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"text-lg font-medium",children:"Export Successful!"}),e.jsx("div",{className:"text-sm text-gray-600",children:"Your dataset has been downloaded"}),e.jsx(v,{name:"close-export-success",onClick:m,className:"mt-4",children:"Close"})]})}),e.jsxs("div",{className:l.ratingWarningContent,children:[e.jsx("h3",{className:l.ratingWarningTitle,children:"Export Dataset"}),e.jsx("div",{className:l.exportModeSection,children:e.jsx(R,{name:"export-mode",value:p,onChange:t=>{(t==="standard"||t==="fine-tuning")&&_(t)},options:[{key:"standard",label:"Standard"},{key:"fine-tuning",label:"Fine-tuning"}],keySelector:t=>t.key,labelSelector:t=>t.label,disabled:s})}),p==="fine-tuning"&&e.jsxs("div",{className:l.splitConfigSection,children:[e.jsx("div",{className:l.splitConfigTitle,children:"Dataset Split Configuration"}),e.jsxs("div",{className:l.splitInputsContainer,children:[e.jsxs("div",{className:l.splitInputGroup,children:[e.jsx("label",{htmlFor:"train-split",className:l.splitInputLabel,children:"Train (%)"}),e.jsx("input",{id:"train-split",type:"number",min:"0",max:"100",value:f,onChange:t=>{const o=parseInt(t.target.value)||0,d=100-o;d>=0&&(E(o),C+S>d&&(u(Math.floor(d/2)),N(d-Math.floor(d/2))))},className:l.splitInput,disabled:s})]}),e.jsxs("div",{className:l.splitInputGroup,children:[e.jsx("label",{htmlFor:"test-split",className:l.splitInputLabel,children:"Test (%)"}),e.jsx("input",{id:"test-split",type:"number",min:"0",max:"100",value:C,onChange:t=>{const o=parseInt(t.target.value)||0,d=100-f-o;d>=0&&(u(o),N(d))},className:l.splitInput,disabled:s})]}),e.jsxs("div",{className:l.splitInputGroup,children:[e.jsx("label",{htmlFor:"val-split",className:l.splitInputLabel,children:"Val (%)"}),e.jsx("input",{id:"val-split",type:"number",min:"0",max:"100",value:S,onChange:t=>{const o=parseInt(t.target.value)||0,d=100-f-o;d>=0&&(N(o),u(d))},className:l.splitInput,disabled:s})]})]}),f+C+S!==100&&e.jsx("div",{className:l.splitTotal,children:e.jsx("span",{className:l.splitTotalError,children:"Must equal 100%"})})]}),e.jsxs("div",{className:l.checkboxesContainer,children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(P,{name:"crisis-maps",label:`Crisis Maps (${j} images)`,value:g,onChange:t=>T(t),disabled:s})}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(P,{name:"drone-images",label:`Drone Images (${z} images)`,value:w,onChange:t=>M(t),disabled:s})})]}),e.jsxs("div",{className:l.ratingWarningButtons,children:[e.jsx(v,{name:"confirm-export",onClick:y,disabled:s,children:s?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"text-white"}),"Exporting..."]}):"Export Selected"}),e.jsx(v,{name:"cancel-export",variant:"tertiary",onClick:m,disabled:s,children:"Cancel"})]})]})]})}):null}export{Ne as E,Ce as F};
 
1
+ import{r as n,j as e,P as V,S as A,o as O,T as H,D as q,z as b,n as v,O as D,J as F,V as G,_ as B,L as R}from"./index-RA4UIF3R.js";const $=({title:c,titleId:i,...r})=>n.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":i},r),c?n.createElement("title",{id:i},c):null,n.createElement("g",{clipPath:"url(#checkbox-indeterminate-line_svg__a)"},n.createElement("path",{d:"M4 3h16a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Zm1 2v14h14V5H5Zm2 6h10v2H7v-2Z"})),n.createElement("defs",null,n.createElement("clipPath",{id:"checkbox-indeterminate-line_svg__a"},n.createElement("path",{d:"M0 0h24v24H0z"})))),U=({title:c,titleId:i,...r})=>n.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":i},r),c?n.createElement("title",{id:i},c):null,n.createElement("g",{clipPath:"url(#filter-line_svg__a)"},n.createElement("path",{d:"M9 13.5 4 6H3V4h18v2h-1l-5 7.5V22H9v-8.5ZM6.404 6 11 12.894V20h2v-7.106L17.596 6H6.404Z"})),n.createElement("defs",null,n.createElement("clipPath",{id:"filter-line_svg__a"},n.createElement("path",{d:"M0 0h24v24H0z"}))));function Z(c){const{className:i,indeterminate:r,value:j}=c;return e.jsxs(e.Fragment,{children:[r&&e.jsx($,{className:i}),j&&!r&&e.jsx(V,{className:i}),!j&&!r&&e.jsx(A,{className:i})]})}const Y="_checkbox_12g7n_1",J="_with-background_12g7n_7",K="_checkmark-container_12g7n_12",Q="_input_12g7n_18",X="_content_12g7n_33",L="_description_12g7n_40",ee="_checked_12g7n_45",ae="_checkmark_12g7n_12",le="_disabled-checkbox_12g7n_58",h={checkbox:Y,withBackground:J,checkmarkContainer:K,input:Q,content:X,description:L,checked:ee,checkmark:ae,disabledCheckbox:le};function P(c){const{className:i,checkmark:r=Z,checkmarkClassName:j,checkmarkContainerClassName:z,disabled:s,error:x,indeterminate:k,inputClassName:I,invertedLogic:p=!1,label:_,labelContainerClassName:f,name:E,onChange:C,readOnly:u,tooltip:S,value:N,description:g,withBackground:T,...w}=c,M=n.useCallback(t=>{const o=t.currentTarget.checked;C(p?!o:o,E)},[E,C,p]),y=p?!N:N,m=O(h.checkbox,i,!k&&y&&h.checked,T&&h.withBackground,s&&h.disabledCheckbox,u&&h.readOnly);return e.jsxs("label",{className:m,title:S,children:[e.jsxs("div",{className:O(h.checkmarkContainer,z),children:[e.jsx("input",{onChange:M,className:O(h.input,I),type:"checkbox",checked:y??!1,disabled:s||u,readOnly:u,...w}),e.jsx(r,{className:O(h.checkmark,j),value:y??!1,indeterminate:k,"aria-hidden":"true"})]}),(_||g)&&e.jsxs("div",{className:h.content,children:[_&&e.jsx("div",{className:f,children:_}),g&&e.jsx("div",{className:h.description,children:g})]}),x&&e.jsx(H,{children:x})]})}function Ce({sources:c,types:i,regions:r,countries:j,imageTypes:z,isLoadingFilters:s=!1}){const[x,k]=n.useState(!1),[I,p]=n.useState(""),{search:_,setSearch:f,srcFilter:E,setSrcFilter:C,catFilter:u,setCatFilter:S,regionFilter:N,setRegionFilter:g,countryFilter:T,setCountryFilter:w,imageTypeFilter:M,setImageTypeFilter:y,uploadTypeFilter:m,setUploadTypeFilter:t,showReferenceExamples:o,setShowReferenceExamples:d,clearAllFilters:W}=q();return n.useEffect(()=>{p(_)},[_]),e.jsxs("div",{className:"mb-6 space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[e.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:e.jsx(v,{name:"toggle-filters",variant:"secondary",onClick:()=>k(!x),className:"whitespace-nowrap",title:x?"Hide Filters":"Show Filters",children:e.jsx(U,{className:"w-4 h-4"})})}),e.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2 flex-1 min-w-[300px]",children:e.jsx(D,{name:"search",placeholder:"Search",value:I,onChange:a=>p(a||""),onKeyDown:a=>{a.key==="Enter"&&f(I)}})}),e.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:e.jsx(v,{name:"clear-filters",variant:"secondary",onClick:W,children:"Clear Filters"})})]}),x&&e.jsx("div",{className:"bg-white/20 backdrop-blur-sm rounded-md p-4",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(F,{name:"source",placeholder:s?"Loading...":"All Sources",options:c,value:E||null,onChange:a=>C(a||""),keySelector:a=>a.s_code,labelSelector:a=>a.label,required:!1,disabled:s})}),e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(F,{name:"category",placeholder:s?"Loading...":"All Categories",options:i,value:u||null,onChange:a=>S(a||""),keySelector:a=>a.t_code,labelSelector:a=>a.label,required:!1,disabled:s})}),e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(F,{name:"region",placeholder:s?"Loading...":"All Regions",options:r,value:N||null,onChange:a=>g(a||""),keySelector:a=>a.r_code,labelSelector:a=>a.label,required:!1,disabled:s})}),e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(G,{name:"country",placeholder:s?"Loading...":"All Countries",options:j,value:T?[T]:[],onChange:a=>w(a[0]||""),keySelector:a=>a.c_code,labelSelector:a=>a.label,disabled:s})}),e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(F,{name:"imageType",placeholder:s?"Loading...":"All Image Types",options:z,value:M||null,onChange:a=>y(a||""),keySelector:a=>a.image_type,labelSelector:a=>a.label,required:!1,disabled:s})}),e.jsx(b,{withInternalPadding:!0,className:"p-2",children:e.jsx(F,{name:"uploadType",placeholder:"All Upload Types",options:[{key:"single",label:"Single Upload"},{key:"multiple",label:"Multiple Upload"}],value:m||null,onChange:a=>t(a||""),keySelector:a=>a.key,labelSelector:a=>a.label,required:!1,disabled:!1})})]})})]})}const te="_fullSizeModalOverlay_cyz3b_1",se="_fullSizeModalContent_cyz3b_29",ne="_ratingWarningContent_cyz3b_53",ie="_ratingWarningTitle_cyz3b_65",re="_exportModeSection_cyz3b_133",ce="_splitConfigSection_cyz3b_143",oe="_splitConfigTitle_cyz3b_153",de="_splitInputsContainer_cyz3b_167",pe="_splitInputGroup_cyz3b_183",me="_splitInputLabel_cyz3b_197",he="_splitInput_cyz3b_167",xe="_splitTotal_cyz3b_247",ue="_splitTotalError_cyz3b_261",ge="_checkboxesContainer_cyz3b_271",be="_ratingWarningButtons_cyz3b_289",ve="_singleExportMessage_cyz3b_309",je="_navigateButtonContainer_cyz3b_333",_e="_loadingOverlay_cyz3b_349",l={fullSizeModalOverlay:te,fullSizeModalContent:se,ratingWarningContent:ne,ratingWarningTitle:ie,exportModeSection:re,splitConfigSection:ce,splitConfigTitle:oe,splitInputsContainer:de,splitInputGroup:pe,splitInputLabel:me,splitInput:he,splitTotal:xe,splitTotalError:ue,checkboxesContainer:ge,ratingWarningButtons:be,singleExportMessage:ve,navigateButtonContainer:je,loadingOverlay:_e};function Ne({isOpen:c,onClose:i,onExport:r,crisisMapsCount:j,droneImagesCount:z,isLoading:s=!1,exportSuccess:x=!1,variant:k="bulk",onNavigateAndExport:I}){const[p,_]=n.useState("standard"),[f,E]=n.useState(80),[C,u]=n.useState(10),[S,N]=n.useState(10),[g,T]=n.useState(!0),[w,M]=n.useState(!0),y=()=>{if(k==="single"){r(p,["crisis_map","drone_image"]);return}if(!g&&!w){alert("Please select at least one image type to export.");return}const t=[];g&&t.push("crisis_map"),w&&t.push("drone_image"),r(p,t)},m=()=>{i()};return c?k==="single"?e.jsx("div",{className:l.fullSizeModalOverlay,onClick:m,children:e.jsxs("div",{className:l.fullSizeModalContent,onClick:t=>t.stopPropagation(),children:[s&&e.jsx("div",{className:l.loadingOverlay,children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(B,{className:"text-ifrcRed"}),e.jsx("div",{className:"text-lg font-medium",children:"Exporting..."}),e.jsx("div",{className:"text-sm text-gray-600",children:"This might take a few seconds"})]})}),x&&e.jsx("div",{className:l.loadingOverlay,children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"text-lg font-medium",children:"Export Successful!"}),e.jsx("div",{className:"text-sm text-gray-600",children:"Your dataset has been downloaded"}),e.jsx(v,{name:"close-export-success",onClick:m,className:"mt-4",children:"Close"})]})}),e.jsxs("div",{className:l.ratingWarningContent,children:[e.jsx("h3",{className:l.ratingWarningTitle,children:"Export Single Item"}),e.jsxs("div",{className:l.singleExportMessage,children:[e.jsx("p",{children:"This only exports the 1 item currently on display."}),e.jsx("p",{children:'You may export the entire dataset from the "list view" here:'})]}),e.jsx("div",{className:l.navigateButtonContainer,children:e.jsx(v,{name:"navigate-to-list",variant:"secondary",onClick:I,children:"Navigate to List View"})}),e.jsxs("div",{className:l.ratingWarningButtons,children:[e.jsx(v,{name:"continue-export",onClick:y,disabled:s,children:s?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"text-white"}),"Exporting..."]}):"Continue"}),e.jsx(v,{name:"cancel-export",variant:"tertiary",onClick:m,disabled:s,children:"Cancel"})]})]})]})}):e.jsx("div",{className:l.fullSizeModalOverlay,onClick:m,children:e.jsxs("div",{className:l.fullSizeModalContent,onClick:t=>t.stopPropagation(),children:[s&&e.jsx("div",{className:l.loadingOverlay,children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(B,{className:"text-ifrcRed"}),e.jsx("div",{className:"text-lg font-medium",children:"Exporting..."}),e.jsx("div",{className:"text-sm text-gray-600",children:"This might take a few seconds"})]})}),x&&e.jsx("div",{className:l.loadingOverlay,children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"text-lg font-medium",children:"Export Successful!"}),e.jsx("div",{className:"text-sm text-gray-600",children:"Your dataset has been downloaded"}),e.jsx(v,{name:"close-export-success",onClick:m,className:"mt-4",children:"Close"})]})}),e.jsxs("div",{className:l.ratingWarningContent,children:[e.jsx("h3",{className:l.ratingWarningTitle,children:"Export Dataset"}),e.jsx("div",{className:l.exportModeSection,children:e.jsx(R,{name:"export-mode",value:p,onChange:t=>{(t==="standard"||t==="fine-tuning")&&_(t)},options:[{key:"standard",label:"Standard"},{key:"fine-tuning",label:"Fine-tuning"}],keySelector:t=>t.key,labelSelector:t=>t.label,disabled:s})}),p==="fine-tuning"&&e.jsxs("div",{className:l.splitConfigSection,children:[e.jsx("div",{className:l.splitConfigTitle,children:"Dataset Split Configuration"}),e.jsxs("div",{className:l.splitInputsContainer,children:[e.jsxs("div",{className:l.splitInputGroup,children:[e.jsx("label",{htmlFor:"train-split",className:l.splitInputLabel,children:"Train (%)"}),e.jsx("input",{id:"train-split",type:"number",min:"0",max:"100",value:f,onChange:t=>{const o=parseInt(t.target.value)||0,d=100-o;d>=0&&(E(o),C+S>d&&(u(Math.floor(d/2)),N(d-Math.floor(d/2))))},className:l.splitInput,disabled:s})]}),e.jsxs("div",{className:l.splitInputGroup,children:[e.jsx("label",{htmlFor:"test-split",className:l.splitInputLabel,children:"Test (%)"}),e.jsx("input",{id:"test-split",type:"number",min:"0",max:"100",value:C,onChange:t=>{const o=parseInt(t.target.value)||0,d=100-f-o;d>=0&&(u(o),N(d))},className:l.splitInput,disabled:s})]}),e.jsxs("div",{className:l.splitInputGroup,children:[e.jsx("label",{htmlFor:"val-split",className:l.splitInputLabel,children:"Val (%)"}),e.jsx("input",{id:"val-split",type:"number",min:"0",max:"100",value:S,onChange:t=>{const o=parseInt(t.target.value)||0,d=100-f-o;d>=0&&(N(o),u(d))},className:l.splitInput,disabled:s})]})]}),f+C+S!==100&&e.jsx("div",{className:l.splitTotal,children:e.jsx("span",{className:l.splitTotalError,children:"Must equal 100%"})})]}),e.jsxs("div",{className:l.checkboxesContainer,children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(P,{name:"crisis-maps",label:`Crisis Maps (${j} images)`,value:g,onChange:t=>T(t),disabled:s})}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(P,{name:"drone-images",label:`Drone Images (${z} images)`,value:w,onChange:t=>M(t),disabled:s})})]}),e.jsxs("div",{className:l.ratingWarningButtons,children:[e.jsx(v,{name:"confirm-export",onClick:y,disabled:s,children:s?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"text-white"}),"Exporting..."]}):"Export Selected"}),e.jsx(v,{name:"cancel-export",variant:"tertiary",onClick:m,disabled:s,children:"Cancel"})]})]})]})}):null}export{Ne as E,Ce as F};
py_backend/static/assets/{index-D2ncrm5K.js β†’ index-B4LyeOKz.js} RENAMED
@@ -1,3 +1,3 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jszip.min-C3B0d4UO.js","assets/index-BCz4bkWK.js","assets/index-FBu17hMI.css"])))=>i.map(i=>d[i]);
2
- import{K as ea,x as aa,j as a,N as Y,n as F,r as m,D as ta,_ as we,L as sa,z as P,v as ie,w as oe,F as ia,M as oa,G as na}from"./index-BCz4bkWK.js";import{u as ra}from"./useAdmin-LSEnRjVv.js";import{F as la,E as ca}from"./ExportModal-Qf6Y7VAO.js";const da="_tabSelector_usssr_1",ga="_imageContainer_usssr_12",ma="_imagePlaceholder_usssr_33",ua="_metadataTags_usssr_45",fa="_metadataTag_usssr_45",pa="_captionContainer_usssr_67",ha="_captionText_usssr_74",_a="_gridLayout_usssr_131",xa="_detailsSection_usssr_155",ya="_loadingContainer_usssr_161",va="_errorContainer_usssr_171",wa="_fullSizeModalOverlay_usssr_205",Ca="_fullSizeModalContent_usssr_219",ja="_ratingWarningContent_usssr_230",Ia="_ratingWarningTitle_usssr_236",Na="_ratingWarningText_usssr_243",ba="_ratingWarningButtons_usssr_250",Sa="_carouselContainer_usssr_365",La="_carouselImageWrapper_usssr_370",Da="_carouselImage_usssr_370",ka="_carouselNavigation_usssr_393",Ma="_carouselButton_usssr_405",Ta="_carouselIndicators_usssr_429",Fa="_carouselIndicator_usssr_429",Ea="_carouselIndicatorActive_usssr_458",Pa="_singleImageContainer_usssr_488",Ra="_viewImageButtonContainer_usssr_494",p={tabSelector:da,imageContainer:ga,imagePlaceholder:ma,metadataTags:ua,metadataTag:fa,captionContainer:pa,captionText:ha,gridLayout:_a,detailsSection:xa,loadingContainer:ya,errorContainer:va,fullSizeModalOverlay:wa,fullSizeModalContent:Ca,ratingWarningContent:ja,ratingWarningTitle:Ia,ratingWarningText:Na,ratingWarningButtons:ba,carouselContainer:Sa,carouselImageWrapper:La,carouselImage:Da,carouselNavigation:ka,carouselButton:Ma,carouselIndicators:Ta,carouselIndicator:Fa,carouselIndicatorActive:Ea,singleImageContainer:Pa,viewImageButtonContainer:Ra};function st(){const{mapId:h}=ea(),v=aa(),{isAuthenticated:ne}=ra();console.log("MapDetailsPage: Current URL:",window.location.href),console.log("MapDetailsPage: Hash:",window.location.hash),console.log("MapDetailsPage: mapId from useParams:",h),console.log("MapDetailsPage: mapId type:",typeof h),console.log("MapDetailsPage: mapId length:",h?.length),console.log("MapDetailsPage: mapId value:",JSON.stringify(h));const Ce=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;if(!h||h==="undefined"||h==="null"||h.trim()===""||!Ce.test(h))return a.jsx(Y,{children:a.jsxs("div",{className:"flex flex-col items-center gap-4 text-center py-12",children:[a.jsx("div",{className:"text-4xl",children:"⚠️"}),a.jsx("div",{className:"text-xl font-semibold",children:"Invalid Map ID"}),a.jsx("div",{children:"The map ID provided is not valid."}),a.jsxs("div",{className:"text-sm text-gray-500 mt-2",children:['Debug Info: mapId = "',h,'" (type: ',typeof h,")"]}),a.jsx(F,{name:"back-to-explore",variant:"secondary",onClick:()=>v("/explore"),children:"Return to Explore"})]})});const[re,je]=m.useState("mapDetails"),[e,ee]=m.useState(null),[W,z]=m.useState(!0),[le,O]=m.useState(null),[ce,Ie]=m.useState([]),[de,Ne]=m.useState([]),[ge,be]=m.useState([]),[me,Se]=m.useState([]),[Le,De]=m.useState([]),[ke,Me]=m.useState(!1),[Te,Fe]=m.useState(!1),[B,q]=m.useState(!1),[Ee,K]=m.useState(!1),[ue,Z]=m.useState(!1),[Pe,ae]=m.useState(!1),[Re,te]=m.useState(!1),[$a,za]=m.useState("standard"),[R,Aa]=m.useState(80),[J,Oa]=m.useState(10),[Ua,Wa]=m.useState(10),[Ba,Ja]=m.useState(!0),[Ha,Va]=m.useState(!0),[Q,X]=m.useState(!1),[$e,fe]=m.useState(!1),[ze,pe]=m.useState(null),[Ae,H]=m.useState(!1),[x,V]=m.useState([]),[M,A]=m.useState(0),[G,he]=m.useState(!1),{search:d,setSearch:Ga,srcFilter:w,setSrcFilter:qa,catFilter:C,setCatFilter:Ka,regionFilter:j,setRegionFilter:Za,countryFilter:I,setCountryFilter:Qa,imageTypeFilter:N,setImageTypeFilter:Xa,uploadTypeFilter:b,setUploadTypeFilter:Ya,showReferenceExamples:k,setShowReferenceExamples:Oe,clearAllFilters:Ue}=ta(),We=[{key:"explore",label:"List"},{key:"mapDetails",label:"Carousel"}],_e=m.useCallback(async t=>{if(console.log("fetchMapData called with id:",t),console.log("fetchMapData id type:",typeof t),!t||t==="undefined"||t==="null"||t.trim()===""){console.log("fetchMapData: Invalid ID detected:",t),O("Invalid Map ID"),z(!1);return}if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)){console.log("fetchMapData: Invalid UUID format:",t),O("Invalid Map ID format"),z(!1);return}console.log("fetchMapData: Making API call for id:",t),q(!0),z(!0);try{const u=await fetch(`/api/images/${t}`);if(!u.ok)throw new Error("Map not found");const s=await u.json();if(ee(s),s.all_image_ids&&s.all_image_ids.length>1)await xe(s.all_image_ids);else if(s.image_count&&s.image_count>1){console.log("Multi-upload detected but no all_image_ids, trying grouped endpoint");try{const l=await fetch("/api/images/grouped");if(l.ok){const r=(await l.json()).find(c=>c.all_image_ids&&c.all_image_ids.includes(s.image_id));r&&r.all_image_ids?await xe(r.all_image_ids):(V([s]),A(0))}else V([s]),A(0)}catch(l){console.error("Failed to fetch from grouped endpoint:",l),V([s]),A(0)}}else V([s]),A(0);await se(t)}catch(u){O(u instanceof Error?u.message:"Unknown error occurred")}finally{z(!1),q(!1)}},[]),xe=m.useCallback(async t=>{console.log("fetchAllImages called with imageIds:",t),he(!0);try{const i=t.map(async s=>{const l=await fetch(`/api/images/${s}`);if(!l.ok)throw new Error(`Failed to fetch image ${s}`);return l.json()}),u=await Promise.all(i);V(u),A(0),console.log("fetchAllImages: Loaded",u.length,"images")}catch(i){console.error("fetchAllImages error:",i),O(i instanceof Error?i.message:"Failed to load all images")}finally{he(!1)}},[]),Be=m.useCallback(()=>{x.length>1&&A(t=>t>0?t-1:x.length-1)},[x.length]),Je=m.useCallback(()=>{x.length>1&&A(t=>t<x.length-1?t+1:0)},[x.length]),He=m.useCallback(t=>{t>=0&&t<x.length&&A(t)},[x.length]),ye=m.useCallback(async t=>{const i=t||(x.length>0?x[M]:e);if(i){H(!0),pe(i),fe(!0);try{const u=new Image;u.onload=()=>{H(!1)},u.onerror=()=>{H(!1)},u.src=i.image_url}catch(u){console.error("Error preloading full-size image:",u),H(!1)}}},[x,M,e]),Ve=m.useCallback(()=>{fe(!1),pe(null),H(!1)},[]);m.useEffect(()=>{if(console.log("MapDetailsPage: mapId from useParams:",h),console.log("MapDetailsPage: mapId type:",typeof h),console.log("MapDetailsPage: mapId value:",h),!h||h==="undefined"||h==="null"||h.trim()===""||h===void 0||h===null){console.log("MapDetailsPage: Invalid mapId, setting error"),O("Map ID is required"),z(!1);return}if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(h)){console.log("MapDetailsPage: Invalid UUID format:",h),O("Invalid Map ID format"),z(!1);return}console.log("MapDetailsPage: Fetching data for mapId:",h),_e(h)},[h,_e]),m.useEffect(()=>{if(!e||W||Q)return;if(!h||h==="undefined"||h==="null"||h.trim()===""){console.log("Auto-navigation skipped: Invalid mapId");return}if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(h)){console.log("Auto-navigation skipped: Invalid mapId format");return}(()=>{const u=!d||e.title?.toLowerCase().includes(d.toLowerCase())||e.generated?.toLowerCase().includes(d.toLowerCase())||e.source?.toLowerCase().includes(d.toLowerCase())||e.event_type?.toLowerCase().includes(d.toLowerCase()),s=!w||e.source===w,l=!C||e.event_type===C,o=!j||e.countries.some(T=>T.r_code===j),r=!I||e.countries.some(T=>T.c_code===I),c=!N||e.image_type===N,n=!k||e.starred===!0,y=u&&s&&l&&o&&r&&c&&n;return console.log("Auto-navigation check:",{mapId:h,search:d,srcFilter:w,catFilter:C,regionFilter:j,countryFilter:I,imageTypeFilter:N,showReferenceExamples:k,matchesSearch:u,matchesSource:s,matchesCategory:l,matchesRegion:o,matchesCountry:r,matchesImageType:c,matchesReferenceExamples:n,matches:y}),y})()||(console.log("Current map does not match filters, looking for first matching item"),fetch("/api/images").then(u=>u.json()).then(u=>{console.log("Auto-navigation: Received images from API:",u.length),console.log("Auto-navigation: First few images:",u.slice(0,3).map(l=>({image_id:l.image_id,title:l.title})));const s=u.find(l=>{const o=!d||l.title?.toLowerCase().includes(d.toLowerCase())||l.generated?.toLowerCase().includes(d.toLowerCase())||l.source?.toLowerCase().includes(d.toLowerCase())||l.event_type?.toLowerCase().includes(d.toLowerCase()),r=!w||l.source===w,c=!C||l.event_type===C,n=!j||l.countries?.some(f=>f.r_code===j),y=!I||l.countries?.some(f=>f.c_code===I),T=!N||l.image_type===N,L=!k||l.starred===!0;return o&&r&&c&&n&&y&&T&&L});console.log("Auto-navigation: Found first matching image:",s?{image_id:s.image_id,title:s.title,source:s.source}:"No matching image found"),s&&s.image_id&&s.image_id!=="undefined"&&s.image_id!=="null"&&s.image_id.trim()!==""&&s.image_id!==h&&(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(s.image_id)?(console.log("Auto-navigating to:",s.image_id),v(`/map/${s.image_id}`)):console.error("Auto-navigation blocked: Invalid image_id format:",s.image_id))}).catch(console.error))},[e,d,w,C,j,I,N,k,h,v,W,Q]);const se=async t=>{if(!(!t||t==="undefined"||t==="null"||t.trim()===""))try{const i=await fetch("/api/images/grouped");if(i.ok){const s=(await i.json()).filter(o=>{const r=!d||o.title?.toLowerCase().includes(d.toLowerCase())||o.generated?.toLowerCase().includes(d.toLowerCase())||o.source?.toLowerCase().includes(d.toLowerCase())||o.event_type?.toLowerCase().includes(d.toLowerCase()),c=!w||o.source===w,n=!C||o.event_type===C,y=!j||o.countries?.some(_=>_.r_code===j),T=!I||o.countries?.some(_=>_.c_code===I),L=!N||o.image_type===N,f=!b||b==="single"&&(!o.image_count||o.image_count<=1)||b==="multiple"&&o.image_count&&o.image_count>1,S=!k||o.starred===!0;return r&&c&&n&&y&&T&&L&&f&&S}),l=s.findIndex(o=>o.image_id===t);Me(s.length>1&&l>0),Fe(s.length>1&&l<s.length-1)}}catch(i){console.error("Failed to check navigation availability:",i)}},ve=async t=>{if(!B){q(!0);try{const i=await fetch("/api/images/grouped");if(i.ok){const u=await i.json(),s=u.filter(n=>{const y=!d||n.title?.toLowerCase().includes(d.toLowerCase())||n.generated?.toLowerCase().includes(d.toLowerCase())||n.source?.toLowerCase().includes(d.toLowerCase())||n.event_type?.toLowerCase().includes(d.toLowerCase()),T=!w||n.source===w,L=!C||n.event_type===C,f=!j||n.countries?.some($=>$.r_code===j),S=!I||n.countries?.some($=>$.c_code===I),_=!N||n.image_type===N,D=!b||b==="single"&&(!n.image_count||n.image_count<=1)||b==="multiple"&&n.image_count&&n.image_count>1,U=!k||n.starred===!0;return y&&T&&L&&f&&S&&_&&D&&U});if(s.findIndex(n=>n.image_id===h)===-1){const n=u.find(y=>y.image_id===h);n&&s.push(n)}const o=s.findIndex(n=>n.image_id===h);if(o===-1){console.error("Current image not found in filtered list");return}let r;t==="previous"?r=o>0?o-1:s.length-1:r=o<s.length-1?o+1:0;const c=s[r];c&&c.image_id&&c.image_id!=="undefined"&&c.image_id!=="null"&&c.image_id.trim()!==""&&(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(c.image_id)?(console.log("Carousel navigating to:",c.image_id),v(`/map/${c.image_id}`)):console.error("Carousel navigation blocked: Invalid image_id format:",c.image_id))}}catch(i){console.error("Failed to navigate to item:",i)}finally{q(!1)}}};m.useEffect(()=>{e&&h&&!W&&!Q&&se(h)},[e,h,d,w,C,j,I,N,b,k,W,Q,se]),m.useEffect(()=>{Promise.all([fetch("/api/sources").then(t=>t.json()),fetch("/api/types").then(t=>t.json()),fetch("/api/image-types").then(t=>t.json()),fetch("/api/regions").then(t=>t.json()),fetch("/api/countries").then(t=>t.json())]).then(([t,i,u,s,l])=>{Ie(t),Ne(i),be(u),Se(s),De(l)}).catch(console.error)},[]);const Ge=async()=>{e&&K(!0)},qe=async()=>{if(e)try{(await fetch(`/api/images/${e.image_id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({starred:!e.starred})})).ok?ee(i=>i?{...i,starred:!i.starred}:null):console.error("Failed to toggle starred status")}catch(t){console.error("Error toggling starred status:",t)}},Ke=async()=>{if(e){X(!0);try{if(console.log("Deleting image with ID:",e.image_id),(await fetch(`/api/images/${e.image_id}`,{method:"DELETE"})).ok){ee(i=>i?{...i,starred:!i.starred}:null),K(!1);try{const i=await fetch("/api/images/grouped");if(i.ok){const s=(await i.json()).filter(o=>{const r=!d||o.title?.toLowerCase().includes(d.toLowerCase())||o.generated?.toLowerCase().includes(d.toLowerCase())||o.source?.toLowerCase().includes(d.toLowerCase())||o.event_type?.toLowerCase().includes(d.toLowerCase()),c=!w||o.source===w,n=!C||o.event_type===C,y=!j||o.countries?.some(_=>_.r_code===j),T=!I||o.countries?.some(_=>_.c_code===I),L=!N||o.image_type===N,f=!b||b==="single"&&(!o.image_count||o.image_count<=1)||b==="multiple"&&o.image_count&&o.image_count>1,S=!k||o.starred===!0;return r&&c&&n&&y&&T&&L&&f&&S}),l=s.filter(o=>o.image_id!==e.image_id);if(l.length>0){const o=s.findIndex(c=>c.image_id===e.image_id);let r;if(o===s.length-1?r=o-1:r=o,console.log("Navigation target:",{currentIndex:o,targetIndex:r,targetId:l[r]?.image_id}),r>=0&&r<l.length){const c=l[r];c&&c.image_id&&c.image_id!=="undefined"&&c.image_id!=="null"&&c.image_id.trim()!==""?/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(c.image_id)?(console.log("Navigating to:",c.image_id),v(`/map/${c.image_id}`)):(console.error("Navigation blocked: Invalid image_id format:",c.image_id),v("/explore")):(console.error("Navigation blocked: Invalid image_id:",c?.image_id),v("/explore"))}else l[0]&&l[0].image_id&&l[0].image_id!=="undefined"&&l[0].image_id!=="null"&&l[0].image_id.trim()!==""?/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(l[0].image_id)?(console.log("Fallback navigation to first item:",l[0].image_id),v(`/map/${l[0].image_id}`)):(console.error("Fallback navigation blocked: Invalid image_id format:",l[0].image_id),v("/explore")):(console.log("No valid remaining items, going to explore page"),v("/explore"))}else console.log("No remaining items, going to explore page"),v("/explore")}else v("/explore")}catch(i){console.error("Failed to navigate to next item:",i),v("/explore")}finally{X(!1)}}else console.error("Delete failed"),X(!1)}catch(t){console.error("Delete failed:",t),X(!1)}}},g=m.useMemo(()=>{if(!e)return null;if(!d&&!w&&!C&&!j&&!I&&!N&&!b&&!k)return e;const t=!d||e.title?.toLowerCase().includes(d.toLowerCase())||e.generated?.toLowerCase().includes(d.toLowerCase())||e.source?.toLowerCase().includes(d.toLowerCase())||e.event_type?.toLowerCase().includes(d.toLowerCase()),i=!w||e.source===w,u=!C||e.event_type===C,s=!j||e.countries.some(y=>y.r_code===j),l=!I||e.countries.some(y=>y.c_code===I),o=!N||e.image_type===N,r=!b||b==="single"&&(!e.image_count||e.image_count<=1)||b==="multiple"&&e.image_count&&e.image_count>1,c=!k||e.starred===!0,n=t&&i&&u&&s&&l&&o&&r&&c;return!n&&(d||w||C||j||I||N||b||k)?(setTimeout(()=>{Ze()},100),e):n?e:null},[e,d,w,C,j,I,N,b,k]),Ze=m.useCallback(async()=>{z(!0);try{const t=await fetch("/api/images/grouped");if(t.ok){const u=(await t.json()).filter(s=>{const l=!d||s.title?.toLowerCase().includes(d.toLowerCase())||s.generated?.toLowerCase().includes(d.toLowerCase())||s.source?.toLowerCase().includes(d.toLowerCase())||s.event_type?.toLowerCase().includes(d.toLowerCase()),o=!w||s.source===w,r=!C||s.event_type===C,c=!j||s.countries?.some(f=>f.r_code===j),n=!I||s.countries?.some(f=>f.c_code===I),y=!N||s.image_type===N,T=!b||b==="single"&&(!s.image_count||s.image_count<=1)||b==="multiple"&&s.image_count&&s.image_count>1,L=!k||s.starred===!0;return l&&o&&r&&c&&n&&y&&T&&L});if(u.length>0){const s=u[0];s&&s.image_id&&v(`/map/${s.image_id}`)}else v("/explore")}}catch(t){console.error("Failed to navigate to matching image:",t),v("/explore")}finally{z(!1)}},[d,w,C,j,I,N,b,k,v]),Qe=()=>{if(!e)return;if(!e.all_image_ids||e.all_image_ids.length<=1){const s=`/upload?step=1&contribute=true&imageIds=${[e.image_id].join(",")}`;v(s);return}const i=`/upload?step=1&contribute=true&imageIds=${e.all_image_ids.join(",")}`;v(i)},E=(t,i)=>({image:`images/${i}`,caption:t.edited||t.generated||"",metadata:{image_id:t.image_count&&t.image_count>1?t.all_image_ids||[t.image_id]:t.image_id,title:t.title,source:t.source,event_type:t.event_type,image_type:t.image_type,countries:t.countries,starred:t.starred,image_count:t.image_count||1}}),Xe=async t=>{if(e){ae(!0),te(!1);try{const i=(await na(async()=>{const{default:r}=await import("./jszip.min-C3B0d4UO.js").then(c=>c.j);return{default:r}},__vite__mapDeps([0,1,2]))).default,u=new i;if(e.image_type==="crisis_map"){const r=u.folder("crisis_maps_dataset"),c=r?.folder("images");if(c)try{const n=e.image_count&&e.image_count>1?e.all_image_ids||[e.image_id]:[e.image_id],y=n.map(async(f,S)=>{try{const _=await fetch(`/api/images/${f}/file`);if(!_.ok)throw new Error(`Failed to fetch image ${f}`);const D=await _.blob(),U=e.file_key.split(".").pop()||"jpg",$=`0001_${String(S+1).padStart(2,"0")}.${U}`;return c.file($,D),{success:!0,fileName:$,imageId:f}}catch(_){return console.error(`Failed to process image ${f}:`,_),{success:!1,fileName:"",imageId:f}}}),L=(await Promise.all(y)).filter(f=>f.success);if(L.length===0)throw new Error("No images could be processed");if(t==="fine-tuning"){const f=[],S=[],_=[],D=L.map(Ye=>`images/${Ye.fileName}`),U=Math.random(),$={image:D.length===1?D[0]:D,caption:e.edited||e.generated||"",metadata:{image_id:n,title:e.title,source:e.source,event_type:e.event_type,image_type:e.image_type,countries:e.countries,starred:e.starred,image_count:e.image_count||1}};U<R/100?f.push($):U<(R+J)/100?S.push($):_.push($),r&&(r.file("train.jsonl",JSON.stringify(f,null,2)),r.file("test.jsonl",JSON.stringify(S,null,2)),r.file("val.jsonl",JSON.stringify(_,null,2)))}else{const f=L.map(_=>`images/${_.fileName}`),S={image:f.length===1?f[0]:f,caption:e.edited||e.generated||"",metadata:{image_id:n,title:e.title,source:e.source,event_type:e.event_type,image_type:e.image_type,countries:e.countries,starred:e.starred,image_count:e.image_count||1}};r&&r.file("0001.json",JSON.stringify(S,null,2))}}catch(n){throw console.error(`Failed to process image ${e.image_id}:`,n),n}}else if(e.image_type==="drone_image"){const r=u.folder("drone_images_dataset"),c=r?.folder("images");if(c)try{const n=await fetch(`/api/images/${e.image_id}/file`);if(!n.ok)throw new Error(`Failed to fetch image ${e.image_id}`);const y=await n.blob(),L=`0001.${e.file_key.split(".").pop()||"jpg"}`;if(c.file(L,y),t==="fine-tuning"){const f=[],S=[],_=[];if(String(e?.image_type)==="crisis_map"){const D=Math.random();D<R/100?f.push(E(e,"0001")):D<(R+J)/100?S.push(E(e,"0001")):_.push(E(e,"0001"))}else if(String(e?.image_type)==="drone_image"){const D=Math.random();D<R/100?f.push(E(e,"0001")):D<(R+J)/100?S.push(E(e,"0001")):_.push(E(e,"0001"))}r&&(r.file("train.jsonl",JSON.stringify(f,null,2)),r.file("test.jsonl",JSON.stringify(S,null,2)),r.file("val.jsonl",JSON.stringify(_,null,2)))}else{const f={image:`images/${L}`,caption:e.edited||e.generated||"",metadata:{image_id:e.image_count&&e.image_count>1?e.all_image_ids||[e.image_id]:e.image_id,title:e.title,source:e.source,event_type:e.event_type,image_type:e.image_type,countries:e.countries,starred:e.starred,image_count:e.image_count||1}};r&&r.file("0001.json",JSON.stringify(f,null,2))}}catch(n){throw console.error(`Failed to process image ${e.image_id}:`,n),n}}else{const r=u.folder("generic_dataset"),c=r?.folder("images");if(c)try{const n=await fetch(`/api/images/${e.image_id}/file`);if(!n.ok)throw new Error(`Failed to fetch image ${e.image_id}`);const y=await n.blob(),L=`0001.${e.file_key.split(".").pop()||"jpg"}`;if(c.file(L,y),t==="fine-tuning"){const f=[],S=[],_=[];if(String(e?.image_type)==="crisis_map"){const D=Math.random();D<R/100?f.push(E(e,"0001")):D<(R+J)/100?S.push(E(e,"0001")):_.push(E(e,"0001"))}else if(String(e?.image_type)==="drone_image"){const D=Math.random();D<R/100?f.push(E(e,"0001")):D<(R+J)/100?S.push(E(e,"0001")):_.push(E(e,"0001"))}r&&(r.file("train.jsonl",JSON.stringify(f,null,2)),r.file("test.jsonl",JSON.stringify(S,null,2)),r.file("val.jsonl",JSON.stringify(_,null,2)))}else{const f={image:`images/${L}`,caption:e.edited||e.generated||"",metadata:{image_id:e.image_count&&e.image_count>1?e.all_image_ids||[e.image_id]:e.image_id,title:e.title,source:e.source,event_type:e.event_type,image_type:e.image_type,countries:e.countries,starred:e.starred,image_count:e.image_count||1}};r&&r.file("0001.json",JSON.stringify(f,null,2))}}catch(n){throw console.error(`Failed to process image ${e.image_id}:`,n),n}}const s=await u.generateAsync({type:"blob"}),l=URL.createObjectURL(s),o=document.createElement("a");o.href=l,o.download=`dataset_${e.image_type}_${e.image_id}_${t}_${new Date().toISOString().split("T")[0]}.zip`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(l),console.log(`Exported ${e.image_type} dataset with 1 image in ${t} mode`),te(!0)}catch(i){console.error("Export failed:",i),alert("Failed to export dataset. Please try again.")}finally{ae(!1)}}};return W?a.jsx(Y,{children:a.jsx("div",{className:p.loadingContainer,children:a.jsxs("div",{className:"flex flex-col items-center gap-4",children:[a.jsx(we,{className:"text-ifrcRed"}),a.jsx("div",{children:"Loading map details..."})]})})}):le||!e?a.jsx(Y,{children:a.jsx("div",{className:p.errorContainer,children:a.jsxs("div",{className:"flex flex-col items-center gap-4 text-center",children:[a.jsx("div",{className:"text-4xl",children:"⚠️"}),a.jsx("div",{className:"text-xl font-semibold",children:"Unable to load map"}),a.jsx("div",{children:le||"Map not found"}),a.jsx(F,{name:"back-to-explore",variant:"secondary",onClick:()=>v("/explore"),children:"Return to Explore"})]})})}):a.jsxs(Y,{children:[a.jsxs("div",{className:"max-w-7xl mx-auto",children:[a.jsxs("div",{className:p.tabSelector,children:[a.jsx(sa,{name:"map-details-view",value:re,onChange:t=>{(t==="mapDetails"||t==="explore")&&(je(t),t==="explore"&&v("/explore"))},options:We,keySelector:t=>t.key,labelSelector:t=>t.label}),a.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[a.jsx(P,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:a.jsxs(F,{name:"reference-examples",variant:k?"primary":"secondary",onClick:()=>Oe(!k),className:"whitespace-nowrap",children:[a.jsx("span",{className:"mr-2",children:k?a.jsx("span",{className:"text-yellow-400",children:"β˜…"}):a.jsx("span",{className:"text-yellow-400",children:"β˜†"})}),"Reference Examples"]})}),a.jsx(F,{name:"export-dataset",variant:"secondary",onClick:()=>Z(!0),children:"Export"})]})]}),a.jsx(la,{sources:ce,types:de,regions:me,countries:Le,imageTypes:ge,isLoadingFilters:!1}),re==="mapDetails"?a.jsx("div",{className:"relative",children:g?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:p.gridLayout,children:[a.jsxs(P,{heading:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{children:g.title||"Map Image"}),g.starred&&a.jsx("span",{className:"text-red-500 text-xl",title:"Starred image",children:"β˜…"})]}),headingLevel:2,withHeaderBorder:!0,withInternalPadding:!0,spacing:"comfortable",children:[a.jsx("div",{className:p.imageContainer,children:e?.image_count&&e.image_count>1||x.length>1?a.jsxs("div",{className:p.carouselContainer,children:[a.jsx("div",{className:p.carouselImageWrapper,children:G?a.jsxs("div",{className:p.imagePlaceholder,children:[a.jsx(we,{className:"text-ifrcRed"}),a.jsx("div",{children:"Loading images..."})]}):x[M]?.detail_url?a.jsx("img",{src:x[M].detail_url,alt:x[M].file_key,className:p.carouselImage,onError:t=>{console.log("MapDetailsPage: Detail image failed to load, falling back to original:",x[M].detail_url);const i=t.target;x[M].image_url&&(i.src=x[M].image_url)},onLoad:()=>console.log("MapDetailsPage: Detail image loaded successfully:",x[M].detail_url)}):x[M]?.image_url?a.jsx("img",{src:x[M].image_url,alt:x[M].file_key,className:p.carouselImage,onLoad:()=>console.log("MapDetailsPage: Original image loaded successfully:",x[M].image_url)}):a.jsx("div",{className:p.imagePlaceholder,children:"No image available"})}),a.jsxs("div",{className:p.carouselNavigation,children:[a.jsx(F,{name:"previous-image",variant:"tertiary",size:1,onClick:Be,disabled:G,className:p.carouselButton,children:a.jsx(ie,{className:"w-4 h-4"})}),a.jsx("div",{className:p.carouselIndicators,children:x.map((t,i)=>a.jsx("button",{onClick:()=>He(i),className:`${p.carouselIndicator} ${i===M?p.carouselIndicatorActive:""}`,disabled:G,children:i+1},i))}),a.jsx(F,{name:"next-image",variant:"tertiary",size:1,onClick:Je,disabled:G,className:p.carouselButton,children:a.jsx(oe,{className:"w-4 h-4"})})]}),a.jsx("div",{className:p.viewImageButtonContainer,children:a.jsx(F,{name:"view-full-size-carousel",variant:"secondary",size:1,onClick:()=>ye(x[M]),disabled:G||!x[M]?.image_url,children:"View Image"})})]}):a.jsxs("div",{className:p.singleImageContainer,children:[g.detail_url?a.jsx("img",{src:g.detail_url,alt:g.file_key,onError:t=>{console.log("MapDetailsPage: Detail image failed to load, falling back to original:",g.detail_url);const i=t.target;g.image_url&&(i.src=g.image_url)},onLoad:()=>console.log("MapDetailsPage: Detail image loaded successfully:",g.detail_url)}):g.image_url?a.jsx("img",{src:g.image_url,alt:g.file_key,onLoad:()=>console.log("MapDetailsPage: Original image loaded successfully:",g.image_url)}):a.jsx("div",{className:p.imagePlaceholder,children:"No image available"}),a.jsx("div",{className:p.viewImageButtonContainer,children:a.jsx(F,{name:"view-full-size-single",variant:"secondary",size:1,onClick:()=>ye(g),disabled:!g.image_url,children:"View Image"})})]})}),a.jsx(P,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:a.jsxs("div",{className:p.metadataTags,children:[g.image_type!=="drone_image"&&a.jsx("span",{className:p.metadataTag,children:ce.find(t=>t.s_code===g.source)?.label||g.source}),a.jsx("span",{className:p.metadataTag,children:de.find(t=>t.t_code===g.event_type)?.label||g.event_type}),a.jsx("span",{className:p.metadataTag,children:ge.find(t=>t.image_type===g.image_type)?.label||g.image_type}),g.countries&&g.countries.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:p.metadataTag,children:me.find(t=>t.r_code===g.countries[0].r_code)?.label||"Unknown Region"}),a.jsx("span",{className:p.metadataTag,children:g.countries.map(t=>t.label).join(", ")})]}),g.image_count&&g.image_count>1&&a.jsxs("span",{className:p.metadataTag,title:`Multi-upload with ${g.image_count} images`,children:["πŸ“· ",g.image_count]}),(!g.image_count||g.image_count<=1)&&a.jsx("span",{className:p.metadataTag,title:"Single Upload",children:"Single"})]})})]}),a.jsx("div",{className:p.detailsSection,children:g.edited&&g.edited.includes("Description:")||g.generated&&g.generated.includes("Description:")?a.jsx(P,{heading:"AI Generated Content",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,spacing:"comfortable",children:a.jsx("div",{className:p.captionContainer,children:a.jsx("div",{className:p.captionText,children:(g.edited||g.generated||"").split(`
3
  `).map((t,i)=>a.jsx("div",{children:t.startsWith("Description:")||t.startsWith("Analysis:")||t.startsWith("Recommended Actions:")?a.jsx("h4",{className:"font-semibold text-gray-800 mt-4 mb-2",children:t}):t.trim()===""?a.jsx("br",{}):a.jsx("p",{className:"mb-2",children:t})},i))})})}):a.jsx(P,{heading:"Description",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,spacing:"comfortable",children:a.jsx("div",{className:p.captionContainer,children:g.generated?a.jsx("div",{className:p.captionText,children:a.jsx("p",{children:g.edited||g.generated})}):a.jsx("p",{children:"β€” no caption yet β€”"})})})})]}),a.jsx("div",{className:"flex items-center justify-center mt-8",children:a.jsx(P,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-lg p-4",children:a.jsxs("div",{className:"flex items-center gap-4",children:[ke&&a.jsx(P,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(F,{name:"previous-item",variant:"tertiary",size:1,className:`bg-white/90 hover:bg-white shadow-lg border border-gray-200 ${B?"opacity-50 cursor-not-allowed":"hover:scale-110"}`,onClick:()=>ve("previous"),disabled:B,children:a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsxs("div",{className:"flex -space-x-1",children:[a.jsx(ie,{className:"w-4 h-4"}),a.jsx(ie,{className:"w-4 h-4"})]}),a.jsx("span",{className:"font-semibold",children:"Previous"})]})})}),ne&&a.jsx(P,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(F,{name:"delete",variant:"tertiary",size:1,className:"bg-red-50 hover:bg-red-100 text-red-700 border border-red-200 hover:border-red-300",onClick:Ge,title:"Delete","aria-label":"Delete saved image",children:a.jsx(ia,{className:"w-4 h-4"})})}),a.jsx(P,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(F,{name:"contribute",onClick:Qe,children:"Contribute"})}),ne&&a.jsx(P,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(F,{name:"toggle-star",variant:"tertiary",size:1,className:`${e?.starred?"bg-red-100 hover:bg-red-200 text-red-800 border-2 border-red-400":"bg-gray-100 hover:bg-gray-200 text-gray-600 border-2 border-gray-300"} w-16 h-8 rounded-full transition-all duration-200 flex items-center justify-center`,onClick:qe,title:e?.starred?"Unstar image":"Star image","aria-label":e?.starred?"Unstar image":"Star image",children:a.jsx("span",{className:`text-lg transition-all duration-200 ${e?.starred?"text-red-600":"text-gray-500"}`,children:e?.starred?"β˜…":"β˜†"})})}),Te&&a.jsx(P,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(F,{name:"next-item",variant:"tertiary",size:1,className:`bg-white/90 hover:bg-white shadow-lg border border-gray-200 ${B?"opacity-50 cursor-not-allowed":"hover:scale-110"}`,onClick:()=>ve("next"),disabled:B,children:a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx("span",{className:"font-semibold",children:"Next"}),a.jsxs("div",{className:"flex -space-x-1",children:[a.jsx(oe,{className:"w-4 h-4"}),a.jsx(oe,{className:"w-4 h-4"})]})]})})})]})})})]}):a.jsxs("div",{className:"text-center py-12",children:[a.jsx("div",{className:"text-xl font-semibold text-gray-600 mb-4",children:"No matches found"}),a.jsx("div",{className:"mt-4",children:a.jsx(F,{name:"clear-filters",variant:"secondary",onClick:Ue,children:"Clear Filters"})})]})}):null]}),Ee&&a.jsx("div",{className:p.fullSizeModalOverlay,onClick:()=>K(!1),children:a.jsx("div",{className:p.fullSizeModalContent,onClick:t=>t.stopPropagation(),children:a.jsxs("div",{className:p.ratingWarningContent,children:[a.jsx("h3",{className:p.ratingWarningTitle,children:"Delete Image?"}),a.jsx("p",{className:p.ratingWarningText,children:"This action cannot be undone. Are you sure you want to delete this saved image and all related data?"}),a.jsxs("div",{className:p.ratingWarningButtons,children:[a.jsx(F,{name:"confirm-delete",variant:"secondary",onClick:Ke,children:"Delete"}),a.jsx(F,{name:"cancel-delete",variant:"tertiary",onClick:()=>K(!1),children:"Cancel"})]})]})})}),ue&&a.jsx(ca,{isOpen:ue,onClose:()=>{Z(!1),te(!1),ae(!1)},onExport:(t,i)=>{i.includes(e.image_type)&&Xe(t)},filteredCount:1,totalCount:1,hasFilters:!1,crisisMapsCount:e.image_type==="crisis_map"?1:0,droneImagesCount:e.image_type==="drone_image"?1:0,isLoading:Pe,exportSuccess:Re,variant:"single",onNavigateToList:()=>{Z(!1),v("/explore")},onNavigateAndExport:()=>{Z(!1),v("/explore?export=true")}}),a.jsx(oa,{isOpen:$e,imageUrl:ze?.image_url||null,preview:null,selectedImageData:null,onClose:Ve,isLoading:Ae})]})}export{st as default};
 
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jszip.min-Bux5isNr.js","assets/index-RA4UIF3R.js","assets/index-FBu17hMI.css"])))=>i.map(i=>d[i]);
2
+ import{K as ea,x as aa,j as a,N as Y,n as F,r as m,D as ta,_ as we,L as sa,z as P,v as ie,w as oe,F as ia,M as oa,G as na}from"./index-RA4UIF3R.js";import{u as ra}from"./useAdmin-k5gw6w_T.js";import{F as la,E as ca}from"./ExportModal-DWGvhKT1.js";const da="_tabSelector_usssr_1",ga="_imageContainer_usssr_12",ma="_imagePlaceholder_usssr_33",ua="_metadataTags_usssr_45",fa="_metadataTag_usssr_45",pa="_captionContainer_usssr_67",ha="_captionText_usssr_74",_a="_gridLayout_usssr_131",xa="_detailsSection_usssr_155",ya="_loadingContainer_usssr_161",va="_errorContainer_usssr_171",wa="_fullSizeModalOverlay_usssr_205",Ca="_fullSizeModalContent_usssr_219",ja="_ratingWarningContent_usssr_230",Ia="_ratingWarningTitle_usssr_236",Na="_ratingWarningText_usssr_243",ba="_ratingWarningButtons_usssr_250",Sa="_carouselContainer_usssr_365",La="_carouselImageWrapper_usssr_370",Da="_carouselImage_usssr_370",ka="_carouselNavigation_usssr_393",Ma="_carouselButton_usssr_405",Ta="_carouselIndicators_usssr_429",Fa="_carouselIndicator_usssr_429",Ea="_carouselIndicatorActive_usssr_458",Pa="_singleImageContainer_usssr_488",Ra="_viewImageButtonContainer_usssr_494",p={tabSelector:da,imageContainer:ga,imagePlaceholder:ma,metadataTags:ua,metadataTag:fa,captionContainer:pa,captionText:ha,gridLayout:_a,detailsSection:xa,loadingContainer:ya,errorContainer:va,fullSizeModalOverlay:wa,fullSizeModalContent:Ca,ratingWarningContent:ja,ratingWarningTitle:Ia,ratingWarningText:Na,ratingWarningButtons:ba,carouselContainer:Sa,carouselImageWrapper:La,carouselImage:Da,carouselNavigation:ka,carouselButton:Ma,carouselIndicators:Ta,carouselIndicator:Fa,carouselIndicatorActive:Ea,singleImageContainer:Pa,viewImageButtonContainer:Ra};function st(){const{mapId:h}=ea(),v=aa(),{isAuthenticated:ne}=ra();console.log("MapDetailsPage: Current URL:",window.location.href),console.log("MapDetailsPage: Hash:",window.location.hash),console.log("MapDetailsPage: mapId from useParams:",h),console.log("MapDetailsPage: mapId type:",typeof h),console.log("MapDetailsPage: mapId length:",h?.length),console.log("MapDetailsPage: mapId value:",JSON.stringify(h));const Ce=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;if(!h||h==="undefined"||h==="null"||h.trim()===""||!Ce.test(h))return a.jsx(Y,{children:a.jsxs("div",{className:"flex flex-col items-center gap-4 text-center py-12",children:[a.jsx("div",{className:"text-4xl",children:"⚠️"}),a.jsx("div",{className:"text-xl font-semibold",children:"Invalid Map ID"}),a.jsx("div",{children:"The map ID provided is not valid."}),a.jsxs("div",{className:"text-sm text-gray-500 mt-2",children:['Debug Info: mapId = "',h,'" (type: ',typeof h,")"]}),a.jsx(F,{name:"back-to-explore",variant:"secondary",onClick:()=>v("/explore"),children:"Return to Explore"})]})});const[re,je]=m.useState("mapDetails"),[e,ee]=m.useState(null),[W,z]=m.useState(!0),[le,O]=m.useState(null),[ce,Ie]=m.useState([]),[de,Ne]=m.useState([]),[ge,be]=m.useState([]),[me,Se]=m.useState([]),[Le,De]=m.useState([]),[ke,Me]=m.useState(!1),[Te,Fe]=m.useState(!1),[B,q]=m.useState(!1),[Ee,K]=m.useState(!1),[ue,Z]=m.useState(!1),[Pe,ae]=m.useState(!1),[Re,te]=m.useState(!1),[$a,za]=m.useState("standard"),[R,Aa]=m.useState(80),[J,Oa]=m.useState(10),[Ua,Wa]=m.useState(10),[Ba,Ja]=m.useState(!0),[Ha,Va]=m.useState(!0),[Q,X]=m.useState(!1),[$e,fe]=m.useState(!1),[ze,pe]=m.useState(null),[Ae,H]=m.useState(!1),[x,V]=m.useState([]),[M,A]=m.useState(0),[G,he]=m.useState(!1),{search:d,setSearch:Ga,srcFilter:w,setSrcFilter:qa,catFilter:C,setCatFilter:Ka,regionFilter:j,setRegionFilter:Za,countryFilter:I,setCountryFilter:Qa,imageTypeFilter:N,setImageTypeFilter:Xa,uploadTypeFilter:b,setUploadTypeFilter:Ya,showReferenceExamples:k,setShowReferenceExamples:Oe,clearAllFilters:Ue}=ta(),We=[{key:"explore",label:"List"},{key:"mapDetails",label:"Carousel"}],_e=m.useCallback(async t=>{if(console.log("fetchMapData called with id:",t),console.log("fetchMapData id type:",typeof t),!t||t==="undefined"||t==="null"||t.trim()===""){console.log("fetchMapData: Invalid ID detected:",t),O("Invalid Map ID"),z(!1);return}if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)){console.log("fetchMapData: Invalid UUID format:",t),O("Invalid Map ID format"),z(!1);return}console.log("fetchMapData: Making API call for id:",t),q(!0),z(!0);try{const u=await fetch(`/api/images/${t}`);if(!u.ok)throw new Error("Map not found");const s=await u.json();if(ee(s),s.all_image_ids&&s.all_image_ids.length>1)await xe(s.all_image_ids);else if(s.image_count&&s.image_count>1){console.log("Multi-upload detected but no all_image_ids, trying grouped endpoint");try{const l=await fetch("/api/images/grouped");if(l.ok){const r=(await l.json()).find(c=>c.all_image_ids&&c.all_image_ids.includes(s.image_id));r&&r.all_image_ids?await xe(r.all_image_ids):(V([s]),A(0))}else V([s]),A(0)}catch(l){console.error("Failed to fetch from grouped endpoint:",l),V([s]),A(0)}}else V([s]),A(0);await se(t)}catch(u){O(u instanceof Error?u.message:"Unknown error occurred")}finally{z(!1),q(!1)}},[]),xe=m.useCallback(async t=>{console.log("fetchAllImages called with imageIds:",t),he(!0);try{const i=t.map(async s=>{const l=await fetch(`/api/images/${s}`);if(!l.ok)throw new Error(`Failed to fetch image ${s}`);return l.json()}),u=await Promise.all(i);V(u),A(0),console.log("fetchAllImages: Loaded",u.length,"images")}catch(i){console.error("fetchAllImages error:",i),O(i instanceof Error?i.message:"Failed to load all images")}finally{he(!1)}},[]),Be=m.useCallback(()=>{x.length>1&&A(t=>t>0?t-1:x.length-1)},[x.length]),Je=m.useCallback(()=>{x.length>1&&A(t=>t<x.length-1?t+1:0)},[x.length]),He=m.useCallback(t=>{t>=0&&t<x.length&&A(t)},[x.length]),ye=m.useCallback(async t=>{const i=t||(x.length>0?x[M]:e);if(i){H(!0),pe(i),fe(!0);try{const u=new Image;u.onload=()=>{H(!1)},u.onerror=()=>{H(!1)},u.src=i.image_url}catch(u){console.error("Error preloading full-size image:",u),H(!1)}}},[x,M,e]),Ve=m.useCallback(()=>{fe(!1),pe(null),H(!1)},[]);m.useEffect(()=>{if(console.log("MapDetailsPage: mapId from useParams:",h),console.log("MapDetailsPage: mapId type:",typeof h),console.log("MapDetailsPage: mapId value:",h),!h||h==="undefined"||h==="null"||h.trim()===""||h===void 0||h===null){console.log("MapDetailsPage: Invalid mapId, setting error"),O("Map ID is required"),z(!1);return}if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(h)){console.log("MapDetailsPage: Invalid UUID format:",h),O("Invalid Map ID format"),z(!1);return}console.log("MapDetailsPage: Fetching data for mapId:",h),_e(h)},[h,_e]),m.useEffect(()=>{if(!e||W||Q)return;if(!h||h==="undefined"||h==="null"||h.trim()===""){console.log("Auto-navigation skipped: Invalid mapId");return}if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(h)){console.log("Auto-navigation skipped: Invalid mapId format");return}(()=>{const u=!d||e.title?.toLowerCase().includes(d.toLowerCase())||e.generated?.toLowerCase().includes(d.toLowerCase())||e.source?.toLowerCase().includes(d.toLowerCase())||e.event_type?.toLowerCase().includes(d.toLowerCase()),s=!w||e.source===w,l=!C||e.event_type===C,o=!j||e.countries.some(T=>T.r_code===j),r=!I||e.countries.some(T=>T.c_code===I),c=!N||e.image_type===N,n=!k||e.starred===!0,y=u&&s&&l&&o&&r&&c&&n;return console.log("Auto-navigation check:",{mapId:h,search:d,srcFilter:w,catFilter:C,regionFilter:j,countryFilter:I,imageTypeFilter:N,showReferenceExamples:k,matchesSearch:u,matchesSource:s,matchesCategory:l,matchesRegion:o,matchesCountry:r,matchesImageType:c,matchesReferenceExamples:n,matches:y}),y})()||(console.log("Current map does not match filters, looking for first matching item"),fetch("/api/images").then(u=>u.json()).then(u=>{console.log("Auto-navigation: Received images from API:",u.length),console.log("Auto-navigation: First few images:",u.slice(0,3).map(l=>({image_id:l.image_id,title:l.title})));const s=u.find(l=>{const o=!d||l.title?.toLowerCase().includes(d.toLowerCase())||l.generated?.toLowerCase().includes(d.toLowerCase())||l.source?.toLowerCase().includes(d.toLowerCase())||l.event_type?.toLowerCase().includes(d.toLowerCase()),r=!w||l.source===w,c=!C||l.event_type===C,n=!j||l.countries?.some(f=>f.r_code===j),y=!I||l.countries?.some(f=>f.c_code===I),T=!N||l.image_type===N,L=!k||l.starred===!0;return o&&r&&c&&n&&y&&T&&L});console.log("Auto-navigation: Found first matching image:",s?{image_id:s.image_id,title:s.title,source:s.source}:"No matching image found"),s&&s.image_id&&s.image_id!=="undefined"&&s.image_id!=="null"&&s.image_id.trim()!==""&&s.image_id!==h&&(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(s.image_id)?(console.log("Auto-navigating to:",s.image_id),v(`/map/${s.image_id}`)):console.error("Auto-navigation blocked: Invalid image_id format:",s.image_id))}).catch(console.error))},[e,d,w,C,j,I,N,k,h,v,W,Q]);const se=async t=>{if(!(!t||t==="undefined"||t==="null"||t.trim()===""))try{const i=await fetch("/api/images/grouped");if(i.ok){const s=(await i.json()).filter(o=>{const r=!d||o.title?.toLowerCase().includes(d.toLowerCase())||o.generated?.toLowerCase().includes(d.toLowerCase())||o.source?.toLowerCase().includes(d.toLowerCase())||o.event_type?.toLowerCase().includes(d.toLowerCase()),c=!w||o.source===w,n=!C||o.event_type===C,y=!j||o.countries?.some(_=>_.r_code===j),T=!I||o.countries?.some(_=>_.c_code===I),L=!N||o.image_type===N,f=!b||b==="single"&&(!o.image_count||o.image_count<=1)||b==="multiple"&&o.image_count&&o.image_count>1,S=!k||o.starred===!0;return r&&c&&n&&y&&T&&L&&f&&S}),l=s.findIndex(o=>o.image_id===t);Me(s.length>1&&l>0),Fe(s.length>1&&l<s.length-1)}}catch(i){console.error("Failed to check navigation availability:",i)}},ve=async t=>{if(!B){q(!0);try{const i=await fetch("/api/images/grouped");if(i.ok){const u=await i.json(),s=u.filter(n=>{const y=!d||n.title?.toLowerCase().includes(d.toLowerCase())||n.generated?.toLowerCase().includes(d.toLowerCase())||n.source?.toLowerCase().includes(d.toLowerCase())||n.event_type?.toLowerCase().includes(d.toLowerCase()),T=!w||n.source===w,L=!C||n.event_type===C,f=!j||n.countries?.some($=>$.r_code===j),S=!I||n.countries?.some($=>$.c_code===I),_=!N||n.image_type===N,D=!b||b==="single"&&(!n.image_count||n.image_count<=1)||b==="multiple"&&n.image_count&&n.image_count>1,U=!k||n.starred===!0;return y&&T&&L&&f&&S&&_&&D&&U});if(s.findIndex(n=>n.image_id===h)===-1){const n=u.find(y=>y.image_id===h);n&&s.push(n)}const o=s.findIndex(n=>n.image_id===h);if(o===-1){console.error("Current image not found in filtered list");return}let r;t==="previous"?r=o>0?o-1:s.length-1:r=o<s.length-1?o+1:0;const c=s[r];c&&c.image_id&&c.image_id!=="undefined"&&c.image_id!=="null"&&c.image_id.trim()!==""&&(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(c.image_id)?(console.log("Carousel navigating to:",c.image_id),v(`/map/${c.image_id}`)):console.error("Carousel navigation blocked: Invalid image_id format:",c.image_id))}}catch(i){console.error("Failed to navigate to item:",i)}finally{q(!1)}}};m.useEffect(()=>{e&&h&&!W&&!Q&&se(h)},[e,h,d,w,C,j,I,N,b,k,W,Q,se]),m.useEffect(()=>{Promise.all([fetch("/api/sources").then(t=>t.json()),fetch("/api/types").then(t=>t.json()),fetch("/api/image-types").then(t=>t.json()),fetch("/api/regions").then(t=>t.json()),fetch("/api/countries").then(t=>t.json())]).then(([t,i,u,s,l])=>{Ie(t),Ne(i),be(u),Se(s),De(l)}).catch(console.error)},[]);const Ge=async()=>{e&&K(!0)},qe=async()=>{if(e)try{(await fetch(`/api/images/${e.image_id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({starred:!e.starred})})).ok?ee(i=>i?{...i,starred:!i.starred}:null):console.error("Failed to toggle starred status")}catch(t){console.error("Error toggling starred status:",t)}},Ke=async()=>{if(e){X(!0);try{if(console.log("Deleting image with ID:",e.image_id),(await fetch(`/api/images/${e.image_id}`,{method:"DELETE"})).ok){ee(i=>i?{...i,starred:!i.starred}:null),K(!1);try{const i=await fetch("/api/images/grouped");if(i.ok){const s=(await i.json()).filter(o=>{const r=!d||o.title?.toLowerCase().includes(d.toLowerCase())||o.generated?.toLowerCase().includes(d.toLowerCase())||o.source?.toLowerCase().includes(d.toLowerCase())||o.event_type?.toLowerCase().includes(d.toLowerCase()),c=!w||o.source===w,n=!C||o.event_type===C,y=!j||o.countries?.some(_=>_.r_code===j),T=!I||o.countries?.some(_=>_.c_code===I),L=!N||o.image_type===N,f=!b||b==="single"&&(!o.image_count||o.image_count<=1)||b==="multiple"&&o.image_count&&o.image_count>1,S=!k||o.starred===!0;return r&&c&&n&&y&&T&&L&&f&&S}),l=s.filter(o=>o.image_id!==e.image_id);if(l.length>0){const o=s.findIndex(c=>c.image_id===e.image_id);let r;if(o===s.length-1?r=o-1:r=o,console.log("Navigation target:",{currentIndex:o,targetIndex:r,targetId:l[r]?.image_id}),r>=0&&r<l.length){const c=l[r];c&&c.image_id&&c.image_id!=="undefined"&&c.image_id!=="null"&&c.image_id.trim()!==""?/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(c.image_id)?(console.log("Navigating to:",c.image_id),v(`/map/${c.image_id}`)):(console.error("Navigation blocked: Invalid image_id format:",c.image_id),v("/explore")):(console.error("Navigation blocked: Invalid image_id:",c?.image_id),v("/explore"))}else l[0]&&l[0].image_id&&l[0].image_id!=="undefined"&&l[0].image_id!=="null"&&l[0].image_id.trim()!==""?/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(l[0].image_id)?(console.log("Fallback navigation to first item:",l[0].image_id),v(`/map/${l[0].image_id}`)):(console.error("Fallback navigation blocked: Invalid image_id format:",l[0].image_id),v("/explore")):(console.log("No valid remaining items, going to explore page"),v("/explore"))}else console.log("No remaining items, going to explore page"),v("/explore")}else v("/explore")}catch(i){console.error("Failed to navigate to next item:",i),v("/explore")}finally{X(!1)}}else console.error("Delete failed"),X(!1)}catch(t){console.error("Delete failed:",t),X(!1)}}},g=m.useMemo(()=>{if(!e)return null;if(!d&&!w&&!C&&!j&&!I&&!N&&!b&&!k)return e;const t=!d||e.title?.toLowerCase().includes(d.toLowerCase())||e.generated?.toLowerCase().includes(d.toLowerCase())||e.source?.toLowerCase().includes(d.toLowerCase())||e.event_type?.toLowerCase().includes(d.toLowerCase()),i=!w||e.source===w,u=!C||e.event_type===C,s=!j||e.countries.some(y=>y.r_code===j),l=!I||e.countries.some(y=>y.c_code===I),o=!N||e.image_type===N,r=!b||b==="single"&&(!e.image_count||e.image_count<=1)||b==="multiple"&&e.image_count&&e.image_count>1,c=!k||e.starred===!0,n=t&&i&&u&&s&&l&&o&&r&&c;return!n&&(d||w||C||j||I||N||b||k)?(setTimeout(()=>{Ze()},100),e):n?e:null},[e,d,w,C,j,I,N,b,k]),Ze=m.useCallback(async()=>{z(!0);try{const t=await fetch("/api/images/grouped");if(t.ok){const u=(await t.json()).filter(s=>{const l=!d||s.title?.toLowerCase().includes(d.toLowerCase())||s.generated?.toLowerCase().includes(d.toLowerCase())||s.source?.toLowerCase().includes(d.toLowerCase())||s.event_type?.toLowerCase().includes(d.toLowerCase()),o=!w||s.source===w,r=!C||s.event_type===C,c=!j||s.countries?.some(f=>f.r_code===j),n=!I||s.countries?.some(f=>f.c_code===I),y=!N||s.image_type===N,T=!b||b==="single"&&(!s.image_count||s.image_count<=1)||b==="multiple"&&s.image_count&&s.image_count>1,L=!k||s.starred===!0;return l&&o&&r&&c&&n&&y&&T&&L});if(u.length>0){const s=u[0];s&&s.image_id&&v(`/map/${s.image_id}`)}else v("/explore")}}catch(t){console.error("Failed to navigate to matching image:",t),v("/explore")}finally{z(!1)}},[d,w,C,j,I,N,b,k,v]),Qe=()=>{if(!e)return;if(!e.all_image_ids||e.all_image_ids.length<=1){const s=`/upload?step=1&contribute=true&imageIds=${[e.image_id].join(",")}`;v(s);return}const i=`/upload?step=1&contribute=true&imageIds=${e.all_image_ids.join(",")}`;v(i)},E=(t,i)=>({image:`images/${i}`,caption:t.edited||t.generated||"",metadata:{image_id:t.image_count&&t.image_count>1?t.all_image_ids||[t.image_id]:t.image_id,title:t.title,source:t.source,event_type:t.event_type,image_type:t.image_type,countries:t.countries,starred:t.starred,image_count:t.image_count||1}}),Xe=async t=>{if(e){ae(!0),te(!1);try{const i=(await na(async()=>{const{default:r}=await import("./jszip.min-Bux5isNr.js").then(c=>c.j);return{default:r}},__vite__mapDeps([0,1,2]))).default,u=new i;if(e.image_type==="crisis_map"){const r=u.folder("crisis_maps_dataset"),c=r?.folder("images");if(c)try{const n=e.image_count&&e.image_count>1?e.all_image_ids||[e.image_id]:[e.image_id],y=n.map(async(f,S)=>{try{const _=await fetch(`/api/images/${f}/file`);if(!_.ok)throw new Error(`Failed to fetch image ${f}`);const D=await _.blob(),U=e.file_key.split(".").pop()||"jpg",$=`0001_${String(S+1).padStart(2,"0")}.${U}`;return c.file($,D),{success:!0,fileName:$,imageId:f}}catch(_){return console.error(`Failed to process image ${f}:`,_),{success:!1,fileName:"",imageId:f}}}),L=(await Promise.all(y)).filter(f=>f.success);if(L.length===0)throw new Error("No images could be processed");if(t==="fine-tuning"){const f=[],S=[],_=[],D=L.map(Ye=>`images/${Ye.fileName}`),U=Math.random(),$={image:D.length===1?D[0]:D,caption:e.edited||e.generated||"",metadata:{image_id:n,title:e.title,source:e.source,event_type:e.event_type,image_type:e.image_type,countries:e.countries,starred:e.starred,image_count:e.image_count||1}};U<R/100?f.push($):U<(R+J)/100?S.push($):_.push($),r&&(r.file("train.jsonl",JSON.stringify(f,null,2)),r.file("test.jsonl",JSON.stringify(S,null,2)),r.file("val.jsonl",JSON.stringify(_,null,2)))}else{const f=L.map(_=>`images/${_.fileName}`),S={image:f.length===1?f[0]:f,caption:e.edited||e.generated||"",metadata:{image_id:n,title:e.title,source:e.source,event_type:e.event_type,image_type:e.image_type,countries:e.countries,starred:e.starred,image_count:e.image_count||1}};r&&r.file("0001.json",JSON.stringify(S,null,2))}}catch(n){throw console.error(`Failed to process image ${e.image_id}:`,n),n}}else if(e.image_type==="drone_image"){const r=u.folder("drone_images_dataset"),c=r?.folder("images");if(c)try{const n=await fetch(`/api/images/${e.image_id}/file`);if(!n.ok)throw new Error(`Failed to fetch image ${e.image_id}`);const y=await n.blob(),L=`0001.${e.file_key.split(".").pop()||"jpg"}`;if(c.file(L,y),t==="fine-tuning"){const f=[],S=[],_=[];if(String(e?.image_type)==="crisis_map"){const D=Math.random();D<R/100?f.push(E(e,"0001")):D<(R+J)/100?S.push(E(e,"0001")):_.push(E(e,"0001"))}else if(String(e?.image_type)==="drone_image"){const D=Math.random();D<R/100?f.push(E(e,"0001")):D<(R+J)/100?S.push(E(e,"0001")):_.push(E(e,"0001"))}r&&(r.file("train.jsonl",JSON.stringify(f,null,2)),r.file("test.jsonl",JSON.stringify(S,null,2)),r.file("val.jsonl",JSON.stringify(_,null,2)))}else{const f={image:`images/${L}`,caption:e.edited||e.generated||"",metadata:{image_id:e.image_count&&e.image_count>1?e.all_image_ids||[e.image_id]:e.image_id,title:e.title,source:e.source,event_type:e.event_type,image_type:e.image_type,countries:e.countries,starred:e.starred,image_count:e.image_count||1}};r&&r.file("0001.json",JSON.stringify(f,null,2))}}catch(n){throw console.error(`Failed to process image ${e.image_id}:`,n),n}}else{const r=u.folder("generic_dataset"),c=r?.folder("images");if(c)try{const n=await fetch(`/api/images/${e.image_id}/file`);if(!n.ok)throw new Error(`Failed to fetch image ${e.image_id}`);const y=await n.blob(),L=`0001.${e.file_key.split(".").pop()||"jpg"}`;if(c.file(L,y),t==="fine-tuning"){const f=[],S=[],_=[];if(String(e?.image_type)==="crisis_map"){const D=Math.random();D<R/100?f.push(E(e,"0001")):D<(R+J)/100?S.push(E(e,"0001")):_.push(E(e,"0001"))}else if(String(e?.image_type)==="drone_image"){const D=Math.random();D<R/100?f.push(E(e,"0001")):D<(R+J)/100?S.push(E(e,"0001")):_.push(E(e,"0001"))}r&&(r.file("train.jsonl",JSON.stringify(f,null,2)),r.file("test.jsonl",JSON.stringify(S,null,2)),r.file("val.jsonl",JSON.stringify(_,null,2)))}else{const f={image:`images/${L}`,caption:e.edited||e.generated||"",metadata:{image_id:e.image_count&&e.image_count>1?e.all_image_ids||[e.image_id]:e.image_id,title:e.title,source:e.source,event_type:e.event_type,image_type:e.image_type,countries:e.countries,starred:e.starred,image_count:e.image_count||1}};r&&r.file("0001.json",JSON.stringify(f,null,2))}}catch(n){throw console.error(`Failed to process image ${e.image_id}:`,n),n}}const s=await u.generateAsync({type:"blob"}),l=URL.createObjectURL(s),o=document.createElement("a");o.href=l,o.download=`dataset_${e.image_type}_${e.image_id}_${t}_${new Date().toISOString().split("T")[0]}.zip`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(l),console.log(`Exported ${e.image_type} dataset with 1 image in ${t} mode`),te(!0)}catch(i){console.error("Export failed:",i),alert("Failed to export dataset. Please try again.")}finally{ae(!1)}}};return W?a.jsx(Y,{children:a.jsx("div",{className:p.loadingContainer,children:a.jsxs("div",{className:"flex flex-col items-center gap-4",children:[a.jsx(we,{className:"text-ifrcRed"}),a.jsx("div",{children:"Loading map details..."})]})})}):le||!e?a.jsx(Y,{children:a.jsx("div",{className:p.errorContainer,children:a.jsxs("div",{className:"flex flex-col items-center gap-4 text-center",children:[a.jsx("div",{className:"text-4xl",children:"⚠️"}),a.jsx("div",{className:"text-xl font-semibold",children:"Unable to load map"}),a.jsx("div",{children:le||"Map not found"}),a.jsx(F,{name:"back-to-explore",variant:"secondary",onClick:()=>v("/explore"),children:"Return to Explore"})]})})}):a.jsxs(Y,{children:[a.jsxs("div",{className:"max-w-7xl mx-auto",children:[a.jsxs("div",{className:p.tabSelector,children:[a.jsx(sa,{name:"map-details-view",value:re,onChange:t=>{(t==="mapDetails"||t==="explore")&&(je(t),t==="explore"&&v("/explore"))},options:We,keySelector:t=>t.key,labelSelector:t=>t.label}),a.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[a.jsx(P,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:a.jsxs(F,{name:"reference-examples",variant:k?"primary":"secondary",onClick:()=>Oe(!k),className:"whitespace-nowrap",children:[a.jsx("span",{className:"mr-2",children:k?a.jsx("span",{className:"text-yellow-400",children:"β˜…"}):a.jsx("span",{className:"text-yellow-400",children:"β˜†"})}),"Reference Examples"]})}),a.jsx(F,{name:"export-dataset",variant:"secondary",onClick:()=>Z(!0),children:"Export"})]})]}),a.jsx(la,{sources:ce,types:de,regions:me,countries:Le,imageTypes:ge,isLoadingFilters:!1}),re==="mapDetails"?a.jsx("div",{className:"relative",children:g?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:p.gridLayout,children:[a.jsxs(P,{heading:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{children:g.title||"Map Image"}),g.starred&&a.jsx("span",{className:"text-red-500 text-xl",title:"Starred image",children:"β˜…"})]}),headingLevel:2,withHeaderBorder:!0,withInternalPadding:!0,spacing:"comfortable",children:[a.jsx("div",{className:p.imageContainer,children:e?.image_count&&e.image_count>1||x.length>1?a.jsxs("div",{className:p.carouselContainer,children:[a.jsx("div",{className:p.carouselImageWrapper,children:G?a.jsxs("div",{className:p.imagePlaceholder,children:[a.jsx(we,{className:"text-ifrcRed"}),a.jsx("div",{children:"Loading images..."})]}):x[M]?.detail_url?a.jsx("img",{src:x[M].detail_url,alt:x[M].file_key,className:p.carouselImage,onError:t=>{console.log("MapDetailsPage: Detail image failed to load, falling back to original:",x[M].detail_url);const i=t.target;x[M].image_url&&(i.src=x[M].image_url)},onLoad:()=>console.log("MapDetailsPage: Detail image loaded successfully:",x[M].detail_url)}):x[M]?.image_url?a.jsx("img",{src:x[M].image_url,alt:x[M].file_key,className:p.carouselImage,onLoad:()=>console.log("MapDetailsPage: Original image loaded successfully:",x[M].image_url)}):a.jsx("div",{className:p.imagePlaceholder,children:"No image available"})}),a.jsxs("div",{className:p.carouselNavigation,children:[a.jsx(F,{name:"previous-image",variant:"tertiary",size:1,onClick:Be,disabled:G,className:p.carouselButton,children:a.jsx(ie,{className:"w-4 h-4"})}),a.jsx("div",{className:p.carouselIndicators,children:x.map((t,i)=>a.jsx("button",{onClick:()=>He(i),className:`${p.carouselIndicator} ${i===M?p.carouselIndicatorActive:""}`,disabled:G,children:i+1},i))}),a.jsx(F,{name:"next-image",variant:"tertiary",size:1,onClick:Je,disabled:G,className:p.carouselButton,children:a.jsx(oe,{className:"w-4 h-4"})})]}),a.jsx("div",{className:p.viewImageButtonContainer,children:a.jsx(F,{name:"view-full-size-carousel",variant:"secondary",size:1,onClick:()=>ye(x[M]),disabled:G||!x[M]?.image_url,children:"View Image"})})]}):a.jsxs("div",{className:p.singleImageContainer,children:[g.detail_url?a.jsx("img",{src:g.detail_url,alt:g.file_key,onError:t=>{console.log("MapDetailsPage: Detail image failed to load, falling back to original:",g.detail_url);const i=t.target;g.image_url&&(i.src=g.image_url)},onLoad:()=>console.log("MapDetailsPage: Detail image loaded successfully:",g.detail_url)}):g.image_url?a.jsx("img",{src:g.image_url,alt:g.file_key,onLoad:()=>console.log("MapDetailsPage: Original image loaded successfully:",g.image_url)}):a.jsx("div",{className:p.imagePlaceholder,children:"No image available"}),a.jsx("div",{className:p.viewImageButtonContainer,children:a.jsx(F,{name:"view-full-size-single",variant:"secondary",size:1,onClick:()=>ye(g),disabled:!g.image_url,children:"View Image"})})]})}),a.jsx(P,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:a.jsxs("div",{className:p.metadataTags,children:[g.image_type!=="drone_image"&&a.jsx("span",{className:p.metadataTag,children:ce.find(t=>t.s_code===g.source)?.label||g.source}),a.jsx("span",{className:p.metadataTag,children:de.find(t=>t.t_code===g.event_type)?.label||g.event_type}),a.jsx("span",{className:p.metadataTag,children:ge.find(t=>t.image_type===g.image_type)?.label||g.image_type}),g.countries&&g.countries.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:p.metadataTag,children:me.find(t=>t.r_code===g.countries[0].r_code)?.label||"Unknown Region"}),a.jsx("span",{className:p.metadataTag,children:g.countries.map(t=>t.label).join(", ")})]}),g.image_count&&g.image_count>1&&a.jsxs("span",{className:p.metadataTag,title:`Multi-upload with ${g.image_count} images`,children:["πŸ“· ",g.image_count]}),(!g.image_count||g.image_count<=1)&&a.jsx("span",{className:p.metadataTag,title:"Single Upload",children:"Single"})]})})]}),a.jsx("div",{className:p.detailsSection,children:g.edited&&g.edited.includes("Description:")||g.generated&&g.generated.includes("Description:")?a.jsx(P,{heading:"AI Generated Content",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,spacing:"comfortable",children:a.jsx("div",{className:p.captionContainer,children:a.jsx("div",{className:p.captionText,children:(g.edited||g.generated||"").split(`
3
  `).map((t,i)=>a.jsx("div",{children:t.startsWith("Description:")||t.startsWith("Analysis:")||t.startsWith("Recommended Actions:")?a.jsx("h4",{className:"font-semibold text-gray-800 mt-4 mb-2",children:t}):t.trim()===""?a.jsx("br",{}):a.jsx("p",{className:"mb-2",children:t})},i))})})}):a.jsx(P,{heading:"Description",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,spacing:"comfortable",children:a.jsx("div",{className:p.captionContainer,children:g.generated?a.jsx("div",{className:p.captionText,children:a.jsx("p",{children:g.edited||g.generated})}):a.jsx("p",{children:"β€” no caption yet β€”"})})})})]}),a.jsx("div",{className:"flex items-center justify-center mt-8",children:a.jsx(P,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-lg p-4",children:a.jsxs("div",{className:"flex items-center gap-4",children:[ke&&a.jsx(P,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(F,{name:"previous-item",variant:"tertiary",size:1,className:`bg-white/90 hover:bg-white shadow-lg border border-gray-200 ${B?"opacity-50 cursor-not-allowed":"hover:scale-110"}`,onClick:()=>ve("previous"),disabled:B,children:a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsxs("div",{className:"flex -space-x-1",children:[a.jsx(ie,{className:"w-4 h-4"}),a.jsx(ie,{className:"w-4 h-4"})]}),a.jsx("span",{className:"font-semibold",children:"Previous"})]})})}),ne&&a.jsx(P,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(F,{name:"delete",variant:"tertiary",size:1,className:"bg-red-50 hover:bg-red-100 text-red-700 border border-red-200 hover:border-red-300",onClick:Ge,title:"Delete","aria-label":"Delete saved image",children:a.jsx(ia,{className:"w-4 h-4"})})}),a.jsx(P,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(F,{name:"contribute",onClick:Qe,children:"Contribute"})}),ne&&a.jsx(P,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(F,{name:"toggle-star",variant:"tertiary",size:1,className:`${e?.starred?"bg-red-100 hover:bg-red-200 text-red-800 border-2 border-red-400":"bg-gray-100 hover:bg-gray-200 text-gray-600 border-2 border-gray-300"} w-16 h-8 rounded-full transition-all duration-200 flex items-center justify-center`,onClick:qe,title:e?.starred?"Unstar image":"Star image","aria-label":e?.starred?"Unstar image":"Star image",children:a.jsx("span",{className:`text-lg transition-all duration-200 ${e?.starred?"text-red-600":"text-gray-500"}`,children:e?.starred?"β˜…":"β˜†"})})}),Te&&a.jsx(P,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(F,{name:"next-item",variant:"tertiary",size:1,className:`bg-white/90 hover:bg-white shadow-lg border border-gray-200 ${B?"opacity-50 cursor-not-allowed":"hover:scale-110"}`,onClick:()=>ve("next"),disabled:B,children:a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx("span",{className:"font-semibold",children:"Next"}),a.jsxs("div",{className:"flex -space-x-1",children:[a.jsx(oe,{className:"w-4 h-4"}),a.jsx(oe,{className:"w-4 h-4"})]})]})})})]})})})]}):a.jsxs("div",{className:"text-center py-12",children:[a.jsx("div",{className:"text-xl font-semibold text-gray-600 mb-4",children:"No matches found"}),a.jsx("div",{className:"mt-4",children:a.jsx(F,{name:"clear-filters",variant:"secondary",onClick:Ue,children:"Clear Filters"})})]})}):null]}),Ee&&a.jsx("div",{className:p.fullSizeModalOverlay,onClick:()=>K(!1),children:a.jsx("div",{className:p.fullSizeModalContent,onClick:t=>t.stopPropagation(),children:a.jsxs("div",{className:p.ratingWarningContent,children:[a.jsx("h3",{className:p.ratingWarningTitle,children:"Delete Image?"}),a.jsx("p",{className:p.ratingWarningText,children:"This action cannot be undone. Are you sure you want to delete this saved image and all related data?"}),a.jsxs("div",{className:p.ratingWarningButtons,children:[a.jsx(F,{name:"confirm-delete",variant:"secondary",onClick:Ke,children:"Delete"}),a.jsx(F,{name:"cancel-delete",variant:"tertiary",onClick:()=>K(!1),children:"Cancel"})]})]})})}),ue&&a.jsx(ca,{isOpen:ue,onClose:()=>{Z(!1),te(!1),ae(!1)},onExport:(t,i)=>{i.includes(e.image_type)&&Xe(t)},filteredCount:1,totalCount:1,hasFilters:!1,crisisMapsCount:e.image_type==="crisis_map"?1:0,droneImagesCount:e.image_type==="drone_image"?1:0,isLoading:Pe,exportSuccess:Re,variant:"single",onNavigateToList:()=>{Z(!1),v("/explore")},onNavigateAndExport:()=>{Z(!1),v("/explore?export=true")}}),a.jsx(oa,{isOpen:$e,imageUrl:ze?.image_url||null,preview:null,selectedImageData:null,onClose:Ve,isLoading:Ae})]})}export{st as default};
py_backend/static/assets/{index-Cj53JezQ.js β†’ index-DjbXFoDc.js} RENAMED
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jszip.min-C3B0d4UO.js","assets/index-BCz4bkWK.js","assets/index-FBu17hMI.css"])))=>i.map(i=>d[i]);
2
- import{j as t,z as b,n as w,v as Fe,w as De,x as Oe,B as Le,r as o,D as Me,N as Re,_ as de,L as Je,F as ze,G as We}from"./index-BCz4bkWK.js";import{u as Ue}from"./useAdmin-LSEnRjVv.js";import{F as Be,E as He}from"./ExportModal-Qf6Y7VAO.js";const Ve="_paginatorContainer_1l5ti_1",Ae="_paginationControls_1l5ti_19",me={paginatorContainer:Ve,paginationControls:Ae};function Ge({currentPage:N,totalPages:h,totalItems:X,itemsPerPage:U,onPageChange:C,className:S=""}){if(h<=1)return null;const u=(()=>{const g=[];if(h<=5)for(let f=1;f<=h;f++)g.push(f);else{let f=Math.max(1,N-2),_=Math.min(h,f+5-1);_===h&&(f=Math.max(1,_-5+1));for(let y=f;y<=_;y++)g.push(y)}return g})();return t.jsx("div",{className:`${me.paginatorContainer} ${S}`,children:t.jsxs("div",{className:me.paginationControls,children:[t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsxs(w,{name:"prev-page",variant:"tertiary",size:1,onClick:()=>C(Math.max(1,N-1)),disabled:N===1,title:"Previous page",children:[t.jsx(Fe,{className:"w-4 h-4"}),t.jsx("span",{className:"hidden sm:inline",children:"Previous"})]})}),t.jsxs("div",{className:"flex items-center gap-1",children:[u[0]>1&&t.jsxs(t.Fragment,{children:[t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx(w,{name:"page-1",variant:"tertiary",size:1,onClick:()=>C(1),children:"1"})}),u[0]>2&&t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx("span",{className:"px-2 text-gray-500",children:"..."})})]}),u.map(g=>t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx(w,{name:`page-${g}`,variant:N===g?"primary":"tertiary",size:1,onClick:()=>C(g),children:g})},g)),u[u.length-1]<h&&t.jsxs(t.Fragment,{children:[u[u.length-1]<h-1&&t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx("span",{className:"px-2 text-gray-500",children:"..."})}),t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx(w,{name:`page-${h}`,variant:"tertiary",size:1,onClick:()=>C(h),children:h})})]})]}),t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsxs(w,{name:"next-page",variant:"tertiary",size:1,onClick:()=>C(Math.min(h,N+1)),disabled:N===h,title:"Next page",children:[t.jsx("span",{className:"hidden sm:inline",children:"Next"}),t.jsx(De,{className:"w-4 h-4"})]})})]})})}const Ze="_tabSelector_o9y1f_1",qe="_metadataTags_o9y1f_8",Ke="_metadataTag_o9y1f_8",Qe="_metadataTagSource_o9y1f_32",Xe="_metadataTagType_o9y1f_43",Ye="_mapItem_o9y1f_54",et="_mapItemImage_o9y1f_72",tt="_mapItemContent_o9y1f_92",at="_mapItemTitle_o9y1f_97",st="_mapItemMetadata_o9y1f_105",it="_fullSizeModalOverlay_o9y1f_134",nt="_fullSizeModalContent_o9y1f_148",lt="_ratingWarningContent_o9y1f_159",rt="_ratingWarningTitle_o9y1f_165",ot="_ratingWarningText_o9y1f_172",ct="_ratingWarningButtons_o9y1f_179",m={tabSelector:Ze,metadataTags:qe,metadataTag:Ke,metadataTagSource:Qe,metadataTagType:Xe,mapItem:Ye,mapItemImage:et,mapItemContent:tt,mapItemTitle:at,mapItemMetadata:st,fullSizeModalOverlay:it,fullSizeModalContent:nt,ratingWarningContent:lt,ratingWarningTitle:rt,ratingWarningText:ot,ratingWarningButtons:ct};function pt(){const N=Oe(),h=Le(),{isAuthenticated:X}=Ue(),[U,C]=o.useState("explore"),[S,M]=o.useState([]),{search:u,srcFilter:g,catFilter:T,regionFilter:f,countryFilter:_,imageTypeFilter:y,uploadTypeFilter:$,showReferenceExamples:E,setShowReferenceExamples:ge}=Me(),[B,pe]=o.useState([]),[H,ue]=o.useState([]),[Y,fe]=o.useState([]),[he,xe]=o.useState([]),[ee,_e]=o.useState([]),[ye,te]=o.useState(!0),[R,ae]=o.useState(!0),[je,V]=o.useState(!1),[Ne,A]=o.useState(!1),[ve,G]=o.useState(!1),[be,J]=o.useState(!1),[z,se]=o.useState(""),[Z,ie]=o.useState(!1),[W,ne]=o.useState(1),[q]=o.useState(10),[K,le]=o.useState(0),[we,re]=o.useState(0),Se=[{key:"explore",label:"List"},{key:"mapDetails",label:"Carousel"}],oe=()=>{ae(!0);const e=new URLSearchParams({page:W.toString(),limit:q.toString()});u&&e.append("search",u),g&&e.append("source",g),T&&e.append("event_type",T),f&&e.append("region",f),_&&e.append("country",_),y&&e.append("image_type",y),$&&e.append("upload_type",$),E&&e.append("starred_only","true"),fetch(`/api/images/grouped?${e.toString()}`).then(s=>s.ok?s.json():(console.error("ExplorePage: Grouped endpoint failed, trying legacy endpoint"),fetch("/api/captions/legacy").then(c=>c.ok?c.json():(console.error("ExplorePage: Legacy endpoint failed, trying regular images endpoint"),fetch("/api/images").then(j=>{if(!j.ok)throw new Error(`HTTP ${j.status}: ${j.statusText}`);return j.json()}))))).then(s=>{console.log("ExplorePage: Fetched captions:",s),M(s)}).catch(s=>{console.error("ExplorePage: Error fetching captions:",s),M([])}).finally(()=>{ae(!1)})},Te=()=>{const e=new URLSearchParams;u&&e.append("search",u),g&&e.append("source",g),T&&e.append("event_type",T),f&&e.append("region",f),_&&e.append("country",_),y&&e.append("image_type",y),$&&e.append("upload_type",$),E&&e.append("starred_only","true"),fetch(`/api/images/grouped/count?${e.toString()}`).then(s=>s.ok?s.json():(console.error("ExplorePage: Count endpoint failed"),{total_count:0})).then(s=>{console.log("ExplorePage: Total count:",s.total_count),le(s.total_count),re(Math.ceil(s.total_count/q))}).catch(s=>{console.error("ExplorePage: Error fetching total count:",s),le(0),re(0)})};o.useEffect(()=>{oe(),Te()},[W,u,g,T,f,_,y,$,E]),o.useEffect(()=>{W!==1&&ne(1)},[u,g,T,f,_,y,$,E]),o.useEffect(()=>{const e=()=>{document.hidden||oe()};return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}},[]),o.useEffect(()=>{new URLSearchParams(h.search).get("export")==="true"&&(V(!0),N("/explore",{replace:!0}))},[h.search,N,u,g,T,f,_,y,E]),o.useEffect(()=>{te(!0),Promise.all([fetch("/api/sources").then(e=>{if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}),fetch("/api/types").then(e=>{if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}),fetch("/api/regions").then(e=>{if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}),fetch("/api/countries").then(e=>{if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}),fetch("/api/image-types").then(e=>{if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()})]).then(([e,s,c,j,P])=>{pe(e),ue(s),fe(c),xe(j),_e(P)}).catch(()=>{}).finally(()=>{te(!1)})},[]);const I=S,Ee=async(e,s="fine-tuning")=>{if(e.length===0){alert("No images to export");return}A(!0),G(!1);try{const c=(await We(async()=>{const{default:i}=await import("./jszip.min-C3B0d4UO.js").then(k=>k.j);return{default:i}},__vite__mapDeps([0,1,2]))).default,j=new c,P=e.filter(i=>i.image_type==="crisis_map"),O=e.filter(i=>i.image_type==="drone_image");if(P.length>0){const i=j.folder("crisis_maps_dataset"),k=i?.folder("images");if(k){let F=1;for(const a of P)try{const v=a.image_count&&a.image_count>1?a.all_image_ids||[a.image_id]:[a.image_id],Q=v.map(async(n,x)=>{try{const l=await fetch(`/api/images/${n}/file`);if(!l.ok)throw new Error(`Failed to fetch image ${n}`);const r=await l.blob(),d=a.file_key.split(".").pop()||"jpg",p=`${String(F).padStart(4,"0")}_${String(x+1).padStart(2,"0")}.${d}`;return k.file(p,r),{success:!0,fileName:p,imageId:n}}catch(l){return console.error(`Failed to process image ${n}:`,l),{success:!1,fileName:"",imageId:n}}}),D=(await Promise.all(Q)).filter(n=>n.success);if(D.length>0){if(s==="fine-tuning"){const n=D.map(r=>`images/${r.fileName}`),x=Math.random(),l={image:n.length===1?n[0]:n,caption:a.edited||a.generated||"",metadata:{image_id:v,title:a.title,source:a.source,event_type:a.event_type,image_type:a.image_type,countries:a.countries,starred:a.starred,image_count:a.image_count||1}};if(!i)continue;if(x<.8){const r=i.file("train.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("train.jsonl",JSON.stringify(d,null,2))}else i.file("train.jsonl",JSON.stringify([l],null,2))}else if(x<.9){const r=i.file("test.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("test.jsonl",JSON.stringify(d,null,2))}else i.file("test.jsonl",JSON.stringify([l],null,2))}else{const r=i.file("val.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("val.jsonl",JSON.stringify(d,null,2))}else i.file("val.jsonl",JSON.stringify([l],null,2))}}else{const n=D.map(l=>`images/${l.fileName}`),x={image:n.length===1?n[0]:n,caption:a.edited||a.generated||"",metadata:{image_id:v,title:a.title,source:a.source,event_type:a.event_type,image_type:a.image_type,countries:a.countries,starred:a.starred,image_count:a.image_count||1}};i&&i.file(`${String(F).padStart(4,"0")}.json`,JSON.stringify(x,null,2))}F++}}catch(v){console.error(`Failed to process caption ${a.image_id}:`,v)}}}if(O.length>0){const i=j.folder("drone_images_dataset"),k=i?.folder("images");if(k){let F=1;for(const a of O)try{const v=a.image_count&&a.image_count>1?a.all_image_ids||[a.image_id]:[a.image_id],Q=v.map(async(n,x)=>{try{const l=await fetch(`/api/images/${n}/file`);if(!l.ok)throw new Error(`Failed to fetch image ${n}`);const r=await l.blob(),d=a.file_key.split(".").pop()||"jpg",p=`${String(F).padStart(4,"0")}_${String(x+1).padStart(2,"0")}.${d}`;return k.file(p,r),{success:!0,fileName:p,imageId:n}}catch(l){return console.error(`Failed to process image ${n}:`,l),{success:!1,fileName:"",imageId:n}}}),D=(await Promise.all(Q)).filter(n=>n.success);if(D.length>0){if(s==="fine-tuning"){const n=D.map(r=>`images/${r.fileName}`),x=Math.random(),l={image:n.length===1?n[0]:n,caption:a.edited||a.generated||"",metadata:{image_id:v,title:a.title,source:a.source,event_type:a.event_type,image_type:a.image_type,countries:a.countries,starred:a.starred,image_count:a.image_count||1}};if(!i)continue;if(x<.8){const r=i.file("train.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("train.jsonl",JSON.stringify(d,null,2))}else i.file("train.jsonl",JSON.stringify([l],null,2))}else if(x<.9){const r=i.file("test.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("test.jsonl",JSON.stringify(d,null,2))}else i.file("test.jsonl",JSON.stringify([l],null,2))}else{const r=i.file("val.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("val.jsonl",JSON.stringify(d,null,2))}else i.file("val.jsonl",JSON.stringify([l],null,2))}}else{const n=D.map(l=>`images/${l.fileName}`),x={image:n.length===1?n[0]:n,caption:a.edited||a.generated||"",metadata:{image_id:v,title:a.title,source:a.source,event_type:a.event_type,image_type:a.image_type,countries:a.countries,starred:a.starred,image_count:a.image_count||1}};i&&i.file(`${String(F).padStart(4,"0")}.json`,JSON.stringify(x,null,2))}F++}}catch(v){console.error(`Failed to process caption ${a.image_id}:`,v)}}}const $e=await j.generateAsync({type:"blob"}),ce=URL.createObjectURL($e),L=document.createElement("a");L.href=ce,L.download=`datasets_${s}_${new Date().toISOString().split("T")[0]}.zip`,document.body.appendChild(L),L.click(),document.body.removeChild(L),URL.revokeObjectURL(ce);const Pe=(P.length||0)+(O.length||0);console.log(`Exported ${s} datasets with ${Pe} total images:`),P.length>0&&console.log(`- Crisis maps: ${P.length} images`),O.length>0&&console.log(`- Drone images: ${O.length} images`),G(!0)}catch(c){console.error("Export failed:",c),alert("Failed to export dataset. Please try again.")}finally{A(!1)}},Ie=e=>{se(e),J(!0)},Ce=async()=>{if(z){ie(!0);try{console.log("Deleting image with ID:",z),(await fetch(`/api/images/${z}`,{method:"DELETE"})).ok?(M(s=>s.filter(c=>c.image_id!==z)),J(!1),se("")):(console.error("Delete failed"),alert("Failed to delete image. Please try again."))}catch(e){console.error("Delete failed:",e),alert("Failed to delete image. Please try again.")}finally{ie(!1)}}};return t.jsxs(Re,{children:[R?t.jsx("div",{className:"flex flex-col items-center justify-center min-h-[60vh]",children:t.jsxs("div",{className:"flex flex-col items-center gap-4",children:[t.jsx(de,{className:"text-ifrcRed"}),t.jsx("div",{children:"Loading examples..."})]})}):t.jsxs("div",{className:"max-w-7xl mx-auto",children:[t.jsxs("div",{className:m.tabSelector,children:[t.jsx(Je,{name:"explore-view",value:U,onChange:e=>{(e==="explore"||e==="mapDetails")&&(C(e),e==="mapDetails"&&S.length>0&&(S[0]?.image_id&&S[0].image_id!=="undefined"&&S[0].image_id!=="null"?N(`/map/${S[0].image_id}`):console.error("Invalid image_id for navigation:",S[0]?.image_id)))},options:Se,keySelector:e=>e.key,labelSelector:e=>e.label}),t.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsxs(w,{name:"reference-examples",variant:E?"primary":"secondary",onClick:()=>ge(!E),className:"whitespace-nowrap",children:[t.jsx("span",{className:"mr-2",children:E?t.jsx("span",{className:"text-yellow-400",children:"β˜…"}):t.jsx("span",{className:"text-yellow-400",children:"β˜†"})}),"Reference Examples"]})}),t.jsx(w,{name:"export-dataset",variant:"secondary",onClick:()=>V(!0),children:"Export"})]})]}),U==="explore"?t.jsxs("div",{className:"space-y-6",children:[t.jsx("div",{className:"mb-6 space-y-4",children:t.jsx("div",{className:"flex flex-wrap items-center gap-4",children:t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2 flex-1 min-w-[300px]",children:t.jsx(Be,{sources:B,types:H,regions:Y,countries:he,imageTypes:ee,isLoadingFilters:ye})})})}),t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"flex justify-between items-center",children:t.jsxs("p",{className:"text-sm text-gray-600",children:[I.length," of ",K," examples"]})}),R&&t.jsx("div",{className:"text-center py-12",children:t.jsxs("div",{className:"flex flex-col items-center gap-4",children:[t.jsx(de,{className:"text-ifrcRed"}),t.jsx("div",{children:"Loading examples..."})]})}),!R&&t.jsxs("div",{className:"space-y-4",children:[I.map(e=>t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsxs("div",{className:`${m.mapItem} flex-1`,onClick:()=>{console.log("ExplorePage: Clicking on image with ID:",e.image_id),console.log("ExplorePage: Image data:",e),e.image_id&&e.image_id!=="undefined"&&e.image_id!=="null"?(console.log("ExplorePage: Navigating to:",`/map/${e.image_id}`),console.log("ExplorePage: Full navigation URL:",`/#/map/${e.image_id}`),N(`/map/${e.image_id}`)):(console.error("Invalid image_id for navigation:",e.image_id),console.error("Full item data:",JSON.stringify(e,null,2)),alert(`Cannot navigate: Invalid image ID (${e.image_id})`))},children:[t.jsx("div",{className:m.mapItemImage,style:{width:"120px",height:"80px"},children:e.thumbnail_url?t.jsxs(t.Fragment,{children:[console.log("ExplorePage: Using thumbnail for fast loading:",e.thumbnail_url),t.jsx("img",{src:e.thumbnail_url,alt:e.file_key,onError:s=>{console.error("ExplorePage: Thumbnail failed to load, falling back to original:",e.thumbnail_url);const c=s.target;e.image_url?c.src=e.image_url:(c.style.display="none",c.parentElement.innerHTML="Img")},onLoad:()=>console.log("ExplorePage: Thumbnail loaded successfully:",e.thumbnail_url)})]}):e.image_url?t.jsxs(t.Fragment,{children:[console.log("ExplorePage: No thumbnail available, using original image:",e.image_url),t.jsx("img",{src:e.image_url,alt:e.file_key,onError:s=>{console.error("ExplorePage: Original image failed to load:",e.image_url);const c=s.target;c.style.display="none",c.parentElement.innerHTML="Img"},onLoad:()=>console.log("ExplorePage: Original image loaded successfully:",e.image_url)})]}):t.jsxs(t.Fragment,{children:[console.log("ExplorePage: No image_url or thumbnail provided for item:",e),"'Img'"]})}),t.jsxs("div",{className:m.mapItemContent,children:[t.jsx("h3",{className:m.mapItemTitle,children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{children:e.title||"Untitled"}),e.starred&&t.jsx("span",{className:"text-red-500 text-lg",title:"Starred image",children:"β˜…"})]})}),t.jsx("div",{className:m.mapItemMetadata,children:t.jsxs("div",{className:m.metadataTags,children:[e.image_type!=="drone_image"&&t.jsx("span",{className:m.metadataTagSource,children:e.source&&e.source.includes(", ")?e.source.split(", ").map(s=>B.find(c=>c.s_code===s.trim())?.label||s.trim()).join(", "):B.find(s=>s.s_code===e.source)?.label||e.source}),t.jsx("span",{className:m.metadataTagType,children:e.event_type&&e.event_type.includes(", ")?e.event_type.split(", ").map(s=>H.find(c=>c.t_code===s.trim())?.label||s.trim()).join(", "):H.find(s=>s.t_code===e.event_type)?.label||e.event_type}),t.jsx("span",{className:m.metadataTag,children:ee.find(s=>s.image_type===e.image_type)?.label||e.image_type}),e.image_count&&e.image_count>1&&t.jsxs("span",{className:m.metadataTag,title:`Multi-upload with ${e.image_count} images`,children:["πŸ“· ",e.image_count]}),(!e.image_count||e.image_count<=1)&&t.jsx("span",{className:m.metadataTag,title:"Single Upload",children:"Single"}),e.countries&&e.countries.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:m.metadataTag,children:Y.find(s=>s.r_code===e.countries[0].r_code)?.label||"Unknown Region"}),t.jsx("span",{className:m.metadataTag,children:e.countries.map(s=>s.label).join(", ")})]})]})})]})]}),X&&t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx(w,{name:`delete-${e.image_id}`,variant:"tertiary",size:1,className:"bg-red-50 hover:bg-red-100 text-red-700 border border-red-200 hover:border-red-300",onClick:()=>Ie(e.image_id),title:"Delete","aria-label":"Delete saved image",children:t.jsx(ze,{className:"w-4 h-4"})})})]},e.image_id)),!I.length&&t.jsx("div",{className:"text-center py-12",children:t.jsx("p",{className:"text-gray-500",children:"No examples found."})}),!R&&I.length>0&&t.jsx(Ge,{currentPage:W,totalPages:we,totalItems:K,itemsPerPage:q,onPageChange:ne})]})]})]}):t.jsx("div",{className:"space-y-6",children:t.jsxs("div",{className:"text-center py-12",children:[t.jsx("p",{className:"text-gray-500",children:"Map Details view coming soon..."}),t.jsx("p",{className:"text-sm text-gray-400 mt-2",children:"This will show detailed information about individual maps"})]})})]}),be&&t.jsx("div",{className:m.fullSizeModalOverlay,onClick:()=>J(!1),children:t.jsx("div",{className:m.fullSizeModalContent,onClick:e=>e.stopPropagation(),children:t.jsxs("div",{className:m.ratingWarningContent,children:[t.jsx("h3",{className:m.ratingWarningTitle,children:"Delete Image?"}),t.jsx("p",{className:m.ratingWarningText,children:"This action cannot be undone. Are you sure you want to delete this saved image and all related data?"}),t.jsxs("div",{className:m.ratingWarningButtons,children:[t.jsx(w,{name:"confirm-delete",variant:"secondary",onClick:Ce,disabled:Z,children:Z?"Deleting...":"Delete"}),t.jsx(w,{name:"cancel-delete",variant:"tertiary",onClick:()=>J(!1),disabled:Z,children:"Cancel"})]})]})})}),t.jsx(He,{isOpen:je,onClose:()=>{V(!1),G(!1),A(!1)},onExport:(e,s)=>{const c=I.filter(j=>s.includes(j.image_type));Ee(c,e)},filteredCount:I.length,totalCount:K,hasFilters:!!(u||g||T||f||_||y||$||E),crisisMapsCount:I.filter(e=>e.image_type==="crisis_map").length,droneImagesCount:I.filter(e=>e.image_type==="drone_image").length,isLoading:Ne,exportSuccess:ve})]})}export{pt as default};
 
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jszip.min-Bux5isNr.js","assets/index-RA4UIF3R.js","assets/index-FBu17hMI.css"])))=>i.map(i=>d[i]);
2
+ import{j as t,z as b,n as w,v as Fe,w as De,x as Oe,B as Le,r as o,D as Me,N as Re,_ as de,L as Je,F as ze,G as We}from"./index-RA4UIF3R.js";import{u as Ue}from"./useAdmin-k5gw6w_T.js";import{F as Be,E as He}from"./ExportModal-DWGvhKT1.js";const Ve="_paginatorContainer_1l5ti_1",Ae="_paginationControls_1l5ti_19",me={paginatorContainer:Ve,paginationControls:Ae};function Ge({currentPage:N,totalPages:h,totalItems:X,itemsPerPage:U,onPageChange:C,className:S=""}){if(h<=1)return null;const u=(()=>{const g=[];if(h<=5)for(let f=1;f<=h;f++)g.push(f);else{let f=Math.max(1,N-2),_=Math.min(h,f+5-1);_===h&&(f=Math.max(1,_-5+1));for(let y=f;y<=_;y++)g.push(y)}return g})();return t.jsx("div",{className:`${me.paginatorContainer} ${S}`,children:t.jsxs("div",{className:me.paginationControls,children:[t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsxs(w,{name:"prev-page",variant:"tertiary",size:1,onClick:()=>C(Math.max(1,N-1)),disabled:N===1,title:"Previous page",children:[t.jsx(Fe,{className:"w-4 h-4"}),t.jsx("span",{className:"hidden sm:inline",children:"Previous"})]})}),t.jsxs("div",{className:"flex items-center gap-1",children:[u[0]>1&&t.jsxs(t.Fragment,{children:[t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx(w,{name:"page-1",variant:"tertiary",size:1,onClick:()=>C(1),children:"1"})}),u[0]>2&&t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx("span",{className:"px-2 text-gray-500",children:"..."})})]}),u.map(g=>t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx(w,{name:`page-${g}`,variant:N===g?"primary":"tertiary",size:1,onClick:()=>C(g),children:g})},g)),u[u.length-1]<h&&t.jsxs(t.Fragment,{children:[u[u.length-1]<h-1&&t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx("span",{className:"px-2 text-gray-500",children:"..."})}),t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx(w,{name:`page-${h}`,variant:"tertiary",size:1,onClick:()=>C(h),children:h})})]})]}),t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsxs(w,{name:"next-page",variant:"tertiary",size:1,onClick:()=>C(Math.min(h,N+1)),disabled:N===h,title:"Next page",children:[t.jsx("span",{className:"hidden sm:inline",children:"Next"}),t.jsx(De,{className:"w-4 h-4"})]})})]})})}const Ze="_tabSelector_o9y1f_1",qe="_metadataTags_o9y1f_8",Ke="_metadataTag_o9y1f_8",Qe="_metadataTagSource_o9y1f_32",Xe="_metadataTagType_o9y1f_43",Ye="_mapItem_o9y1f_54",et="_mapItemImage_o9y1f_72",tt="_mapItemContent_o9y1f_92",at="_mapItemTitle_o9y1f_97",st="_mapItemMetadata_o9y1f_105",it="_fullSizeModalOverlay_o9y1f_134",nt="_fullSizeModalContent_o9y1f_148",lt="_ratingWarningContent_o9y1f_159",rt="_ratingWarningTitle_o9y1f_165",ot="_ratingWarningText_o9y1f_172",ct="_ratingWarningButtons_o9y1f_179",m={tabSelector:Ze,metadataTags:qe,metadataTag:Ke,metadataTagSource:Qe,metadataTagType:Xe,mapItem:Ye,mapItemImage:et,mapItemContent:tt,mapItemTitle:at,mapItemMetadata:st,fullSizeModalOverlay:it,fullSizeModalContent:nt,ratingWarningContent:lt,ratingWarningTitle:rt,ratingWarningText:ot,ratingWarningButtons:ct};function pt(){const N=Oe(),h=Le(),{isAuthenticated:X}=Ue(),[U,C]=o.useState("explore"),[S,M]=o.useState([]),{search:u,srcFilter:g,catFilter:T,regionFilter:f,countryFilter:_,imageTypeFilter:y,uploadTypeFilter:$,showReferenceExamples:E,setShowReferenceExamples:ge}=Me(),[B,pe]=o.useState([]),[H,ue]=o.useState([]),[Y,fe]=o.useState([]),[he,xe]=o.useState([]),[ee,_e]=o.useState([]),[ye,te]=o.useState(!0),[R,ae]=o.useState(!0),[je,V]=o.useState(!1),[Ne,A]=o.useState(!1),[ve,G]=o.useState(!1),[be,J]=o.useState(!1),[z,se]=o.useState(""),[Z,ie]=o.useState(!1),[W,ne]=o.useState(1),[q]=o.useState(10),[K,le]=o.useState(0),[we,re]=o.useState(0),Se=[{key:"explore",label:"List"},{key:"mapDetails",label:"Carousel"}],oe=()=>{ae(!0);const e=new URLSearchParams({page:W.toString(),limit:q.toString()});u&&e.append("search",u),g&&e.append("source",g),T&&e.append("event_type",T),f&&e.append("region",f),_&&e.append("country",_),y&&e.append("image_type",y),$&&e.append("upload_type",$),E&&e.append("starred_only","true"),fetch(`/api/images/grouped?${e.toString()}`).then(s=>s.ok?s.json():(console.error("ExplorePage: Grouped endpoint failed, trying legacy endpoint"),fetch("/api/captions/legacy").then(c=>c.ok?c.json():(console.error("ExplorePage: Legacy endpoint failed, trying regular images endpoint"),fetch("/api/images").then(j=>{if(!j.ok)throw new Error(`HTTP ${j.status}: ${j.statusText}`);return j.json()}))))).then(s=>{console.log("ExplorePage: Fetched captions:",s),M(s)}).catch(s=>{console.error("ExplorePage: Error fetching captions:",s),M([])}).finally(()=>{ae(!1)})},Te=()=>{const e=new URLSearchParams;u&&e.append("search",u),g&&e.append("source",g),T&&e.append("event_type",T),f&&e.append("region",f),_&&e.append("country",_),y&&e.append("image_type",y),$&&e.append("upload_type",$),E&&e.append("starred_only","true"),fetch(`/api/images/grouped/count?${e.toString()}`).then(s=>s.ok?s.json():(console.error("ExplorePage: Count endpoint failed"),{total_count:0})).then(s=>{console.log("ExplorePage: Total count:",s.total_count),le(s.total_count),re(Math.ceil(s.total_count/q))}).catch(s=>{console.error("ExplorePage: Error fetching total count:",s),le(0),re(0)})};o.useEffect(()=>{oe(),Te()},[W,u,g,T,f,_,y,$,E]),o.useEffect(()=>{W!==1&&ne(1)},[u,g,T,f,_,y,$,E]),o.useEffect(()=>{const e=()=>{document.hidden||oe()};return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}},[]),o.useEffect(()=>{new URLSearchParams(h.search).get("export")==="true"&&(V(!0),N("/explore",{replace:!0}))},[h.search,N,u,g,T,f,_,y,E]),o.useEffect(()=>{te(!0),Promise.all([fetch("/api/sources").then(e=>{if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}),fetch("/api/types").then(e=>{if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}),fetch("/api/regions").then(e=>{if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}),fetch("/api/countries").then(e=>{if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}),fetch("/api/image-types").then(e=>{if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()})]).then(([e,s,c,j,P])=>{pe(e),ue(s),fe(c),xe(j),_e(P)}).catch(()=>{}).finally(()=>{te(!1)})},[]);const I=S,Ee=async(e,s="fine-tuning")=>{if(e.length===0){alert("No images to export");return}A(!0),G(!1);try{const c=(await We(async()=>{const{default:i}=await import("./jszip.min-Bux5isNr.js").then(k=>k.j);return{default:i}},__vite__mapDeps([0,1,2]))).default,j=new c,P=e.filter(i=>i.image_type==="crisis_map"),O=e.filter(i=>i.image_type==="drone_image");if(P.length>0){const i=j.folder("crisis_maps_dataset"),k=i?.folder("images");if(k){let F=1;for(const a of P)try{const v=a.image_count&&a.image_count>1?a.all_image_ids||[a.image_id]:[a.image_id],Q=v.map(async(n,x)=>{try{const l=await fetch(`/api/images/${n}/file`);if(!l.ok)throw new Error(`Failed to fetch image ${n}`);const r=await l.blob(),d=a.file_key.split(".").pop()||"jpg",p=`${String(F).padStart(4,"0")}_${String(x+1).padStart(2,"0")}.${d}`;return k.file(p,r),{success:!0,fileName:p,imageId:n}}catch(l){return console.error(`Failed to process image ${n}:`,l),{success:!1,fileName:"",imageId:n}}}),D=(await Promise.all(Q)).filter(n=>n.success);if(D.length>0){if(s==="fine-tuning"){const n=D.map(r=>`images/${r.fileName}`),x=Math.random(),l={image:n.length===1?n[0]:n,caption:a.edited||a.generated||"",metadata:{image_id:v,title:a.title,source:a.source,event_type:a.event_type,image_type:a.image_type,countries:a.countries,starred:a.starred,image_count:a.image_count||1}};if(!i)continue;if(x<.8){const r=i.file("train.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("train.jsonl",JSON.stringify(d,null,2))}else i.file("train.jsonl",JSON.stringify([l],null,2))}else if(x<.9){const r=i.file("test.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("test.jsonl",JSON.stringify(d,null,2))}else i.file("test.jsonl",JSON.stringify([l],null,2))}else{const r=i.file("val.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("val.jsonl",JSON.stringify(d,null,2))}else i.file("val.jsonl",JSON.stringify([l],null,2))}}else{const n=D.map(l=>`images/${l.fileName}`),x={image:n.length===1?n[0]:n,caption:a.edited||a.generated||"",metadata:{image_id:v,title:a.title,source:a.source,event_type:a.event_type,image_type:a.image_type,countries:a.countries,starred:a.starred,image_count:a.image_count||1}};i&&i.file(`${String(F).padStart(4,"0")}.json`,JSON.stringify(x,null,2))}F++}}catch(v){console.error(`Failed to process caption ${a.image_id}:`,v)}}}if(O.length>0){const i=j.folder("drone_images_dataset"),k=i?.folder("images");if(k){let F=1;for(const a of O)try{const v=a.image_count&&a.image_count>1?a.all_image_ids||[a.image_id]:[a.image_id],Q=v.map(async(n,x)=>{try{const l=await fetch(`/api/images/${n}/file`);if(!l.ok)throw new Error(`Failed to fetch image ${n}`);const r=await l.blob(),d=a.file_key.split(".").pop()||"jpg",p=`${String(F).padStart(4,"0")}_${String(x+1).padStart(2,"0")}.${d}`;return k.file(p,r),{success:!0,fileName:p,imageId:n}}catch(l){return console.error(`Failed to process image ${n}:`,l),{success:!1,fileName:"",imageId:n}}}),D=(await Promise.all(Q)).filter(n=>n.success);if(D.length>0){if(s==="fine-tuning"){const n=D.map(r=>`images/${r.fileName}`),x=Math.random(),l={image:n.length===1?n[0]:n,caption:a.edited||a.generated||"",metadata:{image_id:v,title:a.title,source:a.source,event_type:a.event_type,image_type:a.image_type,countries:a.countries,starred:a.starred,image_count:a.image_count||1}};if(!i)continue;if(x<.8){const r=i.file("train.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("train.jsonl",JSON.stringify(d,null,2))}else i.file("train.jsonl",JSON.stringify([l],null,2))}else if(x<.9){const r=i.file("test.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("test.jsonl",JSON.stringify(d,null,2))}else i.file("test.jsonl",JSON.stringify([l],null,2))}else{const r=i.file("val.jsonl");if(r){const d=await r.async("string").then(p=>JSON.parse(p||"[]")).catch(()=>[]);d.push(l),i.file("val.jsonl",JSON.stringify(d,null,2))}else i.file("val.jsonl",JSON.stringify([l],null,2))}}else{const n=D.map(l=>`images/${l.fileName}`),x={image:n.length===1?n[0]:n,caption:a.edited||a.generated||"",metadata:{image_id:v,title:a.title,source:a.source,event_type:a.event_type,image_type:a.image_type,countries:a.countries,starred:a.starred,image_count:a.image_count||1}};i&&i.file(`${String(F).padStart(4,"0")}.json`,JSON.stringify(x,null,2))}F++}}catch(v){console.error(`Failed to process caption ${a.image_id}:`,v)}}}const $e=await j.generateAsync({type:"blob"}),ce=URL.createObjectURL($e),L=document.createElement("a");L.href=ce,L.download=`datasets_${s}_${new Date().toISOString().split("T")[0]}.zip`,document.body.appendChild(L),L.click(),document.body.removeChild(L),URL.revokeObjectURL(ce);const Pe=(P.length||0)+(O.length||0);console.log(`Exported ${s} datasets with ${Pe} total images:`),P.length>0&&console.log(`- Crisis maps: ${P.length} images`),O.length>0&&console.log(`- Drone images: ${O.length} images`),G(!0)}catch(c){console.error("Export failed:",c),alert("Failed to export dataset. Please try again.")}finally{A(!1)}},Ie=e=>{se(e),J(!0)},Ce=async()=>{if(z){ie(!0);try{console.log("Deleting image with ID:",z),(await fetch(`/api/images/${z}`,{method:"DELETE"})).ok?(M(s=>s.filter(c=>c.image_id!==z)),J(!1),se("")):(console.error("Delete failed"),alert("Failed to delete image. Please try again."))}catch(e){console.error("Delete failed:",e),alert("Failed to delete image. Please try again.")}finally{ie(!1)}}};return t.jsxs(Re,{children:[R?t.jsx("div",{className:"flex flex-col items-center justify-center min-h-[60vh]",children:t.jsxs("div",{className:"flex flex-col items-center gap-4",children:[t.jsx(de,{className:"text-ifrcRed"}),t.jsx("div",{children:"Loading examples..."})]})}):t.jsxs("div",{className:"max-w-7xl mx-auto",children:[t.jsxs("div",{className:m.tabSelector,children:[t.jsx(Je,{name:"explore-view",value:U,onChange:e=>{(e==="explore"||e==="mapDetails")&&(C(e),e==="mapDetails"&&S.length>0&&(S[0]?.image_id&&S[0].image_id!=="undefined"&&S[0].image_id!=="null"?N(`/map/${S[0].image_id}`):console.error("Invalid image_id for navigation:",S[0]?.image_id)))},options:Se,keySelector:e=>e.key,labelSelector:e=>e.label}),t.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsxs(w,{name:"reference-examples",variant:E?"primary":"secondary",onClick:()=>ge(!E),className:"whitespace-nowrap",children:[t.jsx("span",{className:"mr-2",children:E?t.jsx("span",{className:"text-yellow-400",children:"β˜…"}):t.jsx("span",{className:"text-yellow-400",children:"β˜†"})}),"Reference Examples"]})}),t.jsx(w,{name:"export-dataset",variant:"secondary",onClick:()=>V(!0),children:"Export"})]})]}),U==="explore"?t.jsxs("div",{className:"space-y-6",children:[t.jsx("div",{className:"mb-6 space-y-4",children:t.jsx("div",{className:"flex flex-wrap items-center gap-4",children:t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2 flex-1 min-w-[300px]",children:t.jsx(Be,{sources:B,types:H,regions:Y,countries:he,imageTypes:ee,isLoadingFilters:ye})})})}),t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"flex justify-between items-center",children:t.jsxs("p",{className:"text-sm text-gray-600",children:[I.length," of ",K," examples"]})}),R&&t.jsx("div",{className:"text-center py-12",children:t.jsxs("div",{className:"flex flex-col items-center gap-4",children:[t.jsx(de,{className:"text-ifrcRed"}),t.jsx("div",{children:"Loading examples..."})]})}),!R&&t.jsxs("div",{className:"space-y-4",children:[I.map(e=>t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsxs("div",{className:`${m.mapItem} flex-1`,onClick:()=>{console.log("ExplorePage: Clicking on image with ID:",e.image_id),console.log("ExplorePage: Image data:",e),e.image_id&&e.image_id!=="undefined"&&e.image_id!=="null"?(console.log("ExplorePage: Navigating to:",`/map/${e.image_id}`),console.log("ExplorePage: Full navigation URL:",`/#/map/${e.image_id}`),N(`/map/${e.image_id}`)):(console.error("Invalid image_id for navigation:",e.image_id),console.error("Full item data:",JSON.stringify(e,null,2)),alert(`Cannot navigate: Invalid image ID (${e.image_id})`))},children:[t.jsx("div",{className:m.mapItemImage,style:{width:"120px",height:"80px"},children:e.thumbnail_url?t.jsxs(t.Fragment,{children:[console.log("ExplorePage: Using thumbnail for fast loading:",e.thumbnail_url),t.jsx("img",{src:e.thumbnail_url,alt:e.file_key,onError:s=>{console.error("ExplorePage: Thumbnail failed to load, falling back to original:",e.thumbnail_url);const c=s.target;e.image_url?c.src=e.image_url:(c.style.display="none",c.parentElement.innerHTML="Img")},onLoad:()=>console.log("ExplorePage: Thumbnail loaded successfully:",e.thumbnail_url)})]}):e.image_url?t.jsxs(t.Fragment,{children:[console.log("ExplorePage: No thumbnail available, using original image:",e.image_url),t.jsx("img",{src:e.image_url,alt:e.file_key,onError:s=>{console.error("ExplorePage: Original image failed to load:",e.image_url);const c=s.target;c.style.display="none",c.parentElement.innerHTML="Img"},onLoad:()=>console.log("ExplorePage: Original image loaded successfully:",e.image_url)})]}):t.jsxs(t.Fragment,{children:[console.log("ExplorePage: No image_url or thumbnail provided for item:",e),"'Img'"]})}),t.jsxs("div",{className:m.mapItemContent,children:[t.jsx("h3",{className:m.mapItemTitle,children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{children:e.title||"Untitled"}),e.starred&&t.jsx("span",{className:"text-red-500 text-lg",title:"Starred image",children:"β˜…"})]})}),t.jsx("div",{className:m.mapItemMetadata,children:t.jsxs("div",{className:m.metadataTags,children:[e.image_type!=="drone_image"&&t.jsx("span",{className:m.metadataTagSource,children:e.source&&e.source.includes(", ")?e.source.split(", ").map(s=>B.find(c=>c.s_code===s.trim())?.label||s.trim()).join(", "):B.find(s=>s.s_code===e.source)?.label||e.source}),t.jsx("span",{className:m.metadataTagType,children:e.event_type&&e.event_type.includes(", ")?e.event_type.split(", ").map(s=>H.find(c=>c.t_code===s.trim())?.label||s.trim()).join(", "):H.find(s=>s.t_code===e.event_type)?.label||e.event_type}),t.jsx("span",{className:m.metadataTag,children:ee.find(s=>s.image_type===e.image_type)?.label||e.image_type}),e.image_count&&e.image_count>1&&t.jsxs("span",{className:m.metadataTag,title:`Multi-upload with ${e.image_count} images`,children:["πŸ“· ",e.image_count]}),(!e.image_count||e.image_count<=1)&&t.jsx("span",{className:m.metadataTag,title:"Single Upload",children:"Single"}),e.countries&&e.countries.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:m.metadataTag,children:Y.find(s=>s.r_code===e.countries[0].r_code)?.label||"Unknown Region"}),t.jsx("span",{className:m.metadataTag,children:e.countries.map(s=>s.label).join(", ")})]})]})})]})]}),X&&t.jsx(b,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:t.jsx(w,{name:`delete-${e.image_id}`,variant:"tertiary",size:1,className:"bg-red-50 hover:bg-red-100 text-red-700 border border-red-200 hover:border-red-300",onClick:()=>Ie(e.image_id),title:"Delete","aria-label":"Delete saved image",children:t.jsx(ze,{className:"w-4 h-4"})})})]},e.image_id)),!I.length&&t.jsx("div",{className:"text-center py-12",children:t.jsx("p",{className:"text-gray-500",children:"No examples found."})}),!R&&I.length>0&&t.jsx(Ge,{currentPage:W,totalPages:we,totalItems:K,itemsPerPage:q,onPageChange:ne})]})]})]}):t.jsx("div",{className:"space-y-6",children:t.jsxs("div",{className:"text-center py-12",children:[t.jsx("p",{className:"text-gray-500",children:"Map Details view coming soon..."}),t.jsx("p",{className:"text-sm text-gray-400 mt-2",children:"This will show detailed information about individual maps"})]})})]}),be&&t.jsx("div",{className:m.fullSizeModalOverlay,onClick:()=>J(!1),children:t.jsx("div",{className:m.fullSizeModalContent,onClick:e=>e.stopPropagation(),children:t.jsxs("div",{className:m.ratingWarningContent,children:[t.jsx("h3",{className:m.ratingWarningTitle,children:"Delete Image?"}),t.jsx("p",{className:m.ratingWarningText,children:"This action cannot be undone. Are you sure you want to delete this saved image and all related data?"}),t.jsxs("div",{className:m.ratingWarningButtons,children:[t.jsx(w,{name:"confirm-delete",variant:"secondary",onClick:Ce,disabled:Z,children:Z?"Deleting...":"Delete"}),t.jsx(w,{name:"cancel-delete",variant:"tertiary",onClick:()=>J(!1),disabled:Z,children:"Cancel"})]})]})})}),t.jsx(He,{isOpen:je,onClose:()=>{V(!1),G(!1),A(!1)},onExport:(e,s)=>{const c=I.filter(j=>s.includes(j.image_type));Ee(c,e)},filteredCount:I.length,totalCount:K,hasFilters:!!(u||g||T||f||_||y||$||E),crisisMapsCount:I.filter(e=>e.image_type==="crisis_map").length,droneImagesCount:I.filter(e=>e.image_type==="drone_image").length,isLoading:Ne,exportSuccess:ve})]})}export{pt as default};
py_backend/static/assets/{index-4L12dHQs.js β†’ index-Dx7kXGv5.js} RENAMED
@@ -1 +1 @@
1
- import{r as s,y as nt,t as ht,a as q,c as gt,j as e,o as N,b as se,R as st,z,g as rt,d as ft,m as vt,e as pt,n as Z,A as xt,f as _t,h as Ct,i as yt,k as he,l as bt,p as ye,q as jt,s as Nt,E as wt,C as St,U as Mt,Q as It,u as Dt,N as je,_ as Et,L as Tt}from"./index-BCz4bkWK.js";const kt=({title:m,titleId:a,...h})=>s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":a},h),m?s.createElement("title",{id:a},m):null,s.createElement("g",{clipPath:"url(#arrow-drop-down-line_svg__a)"},s.createElement("path",{d:"m12 15-4.243-4.243 1.415-1.414L12 12.172l2.828-2.83 1.415 1.415L12 15Z"})),s.createElement("defs",null,s.createElement("clipPath",{id:"arrow-drop-down-line_svg__a"},s.createElement("path",{d:"M0 0h24v24H0z"})))),Lt=({title:m,titleId:a,...h})=>s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":a},h),m?s.createElement("title",{id:a},m):null,s.createElement("g",{clipPath:"url(#arrow-drop-up-line_svg__a)"},s.createElement("path",{d:"m12 11.828-2.828 2.829-1.415-1.414L12 9l4.243 4.243-1.415 1.414L12 11.828Z"})),s.createElement("defs",null,s.createElement("clipPath",{id:"arrow-drop-up-line_svg__a"},s.createElement("path",{d:"M0 0h24v24H0z"})))),Pt=({title:m,titleId:a,...h})=>s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":a},h),m?s.createElement("title",{id:a},m):null,s.createElement("g",{clipPath:"url(#information-line_svg__a)"},s.createElement("path",{d:"M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10Zm0-2a8 8 0 1 0 0-16.001A8 8 0 0 0 12 20ZM11 7h2v2h-2V7Zm0 4h2v6h-2v-6Z"})),s.createElement("defs",null,s.createElement("clipPath",{id:"information-line_svg__a"},s.createElement("path",{d:"M0 0h24v24H0z"})))),Rt=({title:m,titleId:a,...h})=>s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":a},h),m?s.createElement("title",{id:a},m):null,s.createElement("path",{fillRule:"evenodd",d:"m15.063 12 .937.938-4 4-4-4L8.938 12 12 15.063 15.063 12Z",clipRule:"evenodd"}),s.createElement("mask",{id:"table-sorting-line_svg__a",width:8,height:5,x:8,y:12,maskUnits:"userSpaceOnUse",style:{maskType:"luminance"}},s.createElement("path",{fillRule:"evenodd",d:"m15.063 12 .937.938-4 4-4-4L8.938 12 12 15.063 15.063 12Z",clipRule:"evenodd"})),s.createElement("g",{mask:"url(#table-sorting-line_svg__a)"},s.createElement("path",{d:"M-24-22h72v72h-72z"})),s.createElement("path",{fillRule:"evenodd",d:"M8.938 11 8 10.062l4-4 4 4-.938.938L12 7.937 8.937 11Z",clipRule:"evenodd"}),s.createElement("mask",{id:"table-sorting-line_svg__b",width:8,height:5,x:8,y:6,maskUnits:"userSpaceOnUse",style:{maskType:"luminance"}},s.createElement("path",{fillRule:"evenodd",d:"M8.938 11 8 10.062l4-4 4 4-.938.938L12 7.937 8.937 11Z",clipRule:"evenodd"})),s.createElement("g",{mask:"url(#table-sorting-line_svg__b)"},s.createElement("path",{d:"M48 45h-72v-72h72z"}))),$t="_number-output_1blvi_1",Bt={numberOutput:$t};function we(m){const{className:a,invalidText:h=nt,separatorHidden:r,compact:f,currency:g,value:b,tooltip:_,unit:y,prefix:x,suffix:w,maximumFractionDigits:C=1}=m,{currentLanguage:j}=s.useContext(ht),v=s.useMemo(()=>{if(q(b))return h;const S=gt(b,{currency:g,compact:f,separatorHidden:r,maximumFractionDigits:C,unit:y,language:j});return e.jsxs(e.Fragment,{children:[x,S,w]})},[h,b,f,r,g,y,C,x,j,w]);return e.jsx("div",{className:N(Bt.numberOutput,a),title:se(_)?String(_):void 0,children:v})}const At="_tooltip-dummy_rbf3f_1",Ft="_tooltip-content_rbf3f_7",Ot="_pointer_rbf3f_14",Ne={tooltipDummy:At,tooltipContent:Ft,pointer:Ot};function Ht(m){const{className:a,title:h,description:r,preferredWidth:f}=m,[g,b]=s.useState(!1),[_,y]=s.useState(!1),x=s.useRef(),w=s.useRef(null);return s.useEffect(()=>{const C=()=>{y(!0)},j=()=>{y(!1)};if(q(w.current))return;const{current:{parentNode:v}}=w;if(!q(v))return x.current=v,v.addEventListener("mouseover",C),v.addEventListener("mouseout",j),b(!0),()=>{v.removeEventListener("mouseover",C),v.removeEventListener("mouseout",j)}},[]),e.jsxs(e.Fragment,{children:[!g&&e.jsx("div",{className:Ne.tooltipDummy,ref:w}),_&&e.jsx(st,{className:N(Ne.tooltipContent,a),parentRef:x,pointerClassName:Ne.pointer,preferredWidth:f,children:e.jsx(z,{heading:h,withInternalPadding:!0,contentViewType:"vertical",children:r})})]})}function $(m){return m.id}const Vt="common",zt={booleanYesLabel:"Yes",booleanNoLabel:"No"},Ut={namespace:Vt,strings:zt},Wt="_boolean-output_kg1uq_1",Qt={booleanOutput:Wt};function Zt(m){const{className:a,invalidText:h,value:r}=m,f=rt(Ut);let g;return r===!0?g=f.booleanYesLabel:r===!1?g=f.booleanNoLabel:g=h,e.jsx("div",{className:N(Qt.booleanOutput,a),children:g})}const qt="_date-output_4jzjo_1",Gt={dateOutput:qt};function Yt(m){const{value:a,format:h,className:r,invalidText:f}=m,g=s.useMemo(()=>ft(a,h),[a,h]);return e.jsx("div",{className:N(Gt.dateOutput,r),children:g??f})}const Kt="_dropdown-menu_16hml_1",Xt="_icons_16hml_4",Jt="_content_16hml_5",ea="_actions_16hml_6",ta="_dropdown-icon_16hml_10",aa="_dropdown-content_16hml_16",le={dropdownMenu:Kt,icons:Xt,content:Jt,actions:ea,dropdownIcon:ta,dropdownContent:aa};function na(m){const a=s.useRef(null),{className:h,popupClassName:r,children:f,label:g,activeClassName:b,icons:_,variant:y="secondary",actions:x,withoutDropdownIcon:w,componentRef:C,elementRef:j=a,persistent:v,preferredPopupWidth:S}=m,p=s.useRef(null),[k,I]=s.useState(!1);s.useEffect(()=>{C&&(C.current={setShowDropdown:I})},[C,I]);const R=s.useCallback(()=>{I(re=>!re)},[I]),T=s.useCallback((re,ae)=>{ae||re&&v||I(!1)},[I,v]);vt(k,T,p,j);const G=s.useMemo(()=>({setShowDropdown:I}),[I]),U=!!x||!w;return e.jsxs(pt.Provider,{value:G,children:[e.jsx(Z,{name:void 0,className:N(le.dropdownMenu,k&&b,h),elementRef:j,onClick:R,variant:y,actionsContainerClassName:le.actions,iconsContainerClassName:le.icons,childrenContainerClassName:le.content,actions:U?e.jsxs(e.Fragment,{children:[x,!w&&(k?e.jsx(xt,{className:le.dropdownIcon}):e.jsx(_t,{className:le.dropdownIcon}))]}):void 0,icons:_,children:g}),k&&e.jsx(st,{elementRef:p,className:N(le.dropdownContent,r),parentRef:j,preferredWidth:S,children:f})]})}const sa="_info-popup_i3rna_1",ra="_label_i3rna_2",ia="_icon_i3rna_7",oa="_dropdown-container_i3rna_15",la="_content_i3rna_20",ge={infoPopup:sa,label:ra,icon:ia,dropdownContainer:oa,content:la};function ca(m){const{className:a,icon:h=e.jsx(Pt,{}),infoLabel:r,title:f,description:g,withoutIcon:b,popupClassName:_,descriptionClassName:y}=m;return e.jsx(na,{label:e.jsxs("div",{className:ge.label,children:[r,!b&&h&&e.jsx("div",{className:ge.icon,children:h})]}),popupClassName:N(ge.dropdownContainer,_),className:N(ge.infoPopup,a),variant:"tertiary",withoutDropdownIcon:!0,children:e.jsx(z,{heading:f,childrenContainerClassName:N(y,ge.content),withInternalPadding:!0,children:g})})}const da="_progress-wrapper_x340w_1",ua="_title_x340w_7",ma="_total_x340w_11",ha="_progress_x340w_1",fe={progressWrapper:da,title:ua,total:ma,progress:ha};function Ye(m){const{className:a,title:h,description:r,totalValue:f,value:g,showPercentageInTitle:b,children:_,color:y="var(--go-ui-color-primary-red)"}=m,x=se(g)?g:0,w=se(f)?f:0;let C;return w===0?C=0:C=x/w*100,e.jsxs("div",{className:N(fe.progressWrapper,a),children:[(h||b)&&e.jsxs("div",{className:fe.title,children:[h,b&&e.jsx(we,{value:C,suffix:"%"})]}),e.jsx("div",{className:fe.total,children:e.jsx("div",{className:fe.progress,style:{width:`${C}%`,backgroundColor:y}})}),r&&e.jsx("div",{className:fe.description,children:r}),_]})}const ga="_legend-element_1a9ic_1",fa="_color_1a9ic_7",va="_icon-container_1a9ic_14",pa="_icon_1a9ic_14",xa="_label_1a9ic_31",ve={legendElement:ga,color:fa,iconContainer:va,icon:pa,label:xa};function _a(m){const{className:a,colorClassName:h,iconClassName:r,color:f,label:g,iconSrc:b}=m;return e.jsxs("div",{className:N(ve.legendElement,a),children:[b?e.jsx("div",{style:{backgroundColor:f},className:ve.iconContainer,children:e.jsx("img",{className:N(ve.icon,r),src:b,alt:""})}):e.jsx("div",{style:{backgroundColor:f},className:N(ve.color,h)}),e.jsx("div",{className:ve.label,children:g})]})}const Ca="_text-output_10oza_1",ya="_with-background_10oza_6",ba="_label_10oza_11",ja="_with-colon_10oza_12",Na="_value_10oza_17",wa="_text-type_10oza_18",Sa="_strong_10oza_24",ee={textOutput:Ca,withBackground:ya,label:ba,withColon:ja,value:Na,textType:wa,strong:Sa};function Ke(m){const{className:a,label:h,icon:r,description:f,labelClassName:g,descriptionClassName:b,valueClassName:_,strongLabel:y,strongValue:x,strongDescription:w,withoutLabelColon:C,withBackground:j,invalidText:v=nt,...S}=m,{value:p}=m;let k=v;return S.valueType==="number"?k=e.jsx(we,{...S,invalidText:v}):S.valueType==="date"?k=e.jsx(Yt,{...S,invalidText:v}):S.valueType==="boolean"?k=e.jsx(Zt,{...S,invalidText:v}):p instanceof Date||(k=p||v),e.jsxs("div",{className:N(ee.textOutput,j&&ee.withBackground,a),children:[r,h&&e.jsx("div",{className:N(ee.label,y&&ee.strong,g,!C&&ee.withColon),children:h}),e.jsx("div",{className:N(ee.value,x&&ee.strong,S.valueType==="text"&&ee.textType,_),children:k}),f&&e.jsx("div",{className:N(ee.description,w&&ee.strong,b),children:f})]})}const Ma="_pie-chart_pyr7m_1",Ia="_legend_pyr7m_7",Da="_legend-item_pyr7m_13",pe={pieChart:Ma,legend:Ia,legendItem:Da},Ea=70,Ta=40;function Xe(m,a=1){return Math.round(m*10**a)/10**a}function Je(m,a){const h=(a-90)*Math.PI/180;return{x:Xe(m+m*Math.cos(h)),y:Xe(m+m*Math.sin(h))}}function ka(m,a,h){let r=h;const f=r-a===360;f&&(r-=1);const g=Je(m,a),b=Je(m,r),_=r-a<=180?0:1,y=["M",g.x,g.y,"A",m,m,0,_,1,b.x,b.y];return f?y.push("Z"):y.push("L",m,m,"L",g.x,g.y,"Z"),y.join(" ")}function xe(m){const{className:a,data:h,valueSelector:r,labelSelector:f,keySelector:g,colorSelector:b,colors:_,pieRadius:y=Ea,chartPadding:x=Ta,legendClassName:w,showPercentageInLegend:C}=m,j=Ct(h?.map(p=>r(p))),v=q(j)||j===0?1:j,S=s.useMemo(()=>{let p=0;const k=h?.map(I=>{const R=r(I);if(q(R))return;const T=360*(R/v);return p+=T,{key:g(I),value:R,label:f(I),startAngle:p-T,percentage:yt(R,v),endAngle:p,datum:I}}).filter(se)??[];return b?k.map(({datum:I,...R})=>({...R,color:b(I)})):k.map(({datum:I,...R},T)=>({...R,color:_[T%_.length]}))},[h,g,r,f,v,b,_]);return e.jsxs("div",{className:N(pe.pieChart,a),children:[e.jsx("svg",{className:pe.svg,style:{width:`${x+y*2}px`,height:`${x+y*2}px`},children:e.jsx("g",{style:{transform:`translate(${x/2}px, ${x/2}px)`},children:S.map(p=>e.jsx("path",{className:pe.path,d:ka(y,p.startAngle,p.endAngle),fill:p.color,children:e.jsx(Ht,{description:e.jsx(Ke,{label:p.label,value:p.value})})},p.key))})}),e.jsx("div",{className:N(pe.legend,w),children:S.map(p=>e.jsx(_a,{className:pe.legendItem,label:C?e.jsx(Ke,{label:p.label,value:p.percentage,valueType:"number",prefix:"(",suffix:"%)",withoutLabelColon:!0}):p.label,color:p.color},p.key))})]})}const La="_td_1k4cn_1",Pa={td:La};function Ra(m){const{className:a,children:h,...r}=m;return e.jsx("td",{className:N(a,Pa.td),...r,children:h})}function it(m){const{className:a,children:h,...r}=m;return e.jsx("tr",{className:a,...r,children:h})}const $a="_row_1829z_1",Ba="_cell_1829z_2",et={row:$a,cell:Ba};function Aa(m){const{data:a,keySelector:h,columns:r,rowClassName:f,cellClassName:g,rowModifier:b}=m;return e.jsx(e.Fragment,{children:a?.map((_,y)=>{const x=h(_,y),w=r.map(v=>{const{id:S,cellRenderer:p,cellRendererClassName:k,cellRendererParams:I,cellContainerClassName:R}=v,T=I(x,_,y,a),G=e.jsx(p,{className:k,...T,name:S});return e.jsx(Ra,{className:N(et.cell,R,typeof g=="function"?g(x,_,S):g),children:G},S)}),C=e.jsx(it,{className:N(et.row,typeof f=="function"?f(x,_):f),children:w});let j=C;return b&&(j=b({rowKey:x,row:C,cells:w,columns:r,datum:_})),e.jsx(s.Fragment,{children:j},x)})})}const Fa="_th_cdv41_1",Oa="_resize-handle_cdv41_8",tt={th:Fa,resizeHandle:Oa};function Ha(m){const{className:a,children:h,onResize:r,onResizeComplete:f,name:g,...b}=m,_=s.useRef(null),y=s.useRef(),x=s.useRef(),w=s.useRef(),C=s.useCallback(v=>{var S;if(se(y.current)&&_.current&&r){v.preventDefault(),v.stopPropagation();const p=v.clientX-y.current;if(se(x.current)){const k=x.current+p;w.current=k,r(k,g)}else x.current=(S=_.current)==null?void 0:S.offsetWidth}},[r,g]),j=s.useCallback(v=>{var S;v.preventDefault(),y.current=v.clientX,x.current=(S=_.current)==null?void 0:S.offsetWidth,window.addEventListener("mousemove",C,!0)},[C]);return s.useEffect(()=>{const v=()=>{y.current=void 0,x.current=void 0,f&&se(w.current)&&f(w.current,g),window.removeEventListener("mousemove",C,!0)};return window.addEventListener("mouseup",v,!0),()=>{window.removeEventListener("mouseup",v,!0),window.removeEventListener("mousemove",C,!0)}},[C,g,f]),e.jsxs("th",{ref:_,className:N(a,tt.th),...b,children:[r&&e.jsx("div",{role:"presentation",className:tt.resizeHandle,onMouseDown:j}),h]})}const Va="_table_nilhy_1",za="_table-overflow-wrapper_nilhy_8",Ua="_table-element_nilhy_13",Wa="_header-row_nilhy_23",Qa="_header-element_nilhy_24",Za="_header-component_nilhy_29",ce={table:Va,tableOverflowWrapper:za,tableElement:Ua,headerRow:Wa,headerElement:Qa,headerComponent:Za};function qa(m,a){return a??m.columnWidth??wt}function B(m){const{data:a,keySelector:h,columns:r,caption:f,className:g,captionClassName:b,headerRowClassName:_,headerCellClassName:y,rowClassName:x,cellClassName:w,rowModifier:C,fixedColumnWidth:j,resizableColumn:v,headersHidden:S,pending:p,filtered:k,errored:I=!1}=m,R=s.useRef(null),[T]=he.useState(()=>bt()),[G,U]=he.useState({});s.useEffect(()=>{U(W=>{if(q(R.current))return W;const E=R.current.getBoundingClientRect(),{width:O}=E;let A=r.map(M=>({id:M.id,stretch:!!M.columnStretch,width:qa(M,W[M.id])}));const X=ye(A.filter(M=>M.stretch).map(M=>M.width)),ne=ye(A.filter(M=>!M.stretch).map(M=>M.width)),Y=(O-ne)/X;return Y>1&&(A=A.map(M=>({...M,width:M.stretch?M.width*Y:M.width}))),jt(A,M=>M.id,M=>M.width)})},[r]);const re=he.useCallback((W,E)=>{const O=document.getElementById(`${T}-${E}`),A=Math.max(W,80);if(q(O)||(O.style.width=`${A}px`,!j))return;const X=document.getElementById(T);if(q(X))return;const ne=ye(r.map(Y=>Y.id===E?A:G[Y.id]));X.style.width=`${ne}px`},[T,G,r,j]),ae=he.useCallback((W,E)=>{se(E)&&U(O=>({...O,[E]:Math.max(W,80)}))},[U]),be=he.useMemo(()=>ye(r.map(W=>G[W.id])),[G,r]),K=q(a)||a.length===0||Object.keys(G).length===0;return e.jsxs("div",{ref:R,className:N(ce.table,g),children:[!K&&e.jsx("div",{className:ce.tableOverflowWrapper,children:e.jsxs("table",{className:ce.tableElement,style:j?{width:`${be}px`}:void 0,id:T,children:[f&&e.jsx("caption",{className:b,children:f}),e.jsx("colgroup",{children:r.map(W=>{const{id:E,columnClassName:O}=W,A=G[E],X=j?{width:`${A}px`}:void 0;return e.jsx("col",{id:`${T}-${E}`,style:X,className:N(ce.column,O)},E)})}),!S&&e.jsx("thead",{children:e.jsx(it,{className:N(ce.headerRow,_),children:r.map((W,E)=>{const{id:O,title:A,headerCellRenderer:X,headerCellRendererClassName:ne,headerCellRendererParams:Y,headerContainerClassName:M}=W,ie=e.jsx(X,{...Y,name:O,title:A,index:E,className:N(ne,ce.headerComponent)});return e.jsx(Ha,{scope:"col",name:O,onResize:v?re:void 0,onResizeComplete:v?ae:void 0,className:N(ce.headerElement,typeof y=="function"?y(O):y,M),children:ie},O)})})}),e.jsx("tbody",{children:e.jsx(Aa,{data:a,keySelector:h,columns:r,rowClassName:x,cellClassName:w,rowModifier:C})})]})}),e.jsx(Nt,{filtered:k,empty:K,errored:I,pending:p,overlayPending:!0})]})}function Ga(m){const{className:a,value:h}=m;return q(h)?null:e.jsx("div",{className:a,children:h})}const Ya="common",Ka={sortTableButtonTitle:"Sort Table"},Xa={namespace:Ya,strings:Ka},Ja="_header-cell_vn24d_1",en="_sort-button_vn24d_8",tn="_icon_vn24d_12",an="_info-popup-icon_vn24d_17",de={headerCell:Ja,sortButton:en,icon:tn,infoPopupIcon:an};function ot(m){const{className:a,titleClassName:h,title:r,name:f,sortable:g,defaultSortDirection:b="asc",infoTitle:_,infoDescription:y}=m,{sorting:x,setSorting:w}=s.useContext(St),C=rt(Xa),j=x?.name===f?x.direction:void 0,v=s.useRef(null),S=s.useCallback(()=>{if(q(w))return;let p;q(j)?p=b:j==="asc"?p="dsc":j==="dsc"&&(p="asc"),w(p?{name:f,direction:p}:void 0)},[f,w,j,b]);return e.jsxs("div",{ref:v,className:N(a,de.headerCell),children:[g&&e.jsxs(Z,{name:void 0,variant:"tertiary",onClick:S,title:C.sortTableButtonTitle,className:de.sortButton,children:[q(j)&&e.jsx(Rt,{className:de.icon}),j==="asc"&&e.jsx(Lt,{className:de.icon}),j==="dsc"&&e.jsx(kt,{className:de.icon})]}),e.jsx("div",{className:N(h,de.title),children:r}),_&&y&&e.jsx(ca,{className:de.infoPopupIcon,title:_,description:y})]})}const at={};function Q(m,a,h,r){return{id:m,title:a,columnClassName:r?.columnClassName,headerCellRenderer:ot,headerCellRendererClassName:r?.headerCellRendererClassName,headerContainerClassName:r?.headerContainerClassName,headerCellRendererParams:{sortable:r?.sortable,infoTitle:r?.headerInfoTitle,infoDescription:r?.headerInfoDescription},cellRendererClassName:r?.cellRendererClassName,cellContainerClassName:r?.cellContainerClassName,cellRenderer:Ga,cellRendererParams:(f,g)=>({value:h(g)||"--"}),valueSelector:h,valueComparator:(f,g)=>Mt(h(f),h(g)),columnWidth:r?.columnWidth,columnStretch:r?.columnStretch,columnStyle:r?.columnStyle}}function D(m,a,h,r){return{id:m,title:a,columnClassName:r?.columnClassName,headerCellRenderer:ot,headerCellRendererClassName:N(at.numberCellHeader,r?.headerCellRendererClassName),headerContainerClassName:r?.headerContainerClassName,headerCellRendererParams:{sortable:r?.sortable,infoTitle:r?.headerInfoTitle,infoDescription:r?.headerInfoDescription},cellRendererClassName:N(at.numberCell,r?.cellRendererClassName),cellContainerClassName:r?.cellContainerClassName,cellRenderer:we,cellRendererParams:(f,g)=>({value:h(g),suffix:r?.suffix,maximumFractionDigits:r?.maximumFractionDigits,invalidText:"--"}),valueSelector:h,valueComparator:(f,g)=>It(h(f),h(g)),columnWidth:r?.columnWidth,columnStretch:r?.columnStretch,columnStyle:r?.columnStyle}}const nn="_tabSelector_vlxoe_1",sn="_progressSection_vlxoe_14",rn="_progressLabel_vlxoe_20",on="_chartGrid_vlxoe_28",ln="_chartContainer_vlxoe_40",cn="_tableContainer_vlxoe_51",dn="_modelPerformance_vlxoe_59",un="_loadingContainer_vlxoe_67",mn="_errorContainer_vlxoe_77",hn="_userInteractionCards_vlxoe_96",gn="_userInteractionCard_vlxoe_96",fn="_userInteractionCardValue_vlxoe_116",vn="_userInteractionCardLabel_vlxoe_123",pn="_userInteractionCardButton_vlxoe_130",xn="_summaryStatsCards_vlxoe_148",_n="_summaryStatsCard_vlxoe_148",Cn="_summaryStatsCardValue_vlxoe_169",yn="_summaryStatsCardLabel_vlxoe_176",c={tabSelector:nn,progressSection:sn,progressLabel:rn,chartGrid:on,chartContainer:ln,tableContainer:cn,modelPerformance:dn,loadingContainer:un,errorContainer:mn,userInteractionCards:hn,userInteractionCard:gn,userInteractionCardValue:fn,userInteractionCardLabel:vn,userInteractionCardButton:pn,summaryStatsCards:xn,summaryStatsCard:_n,summaryStatsCardValue:Cn,summaryStatsCardLabel:yn};function jn(){const[m]=Dt(),[a,h]=s.useState(null),[r,f]=s.useState(!0),[g,b]=s.useState("crisis_maps"),[_,y]=s.useState([]),[x,w]=s.useState([]),[C,j]=s.useState([]),[v,S]=s.useState([]),[p,k]=s.useState(!1),[I,R]=s.useState(!1),[T,G]=s.useState(!1),[U,re]=s.useState(!1),[ae,be]=s.useState(!1),[K,W]=s.useState(!1),E=t=>{k(t==="editTime"),R(t==="percentage"),G(t==="delete"),re(t==="regions"),be(t==="sources"),W(t==="types")},O=[{key:"crisis_maps",label:"Crisis Maps"},{key:"drone_images",label:"Drone Images"}],A=s.useCallback((t,l)=>{if(!t||!l)return 0;const i=t.toLowerCase().replace(/[^\w\s]/g,"").split(/\s+/).filter(u=>u.length>0),n=l.toLowerCase().replace(/[^\w\s]/g,"").split(/\s+/).filter(u=>u.length>0);if(i.length===0&&n.length===0)return 1;if(i.length===0||n.length===0)return 0;const o=new Set(i),d=new Set(n),P=new Set([...o].filter(u=>d.has(u))),F=new Set([...o,...d]);return P.size/F.size},[]),X=s.useCallback(async()=>{f(!0);try{const l=await(await fetch("/api/images")).json(),i={},n=l.filter(u=>u.image_type==="crisis_map"),o=l.filter(u=>u.image_type==="drone_image"),d={totalCaptions:l.length,sources:{},types:{},regions:{},models:{},modelEditTimes:i,percentageModified:0,modelPercentageData:{},totalDeleteCount:0,deleteRate:0,crisisMaps:n,droneImages:o};l.forEach(u=>{if(u.source&&(d.sources[u.source]=(d.sources[u.source]||0)+1),u.event_type&&(d.types[u.event_type]=(d.types[u.event_type]||0)+1),u.countries&&u.countries.forEach(L=>{L.r_code&&(d.regions[L.r_code]=(d.regions[L.r_code]||0)+1)}),u.model){const L=u.model,V=d.models[L]||={count:0,avgAccuracy:0,avgContext:0,avgUsability:0,totalScore:0,deleteCount:0};if(V.count++,u.accuracy!=null&&(V.avgAccuracy+=u.accuracy),u.context!=null&&(V.avgContext+=u.context),u.usability!=null&&(V.avgUsability+=u.usability),u.created_at&&u.updated_at){const te=new Date(u.created_at).getTime(),Ce=new Date(u.updated_at).getTime()-te;Ce>0&&(i[L]||(i[L]=[]),i[L].push(Ce))}}}),_.forEach(u=>{u.s_code&&!d.sources[u.s_code]&&(d.sources[u.s_code]=0)}),x.forEach(u=>{u.t_code&&!d.types[u.t_code]&&(d.types[u.t_code]=0)}),C.forEach(u=>{u.r_code&&!d.regions[u.r_code]&&(d.regions[u.r_code]=0)}),["GPT-4","Claude","Gemini","Llama","Other"].forEach(u=>{d.models[u]||(d.models[u]={count:0,avgAccuracy:0,avgContext:0,avgUsability:0,totalScore:0,deleteCount:0})}),Object.values(d.models).forEach(u=>{u.count>0&&(u.avgAccuracy=Math.round(u.avgAccuracy/u.count),u.avgContext=Math.round(u.avgContext/u.count),u.avgUsability=Math.round(u.avgUsability/u.count),u.totalScore=Math.round((u.avgAccuracy+u.avgContext+u.avgUsability)/3))});const F=l.filter(u=>u.generated&&u.edited);if(F.length>0){const L=[...F.map(oe=>A(oe.generated,oe.edited))].sort((oe,Ce)=>oe-Ce),V=Math.floor(L.length/2),te=L.length%2===0?(L[V-1]+L[V])/2:L[V];d.percentageModified=Math.round((1-te)*100)}const H={};l.forEach(u=>{if(u.model&&u.generated&&u.edited){const L=A(u.generated,u.edited),V=Math.round((1-L)*100);H[u.model]||(H[u.model]=[]),H[u.model].push(V)}}),d.modelPercentageData=H;try{const u=await fetch("/api/models");if(u.ok){const L=await u.json();if(L.models){L.models.forEach(te=>{d.models[te.m_code]&&(d.models[te.m_code].deleteCount=te.delete_count||0)});const V=L.models.reduce((te,oe)=>te+(oe.delete_count||0),0);d.totalDeleteCount=V,d.deleteRate=V>0?Math.round(V/(V+l.length)*100):0}}}catch(u){console.log("Could not fetch model delete counts:",u)}h(d)}catch{h(null)}finally{f(!1)}},[_,x,C,A]),ne=s.useCallback(async()=>{try{const[t,l,i,n]=await Promise.all([fetch("/api/sources"),fetch("/api/types"),fetch("/api/regions"),fetch("/api/models")]),o=await t.json(),d=await l.json(),P=await i.json(),F=await n.json();y(o),w(d),j(P),S(F.models||[])}catch(t){console.log("Could not fetch lookup data:",t)}},[]);s.useEffect(()=>{const t=m.get("view");(t==="crisis_maps"||t==="drone_images")&&b(t)},[m]),s.useEffect(()=>{ne()},[ne]),s.useEffect(()=>{_.length>0&&x.length>0&&C.length>0&&v.length>0&&X()},[_,x,C,v,X]);const Y=s.useCallback(t=>{const l=_.find(i=>i.s_code===t);return l?l.label:t},[_]),M=s.useCallback(t=>{if(t.length===0)return 0;const l=[...t].sort((n,o)=>n-o),i=Math.floor(l.length/2);return l.length%2===0?Math.round((l[i-1]+l[i])/2):l[i]},[]),ie=s.useCallback(t=>{const l=Math.floor(t/1e3),i=Math.floor(l/60),n=Math.floor(i/60);return n>0?`${n}h ${i%60}m`:i>0?`${i}m ${l%60}s`:`${l}s`},[]),_e=s.useCallback(t=>{const l=x.find(i=>i.t_code===t);return l?l.label:t},[x]),J=s.useCallback(t=>{const l=v.find(i=>i.m_code===t);return l?l.label:t},[v]),Se=s.useMemo(()=>a?Object.entries(a.modelEditTimes||{}).filter(([,t])=>t.length>0).sort(([,t],[,l])=>M(l)-M(t)).map(([t,l],i)=>({id:i+1,name:J(t),count:l.length,avgEditTime:M(l),minEditTime:Math.min(...l),maxEditTime:Math.max(...l)})):[],[a,M,J]),Me=s.useMemo(()=>a?Object.entries(a.modelPercentageData||{}).filter(([,t])=>t.length>0).sort(([,t],[,l])=>{const i=[...t].sort((H,u)=>H-u),n=[...l].sort((H,u)=>H-u),o=Math.floor(i.length/2),d=Math.floor(n.length/2),P=i.length%2===0?(i[o-1]+i[o])/2:i[o];return(n.length%2===0?(n[d-1]+n[d])/2:n[d])-P}).map(([t,l],i)=>{const n=[...l].sort((P,F)=>P-F),o=Math.floor(n.length/2),d=n.length%2===0?Math.round((n[o-1]+n[o])/2):n[o];return{id:i+1,name:J(t),count:l.length,avgPercentageModified:d,minPercentageModified:Math.min(...l),maxPercentageModified:Math.max(...l)}}):[],[a,J]),Ie=s.useMemo(()=>a?Object.entries(a.models).filter(([,t])=>t.count>0).map(([t,l],i)=>{const n=[l.avgAccuracy,l.avgContext,l.avgUsability],o=n.reduce((F,H)=>F+H,0)/n.length,d=n.reduce((F,H)=>F+Math.pow(H-o,2),0)/n.length,P=Math.round(100-Math.sqrt(d));return{id:i+1,name:J(t),consistency:Math.max(0,P),avgScore:Math.round(o),count:l.count}}).sort((t,l)=>l.consistency-t.consistency):[],[a,J]),De=s.useMemo(()=>[Q("name","Region",t=>t.name),D("count","Count",t=>t.count),D("percentage","% of Total",t=>t.percentage,{suffix:"%",maximumFractionDigits:0})],[]),Ee=s.useMemo(()=>[Q("name","Type",t=>t.name),D("count","Count",t=>t.count),D("percentage","% of Total",t=>t.percentage,{suffix:"%",maximumFractionDigits:0})],[]),lt=s.useMemo(()=>[Q("name","Source",t=>t.name),D("count","Count",t=>t.count),D("percentage","% of Total",t=>t.percentage,{suffix:"%",maximumFractionDigits:0})],[]),Te=s.useMemo(()=>[Q("name","Model",t=>t.name),D("count","Count",t=>t.count),D("accuracy","Accuracy",t=>t.accuracy,{suffix:"%",maximumFractionDigits:0}),D("context","Context",t=>t.context,{suffix:"%",maximumFractionDigits:0}),D("usability","Usability",t=>t.usability,{suffix:"%",maximumFractionDigits:0}),D("totalScore","Total Score",t=>t.totalScore,{suffix:"%",maximumFractionDigits:0})],[]),ke=s.useMemo(()=>[Q("name","Model",t=>t.name),D("count","Count",t=>t.count),Q("avgEditTime","Median Edit Time",t=>ie(t.avgEditTime)),Q("minEditTime","Min Edit Time",t=>ie(t.minEditTime)),Q("maxEditTime","Max Edit Time",t=>ie(t.maxEditTime))],[]),Le=s.useMemo(()=>[Q("name","Model",t=>t.name),D("count","Count",t=>t.count),D("avgPercentageModified","Median % Modified",t=>t.avgPercentageModified,{suffix:"%",maximumFractionDigits:0}),D("minPercentageModified","Min % Modified",t=>t.minPercentageModified,{suffix:"%",maximumFractionDigits:0}),D("maxPercentageModified","Max % Modified",t=>t.maxPercentageModified,{suffix:"%",maximumFractionDigits:0})],[]),Pe=s.useMemo(()=>[Q("name","Model",t=>t.name),D("count","Total Count",t=>t.count),D("deleteCount","Delete Count",t=>t.deleteCount),D("deleteRate","Delete Rate",t=>t.deleteRate,{suffix:"%",maximumFractionDigits:1})],[]),ct=s.useMemo(()=>[Q("source","Source",t=>t.source),D("avgQuality","Average Quality",t=>t.avgQuality,{suffix:"%",maximumFractionDigits:0}),D("count","Count",t=>t.count)],[]),Re=s.useMemo(()=>[Q("eventType","Event Type",t=>t.eventType),D("avgQuality","Average Quality",t=>t.avgQuality,{suffix:"%",maximumFractionDigits:0}),D("count","Count",t=>t.count)],[]),$e=s.useMemo(()=>[Q("name","Model",t=>t.name),D("consistency","Consistency",t=>t.consistency,{suffix:"%",maximumFractionDigits:0}),D("avgScore","Average Score",t=>t.avgScore,{suffix:"%",maximumFractionDigits:0}),D("count","Count",t=>t.count)],[]),ue=s.useCallback(t=>a?t==="crisis_map"?a.crisisMaps.length:t==="drone_image"?a.droneImages.length:0:0,[a]),Be=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.countries&&n.countries.forEach(o=>{o.r_code&&(i[o.r_code]=(i[o.r_code]||0)+1)})}),Object.entries(i).filter(([,n])=>n>0).map(([n,o])=>({name:C.find(d=>d.r_code===n)?.label||n,value:o}))},[a,C]),Ae=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};l.forEach(o=>{o.countries&&o.countries.forEach(d=>{d.r_code&&(i[d.r_code]=(i[d.r_code]||0)+1)})});const n=C.reduce((o,d)=>(d.r_code&&(o[d.r_code]={name:d.label,count:i[d.r_code]||0}),o),{});return Object.entries(n).sort(([,o],[,d])=>d.count-o.count).map(([,{name:o,count:d}],P)=>({id:P+1,name:o,count:d,percentage:l.length>0?Math.round(d/l.length*100):0}))},[a,C]),dt=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.source&&(i[n.source]=(i[n.source]||0)+1)}),Object.entries(i).filter(([,n])=>n>0).map(([n,o])=>({name:_.find(d=>d.s_code===n)?.label||n,value:o}))},[a,_]),ut=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.source&&(i[n.source]=(i[n.source]||0)+1)}),Object.entries(i).sort(([,n],[,o])=>o-n).map(([n,o],d)=>({id:d+1,name:Y(n),count:o,percentage:l.length>0?Math.round(o/l.length*100):0}))},[a,Y]),Fe=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.event_type&&(i[n.event_type]=(i[n.event_type]||0)+1)}),Object.entries(i).filter(([,n])=>n>0).map(([n,o])=>({name:x.find(d=>d.t_code===n)?.label||n,value:o}))},[a,x]),Oe=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.event_type&&(i[n.event_type]=(i[n.event_type]||0)+1)}),Object.entries(i).sort(([,n],[,o])=>o-n).map(([n,o],d)=>({id:d+1,name:_e(n),count:o,percentage:l.length>0?Math.round(o/l.length*100):0}))},[a,_e]),He=s.useCallback(t=>{if(!a)return"No data available";const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i=new Set;l.forEach(d=>{d.model&&i.add(d.model)}),console.log(`Debug ${t}:`,{totalImages:l.length,usedModels:Array.from(i),availableEditTimes:Object.keys(a.modelEditTimes),modelEditTimesData:a.modelEditTimes});const o=Object.entries(a.modelEditTimes).filter(([d])=>i.has(d)).flatMap(([,d])=>d);return o.length===0?"No data available":ie(M(o))},[a,ie,M]),Ve=s.useCallback(()=>{if(!a)return"No data available";const t=a.totalCaptions||0,l=a.percentageModified||0;return t>0?Math.round(l/t*100):0},[a]),ze=s.useCallback(()=>a&&a.deleteRate>=0?`${a.deleteRate}%`:"No data available",[a]),Ue=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i=new Set;return l.forEach(o=>{o.model&&i.add(o.model)}),Se.filter(o=>{const d=v.find(P=>P.label===o.name)?.m_code;return d&&i.has(d)})},[a,Se,v]),We=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i=new Set;return l.forEach(o=>{o.model&&i.add(o.model)}),Me.filter(o=>{const d=v.find(P=>P.label===o.name)?.m_code;return d&&i.has(d)})},[a,Me,v]),Qe=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.model&&(i[n.model]||(i[n.model]={count:0,deleteCount:0}),i[n.model].count++)}),Object.entries(i).map(([n,o],d)=>{const F=a.models?.[n]?.deleteCount||0,H=o.count>0?Math.round(F/o.count*100*10)/10:0;return{id:d+1,name:J(n),count:o.count,deleteCount:F,deleteRate:H}}).sort((n,o)=>o.count-n.count)},[a,J]),Ze=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.model&&(i[n.model]||(i[n.model]={count:0,totalAccuracy:0,totalContext:0,totalUsability:0}),i[n.model].count++,n.accuracy!=null&&(i[n.model].totalAccuracy+=n.accuracy),n.context!=null&&(i[n.model].totalContext+=n.context),n.usability!=null&&(i[n.model].totalUsability+=n.usability))}),Object.entries(i).map(([n,o],d)=>({id:d+1,name:J(n),count:o.count,accuracy:o.count>0?Math.round(o.totalAccuracy/o.count):0,context:o.count>0?Math.round(o.totalContext/o.count):0,usability:o.count>0?Math.round(o.totalUsability/o.count):0,totalScore:o.count>0?Math.round((o.totalAccuracy+o.totalContext+o.totalUsability)/(3*o.count)):0})).sort((n,o)=>o.totalScore-n.totalScore)},[a,J]),mt=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.source&&(i[n.source]||(i[n.source]={total:0,count:0,totalImages:0}),i[n.source].totalImages+=1,n.accuracy!=null&&(i[n.source].total+=n.accuracy,i[n.source].count+=1))}),Object.entries(i).map(([n,o],d)=>({id:d+1,source:Y(n),avgQuality:o.count>0?Math.round(o.total/o.count):0,count:o.totalImages}))},[a,Y]),qe=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.event_type&&(i[n.event_type]||(i[n.event_type]={total:0,count:0,totalImages:0}),i[n.event_type].totalImages+=1,n.accuracy!=null&&(i[n.event_type].total+=n.accuracy,i[n.event_type].count+=1))}),Object.entries(i).map(([n,o],d)=>({id:d+1,eventType:_e(n),avgQuality:o.count>0?Math.round(o.total/o.count):0,count:o.totalImages}))},[a,_e]),Ge=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i=new Set;return l.forEach(o=>{o.model&&i.add(o.model)}),Ie.filter(o=>{const d=v.find(P=>P.label===o.name)?.m_code;return d&&i.has(d)})},[a,Ie,v]);if(r)return e.jsx(je,{children:e.jsx("div",{className:c.loadingContainer,children:e.jsx(Et,{})})});if(!a)return e.jsx(je,{children:e.jsx("div",{className:c.errorContainer,children:e.jsx("div",{className:"text-red-500",children:"Failed to load analytics data. Please try again."})})});const me=["#F5333F","#F64752","#F75C65","#F87079","#F9858C","#FA999F","#FBADB2","#FCC2C5"];return e.jsx(je,{children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsx("div",{className:c.tabSelector,children:e.jsx(Tt,{name:"analytics-view",value:g,onChange:t=>{(t==="crisis_maps"||t==="drone_images")&&b(t)},options:O,keySelector:t=>t.key,labelSelector:t=>t.label})}),g==="crisis_maps"?e.jsxs("div",{className:c.chartGrid,children:[e.jsxs(z,{heading:"Summary Statistics",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.summaryStatsCards,children:[e.jsxs("div",{className:c.summaryStatsCard,children:[e.jsx("div",{className:c.summaryStatsCardValue,children:ue("crisis_map")}),e.jsx("div",{className:c.summaryStatsCardLabel,children:"Total Crisis Maps"})]}),e.jsxs("div",{className:c.summaryStatsCard,children:[e.jsx("div",{className:c.summaryStatsCardValue,children:"2000"}),e.jsx("div",{className:c.summaryStatsCardLabel,children:"Target Amount"})]})]}),e.jsxs("div",{className:c.progressSection,children:[e.jsxs("div",{className:c.progressLabel,children:[e.jsx("span",{children:"Progress towards target"}),e.jsxs("span",{children:[Math.round(ue("crisis_map")/2e3*100),"%"]})]}),e.jsx(Ye,{value:ue("crisis_map"),totalValue:2e3})]})]}),e.jsxs(z,{heading:"Distribution Analysis",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.userInteractionCards,children:[e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardLabel,children:"Regions Distribution"}),e.jsx("div",{className:c.chartContainer,children:e.jsx(xe,{data:Be("crisis_map"),valueSelector:t=>t.value,labelSelector:t=>t.name,keySelector:t=>t.name,colors:me,showPercentageInLegend:!0})}),e.jsx(Z,{name:"view-regions-details",variant:U?"primary":"secondary",onClick:()=>E(U?"none":"regions"),className:c.userInteractionCardButton,children:U?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardLabel,children:"Sources Distribution"}),e.jsx("div",{className:c.chartContainer,children:e.jsx(xe,{data:dt("crisis_map"),valueSelector:t=>t.value,labelSelector:t=>t.name,keySelector:t=>t.name,colors:me,showPercentageInLegend:!0})}),e.jsx(Z,{name:"view-sources-details",variant:ae?"primary":"secondary",onClick:()=>E(ae?"none":"sources"),className:c.userInteractionCardButton,children:ae?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardLabel,children:"Types Distribution"}),e.jsx("div",{className:c.chartContainer,children:e.jsx(xe,{data:Fe("crisis_map"),valueSelector:t=>t.value,labelSelector:t=>t.name,keySelector:t=>t.name,colors:me,showPercentageInLegend:!0})}),e.jsx(Z,{name:"view-types-details",variant:K?"primary":"secondary",onClick:()=>E(K?"none":"types"),className:c.userInteractionCardButton,children:K?"Hide Details":"View Details"})]})]}),U&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ae("crisis_map"),columns:De,keySelector:$,filtered:!1,pending:!1})}),ae&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:ut("crisis_map"),columns:lt,keySelector:$,filtered:!1,pending:!1})}),K&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Oe("crisis_map"),columns:Ee,keySelector:$,filtered:!1,pending:!1})})]}),e.jsxs(z,{heading:"User Interaction Statistics",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.userInteractionCards,children:[e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:He("crisis_map")}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Median Edit Time"}),e.jsx(Z,{name:"view-edit-time-details",variant:p?"primary":"secondary",onClick:()=>E(p?"none":"editTime"),className:c.userInteractionCardButton,children:p?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:Ve()}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Median % Modified"}),e.jsx(Z,{name:"view-percentage-details",variant:I?"primary":"secondary",onClick:()=>E(I?"none":"percentage"),className:c.userInteractionCardButton,children:I?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:ze()}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Delete Rate"}),e.jsx(Z,{name:"view-delete-details",variant:T?"primary":"secondary",onClick:()=>E(T?"none":"delete"),className:c.userInteractionCardButton,children:T?"Hide Details":"View Details"})]})]}),p&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ue("crisis_map"),columns:ke,keySelector:$,filtered:!1,pending:!1})}),I&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:We("crisis_map"),columns:Le,keySelector:$,filtered:!1,pending:!1})}),T&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Qe("crisis_map"),columns:Pe,keySelector:$,filtered:!1,pending:!1})})]}),e.jsx(z,{heading:"Model Performance",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ze("crisis_map"),columns:Te,keySelector:$,filtered:!1,pending:!1})})}),e.jsx(z,{heading:"Quality-Source Correlation",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.tableContainer,children:e.jsx(B,{data:mt("crisis_map"),columns:ct,keySelector:$,filtered:!1,pending:!1})})}),e.jsx(z,{heading:"Quality-Event Type Correlation",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.tableContainer,children:e.jsx(B,{data:qe("crisis_map"),columns:Re,keySelector:$,filtered:!1,pending:!1})})}),e.jsx(z,{heading:"Model Consistency Analysis",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.tableContainer,children:e.jsx(B,{data:Ge("crisis_map"),columns:$e,keySelector:$,filtered:!1,pending:!1})})})]}):e.jsxs("div",{className:c.chartGrid,children:[e.jsxs(z,{heading:"Summary Statistics",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.summaryStatsCards,children:[e.jsxs("div",{className:c.summaryStatsCard,children:[e.jsx("div",{className:c.summaryStatsCardValue,children:ue("drone_image")}),e.jsx("div",{className:c.summaryStatsCardLabel,children:"Total Drone Images"})]}),e.jsxs("div",{className:c.summaryStatsCard,children:[e.jsx("div",{className:c.summaryStatsCardValue,children:"2000"}),e.jsx("div",{className:c.summaryStatsCardLabel,children:"Target Amount"})]})]}),e.jsxs("div",{className:c.progressSection,children:[e.jsxs("div",{className:c.progressLabel,children:[e.jsx("span",{children:"Progress towards target"}),e.jsxs("span",{children:[Math.round(ue("drone_image")/2e3*100),"%"]})]}),e.jsx(Ye,{value:ue("drone_image"),totalValue:2e3})]})]}),e.jsxs(z,{heading:"Distribution Analysis",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.userInteractionCards,children:[e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardLabel,children:"Regions Distribution"}),e.jsx("div",{className:c.chartContainer,children:e.jsx(xe,{data:Be("drone_image"),valueSelector:t=>t.value,labelSelector:t=>t.name,keySelector:t=>t.name,colors:me,showPercentageInLegend:!0})}),e.jsx(Z,{name:"view-regions-details",variant:U?"primary":"secondary",onClick:()=>E(U?"none":"regions"),className:c.userInteractionCardButton,children:U?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardLabel,children:"Types Distribution"}),e.jsx("div",{className:c.chartContainer,children:e.jsx(xe,{data:Fe("drone_image"),valueSelector:t=>t.value,labelSelector:t=>t.name,keySelector:t=>t.name,colors:me,showPercentageInLegend:!0})}),e.jsx(Z,{name:"view-types-details",variant:K?"primary":"secondary",onClick:()=>E(K?"none":"types"),className:c.userInteractionCardButton,children:K?"Hide Details":"View Details"})]})]}),U&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ae("drone_image"),columns:De,keySelector:$,filtered:!1,pending:!1})}),K&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Oe("drone_image"),columns:Ee,keySelector:$,filtered:!1,pending:!1})})]}),e.jsxs(z,{heading:"User Interaction Statistics",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.userInteractionCards,children:[e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:He("drone_image")}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Median Edit Time"}),e.jsx(Z,{name:"view-edit-time-details",variant:p?"primary":"secondary",onClick:()=>E(p?"none":"editTime"),className:c.userInteractionCardButton,children:p?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:Ve()}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Median % Modified"}),e.jsx(Z,{name:"view-percentage-details",variant:I?"primary":"secondary",onClick:()=>E(I?"none":"percentage"),className:c.userInteractionCardButton,children:I?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:ze()}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Delete Rate"}),e.jsx(Z,{name:"view-delete-details",variant:T?"primary":"secondary",onClick:()=>E(T?"none":"delete"),className:c.userInteractionCardButton,children:T?"Hide Details":"View Details"})]})]}),p&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ue("drone_image"),columns:ke,keySelector:$,filtered:!1,pending:!1})}),I&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:We("drone_image"),columns:Le,keySelector:$,filtered:!1,pending:!1})}),T&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Qe("drone_image"),columns:Pe,keySelector:$,filtered:!1,pending:!1})})]}),e.jsx(z,{heading:"Model Performance",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ze("drone_image"),columns:Te,keySelector:$,filtered:!1,pending:!1})})}),e.jsx(z,{heading:"Quality-Event Type Correlation",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.tableContainer,children:e.jsx(B,{data:qe("drone_image"),columns:Re,keySelector:$,filtered:!1,pending:!1})})}),e.jsx(z,{heading:"Model Consistency Analysis",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.tableContainer,children:e.jsx(B,{data:Ge("drone_image"),columns:$e,keySelector:$,filtered:!1,pending:!1})})})]})]})})}export{jn as default};
 
1
+ import{r as s,y as nt,t as ht,a as q,c as gt,j as e,o as N,b as se,R as st,z,g as rt,d as ft,m as vt,e as pt,n as Z,A as xt,f as _t,h as Ct,i as yt,k as he,l as bt,p as ye,q as jt,s as Nt,E as wt,C as St,U as Mt,Q as It,u as Dt,N as je,_ as Et,L as Tt}from"./index-RA4UIF3R.js";const kt=({title:m,titleId:a,...h})=>s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":a},h),m?s.createElement("title",{id:a},m):null,s.createElement("g",{clipPath:"url(#arrow-drop-down-line_svg__a)"},s.createElement("path",{d:"m12 15-4.243-4.243 1.415-1.414L12 12.172l2.828-2.83 1.415 1.415L12 15Z"})),s.createElement("defs",null,s.createElement("clipPath",{id:"arrow-drop-down-line_svg__a"},s.createElement("path",{d:"M0 0h24v24H0z"})))),Lt=({title:m,titleId:a,...h})=>s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":a},h),m?s.createElement("title",{id:a},m):null,s.createElement("g",{clipPath:"url(#arrow-drop-up-line_svg__a)"},s.createElement("path",{d:"m12 11.828-2.828 2.829-1.415-1.414L12 9l4.243 4.243-1.415 1.414L12 11.828Z"})),s.createElement("defs",null,s.createElement("clipPath",{id:"arrow-drop-up-line_svg__a"},s.createElement("path",{d:"M0 0h24v24H0z"})))),Pt=({title:m,titleId:a,...h})=>s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":a},h),m?s.createElement("title",{id:a},m):null,s.createElement("g",{clipPath:"url(#information-line_svg__a)"},s.createElement("path",{d:"M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10Zm0-2a8 8 0 1 0 0-16.001A8 8 0 0 0 12 20ZM11 7h2v2h-2V7Zm0 4h2v6h-2v-6Z"})),s.createElement("defs",null,s.createElement("clipPath",{id:"information-line_svg__a"},s.createElement("path",{d:"M0 0h24v24H0z"})))),Rt=({title:m,titleId:a,...h})=>s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"1em",height:"1em","aria-labelledby":a},h),m?s.createElement("title",{id:a},m):null,s.createElement("path",{fillRule:"evenodd",d:"m15.063 12 .937.938-4 4-4-4L8.938 12 12 15.063 15.063 12Z",clipRule:"evenodd"}),s.createElement("mask",{id:"table-sorting-line_svg__a",width:8,height:5,x:8,y:12,maskUnits:"userSpaceOnUse",style:{maskType:"luminance"}},s.createElement("path",{fillRule:"evenodd",d:"m15.063 12 .937.938-4 4-4-4L8.938 12 12 15.063 15.063 12Z",clipRule:"evenodd"})),s.createElement("g",{mask:"url(#table-sorting-line_svg__a)"},s.createElement("path",{d:"M-24-22h72v72h-72z"})),s.createElement("path",{fillRule:"evenodd",d:"M8.938 11 8 10.062l4-4 4 4-.938.938L12 7.937 8.937 11Z",clipRule:"evenodd"}),s.createElement("mask",{id:"table-sorting-line_svg__b",width:8,height:5,x:8,y:6,maskUnits:"userSpaceOnUse",style:{maskType:"luminance"}},s.createElement("path",{fillRule:"evenodd",d:"M8.938 11 8 10.062l4-4 4 4-.938.938L12 7.937 8.937 11Z",clipRule:"evenodd"})),s.createElement("g",{mask:"url(#table-sorting-line_svg__b)"},s.createElement("path",{d:"M48 45h-72v-72h72z"}))),$t="_number-output_1blvi_1",Bt={numberOutput:$t};function we(m){const{className:a,invalidText:h=nt,separatorHidden:r,compact:f,currency:g,value:b,tooltip:_,unit:y,prefix:x,suffix:w,maximumFractionDigits:C=1}=m,{currentLanguage:j}=s.useContext(ht),v=s.useMemo(()=>{if(q(b))return h;const S=gt(b,{currency:g,compact:f,separatorHidden:r,maximumFractionDigits:C,unit:y,language:j});return e.jsxs(e.Fragment,{children:[x,S,w]})},[h,b,f,r,g,y,C,x,j,w]);return e.jsx("div",{className:N(Bt.numberOutput,a),title:se(_)?String(_):void 0,children:v})}const At="_tooltip-dummy_rbf3f_1",Ft="_tooltip-content_rbf3f_7",Ot="_pointer_rbf3f_14",Ne={tooltipDummy:At,tooltipContent:Ft,pointer:Ot};function Ht(m){const{className:a,title:h,description:r,preferredWidth:f}=m,[g,b]=s.useState(!1),[_,y]=s.useState(!1),x=s.useRef(),w=s.useRef(null);return s.useEffect(()=>{const C=()=>{y(!0)},j=()=>{y(!1)};if(q(w.current))return;const{current:{parentNode:v}}=w;if(!q(v))return x.current=v,v.addEventListener("mouseover",C),v.addEventListener("mouseout",j),b(!0),()=>{v.removeEventListener("mouseover",C),v.removeEventListener("mouseout",j)}},[]),e.jsxs(e.Fragment,{children:[!g&&e.jsx("div",{className:Ne.tooltipDummy,ref:w}),_&&e.jsx(st,{className:N(Ne.tooltipContent,a),parentRef:x,pointerClassName:Ne.pointer,preferredWidth:f,children:e.jsx(z,{heading:h,withInternalPadding:!0,contentViewType:"vertical",children:r})})]})}function $(m){return m.id}const Vt="common",zt={booleanYesLabel:"Yes",booleanNoLabel:"No"},Ut={namespace:Vt,strings:zt},Wt="_boolean-output_kg1uq_1",Qt={booleanOutput:Wt};function Zt(m){const{className:a,invalidText:h,value:r}=m,f=rt(Ut);let g;return r===!0?g=f.booleanYesLabel:r===!1?g=f.booleanNoLabel:g=h,e.jsx("div",{className:N(Qt.booleanOutput,a),children:g})}const qt="_date-output_4jzjo_1",Gt={dateOutput:qt};function Yt(m){const{value:a,format:h,className:r,invalidText:f}=m,g=s.useMemo(()=>ft(a,h),[a,h]);return e.jsx("div",{className:N(Gt.dateOutput,r),children:g??f})}const Kt="_dropdown-menu_16hml_1",Xt="_icons_16hml_4",Jt="_content_16hml_5",ea="_actions_16hml_6",ta="_dropdown-icon_16hml_10",aa="_dropdown-content_16hml_16",le={dropdownMenu:Kt,icons:Xt,content:Jt,actions:ea,dropdownIcon:ta,dropdownContent:aa};function na(m){const a=s.useRef(null),{className:h,popupClassName:r,children:f,label:g,activeClassName:b,icons:_,variant:y="secondary",actions:x,withoutDropdownIcon:w,componentRef:C,elementRef:j=a,persistent:v,preferredPopupWidth:S}=m,p=s.useRef(null),[k,I]=s.useState(!1);s.useEffect(()=>{C&&(C.current={setShowDropdown:I})},[C,I]);const R=s.useCallback(()=>{I(re=>!re)},[I]),T=s.useCallback((re,ae)=>{ae||re&&v||I(!1)},[I,v]);vt(k,T,p,j);const G=s.useMemo(()=>({setShowDropdown:I}),[I]),U=!!x||!w;return e.jsxs(pt.Provider,{value:G,children:[e.jsx(Z,{name:void 0,className:N(le.dropdownMenu,k&&b,h),elementRef:j,onClick:R,variant:y,actionsContainerClassName:le.actions,iconsContainerClassName:le.icons,childrenContainerClassName:le.content,actions:U?e.jsxs(e.Fragment,{children:[x,!w&&(k?e.jsx(xt,{className:le.dropdownIcon}):e.jsx(_t,{className:le.dropdownIcon}))]}):void 0,icons:_,children:g}),k&&e.jsx(st,{elementRef:p,className:N(le.dropdownContent,r),parentRef:j,preferredWidth:S,children:f})]})}const sa="_info-popup_i3rna_1",ra="_label_i3rna_2",ia="_icon_i3rna_7",oa="_dropdown-container_i3rna_15",la="_content_i3rna_20",ge={infoPopup:sa,label:ra,icon:ia,dropdownContainer:oa,content:la};function ca(m){const{className:a,icon:h=e.jsx(Pt,{}),infoLabel:r,title:f,description:g,withoutIcon:b,popupClassName:_,descriptionClassName:y}=m;return e.jsx(na,{label:e.jsxs("div",{className:ge.label,children:[r,!b&&h&&e.jsx("div",{className:ge.icon,children:h})]}),popupClassName:N(ge.dropdownContainer,_),className:N(ge.infoPopup,a),variant:"tertiary",withoutDropdownIcon:!0,children:e.jsx(z,{heading:f,childrenContainerClassName:N(y,ge.content),withInternalPadding:!0,children:g})})}const da="_progress-wrapper_x340w_1",ua="_title_x340w_7",ma="_total_x340w_11",ha="_progress_x340w_1",fe={progressWrapper:da,title:ua,total:ma,progress:ha};function Ye(m){const{className:a,title:h,description:r,totalValue:f,value:g,showPercentageInTitle:b,children:_,color:y="var(--go-ui-color-primary-red)"}=m,x=se(g)?g:0,w=se(f)?f:0;let C;return w===0?C=0:C=x/w*100,e.jsxs("div",{className:N(fe.progressWrapper,a),children:[(h||b)&&e.jsxs("div",{className:fe.title,children:[h,b&&e.jsx(we,{value:C,suffix:"%"})]}),e.jsx("div",{className:fe.total,children:e.jsx("div",{className:fe.progress,style:{width:`${C}%`,backgroundColor:y}})}),r&&e.jsx("div",{className:fe.description,children:r}),_]})}const ga="_legend-element_1a9ic_1",fa="_color_1a9ic_7",va="_icon-container_1a9ic_14",pa="_icon_1a9ic_14",xa="_label_1a9ic_31",ve={legendElement:ga,color:fa,iconContainer:va,icon:pa,label:xa};function _a(m){const{className:a,colorClassName:h,iconClassName:r,color:f,label:g,iconSrc:b}=m;return e.jsxs("div",{className:N(ve.legendElement,a),children:[b?e.jsx("div",{style:{backgroundColor:f},className:ve.iconContainer,children:e.jsx("img",{className:N(ve.icon,r),src:b,alt:""})}):e.jsx("div",{style:{backgroundColor:f},className:N(ve.color,h)}),e.jsx("div",{className:ve.label,children:g})]})}const Ca="_text-output_10oza_1",ya="_with-background_10oza_6",ba="_label_10oza_11",ja="_with-colon_10oza_12",Na="_value_10oza_17",wa="_text-type_10oza_18",Sa="_strong_10oza_24",ee={textOutput:Ca,withBackground:ya,label:ba,withColon:ja,value:Na,textType:wa,strong:Sa};function Ke(m){const{className:a,label:h,icon:r,description:f,labelClassName:g,descriptionClassName:b,valueClassName:_,strongLabel:y,strongValue:x,strongDescription:w,withoutLabelColon:C,withBackground:j,invalidText:v=nt,...S}=m,{value:p}=m;let k=v;return S.valueType==="number"?k=e.jsx(we,{...S,invalidText:v}):S.valueType==="date"?k=e.jsx(Yt,{...S,invalidText:v}):S.valueType==="boolean"?k=e.jsx(Zt,{...S,invalidText:v}):p instanceof Date||(k=p||v),e.jsxs("div",{className:N(ee.textOutput,j&&ee.withBackground,a),children:[r,h&&e.jsx("div",{className:N(ee.label,y&&ee.strong,g,!C&&ee.withColon),children:h}),e.jsx("div",{className:N(ee.value,x&&ee.strong,S.valueType==="text"&&ee.textType,_),children:k}),f&&e.jsx("div",{className:N(ee.description,w&&ee.strong,b),children:f})]})}const Ma="_pie-chart_pyr7m_1",Ia="_legend_pyr7m_7",Da="_legend-item_pyr7m_13",pe={pieChart:Ma,legend:Ia,legendItem:Da},Ea=70,Ta=40;function Xe(m,a=1){return Math.round(m*10**a)/10**a}function Je(m,a){const h=(a-90)*Math.PI/180;return{x:Xe(m+m*Math.cos(h)),y:Xe(m+m*Math.sin(h))}}function ka(m,a,h){let r=h;const f=r-a===360;f&&(r-=1);const g=Je(m,a),b=Je(m,r),_=r-a<=180?0:1,y=["M",g.x,g.y,"A",m,m,0,_,1,b.x,b.y];return f?y.push("Z"):y.push("L",m,m,"L",g.x,g.y,"Z"),y.join(" ")}function xe(m){const{className:a,data:h,valueSelector:r,labelSelector:f,keySelector:g,colorSelector:b,colors:_,pieRadius:y=Ea,chartPadding:x=Ta,legendClassName:w,showPercentageInLegend:C}=m,j=Ct(h?.map(p=>r(p))),v=q(j)||j===0?1:j,S=s.useMemo(()=>{let p=0;const k=h?.map(I=>{const R=r(I);if(q(R))return;const T=360*(R/v);return p+=T,{key:g(I),value:R,label:f(I),startAngle:p-T,percentage:yt(R,v),endAngle:p,datum:I}}).filter(se)??[];return b?k.map(({datum:I,...R})=>({...R,color:b(I)})):k.map(({datum:I,...R},T)=>({...R,color:_[T%_.length]}))},[h,g,r,f,v,b,_]);return e.jsxs("div",{className:N(pe.pieChart,a),children:[e.jsx("svg",{className:pe.svg,style:{width:`${x+y*2}px`,height:`${x+y*2}px`},children:e.jsx("g",{style:{transform:`translate(${x/2}px, ${x/2}px)`},children:S.map(p=>e.jsx("path",{className:pe.path,d:ka(y,p.startAngle,p.endAngle),fill:p.color,children:e.jsx(Ht,{description:e.jsx(Ke,{label:p.label,value:p.value})})},p.key))})}),e.jsx("div",{className:N(pe.legend,w),children:S.map(p=>e.jsx(_a,{className:pe.legendItem,label:C?e.jsx(Ke,{label:p.label,value:p.percentage,valueType:"number",prefix:"(",suffix:"%)",withoutLabelColon:!0}):p.label,color:p.color},p.key))})]})}const La="_td_1k4cn_1",Pa={td:La};function Ra(m){const{className:a,children:h,...r}=m;return e.jsx("td",{className:N(a,Pa.td),...r,children:h})}function it(m){const{className:a,children:h,...r}=m;return e.jsx("tr",{className:a,...r,children:h})}const $a="_row_1829z_1",Ba="_cell_1829z_2",et={row:$a,cell:Ba};function Aa(m){const{data:a,keySelector:h,columns:r,rowClassName:f,cellClassName:g,rowModifier:b}=m;return e.jsx(e.Fragment,{children:a?.map((_,y)=>{const x=h(_,y),w=r.map(v=>{const{id:S,cellRenderer:p,cellRendererClassName:k,cellRendererParams:I,cellContainerClassName:R}=v,T=I(x,_,y,a),G=e.jsx(p,{className:k,...T,name:S});return e.jsx(Ra,{className:N(et.cell,R,typeof g=="function"?g(x,_,S):g),children:G},S)}),C=e.jsx(it,{className:N(et.row,typeof f=="function"?f(x,_):f),children:w});let j=C;return b&&(j=b({rowKey:x,row:C,cells:w,columns:r,datum:_})),e.jsx(s.Fragment,{children:j},x)})})}const Fa="_th_cdv41_1",Oa="_resize-handle_cdv41_8",tt={th:Fa,resizeHandle:Oa};function Ha(m){const{className:a,children:h,onResize:r,onResizeComplete:f,name:g,...b}=m,_=s.useRef(null),y=s.useRef(),x=s.useRef(),w=s.useRef(),C=s.useCallback(v=>{var S;if(se(y.current)&&_.current&&r){v.preventDefault(),v.stopPropagation();const p=v.clientX-y.current;if(se(x.current)){const k=x.current+p;w.current=k,r(k,g)}else x.current=(S=_.current)==null?void 0:S.offsetWidth}},[r,g]),j=s.useCallback(v=>{var S;v.preventDefault(),y.current=v.clientX,x.current=(S=_.current)==null?void 0:S.offsetWidth,window.addEventListener("mousemove",C,!0)},[C]);return s.useEffect(()=>{const v=()=>{y.current=void 0,x.current=void 0,f&&se(w.current)&&f(w.current,g),window.removeEventListener("mousemove",C,!0)};return window.addEventListener("mouseup",v,!0),()=>{window.removeEventListener("mouseup",v,!0),window.removeEventListener("mousemove",C,!0)}},[C,g,f]),e.jsxs("th",{ref:_,className:N(a,tt.th),...b,children:[r&&e.jsx("div",{role:"presentation",className:tt.resizeHandle,onMouseDown:j}),h]})}const Va="_table_nilhy_1",za="_table-overflow-wrapper_nilhy_8",Ua="_table-element_nilhy_13",Wa="_header-row_nilhy_23",Qa="_header-element_nilhy_24",Za="_header-component_nilhy_29",ce={table:Va,tableOverflowWrapper:za,tableElement:Ua,headerRow:Wa,headerElement:Qa,headerComponent:Za};function qa(m,a){return a??m.columnWidth??wt}function B(m){const{data:a,keySelector:h,columns:r,caption:f,className:g,captionClassName:b,headerRowClassName:_,headerCellClassName:y,rowClassName:x,cellClassName:w,rowModifier:C,fixedColumnWidth:j,resizableColumn:v,headersHidden:S,pending:p,filtered:k,errored:I=!1}=m,R=s.useRef(null),[T]=he.useState(()=>bt()),[G,U]=he.useState({});s.useEffect(()=>{U(W=>{if(q(R.current))return W;const E=R.current.getBoundingClientRect(),{width:O}=E;let A=r.map(M=>({id:M.id,stretch:!!M.columnStretch,width:qa(M,W[M.id])}));const X=ye(A.filter(M=>M.stretch).map(M=>M.width)),ne=ye(A.filter(M=>!M.stretch).map(M=>M.width)),Y=(O-ne)/X;return Y>1&&(A=A.map(M=>({...M,width:M.stretch?M.width*Y:M.width}))),jt(A,M=>M.id,M=>M.width)})},[r]);const re=he.useCallback((W,E)=>{const O=document.getElementById(`${T}-${E}`),A=Math.max(W,80);if(q(O)||(O.style.width=`${A}px`,!j))return;const X=document.getElementById(T);if(q(X))return;const ne=ye(r.map(Y=>Y.id===E?A:G[Y.id]));X.style.width=`${ne}px`},[T,G,r,j]),ae=he.useCallback((W,E)=>{se(E)&&U(O=>({...O,[E]:Math.max(W,80)}))},[U]),be=he.useMemo(()=>ye(r.map(W=>G[W.id])),[G,r]),K=q(a)||a.length===0||Object.keys(G).length===0;return e.jsxs("div",{ref:R,className:N(ce.table,g),children:[!K&&e.jsx("div",{className:ce.tableOverflowWrapper,children:e.jsxs("table",{className:ce.tableElement,style:j?{width:`${be}px`}:void 0,id:T,children:[f&&e.jsx("caption",{className:b,children:f}),e.jsx("colgroup",{children:r.map(W=>{const{id:E,columnClassName:O}=W,A=G[E],X=j?{width:`${A}px`}:void 0;return e.jsx("col",{id:`${T}-${E}`,style:X,className:N(ce.column,O)},E)})}),!S&&e.jsx("thead",{children:e.jsx(it,{className:N(ce.headerRow,_),children:r.map((W,E)=>{const{id:O,title:A,headerCellRenderer:X,headerCellRendererClassName:ne,headerCellRendererParams:Y,headerContainerClassName:M}=W,ie=e.jsx(X,{...Y,name:O,title:A,index:E,className:N(ne,ce.headerComponent)});return e.jsx(Ha,{scope:"col",name:O,onResize:v?re:void 0,onResizeComplete:v?ae:void 0,className:N(ce.headerElement,typeof y=="function"?y(O):y,M),children:ie},O)})})}),e.jsx("tbody",{children:e.jsx(Aa,{data:a,keySelector:h,columns:r,rowClassName:x,cellClassName:w,rowModifier:C})})]})}),e.jsx(Nt,{filtered:k,empty:K,errored:I,pending:p,overlayPending:!0})]})}function Ga(m){const{className:a,value:h}=m;return q(h)?null:e.jsx("div",{className:a,children:h})}const Ya="common",Ka={sortTableButtonTitle:"Sort Table"},Xa={namespace:Ya,strings:Ka},Ja="_header-cell_vn24d_1",en="_sort-button_vn24d_8",tn="_icon_vn24d_12",an="_info-popup-icon_vn24d_17",de={headerCell:Ja,sortButton:en,icon:tn,infoPopupIcon:an};function ot(m){const{className:a,titleClassName:h,title:r,name:f,sortable:g,defaultSortDirection:b="asc",infoTitle:_,infoDescription:y}=m,{sorting:x,setSorting:w}=s.useContext(St),C=rt(Xa),j=x?.name===f?x.direction:void 0,v=s.useRef(null),S=s.useCallback(()=>{if(q(w))return;let p;q(j)?p=b:j==="asc"?p="dsc":j==="dsc"&&(p="asc"),w(p?{name:f,direction:p}:void 0)},[f,w,j,b]);return e.jsxs("div",{ref:v,className:N(a,de.headerCell),children:[g&&e.jsxs(Z,{name:void 0,variant:"tertiary",onClick:S,title:C.sortTableButtonTitle,className:de.sortButton,children:[q(j)&&e.jsx(Rt,{className:de.icon}),j==="asc"&&e.jsx(Lt,{className:de.icon}),j==="dsc"&&e.jsx(kt,{className:de.icon})]}),e.jsx("div",{className:N(h,de.title),children:r}),_&&y&&e.jsx(ca,{className:de.infoPopupIcon,title:_,description:y})]})}const at={};function Q(m,a,h,r){return{id:m,title:a,columnClassName:r?.columnClassName,headerCellRenderer:ot,headerCellRendererClassName:r?.headerCellRendererClassName,headerContainerClassName:r?.headerContainerClassName,headerCellRendererParams:{sortable:r?.sortable,infoTitle:r?.headerInfoTitle,infoDescription:r?.headerInfoDescription},cellRendererClassName:r?.cellRendererClassName,cellContainerClassName:r?.cellContainerClassName,cellRenderer:Ga,cellRendererParams:(f,g)=>({value:h(g)||"--"}),valueSelector:h,valueComparator:(f,g)=>Mt(h(f),h(g)),columnWidth:r?.columnWidth,columnStretch:r?.columnStretch,columnStyle:r?.columnStyle}}function D(m,a,h,r){return{id:m,title:a,columnClassName:r?.columnClassName,headerCellRenderer:ot,headerCellRendererClassName:N(at.numberCellHeader,r?.headerCellRendererClassName),headerContainerClassName:r?.headerContainerClassName,headerCellRendererParams:{sortable:r?.sortable,infoTitle:r?.headerInfoTitle,infoDescription:r?.headerInfoDescription},cellRendererClassName:N(at.numberCell,r?.cellRendererClassName),cellContainerClassName:r?.cellContainerClassName,cellRenderer:we,cellRendererParams:(f,g)=>({value:h(g),suffix:r?.suffix,maximumFractionDigits:r?.maximumFractionDigits,invalidText:"--"}),valueSelector:h,valueComparator:(f,g)=>It(h(f),h(g)),columnWidth:r?.columnWidth,columnStretch:r?.columnStretch,columnStyle:r?.columnStyle}}const nn="_tabSelector_vlxoe_1",sn="_progressSection_vlxoe_14",rn="_progressLabel_vlxoe_20",on="_chartGrid_vlxoe_28",ln="_chartContainer_vlxoe_40",cn="_tableContainer_vlxoe_51",dn="_modelPerformance_vlxoe_59",un="_loadingContainer_vlxoe_67",mn="_errorContainer_vlxoe_77",hn="_userInteractionCards_vlxoe_96",gn="_userInteractionCard_vlxoe_96",fn="_userInteractionCardValue_vlxoe_116",vn="_userInteractionCardLabel_vlxoe_123",pn="_userInteractionCardButton_vlxoe_130",xn="_summaryStatsCards_vlxoe_148",_n="_summaryStatsCard_vlxoe_148",Cn="_summaryStatsCardValue_vlxoe_169",yn="_summaryStatsCardLabel_vlxoe_176",c={tabSelector:nn,progressSection:sn,progressLabel:rn,chartGrid:on,chartContainer:ln,tableContainer:cn,modelPerformance:dn,loadingContainer:un,errorContainer:mn,userInteractionCards:hn,userInteractionCard:gn,userInteractionCardValue:fn,userInteractionCardLabel:vn,userInteractionCardButton:pn,summaryStatsCards:xn,summaryStatsCard:_n,summaryStatsCardValue:Cn,summaryStatsCardLabel:yn};function jn(){const[m]=Dt(),[a,h]=s.useState(null),[r,f]=s.useState(!0),[g,b]=s.useState("crisis_maps"),[_,y]=s.useState([]),[x,w]=s.useState([]),[C,j]=s.useState([]),[v,S]=s.useState([]),[p,k]=s.useState(!1),[I,R]=s.useState(!1),[T,G]=s.useState(!1),[U,re]=s.useState(!1),[ae,be]=s.useState(!1),[K,W]=s.useState(!1),E=t=>{k(t==="editTime"),R(t==="percentage"),G(t==="delete"),re(t==="regions"),be(t==="sources"),W(t==="types")},O=[{key:"crisis_maps",label:"Crisis Maps"},{key:"drone_images",label:"Drone Images"}],A=s.useCallback((t,l)=>{if(!t||!l)return 0;const i=t.toLowerCase().replace(/[^\w\s]/g,"").split(/\s+/).filter(u=>u.length>0),n=l.toLowerCase().replace(/[^\w\s]/g,"").split(/\s+/).filter(u=>u.length>0);if(i.length===0&&n.length===0)return 1;if(i.length===0||n.length===0)return 0;const o=new Set(i),d=new Set(n),P=new Set([...o].filter(u=>d.has(u))),F=new Set([...o,...d]);return P.size/F.size},[]),X=s.useCallback(async()=>{f(!0);try{const l=await(await fetch("/api/images")).json(),i={},n=l.filter(u=>u.image_type==="crisis_map"),o=l.filter(u=>u.image_type==="drone_image"),d={totalCaptions:l.length,sources:{},types:{},regions:{},models:{},modelEditTimes:i,percentageModified:0,modelPercentageData:{},totalDeleteCount:0,deleteRate:0,crisisMaps:n,droneImages:o};l.forEach(u=>{if(u.source&&(d.sources[u.source]=(d.sources[u.source]||0)+1),u.event_type&&(d.types[u.event_type]=(d.types[u.event_type]||0)+1),u.countries&&u.countries.forEach(L=>{L.r_code&&(d.regions[L.r_code]=(d.regions[L.r_code]||0)+1)}),u.model){const L=u.model,V=d.models[L]||={count:0,avgAccuracy:0,avgContext:0,avgUsability:0,totalScore:0,deleteCount:0};if(V.count++,u.accuracy!=null&&(V.avgAccuracy+=u.accuracy),u.context!=null&&(V.avgContext+=u.context),u.usability!=null&&(V.avgUsability+=u.usability),u.created_at&&u.updated_at){const te=new Date(u.created_at).getTime(),Ce=new Date(u.updated_at).getTime()-te;Ce>0&&(i[L]||(i[L]=[]),i[L].push(Ce))}}}),_.forEach(u=>{u.s_code&&!d.sources[u.s_code]&&(d.sources[u.s_code]=0)}),x.forEach(u=>{u.t_code&&!d.types[u.t_code]&&(d.types[u.t_code]=0)}),C.forEach(u=>{u.r_code&&!d.regions[u.r_code]&&(d.regions[u.r_code]=0)}),["GPT-4","Claude","Gemini","Llama","Other"].forEach(u=>{d.models[u]||(d.models[u]={count:0,avgAccuracy:0,avgContext:0,avgUsability:0,totalScore:0,deleteCount:0})}),Object.values(d.models).forEach(u=>{u.count>0&&(u.avgAccuracy=Math.round(u.avgAccuracy/u.count),u.avgContext=Math.round(u.avgContext/u.count),u.avgUsability=Math.round(u.avgUsability/u.count),u.totalScore=Math.round((u.avgAccuracy+u.avgContext+u.avgUsability)/3))});const F=l.filter(u=>u.generated&&u.edited);if(F.length>0){const L=[...F.map(oe=>A(oe.generated,oe.edited))].sort((oe,Ce)=>oe-Ce),V=Math.floor(L.length/2),te=L.length%2===0?(L[V-1]+L[V])/2:L[V];d.percentageModified=Math.round((1-te)*100)}const H={};l.forEach(u=>{if(u.model&&u.generated&&u.edited){const L=A(u.generated,u.edited),V=Math.round((1-L)*100);H[u.model]||(H[u.model]=[]),H[u.model].push(V)}}),d.modelPercentageData=H;try{const u=await fetch("/api/models");if(u.ok){const L=await u.json();if(L.models){L.models.forEach(te=>{d.models[te.m_code]&&(d.models[te.m_code].deleteCount=te.delete_count||0)});const V=L.models.reduce((te,oe)=>te+(oe.delete_count||0),0);d.totalDeleteCount=V,d.deleteRate=V>0?Math.round(V/(V+l.length)*100):0}}}catch(u){console.log("Could not fetch model delete counts:",u)}h(d)}catch{h(null)}finally{f(!1)}},[_,x,C,A]),ne=s.useCallback(async()=>{try{const[t,l,i,n]=await Promise.all([fetch("/api/sources"),fetch("/api/types"),fetch("/api/regions"),fetch("/api/models")]),o=await t.json(),d=await l.json(),P=await i.json(),F=await n.json();y(o),w(d),j(P),S(F.models||[])}catch(t){console.log("Could not fetch lookup data:",t)}},[]);s.useEffect(()=>{const t=m.get("view");(t==="crisis_maps"||t==="drone_images")&&b(t)},[m]),s.useEffect(()=>{ne()},[ne]),s.useEffect(()=>{_.length>0&&x.length>0&&C.length>0&&v.length>0&&X()},[_,x,C,v,X]);const Y=s.useCallback(t=>{const l=_.find(i=>i.s_code===t);return l?l.label:t},[_]),M=s.useCallback(t=>{if(t.length===0)return 0;const l=[...t].sort((n,o)=>n-o),i=Math.floor(l.length/2);return l.length%2===0?Math.round((l[i-1]+l[i])/2):l[i]},[]),ie=s.useCallback(t=>{const l=Math.floor(t/1e3),i=Math.floor(l/60),n=Math.floor(i/60);return n>0?`${n}h ${i%60}m`:i>0?`${i}m ${l%60}s`:`${l}s`},[]),_e=s.useCallback(t=>{const l=x.find(i=>i.t_code===t);return l?l.label:t},[x]),J=s.useCallback(t=>{const l=v.find(i=>i.m_code===t);return l?l.label:t},[v]),Se=s.useMemo(()=>a?Object.entries(a.modelEditTimes||{}).filter(([,t])=>t.length>0).sort(([,t],[,l])=>M(l)-M(t)).map(([t,l],i)=>({id:i+1,name:J(t),count:l.length,avgEditTime:M(l),minEditTime:Math.min(...l),maxEditTime:Math.max(...l)})):[],[a,M,J]),Me=s.useMemo(()=>a?Object.entries(a.modelPercentageData||{}).filter(([,t])=>t.length>0).sort(([,t],[,l])=>{const i=[...t].sort((H,u)=>H-u),n=[...l].sort((H,u)=>H-u),o=Math.floor(i.length/2),d=Math.floor(n.length/2),P=i.length%2===0?(i[o-1]+i[o])/2:i[o];return(n.length%2===0?(n[d-1]+n[d])/2:n[d])-P}).map(([t,l],i)=>{const n=[...l].sort((P,F)=>P-F),o=Math.floor(n.length/2),d=n.length%2===0?Math.round((n[o-1]+n[o])/2):n[o];return{id:i+1,name:J(t),count:l.length,avgPercentageModified:d,minPercentageModified:Math.min(...l),maxPercentageModified:Math.max(...l)}}):[],[a,J]),Ie=s.useMemo(()=>a?Object.entries(a.models).filter(([,t])=>t.count>0).map(([t,l],i)=>{const n=[l.avgAccuracy,l.avgContext,l.avgUsability],o=n.reduce((F,H)=>F+H,0)/n.length,d=n.reduce((F,H)=>F+Math.pow(H-o,2),0)/n.length,P=Math.round(100-Math.sqrt(d));return{id:i+1,name:J(t),consistency:Math.max(0,P),avgScore:Math.round(o),count:l.count}}).sort((t,l)=>l.consistency-t.consistency):[],[a,J]),De=s.useMemo(()=>[Q("name","Region",t=>t.name),D("count","Count",t=>t.count),D("percentage","% of Total",t=>t.percentage,{suffix:"%",maximumFractionDigits:0})],[]),Ee=s.useMemo(()=>[Q("name","Type",t=>t.name),D("count","Count",t=>t.count),D("percentage","% of Total",t=>t.percentage,{suffix:"%",maximumFractionDigits:0})],[]),lt=s.useMemo(()=>[Q("name","Source",t=>t.name),D("count","Count",t=>t.count),D("percentage","% of Total",t=>t.percentage,{suffix:"%",maximumFractionDigits:0})],[]),Te=s.useMemo(()=>[Q("name","Model",t=>t.name),D("count","Count",t=>t.count),D("accuracy","Accuracy",t=>t.accuracy,{suffix:"%",maximumFractionDigits:0}),D("context","Context",t=>t.context,{suffix:"%",maximumFractionDigits:0}),D("usability","Usability",t=>t.usability,{suffix:"%",maximumFractionDigits:0}),D("totalScore","Total Score",t=>t.totalScore,{suffix:"%",maximumFractionDigits:0})],[]),ke=s.useMemo(()=>[Q("name","Model",t=>t.name),D("count","Count",t=>t.count),Q("avgEditTime","Median Edit Time",t=>ie(t.avgEditTime)),Q("minEditTime","Min Edit Time",t=>ie(t.minEditTime)),Q("maxEditTime","Max Edit Time",t=>ie(t.maxEditTime))],[]),Le=s.useMemo(()=>[Q("name","Model",t=>t.name),D("count","Count",t=>t.count),D("avgPercentageModified","Median % Modified",t=>t.avgPercentageModified,{suffix:"%",maximumFractionDigits:0}),D("minPercentageModified","Min % Modified",t=>t.minPercentageModified,{suffix:"%",maximumFractionDigits:0}),D("maxPercentageModified","Max % Modified",t=>t.maxPercentageModified,{suffix:"%",maximumFractionDigits:0})],[]),Pe=s.useMemo(()=>[Q("name","Model",t=>t.name),D("count","Total Count",t=>t.count),D("deleteCount","Delete Count",t=>t.deleteCount),D("deleteRate","Delete Rate",t=>t.deleteRate,{suffix:"%",maximumFractionDigits:1})],[]),ct=s.useMemo(()=>[Q("source","Source",t=>t.source),D("avgQuality","Average Quality",t=>t.avgQuality,{suffix:"%",maximumFractionDigits:0}),D("count","Count",t=>t.count)],[]),Re=s.useMemo(()=>[Q("eventType","Event Type",t=>t.eventType),D("avgQuality","Average Quality",t=>t.avgQuality,{suffix:"%",maximumFractionDigits:0}),D("count","Count",t=>t.count)],[]),$e=s.useMemo(()=>[Q("name","Model",t=>t.name),D("consistency","Consistency",t=>t.consistency,{suffix:"%",maximumFractionDigits:0}),D("avgScore","Average Score",t=>t.avgScore,{suffix:"%",maximumFractionDigits:0}),D("count","Count",t=>t.count)],[]),ue=s.useCallback(t=>a?t==="crisis_map"?a.crisisMaps.length:t==="drone_image"?a.droneImages.length:0:0,[a]),Be=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.countries&&n.countries.forEach(o=>{o.r_code&&(i[o.r_code]=(i[o.r_code]||0)+1)})}),Object.entries(i).filter(([,n])=>n>0).map(([n,o])=>({name:C.find(d=>d.r_code===n)?.label||n,value:o}))},[a,C]),Ae=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};l.forEach(o=>{o.countries&&o.countries.forEach(d=>{d.r_code&&(i[d.r_code]=(i[d.r_code]||0)+1)})});const n=C.reduce((o,d)=>(d.r_code&&(o[d.r_code]={name:d.label,count:i[d.r_code]||0}),o),{});return Object.entries(n).sort(([,o],[,d])=>d.count-o.count).map(([,{name:o,count:d}],P)=>({id:P+1,name:o,count:d,percentage:l.length>0?Math.round(d/l.length*100):0}))},[a,C]),dt=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.source&&(i[n.source]=(i[n.source]||0)+1)}),Object.entries(i).filter(([,n])=>n>0).map(([n,o])=>({name:_.find(d=>d.s_code===n)?.label||n,value:o}))},[a,_]),ut=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.source&&(i[n.source]=(i[n.source]||0)+1)}),Object.entries(i).sort(([,n],[,o])=>o-n).map(([n,o],d)=>({id:d+1,name:Y(n),count:o,percentage:l.length>0?Math.round(o/l.length*100):0}))},[a,Y]),Fe=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.event_type&&(i[n.event_type]=(i[n.event_type]||0)+1)}),Object.entries(i).filter(([,n])=>n>0).map(([n,o])=>({name:x.find(d=>d.t_code===n)?.label||n,value:o}))},[a,x]),Oe=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.event_type&&(i[n.event_type]=(i[n.event_type]||0)+1)}),Object.entries(i).sort(([,n],[,o])=>o-n).map(([n,o],d)=>({id:d+1,name:_e(n),count:o,percentage:l.length>0?Math.round(o/l.length*100):0}))},[a,_e]),He=s.useCallback(t=>{if(!a)return"No data available";const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i=new Set;l.forEach(d=>{d.model&&i.add(d.model)}),console.log(`Debug ${t}:`,{totalImages:l.length,usedModels:Array.from(i),availableEditTimes:Object.keys(a.modelEditTimes),modelEditTimesData:a.modelEditTimes});const o=Object.entries(a.modelEditTimes).filter(([d])=>i.has(d)).flatMap(([,d])=>d);return o.length===0?"No data available":ie(M(o))},[a,ie,M]),Ve=s.useCallback(()=>{if(!a)return"No data available";const t=a.totalCaptions||0,l=a.percentageModified||0;return t>0?Math.round(l/t*100):0},[a]),ze=s.useCallback(()=>a&&a.deleteRate>=0?`${a.deleteRate}%`:"No data available",[a]),Ue=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i=new Set;return l.forEach(o=>{o.model&&i.add(o.model)}),Se.filter(o=>{const d=v.find(P=>P.label===o.name)?.m_code;return d&&i.has(d)})},[a,Se,v]),We=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i=new Set;return l.forEach(o=>{o.model&&i.add(o.model)}),Me.filter(o=>{const d=v.find(P=>P.label===o.name)?.m_code;return d&&i.has(d)})},[a,Me,v]),Qe=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.model&&(i[n.model]||(i[n.model]={count:0,deleteCount:0}),i[n.model].count++)}),Object.entries(i).map(([n,o],d)=>{const F=a.models?.[n]?.deleteCount||0,H=o.count>0?Math.round(F/o.count*100*10)/10:0;return{id:d+1,name:J(n),count:o.count,deleteCount:F,deleteRate:H}}).sort((n,o)=>o.count-n.count)},[a,J]),Ze=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.model&&(i[n.model]||(i[n.model]={count:0,totalAccuracy:0,totalContext:0,totalUsability:0}),i[n.model].count++,n.accuracy!=null&&(i[n.model].totalAccuracy+=n.accuracy),n.context!=null&&(i[n.model].totalContext+=n.context),n.usability!=null&&(i[n.model].totalUsability+=n.usability))}),Object.entries(i).map(([n,o],d)=>({id:d+1,name:J(n),count:o.count,accuracy:o.count>0?Math.round(o.totalAccuracy/o.count):0,context:o.count>0?Math.round(o.totalContext/o.count):0,usability:o.count>0?Math.round(o.totalUsability/o.count):0,totalScore:o.count>0?Math.round((o.totalAccuracy+o.totalContext+o.totalUsability)/(3*o.count)):0})).sort((n,o)=>o.totalScore-n.totalScore)},[a,J]),mt=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.source&&(i[n.source]||(i[n.source]={total:0,count:0,totalImages:0}),i[n.source].totalImages+=1,n.accuracy!=null&&(i[n.source].total+=n.accuracy,i[n.source].count+=1))}),Object.entries(i).map(([n,o],d)=>({id:d+1,source:Y(n),avgQuality:o.count>0?Math.round(o.total/o.count):0,count:o.totalImages}))},[a,Y]),qe=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i={};return l.forEach(n=>{n.event_type&&(i[n.event_type]||(i[n.event_type]={total:0,count:0,totalImages:0}),i[n.event_type].totalImages+=1,n.accuracy!=null&&(i[n.event_type].total+=n.accuracy,i[n.event_type].count+=1))}),Object.entries(i).map(([n,o],d)=>({id:d+1,eventType:_e(n),avgQuality:o.count>0?Math.round(o.total/o.count):0,count:o.totalImages}))},[a,_e]),Ge=s.useCallback(t=>{if(!a)return[];const l=t==="crisis_map"?a.crisisMaps:a.droneImages,i=new Set;return l.forEach(o=>{o.model&&i.add(o.model)}),Ie.filter(o=>{const d=v.find(P=>P.label===o.name)?.m_code;return d&&i.has(d)})},[a,Ie,v]);if(r)return e.jsx(je,{children:e.jsx("div",{className:c.loadingContainer,children:e.jsx(Et,{})})});if(!a)return e.jsx(je,{children:e.jsx("div",{className:c.errorContainer,children:e.jsx("div",{className:"text-red-500",children:"Failed to load analytics data. Please try again."})})});const me=["#F5333F","#F64752","#F75C65","#F87079","#F9858C","#FA999F","#FBADB2","#FCC2C5"];return e.jsx(je,{children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsx("div",{className:c.tabSelector,children:e.jsx(Tt,{name:"analytics-view",value:g,onChange:t=>{(t==="crisis_maps"||t==="drone_images")&&b(t)},options:O,keySelector:t=>t.key,labelSelector:t=>t.label})}),g==="crisis_maps"?e.jsxs("div",{className:c.chartGrid,children:[e.jsxs(z,{heading:"Summary Statistics",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.summaryStatsCards,children:[e.jsxs("div",{className:c.summaryStatsCard,children:[e.jsx("div",{className:c.summaryStatsCardValue,children:ue("crisis_map")}),e.jsx("div",{className:c.summaryStatsCardLabel,children:"Total Crisis Maps"})]}),e.jsxs("div",{className:c.summaryStatsCard,children:[e.jsx("div",{className:c.summaryStatsCardValue,children:"2000"}),e.jsx("div",{className:c.summaryStatsCardLabel,children:"Target Amount"})]})]}),e.jsxs("div",{className:c.progressSection,children:[e.jsxs("div",{className:c.progressLabel,children:[e.jsx("span",{children:"Progress towards target"}),e.jsxs("span",{children:[Math.round(ue("crisis_map")/2e3*100),"%"]})]}),e.jsx(Ye,{value:ue("crisis_map"),totalValue:2e3})]})]}),e.jsxs(z,{heading:"Distribution Analysis",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.userInteractionCards,children:[e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardLabel,children:"Regions Distribution"}),e.jsx("div",{className:c.chartContainer,children:e.jsx(xe,{data:Be("crisis_map"),valueSelector:t=>t.value,labelSelector:t=>t.name,keySelector:t=>t.name,colors:me,showPercentageInLegend:!0})}),e.jsx(Z,{name:"view-regions-details",variant:U?"primary":"secondary",onClick:()=>E(U?"none":"regions"),className:c.userInteractionCardButton,children:U?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardLabel,children:"Sources Distribution"}),e.jsx("div",{className:c.chartContainer,children:e.jsx(xe,{data:dt("crisis_map"),valueSelector:t=>t.value,labelSelector:t=>t.name,keySelector:t=>t.name,colors:me,showPercentageInLegend:!0})}),e.jsx(Z,{name:"view-sources-details",variant:ae?"primary":"secondary",onClick:()=>E(ae?"none":"sources"),className:c.userInteractionCardButton,children:ae?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardLabel,children:"Types Distribution"}),e.jsx("div",{className:c.chartContainer,children:e.jsx(xe,{data:Fe("crisis_map"),valueSelector:t=>t.value,labelSelector:t=>t.name,keySelector:t=>t.name,colors:me,showPercentageInLegend:!0})}),e.jsx(Z,{name:"view-types-details",variant:K?"primary":"secondary",onClick:()=>E(K?"none":"types"),className:c.userInteractionCardButton,children:K?"Hide Details":"View Details"})]})]}),U&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ae("crisis_map"),columns:De,keySelector:$,filtered:!1,pending:!1})}),ae&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:ut("crisis_map"),columns:lt,keySelector:$,filtered:!1,pending:!1})}),K&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Oe("crisis_map"),columns:Ee,keySelector:$,filtered:!1,pending:!1})})]}),e.jsxs(z,{heading:"User Interaction Statistics",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.userInteractionCards,children:[e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:He("crisis_map")}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Median Edit Time"}),e.jsx(Z,{name:"view-edit-time-details",variant:p?"primary":"secondary",onClick:()=>E(p?"none":"editTime"),className:c.userInteractionCardButton,children:p?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:Ve()}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Median % Modified"}),e.jsx(Z,{name:"view-percentage-details",variant:I?"primary":"secondary",onClick:()=>E(I?"none":"percentage"),className:c.userInteractionCardButton,children:I?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:ze()}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Delete Rate"}),e.jsx(Z,{name:"view-delete-details",variant:T?"primary":"secondary",onClick:()=>E(T?"none":"delete"),className:c.userInteractionCardButton,children:T?"Hide Details":"View Details"})]})]}),p&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ue("crisis_map"),columns:ke,keySelector:$,filtered:!1,pending:!1})}),I&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:We("crisis_map"),columns:Le,keySelector:$,filtered:!1,pending:!1})}),T&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Qe("crisis_map"),columns:Pe,keySelector:$,filtered:!1,pending:!1})})]}),e.jsx(z,{heading:"Model Performance",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ze("crisis_map"),columns:Te,keySelector:$,filtered:!1,pending:!1})})}),e.jsx(z,{heading:"Quality-Source Correlation",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.tableContainer,children:e.jsx(B,{data:mt("crisis_map"),columns:ct,keySelector:$,filtered:!1,pending:!1})})}),e.jsx(z,{heading:"Quality-Event Type Correlation",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.tableContainer,children:e.jsx(B,{data:qe("crisis_map"),columns:Re,keySelector:$,filtered:!1,pending:!1})})}),e.jsx(z,{heading:"Model Consistency Analysis",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.tableContainer,children:e.jsx(B,{data:Ge("crisis_map"),columns:$e,keySelector:$,filtered:!1,pending:!1})})})]}):e.jsxs("div",{className:c.chartGrid,children:[e.jsxs(z,{heading:"Summary Statistics",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.summaryStatsCards,children:[e.jsxs("div",{className:c.summaryStatsCard,children:[e.jsx("div",{className:c.summaryStatsCardValue,children:ue("drone_image")}),e.jsx("div",{className:c.summaryStatsCardLabel,children:"Total Drone Images"})]}),e.jsxs("div",{className:c.summaryStatsCard,children:[e.jsx("div",{className:c.summaryStatsCardValue,children:"2000"}),e.jsx("div",{className:c.summaryStatsCardLabel,children:"Target Amount"})]})]}),e.jsxs("div",{className:c.progressSection,children:[e.jsxs("div",{className:c.progressLabel,children:[e.jsx("span",{children:"Progress towards target"}),e.jsxs("span",{children:[Math.round(ue("drone_image")/2e3*100),"%"]})]}),e.jsx(Ye,{value:ue("drone_image"),totalValue:2e3})]})]}),e.jsxs(z,{heading:"Distribution Analysis",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.userInteractionCards,children:[e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardLabel,children:"Regions Distribution"}),e.jsx("div",{className:c.chartContainer,children:e.jsx(xe,{data:Be("drone_image"),valueSelector:t=>t.value,labelSelector:t=>t.name,keySelector:t=>t.name,colors:me,showPercentageInLegend:!0})}),e.jsx(Z,{name:"view-regions-details",variant:U?"primary":"secondary",onClick:()=>E(U?"none":"regions"),className:c.userInteractionCardButton,children:U?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardLabel,children:"Types Distribution"}),e.jsx("div",{className:c.chartContainer,children:e.jsx(xe,{data:Fe("drone_image"),valueSelector:t=>t.value,labelSelector:t=>t.name,keySelector:t=>t.name,colors:me,showPercentageInLegend:!0})}),e.jsx(Z,{name:"view-types-details",variant:K?"primary":"secondary",onClick:()=>E(K?"none":"types"),className:c.userInteractionCardButton,children:K?"Hide Details":"View Details"})]})]}),U&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ae("drone_image"),columns:De,keySelector:$,filtered:!1,pending:!1})}),K&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Oe("drone_image"),columns:Ee,keySelector:$,filtered:!1,pending:!1})})]}),e.jsxs(z,{heading:"User Interaction Statistics",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:[e.jsxs("div",{className:c.userInteractionCards,children:[e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:He("drone_image")}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Median Edit Time"}),e.jsx(Z,{name:"view-edit-time-details",variant:p?"primary":"secondary",onClick:()=>E(p?"none":"editTime"),className:c.userInteractionCardButton,children:p?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:Ve()}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Median % Modified"}),e.jsx(Z,{name:"view-percentage-details",variant:I?"primary":"secondary",onClick:()=>E(I?"none":"percentage"),className:c.userInteractionCardButton,children:I?"Hide Details":"View Details"})]}),e.jsxs("div",{className:c.userInteractionCard,children:[e.jsx("div",{className:c.userInteractionCardValue,children:ze()}),e.jsx("div",{className:c.userInteractionCardLabel,children:"Delete Rate"}),e.jsx(Z,{name:"view-delete-details",variant:T?"primary":"secondary",onClick:()=>E(T?"none":"delete"),className:c.userInteractionCardButton,children:T?"Hide Details":"View Details"})]})]}),p&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ue("drone_image"),columns:ke,keySelector:$,filtered:!1,pending:!1})}),I&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:We("drone_image"),columns:Le,keySelector:$,filtered:!1,pending:!1})}),T&&e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Qe("drone_image"),columns:Pe,keySelector:$,filtered:!1,pending:!1})})]}),e.jsx(z,{heading:"Model Performance",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.modelPerformance,children:e.jsx(B,{data:Ze("drone_image"),columns:Te,keySelector:$,filtered:!1,pending:!1})})}),e.jsx(z,{heading:"Quality-Event Type Correlation",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.tableContainer,children:e.jsx(B,{data:qe("drone_image"),columns:Re,keySelector:$,filtered:!1,pending:!1})})}),e.jsx(z,{heading:"Model Consistency Analysis",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,children:e.jsx("div",{className:c.tableContainer,children:e.jsx(B,{data:Ge("drone_image"),columns:$e,keySelector:$,filtered:!1,pending:!1})})})]})]})})}export{jn as default};
py_backend/static/assets/{index-BCz4bkWK.js β†’ index-RA4UIF3R.js} RENAMED
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-4L12dHQs.js","assets/index-B1uKTNcW.css","assets/index-Cj53JezQ.js","assets/useAdmin-LSEnRjVv.js","assets/ExportModal-Qf6Y7VAO.js","assets/ExportModal-BoB3JpqO.css","assets/index-C85X4vtS.css","assets/AdminPage-a1ONalH9.js","assets/AdminPage-VgSjQ50W.css","assets/index-D2ncrm5K.js","assets/index-tDgjKyWF.css"])))=>i.map(i=>d[i]);
2
  function $g(e,n){for(var i=0;i<n.length;i++){const o=n[i];if(typeof o!="string"&&!Array.isArray(o)){for(const s in o)if(s!=="default"&&!(s in e)){const u=Object.getOwnPropertyDescriptor(o,s);u&&Object.defineProperty(e,s,u.get?u:{enumerable:!0,get:()=>o[s]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))o(s);new MutationObserver(s=>{for(const u of s)if(u.type==="childList")for(const d of u.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&o(d)}).observe(document,{childList:!0,subtree:!0});function i(s){const u={};return s.integrity&&(u.integrity=s.integrity),s.referrerPolicy&&(u.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?u.credentials="include":s.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function o(s){if(s.ep)return;s.ep=!0;const u=i(s);fetch(s.href,u)}})();var _P=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function zg(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Zc={exports:{}},La={},Qc={exports:{}},We={};/**
3
  * @license React
4
  * react.production.min.js
@@ -158,4 +158,4 @@ ${i||"AI-generated recommended actions will appear here..."}`,onChange:m,rows:12
158
 
159
  Analysis: ${Er}
160
 
161
- Recommended Actions: ${Nr}`,Te={title:U,edited:Pe,accuracy:rn.accuracy,context:rn.context,usability:rn.usability};console.log("Updating caption:",Te);const je=await fetch(`/api/images/${ct}/caption`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(Te)}),pe=await vn(je);if(!je.ok)throw new Error(pe.error||"Caption update failed");Lt(null),mt([]),Jr(3)}catch(T){na(T,"Submit")}finally{y(!1)}}async function oa(){if(console.log("handleDelete called with uploadedImageId:",ct),!ct){alert("No image to delete. Please try refreshing the page.");return}z(!0)}async function Cu(){try{console.log("Deleting image with ID:",ct);const T=await fetch(`/api/images/${ct}`,{method:"DELETE"});if(!T.ok){const Pe=await vn(T);throw new Error(Pe.error||`Delete failed with status ${T.status}`)}z(!1),ti()}catch(T){na(T,"Delete")}}const ti=()=>{kr(!1),o(1),_(null),P([]),x(null),Lt(null),mt([]),fn(null),W(""),$(""),Z(""),O(""),I([]),he(""),be(""),ue(""),H(""),Se(""),re(""),Q(""),nt(""),Wt(!1),St(""),wt(""),ki({accuracy:50,context:50,usability:50}),Ni(""),br(""),zn(""),hn(""),pt([]),we(!1),ve(null),ze(!1),Xe(null),Je(!1),mn(null),Ve(!1),Rt(""),gn(!1),He(null),_t(!1),Qe(null),n("/upload",{replace:!0})},dr=v.useCallback(T=>{T==="/upload"||T==="/"||(C.current?(Me(T),le(!0)):n(T))},[n]);async function ni(){if(Ee&&C.current)try{await fetch(`/api/images/${C.current}`,{method:"DELETE"}),le(!1),Me(null),n(Ee)}catch(T){console.error("Failed to delete image before navigation:",T),le(!1),Me(null),n(Ee)}}const co=async()=>{if(Mn){Ve(!0),Rt("Starting file conversion...");try{const T=new FormData;T.append("file",Mn),T.append("preprocess_only","true"),Rt("Converting file format...");const Pe=await fetch("/api/images/preprocess",{method:"POST",body:T});if(!Pe.ok)throw new Error("Preprocessing failed");const Te=await Pe.json();Rt("Finalizing conversion...");const je=atob(Te.processed_content),pe=new Uint8Array(je.length);for(let qe=0;qe<je.length;qe++)pe[qe]=je.charCodeAt(qe);const Re=new File([pe],Te.processed_filename,{type:Te.processed_mime_type}),dt=URL.createObjectURL(Re);N.length===0?(_(Re),P([Re])):P(qe=>[...qe,Re]),x(dt),Rt("Conversion complete!"),setTimeout(()=>{Je(!1),mn(null),Ve(!1),Rt("")},1e3)}catch(T){console.error("Preprocessing error:",T),Rt("Conversion failed. Please try again."),setTimeout(()=>{Je(!1),mn(null),Ve(!1),Rt("")},2e3)}}},Su=()=>{Je(!1),mn(null),Ve(!1),Rt("")},_u=async T=>{f(!0);try{const Pe=T.map(async Re=>{const dt=await fetch(`/api/images/${Re}`);if(!dt.ok)throw new Error(`Failed to fetch image ${Re}`);const qe=await dt.json(),$t=await fetch(`/api/images/${Re}/file`);if(!$t.ok)throw new Error(`Failed to fetch image file ${Re}`);const et=await $t.blob(),on=qe.file_key.split("/").pop()||`contributed_${Re}.png`;return{file:new File([et],on,{type:et.type}),imageData:qe}}),Te=await Promise.all(Pe),je=Te.map(Re=>Re.file),pe=Te[0]?.imageData;P(je),mt(T),T.length===1&&Lt(T[0]),je.length>=1&&_(je[0]),pe?.image_type&&ce(pe.image_type)}catch(Pe){console.error("Failed to fetch contributed images:",Pe),alert(`Failed to load contributed images: ${Pe instanceof Error?Pe.message:"Unknown error"}`)}finally{f(!1)}};return v.useEffect(()=>{Promise.all([fetch("/api/sources").then(T=>T.json()),fetch("/api/types").then(T=>T.json()),fetch("/api/spatial-references").then(T=>T.json()),fetch("/api/image-types").then(T=>T.json()),fetch("/api/countries").then(T=>T.json()),fetch("/api/models").then(T=>T.json())]).then(([T,Pe,Te,je,pe,Re])=>{!localStorage.getItem(Il)&&Re?.length&&localStorage.setItem(Il,Re[0].m_code),nn(T),un(Pe),Kr(Te),dn(je),Qn(pe),T.length>0&&$(T[0].s_code),Z("OTHER"),O("OTHER"),je.length>0&&!e.get("imageType")&&!K&&ce(je[0].image_type)})},[e,K]),v.useEffect(()=>(window.confirmNavigationIfNeeded=T=>{dr(T)},()=>{delete window.confirmNavigationIfNeeded}),[dr]),v.useEffect(()=>{const T=je=>{if(C.current){const pe="You have an uploaded image that will be deleted if you leave this page. Are you sure you want to leave?";return je.preventDefault(),je.returnValue=pe,pe}},Pe=()=>{C.current&&fetch(`/api/images/${C.current}`,{method:"DELETE"}).catch(console.error)},Te=je=>{const pe=je.target,Re=pe.closest("a[href]")||pe.closest("[data-navigate]");if(Re&&C.current){const dt=Re.getAttribute("href")||Re.getAttribute("data-navigate");dt&&dt!=="#"&&!dt.startsWith("javascript:")&&!dt.startsWith("mailto:")&&(je.preventDefault(),je.stopPropagation(),dr(dt))}};return window.addEventListener("beforeunload",T),document.addEventListener("click",Te,!0),()=>{window.removeEventListener("beforeunload",T),document.removeEventListener("click",Te,!0),Pe()}},[dr]),v.useEffect(()=>{if(!E){x(null);return}const T=URL.createObjectURL(E);return x(T),()=>URL.revokeObjectURL(T)},[E]),v.useEffect(()=>{const T=e.get("contribute"),Pe=e.get("imageIds");if(T==="true"&&Pe){const Te=Pe.split(",").filter(je=>je.trim());Te.length>0&&_u(Te)}},[e]),v.useEffect(()=>{i==="2b"&&Pr(0)},[i]),g.jsxs(Gf,{children:[i!==3&&g.jsx("div",{className:"max-w-7xl mx-auto",children:g.jsxs("div",{className:V.uploadContainer,"data-step":i,children:[i===1&&!e.get("step")&&!d&&g.jsx(Ig,{files:N,file:E,preview:m,imageType:K,onFileChange:Lr,onRemoveImage:Li,onAddImage:lo,onImageTypeChange:Mr,onChangeFile:ei}),i===1&&e.get("contribute")==="true"&&!d&&N.length>0&&g.jsx(Ig,{files:N,file:E,preview:m,imageType:K,onFileChange:Lr,onRemoveImage:Li,onAddImage:lo,onImageTypeChange:Mr,onChangeFile:ei}),s&&g.jsxs("div",{className:V.loadingContainer,children:[g.jsx($o,{className:"text-ifrcRed"}),g.jsx("p",{className:V.loadingText,children:"Generating..."})]}),d&&g.jsxs("div",{className:V.loadingContainer,children:[g.jsx($o,{className:"text-ifrcRed"}),g.jsx("p",{className:V.loadingText,children:"Loading contribution..."})]}),(i===1&&!s&&!d||i===1&&e.get("contribute")==="true"&&!s&&!d&&N.length>0)&&g.jsx("div",{className:V.generateButtonContainer,children:Kt?g.jsx(Ue,{name:"generate-from-url",onClick:ra,children:"Generate Caption"}):g.jsx(Ue,{name:"generate",disabled:N.length===0,onClick:ra,children:"Generate"})}),i==="2a"&&g.jsxs("div",{className:V.step2Layout,children:[g.jsx("div",{className:V.mapColumn,children:g.jsx(Ag,{files:N,imageUrl:Kt,preview:m,onViewFullSize:T=>{Kn(T||null),Yr(!0)}})}),g.jsx("div",{className:V.contentColumn,children:g.jsxs("div",{className:V.metadataSectionCard,children:[g.jsx(Wj,{files:N,imageType:K,title:U,source:L,eventType:q,epsg:fe,countries:de,centerLon:ne,centerLat:Ce,amslM:G,aglM:k,headingDeg:oe,yawDeg:se,pitchDeg:ee,rollDeg:Y,rtkFix:tn,stdHM:st,stdVM:ut,metadataArray:ht,sources:Nt,types:jn,spatialReferences:Pn,imageTypes:cn,countriesOptions:Sr,onTitleChange:T=>W(T||""),onSourceChange:Xo,onEventTypeChange:oo,onEpsgChange:ao,onCountriesChange:so,onCenterLonChange:vu,onCenterLatChange:yu,onAmslMChange:Jo,onAglMChange:ys,onHeadingDegChange:ea,onYawDegChange:Mi,onPitchDegChange:wu,onRollDegChange:ta,onRtkFixChange:rt,onStdHMChange:ws,onStdVMChange:xs,onImageTypeChange:Mr,updateMetadataForImage:cr}),g.jsxs("div",{className:V.confirmSection,children:[g.jsx(df,{name:"delete",variant:"tertiary",onClick:oa,title:"Delete",ariaLabel:"Delete uploaded image",children:g.jsx(uf,{})}),g.jsx(Ue,{name:"confirm-metadata",onClick:()=>Jr("2b"),children:"Next"})]})]})})]}),i==="2b"&&g.jsxs("div",{className:V.step2bLayout,children:[p&&g.jsxs("div",{className:V.loadingContainer,children:[g.jsx($o,{className:"text-ifrcRed"}),g.jsx("p",{className:V.loadingText,children:"Submitting..."})]}),g.jsxs("div",{className:`${V.topRow} ${pn?V.ratingHidden:""}`,children:[g.jsx("div",{className:V.imageSection,children:g.jsx(Ag,{files:N,imageUrl:Kt,preview:m,onViewFullSize:T=>{Kn(T||null),Yr(!0)},currentImageIndex:ur,onGoToPrevious:Cs,onGoToNext:Ss,onGoToImage:_s,showCarousel:!0})}),!pn&&g.jsx("div",{className:V.metadataSectionCard,children:g.jsx(Gj,{isPerformanceConfirmed:pn,scores:rn,onScoreChange:(T,Pe)=>ki(Te=>({...Te,[T]:Pe})),onConfirmRatings:()=>kr(!0),onEditRatings:()=>kr(!1)})})]}),g.jsx("div",{className:V.metadataSectionCard,children:g.jsx(Zj,{description:_r,analysis:Er,recommendedActions:Nr,onDescriptionChange:T=>br(T||""),onAnalysisChange:T=>zn(T||""),onRecommendedActionsChange:T=>hn(T||""),onBack:()=>Jr("2a"),onDelete:oa,onSubmit:uo,onEditRatings:()=>kr(!1),isPerformanceConfirmed:pn,isSubmitting:p})})]})]})}),i===3&&g.jsxs("div",{className:V.successContainer,children:[g.jsx(Qi,{level:2,className:V.successHeading,children:"Saved!"}),g.jsx("p",{className:V.successText,children:e.get("contribute")==="true"?"Your contribution has been successfully saved.":"Your caption has been successfully saved."}),g.jsx("div",{className:V.successButton,children:g.jsx(Ue,{name:"upload-another",onClick:()=>{ti()},children:"Upload Another"})})]}),g.jsx(Qj,{isOpen:Ti,imageUrl:Kt,preview:m,selectedImageData:ji,onClose:()=>{Yr(!1),Kn(null)}}),g.jsx(Kj,{isOpen:Tr,onClose:()=>j(!1)}),g.jsx(Yj,{isOpen:R,onConfirm:Cu,onCancel:()=>z(!1)}),g.jsx(Xj,{isOpen:X,onConfirm:ni,onCancel:()=>le(!1)}),g.jsx(Jj,{isOpen:ye,fallbackInfo:ge,onClose:()=>we(!1)}),g.jsx(eP,{isOpen:Fe,preprocessingInfo:jt,onClose:()=>ze(!1)}),g.jsx(tP,{isOpen:Ze,preprocessingFile:Mn,isPreprocessing:Ln,preprocessingProgress:Pi,onConfirm:co,onCancel:Su}),g.jsx(nP,{isOpen:Bn,unsupportedFile:Xr,onClose:()=>gn(!1)}),g.jsx(rP,{isOpen:it,oversizedFile:jr,onClose:()=>_t(!1),onCancel:()=>_t(!1)})]})}const iP="_helpContainer_1wavj_1",oP="_helpSection_1wavj_13",aP="_sectionHeader_1wavj_49",sP="_sectionTitle_1wavj_91",lP="_sectionContent_1wavj_105",uP="_guidelinesList_1wavj_119",cP="_buttonContainer_1wavj_181",ft={helpContainer:iP,helpSection:oP,sectionHeader:aP,sectionTitle:sP,sectionContent:lP,guidelinesList:uP,buttonContainer:cP};function dP(){const e=cs(),{setShowReferenceExamples:n}=qj(),i=()=>{e("/upload")},o=()=>{n(!0),e("/explore")},s=()=>{e("/analytics?view=crisis_maps")};return g.jsx(Gf,{className:"py-10",children:g.jsx("div",{className:ft.helpContainer,children:g.jsxs("div",{className:"space-y-8",children:[g.jsxs("div",{className:ft.helpSection,children:[g.jsx("div",{className:ft.sectionHeader,children:g.jsx(Qi,{level:3,className:ft.sectionTitle,children:"Introduction"})}),g.jsx("div",{className:ft.sectionContent,children:"In collaboration with the IFRC, PromptAid Vision is a tool that generates textual descriptions of crisis maps/crisis drone images utiliing Visual language models. This prototype is for collecting data for the fine-tuning of our own models. We aim to utilize AI tools to support national societies with rapid decision making during emergencies."}),g.jsx("div",{className:ft.buttonContainer,children:g.jsx(Ue,{name:"upload-now",variant:"secondary",onClick:i,children:"Upload now β†’"})})]}),g.jsxs("div",{className:ft.helpSection,children:[g.jsx("div",{className:ft.sectionHeader,children:g.jsx(Qi,{level:3,className:ft.sectionTitle,children:"Guidelines"})}),g.jsxs("div",{className:ft.sectionContent,children:["To make the process smoother, please follow the guidelines below:",g.jsxs("ul",{className:ft.guidelinesList,children:[g.jsx("li",{children:"Avoid uploading images that are not crisis maps/crisis drone images."}),g.jsx("li",{children:"Confirm the image details prior to modifying the description."}),g.jsx("li",{children:"Before the modification, please read the description generated and provide a rating via the rating sliders."}),g.jsx("li",{children:'Click the "Submit" button to save the description.'})]})]}),g.jsx("div",{className:ft.buttonContainer,children:g.jsx(Ue,{name:"see-examples",variant:"secondary",onClick:o,children:"See examples β†’"})})]}),g.jsxs("div",{className:ft.helpSection,children:[g.jsx("div",{className:ft.sectionHeader,children:g.jsx(Qi,{level:3,className:ft.sectionTitle,children:"VLMs"})}),g.jsx("div",{className:ft.sectionContent,children:"PromptAid Vision uses a variety of Visual Language Models (VLMs). A random VLM is selected for each upload. Therefore feel free to delete and reupload. You can view performance details here:"}),g.jsx("div",{className:ft.buttonContainer,children:g.jsx(Ue,{name:"view-vlm-details",variant:"secondary",onClick:s,children:"View VLM details β†’"})})]}),g.jsxs("div",{className:ft.helpSection,children:[g.jsx("div",{className:ft.sectionHeader,children:g.jsx(Qi,{level:3,className:ft.sectionTitle,children:"Dataset"})}),g.jsx("div",{className:ft.sectionContent,children:"All users are able to export the dataset. You could apply filters when exporting, and it have the option to organize based on model fine-tuning formats."}),g.jsx("div",{className:ft.buttonContainer,children:g.jsx(Ue,{name:"export-dataset",variant:"secondary",onClick:()=>{n(!1),e("/explore"),setTimeout(()=>{const u=document.querySelector('[name="export-dataset"]');u&&u.click()},100)},children:"Export dataset β†’"})})]}),g.jsxs("div",{className:ft.helpSection,children:[g.jsx("div",{className:ft.sectionHeader,children:g.jsx(Qi,{level:3,className:ft.sectionTitle,children:"Contact us"})}),g.jsx("div",{className:ft.sectionContent,children:"Need help or have questions about PromptAid Vision? Our team is here to support you."}),g.jsx("div",{className:ft.buttonContainer,children:g.jsx(Ue,{name:"contact-support",variant:"secondary",disabled:!0,children:"Get in touch β†’"})})]})]})})})}const fP=v.createContext(void 0),hP=({children:e})=>{const[n,i]=v.useState(!1),[o,s]=v.useState(!0),u=async()=>{const y=localStorage.getItem("adminToken");if(!y){i(!1),s(!1);return}try{(await fetch("/api/admin/verify",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${y}`}})).ok?i(!0):(localStorage.removeItem("adminToken"),i(!1))}catch(w){console.error("Error verifying admin token:",w),localStorage.removeItem("adminToken"),i(!1)}finally{s(!1)}},d=async y=>{try{const w=await fetch("/api/admin/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:y})});if(w.ok){const C=await w.json();return localStorage.setItem("adminToken",C.access_token),i(!0),!0}else return!1}catch(w){return console.error("Login error:",w),!1}},f=()=>{localStorage.removeItem("adminToken"),i(!1)};v.useEffect(()=>{u()},[]);const p={isAuthenticated:n,isLoading:o,login:d,logout:f,verifyToken:u};return g.jsx(fP.Provider,{value:p,children:e})},pP=v.lazy(()=>Zn(()=>import("./index-4L12dHQs.js"),__vite__mapDeps([0,1]))),mP=v.lazy(()=>Zn(()=>import("./index-Cj53JezQ.js"),__vite__mapDeps([2,3,4,5,6]))),gP=v.lazy(()=>Zn(()=>import("./AdminPage-a1ONalH9.js"),__vite__mapDeps([7,3,8]))),vP=v.lazy(()=>Zn(()=>import("./index-D2ncrm5K.js"),__vite__mapDeps([9,3,4,5,10])));class yP extends v.Component{constructor(n){super(n),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,i){console.error("Error caught by boundary:",n,i)}render(){return this.state.hasError?g.jsxs("div",{style:{padding:"20px",textAlign:"center"},children:[g.jsx("h2",{children:"Something went wrong"}),g.jsx("p",{children:"Please refresh the page to try again."}),g.jsx("button",{onClick:()=>window.location.reload(),children:"Refresh Page"})]}):this.props.children}}const wi=e=>{const n=e();return n.catch(()=>{}),n},wP=()=>{"requestIdleCallback"in window?requestIdleCallback(()=>{wi(()=>Zn(()=>import("./index-4L12dHQs.js"),__vite__mapDeps([0,1]))),wi(()=>Zn(()=>import("./index-Cj53JezQ.js"),__vite__mapDeps([2,3,4,5,6]))),wi(()=>Zn(()=>import("./AdminPage-a1ONalH9.js"),__vite__mapDeps([7,3,8]))),wi(()=>Zn(()=>import("./index-D2ncrm5K.js"),__vite__mapDeps([9,3,4,5,10])))}):setTimeout(()=>{wi(()=>Zn(()=>import("./index-4L12dHQs.js"),__vite__mapDeps([0,1]))),wi(()=>Zn(()=>import("./index-Cj53JezQ.js"),__vite__mapDeps([2,3,4,5,6]))),wi(()=>Zn(()=>import("./AdminPage-a1ONalH9.js"),__vite__mapDeps([7,3,8]))),wi(()=>Zn(()=>import("./index-D2ncrm5K.js"),__vite__mapDeps([9,3,4,5,10])))},1e3)},xP=vx([{element:g.jsx(LT,{}),children:[{path:"/",element:g.jsx(Fg,{})},{path:"/upload",element:g.jsx(Fg,{})},{path:"/analytics",element:g.jsx(v.Suspense,{fallback:g.jsx("div",{children:"Loading Analytics..."}),children:g.jsx(pP,{})})},{path:"/explore",element:g.jsx(v.Suspense,{fallback:g.jsx("div",{children:"Loading Explore..."}),children:g.jsx(mP,{})})},{path:"/help",element:g.jsx(dP,{})},{path:"/admin",element:g.jsx(v.Suspense,{fallback:g.jsx("div",{children:"Loading Admin..."}),children:g.jsx(gP,{})})},{path:"/map/:mapId",element:g.jsx(v.Suspense,{fallback:g.jsx("div",{children:"Loading Map Details..."}),children:g.jsx(vP,{})})}]}],{basename:"/"});function CP(){const[e,n]=v.useState([]);v.useEffect(()=>{wP()},[]);const i=v.useCallback(f=>{n(p=>Bx([...p,f],y=>y.name)??p)},[n]),o=v.useCallback(f=>{n(p=>{const y=p.findIndex(C=>C.name===f);if(y===-1)return p;const w=[...p];return w.splice(y,1),w})},[n]),s=v.useCallback((f,p)=>{n(y=>{const w=y.findIndex(m=>m.name===f);if(w===-1)return y;const C=[...y];return C[w]={...C[w],...p},C})},[n]),u=v.useMemo(()=>({alerts:e,addAlert:i,removeAlert:o,updateAlert:s}),[e,i,o,s]),d=v.useMemo(()=>({languageNamespaceStatus:{},setLanguageNamespaceStatus:()=>{},currentLanguage:"en",setCurrentLanguage:()=>{},strings:{},setStrings:()=>{},registerNamespace:()=>{}}),[]);return g.jsx(yP,{children:g.jsx(Fx.Provider,{value:u,children:g.jsx(i0.Provider,{value:d,children:g.jsx(hP,{children:g.jsx(Vj,{children:g.jsx(Nx,{router:xP})})})})})})}function SP(){return g.jsx(CP,{})}console.log("React version at runtime:",v.version,"createContext exists?",!!v.createContext);V1.createRoot(document.getElementById("root")).render(g.jsx(v.StrictMode,{children:g.jsx(SP,{})}));export{bC as A,Ko as B,EP as C,qj as D,TP as E,uf as F,Zn as G,V as H,Qi as I,Wi as J,bP as K,bT as L,Qj as M,Gf as N,Tt as O,jC as P,PP as Q,u0 as R,TC as S,c0 as T,jP as U,Mg as V,fP as W,_P as X,zg as Y,$o as _,$e as a,Mt as b,DP as c,OP as d,NP as e,SC as f,s0 as g,LP as h,MP as i,g as j,sr as k,qx as l,FE as m,Ue as n,Oe as o,Zx as p,Ga as q,v as r,l0 as s,i0 as t,Dx as u,PC as v,MC as w,cs as x,kP as y,ar as z};
 
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Dx7kXGv5.js","assets/index-B1uKTNcW.css","assets/index-DjbXFoDc.js","assets/useAdmin-k5gw6w_T.js","assets/ExportModal-DWGvhKT1.js","assets/ExportModal-BoB3JpqO.css","assets/index-C85X4vtS.css","assets/AdminPage-QC43WsfP.js","assets/AdminPage-VgSjQ50W.css","assets/index-B4LyeOKz.js","assets/index-tDgjKyWF.css"])))=>i.map(i=>d[i]);
2
  function $g(e,n){for(var i=0;i<n.length;i++){const o=n[i];if(typeof o!="string"&&!Array.isArray(o)){for(const s in o)if(s!=="default"&&!(s in e)){const u=Object.getOwnPropertyDescriptor(o,s);u&&Object.defineProperty(e,s,u.get?u:{enumerable:!0,get:()=>o[s]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))o(s);new MutationObserver(s=>{for(const u of s)if(u.type==="childList")for(const d of u.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&o(d)}).observe(document,{childList:!0,subtree:!0});function i(s){const u={};return s.integrity&&(u.integrity=s.integrity),s.referrerPolicy&&(u.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?u.credentials="include":s.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function o(s){if(s.ep)return;s.ep=!0;const u=i(s);fetch(s.href,u)}})();var _P=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function zg(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Zc={exports:{}},La={},Qc={exports:{}},We={};/**
3
  * @license React
4
  * react.production.min.js
 
158
 
159
  Analysis: ${Er}
160
 
161
+ Recommended Actions: ${Nr}`,Te={title:U,edited:Pe,accuracy:rn.accuracy,context:rn.context,usability:rn.usability};console.log("Updating caption:",Te);const je=await fetch(`/api/images/${ct}/caption`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(Te)}),pe=await vn(je);if(!je.ok)throw new Error(pe.error||"Caption update failed");Lt(null),mt([]),Jr(3)}catch(T){na(T,"Submit")}finally{y(!1)}}async function oa(){if(console.log("handleDelete called with uploadedImageId:",ct),!ct){alert("No image to delete. Please try refreshing the page.");return}z(!0)}async function Cu(){try{console.log("Deleting image with ID:",ct);const T=await fetch(`/api/images/${ct}`,{method:"DELETE"});if(!T.ok){const Pe=await vn(T);throw new Error(Pe.error||`Delete failed with status ${T.status}`)}z(!1),ti()}catch(T){na(T,"Delete")}}const ti=()=>{kr(!1),o(1),_(null),P([]),x(null),Lt(null),mt([]),fn(null),W(""),$(""),Z(""),O(""),I([]),he(""),be(""),ue(""),H(""),Se(""),re(""),Q(""),nt(""),Wt(!1),St(""),wt(""),ki({accuracy:50,context:50,usability:50}),Ni(""),br(""),zn(""),hn(""),pt([]),we(!1),ve(null),ze(!1),Xe(null),Je(!1),mn(null),Ve(!1),Rt(""),gn(!1),He(null),_t(!1),Qe(null),n("/upload",{replace:!0})},dr=v.useCallback(T=>{T==="/upload"||T==="/"||(C.current?(Me(T),le(!0)):n(T))},[n]);async function ni(){if(Ee&&C.current)try{await fetch(`/api/images/${C.current}`,{method:"DELETE"}),le(!1),Me(null),n(Ee)}catch(T){console.error("Failed to delete image before navigation:",T),le(!1),Me(null),n(Ee)}}const co=async()=>{if(Mn){Ve(!0),Rt("Starting file conversion...");try{const T=new FormData;T.append("file",Mn),T.append("preprocess_only","true"),Rt("Converting file format...");const Pe=await fetch("/api/images/preprocess",{method:"POST",body:T});if(!Pe.ok)throw new Error("Preprocessing failed");const Te=await Pe.json();Rt("Finalizing conversion...");const je=atob(Te.processed_content),pe=new Uint8Array(je.length);for(let qe=0;qe<je.length;qe++)pe[qe]=je.charCodeAt(qe);const Re=new File([pe],Te.processed_filename,{type:Te.processed_mime_type}),dt=URL.createObjectURL(Re);N.length===0?(_(Re),P([Re])):P(qe=>[...qe,Re]),x(dt),Rt("Conversion complete!"),setTimeout(()=>{Je(!1),mn(null),Ve(!1),Rt("")},1e3)}catch(T){console.error("Preprocessing error:",T),Rt("Conversion failed. Please try again."),setTimeout(()=>{Je(!1),mn(null),Ve(!1),Rt("")},2e3)}}},Su=()=>{Je(!1),mn(null),Ve(!1),Rt("")},_u=async T=>{f(!0);try{const Pe=T.map(async Re=>{const dt=await fetch(`/api/images/${Re}`);if(!dt.ok)throw new Error(`Failed to fetch image ${Re}`);const qe=await dt.json(),$t=await fetch(`/api/images/${Re}/file`);if(!$t.ok)throw new Error(`Failed to fetch image file ${Re}`);const et=await $t.blob(),on=qe.file_key.split("/").pop()||`contributed_${Re}.png`;return{file:new File([et],on,{type:et.type}),imageData:qe}}),Te=await Promise.all(Pe),je=Te.map(Re=>Re.file),pe=Te[0]?.imageData;P(je),mt(T),T.length===1&&Lt(T[0]),je.length>=1&&_(je[0]),pe?.image_type&&ce(pe.image_type)}catch(Pe){console.error("Failed to fetch contributed images:",Pe),alert(`Failed to load contributed images: ${Pe instanceof Error?Pe.message:"Unknown error"}`)}finally{f(!1)}};return v.useEffect(()=>{Promise.all([fetch("/api/sources").then(T=>T.json()),fetch("/api/types").then(T=>T.json()),fetch("/api/spatial-references").then(T=>T.json()),fetch("/api/image-types").then(T=>T.json()),fetch("/api/countries").then(T=>T.json()),fetch("/api/models").then(T=>T.json())]).then(([T,Pe,Te,je,pe,Re])=>{!localStorage.getItem(Il)&&Re?.length&&localStorage.setItem(Il,Re[0].m_code),nn(T),un(Pe),Kr(Te),dn(je),Qn(pe),T.length>0&&$(T[0].s_code),Z("OTHER"),O("OTHER"),je.length>0&&!e.get("imageType")&&!K&&ce(je[0].image_type)})},[e,K]),v.useEffect(()=>(window.confirmNavigationIfNeeded=T=>{dr(T)},()=>{delete window.confirmNavigationIfNeeded}),[dr]),v.useEffect(()=>{const T=je=>{if(C.current){const pe="You have an uploaded image that will be deleted if you leave this page. Are you sure you want to leave?";return je.preventDefault(),je.returnValue=pe,pe}},Pe=()=>{C.current&&fetch(`/api/images/${C.current}`,{method:"DELETE"}).catch(console.error)},Te=je=>{const pe=je.target,Re=pe.closest("a[href]")||pe.closest("[data-navigate]");if(Re&&C.current){const dt=Re.getAttribute("href")||Re.getAttribute("data-navigate");dt&&dt!=="#"&&!dt.startsWith("javascript:")&&!dt.startsWith("mailto:")&&(je.preventDefault(),je.stopPropagation(),dr(dt))}};return window.addEventListener("beforeunload",T),document.addEventListener("click",Te,!0),()=>{window.removeEventListener("beforeunload",T),document.removeEventListener("click",Te,!0),Pe()}},[dr]),v.useEffect(()=>{if(!E){x(null);return}const T=URL.createObjectURL(E);return x(T),()=>URL.revokeObjectURL(T)},[E]),v.useEffect(()=>{const T=e.get("contribute"),Pe=e.get("imageIds");if(T==="true"&&Pe){const Te=Pe.split(",").filter(je=>je.trim());Te.length>0&&_u(Te)}},[e]),v.useEffect(()=>{i==="2b"&&Pr(0)},[i]),g.jsxs(Gf,{children:[i!==3&&g.jsx("div",{className:"max-w-7xl mx-auto",children:g.jsxs("div",{className:V.uploadContainer,"data-step":i,children:[i===1&&!e.get("step")&&!d&&g.jsx(Ig,{files:N,file:E,preview:m,imageType:K,onFileChange:Lr,onRemoveImage:Li,onAddImage:lo,onImageTypeChange:Mr,onChangeFile:ei}),i===1&&e.get("contribute")==="true"&&!d&&N.length>0&&g.jsx(Ig,{files:N,file:E,preview:m,imageType:K,onFileChange:Lr,onRemoveImage:Li,onAddImage:lo,onImageTypeChange:Mr,onChangeFile:ei}),s&&g.jsxs("div",{className:V.loadingContainer,children:[g.jsx($o,{className:"text-ifrcRed"}),g.jsx("p",{className:V.loadingText,children:"Generating..."})]}),d&&g.jsxs("div",{className:V.loadingContainer,children:[g.jsx($o,{className:"text-ifrcRed"}),g.jsx("p",{className:V.loadingText,children:"Loading contribution..."})]}),(i===1&&!s&&!d||i===1&&e.get("contribute")==="true"&&!s&&!d&&N.length>0)&&g.jsx("div",{className:V.generateButtonContainer,children:Kt?g.jsx(Ue,{name:"generate-from-url",onClick:ra,children:"Generate Caption"}):g.jsx(Ue,{name:"generate",disabled:N.length===0,onClick:ra,children:"Generate"})}),i==="2a"&&g.jsxs("div",{className:V.step2Layout,children:[g.jsx("div",{className:V.mapColumn,children:g.jsx(Ag,{files:N,imageUrl:Kt,preview:m,onViewFullSize:T=>{Kn(T||null),Yr(!0)}})}),g.jsx("div",{className:V.contentColumn,children:g.jsxs("div",{className:V.metadataSectionCard,children:[g.jsx(Wj,{files:N,imageType:K,title:U,source:L,eventType:q,epsg:fe,countries:de,centerLon:ne,centerLat:Ce,amslM:G,aglM:k,headingDeg:oe,yawDeg:se,pitchDeg:ee,rollDeg:Y,rtkFix:tn,stdHM:st,stdVM:ut,metadataArray:ht,sources:Nt,types:jn,spatialReferences:Pn,imageTypes:cn,countriesOptions:Sr,onTitleChange:T=>W(T||""),onSourceChange:Xo,onEventTypeChange:oo,onEpsgChange:ao,onCountriesChange:so,onCenterLonChange:vu,onCenterLatChange:yu,onAmslMChange:Jo,onAglMChange:ys,onHeadingDegChange:ea,onYawDegChange:Mi,onPitchDegChange:wu,onRollDegChange:ta,onRtkFixChange:rt,onStdHMChange:ws,onStdVMChange:xs,onImageTypeChange:Mr,updateMetadataForImage:cr}),g.jsxs("div",{className:V.confirmSection,children:[g.jsx(df,{name:"delete",variant:"tertiary",onClick:oa,title:"Delete",ariaLabel:"Delete uploaded image",children:g.jsx(uf,{})}),g.jsx(Ue,{name:"confirm-metadata",onClick:()=>Jr("2b"),children:"Next"})]})]})})]}),i==="2b"&&g.jsxs("div",{className:V.step2bLayout,children:[p&&g.jsxs("div",{className:V.loadingContainer,children:[g.jsx($o,{className:"text-ifrcRed"}),g.jsx("p",{className:V.loadingText,children:"Submitting..."})]}),g.jsxs("div",{className:`${V.topRow} ${pn?V.ratingHidden:""}`,children:[g.jsx("div",{className:V.imageSection,children:g.jsx(Ag,{files:N,imageUrl:Kt,preview:m,onViewFullSize:T=>{Kn(T||null),Yr(!0)},currentImageIndex:ur,onGoToPrevious:Cs,onGoToNext:Ss,onGoToImage:_s,showCarousel:!0})}),!pn&&g.jsx("div",{className:V.metadataSectionCard,children:g.jsx(Gj,{isPerformanceConfirmed:pn,scores:rn,onScoreChange:(T,Pe)=>ki(Te=>({...Te,[T]:Pe})),onConfirmRatings:()=>kr(!0),onEditRatings:()=>kr(!1)})})]}),g.jsx("div",{className:V.metadataSectionCard,children:g.jsx(Zj,{description:_r,analysis:Er,recommendedActions:Nr,onDescriptionChange:T=>br(T||""),onAnalysisChange:T=>zn(T||""),onRecommendedActionsChange:T=>hn(T||""),onBack:()=>Jr("2a"),onDelete:oa,onSubmit:uo,onEditRatings:()=>kr(!1),isPerformanceConfirmed:pn,isSubmitting:p})})]})]})}),i===3&&g.jsxs("div",{className:V.successContainer,children:[g.jsx(Qi,{level:2,className:V.successHeading,children:"Saved!"}),g.jsx("p",{className:V.successText,children:e.get("contribute")==="true"?"Your contribution has been successfully saved.":"Your caption has been successfully saved."}),g.jsx("div",{className:V.successButton,children:g.jsx(Ue,{name:"upload-another",onClick:()=>{ti()},children:"Upload Another"})})]}),g.jsx(Qj,{isOpen:Ti,imageUrl:Kt,preview:m,selectedImageData:ji,onClose:()=>{Yr(!1),Kn(null)}}),g.jsx(Kj,{isOpen:Tr,onClose:()=>j(!1)}),g.jsx(Yj,{isOpen:R,onConfirm:Cu,onCancel:()=>z(!1)}),g.jsx(Xj,{isOpen:X,onConfirm:ni,onCancel:()=>le(!1)}),g.jsx(Jj,{isOpen:ye,fallbackInfo:ge,onClose:()=>we(!1)}),g.jsx(eP,{isOpen:Fe,preprocessingInfo:jt,onClose:()=>ze(!1)}),g.jsx(tP,{isOpen:Ze,preprocessingFile:Mn,isPreprocessing:Ln,preprocessingProgress:Pi,onConfirm:co,onCancel:Su}),g.jsx(nP,{isOpen:Bn,unsupportedFile:Xr,onClose:()=>gn(!1)}),g.jsx(rP,{isOpen:it,oversizedFile:jr,onClose:()=>_t(!1),onCancel:()=>_t(!1)})]})}const iP="_helpContainer_1wavj_1",oP="_helpSection_1wavj_13",aP="_sectionHeader_1wavj_49",sP="_sectionTitle_1wavj_91",lP="_sectionContent_1wavj_105",uP="_guidelinesList_1wavj_119",cP="_buttonContainer_1wavj_181",ft={helpContainer:iP,helpSection:oP,sectionHeader:aP,sectionTitle:sP,sectionContent:lP,guidelinesList:uP,buttonContainer:cP};function dP(){const e=cs(),{setShowReferenceExamples:n}=qj(),i=()=>{e("/upload")},o=()=>{n(!0),e("/explore")},s=()=>{e("/analytics?view=crisis_maps")};return g.jsx(Gf,{className:"py-10",children:g.jsx("div",{className:ft.helpContainer,children:g.jsxs("div",{className:"space-y-8",children:[g.jsxs("div",{className:ft.helpSection,children:[g.jsx("div",{className:ft.sectionHeader,children:g.jsx(Qi,{level:3,className:ft.sectionTitle,children:"Introduction"})}),g.jsx("div",{className:ft.sectionContent,children:"In collaboration with the IFRC, PromptAid Vision is a tool that generates textual descriptions of crisis maps/crisis drone images utiliing Visual language models. This prototype is for collecting data for the fine-tuning of our own models. We aim to utilize AI tools to support national societies with rapid decision making during emergencies."}),g.jsx("div",{className:ft.buttonContainer,children:g.jsx(Ue,{name:"upload-now",variant:"secondary",onClick:i,children:"Upload now β†’"})})]}),g.jsxs("div",{className:ft.helpSection,children:[g.jsx("div",{className:ft.sectionHeader,children:g.jsx(Qi,{level:3,className:ft.sectionTitle,children:"Guidelines"})}),g.jsxs("div",{className:ft.sectionContent,children:["To make the process smoother, please follow the guidelines below:",g.jsxs("ul",{className:ft.guidelinesList,children:[g.jsx("li",{children:"Avoid uploading images that are not crisis maps/crisis drone images."}),g.jsx("li",{children:"Confirm the image details prior to modifying the description."}),g.jsx("li",{children:"Before the modification, please read the description generated and provide a rating via the rating sliders."}),g.jsx("li",{children:'Click the "Submit" button to save the description.'})]})]}),g.jsx("div",{className:ft.buttonContainer,children:g.jsx(Ue,{name:"see-examples",variant:"secondary",onClick:o,children:"See examples β†’"})})]}),g.jsxs("div",{className:ft.helpSection,children:[g.jsx("div",{className:ft.sectionHeader,children:g.jsx(Qi,{level:3,className:ft.sectionTitle,children:"VLMs"})}),g.jsx("div",{className:ft.sectionContent,children:"PromptAid Vision uses a variety of Visual Language Models (VLMs). A random VLM is selected for each upload. Therefore feel free to delete and reupload. You can view performance details here:"}),g.jsx("div",{className:ft.buttonContainer,children:g.jsx(Ue,{name:"view-vlm-details",variant:"secondary",onClick:s,children:"View VLM details β†’"})})]}),g.jsxs("div",{className:ft.helpSection,children:[g.jsx("div",{className:ft.sectionHeader,children:g.jsx(Qi,{level:3,className:ft.sectionTitle,children:"Dataset"})}),g.jsx("div",{className:ft.sectionContent,children:"All users are able to export the dataset. You could apply filters when exporting, and it have the option to organize based on model fine-tuning formats."}),g.jsx("div",{className:ft.buttonContainer,children:g.jsx(Ue,{name:"export-dataset",variant:"secondary",onClick:()=>{n(!1),e("/explore"),setTimeout(()=>{const u=document.querySelector('[name="export-dataset"]');u&&u.click()},100)},children:"Export dataset β†’"})})]}),g.jsxs("div",{className:ft.helpSection,children:[g.jsx("div",{className:ft.sectionHeader,children:g.jsx(Qi,{level:3,className:ft.sectionTitle,children:"Contact us"})}),g.jsx("div",{className:ft.sectionContent,children:"Need help or have questions about PromptAid Vision? Our team is here to support you."}),g.jsx("div",{className:ft.buttonContainer,children:g.jsx(Ue,{name:"contact-support",variant:"secondary",disabled:!0,children:"Get in touch β†’"})})]})]})})})}const fP=v.createContext(void 0),hP=({children:e})=>{const[n,i]=v.useState(!1),[o,s]=v.useState(!0),u=async()=>{const y=localStorage.getItem("adminToken");if(!y){i(!1),s(!1);return}try{(await fetch("/api/admin/verify",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${y}`}})).ok?i(!0):(localStorage.removeItem("adminToken"),i(!1))}catch(w){console.error("Error verifying admin token:",w),localStorage.removeItem("adminToken"),i(!1)}finally{s(!1)}},d=async y=>{try{const w=await fetch("/api/admin/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:y})});if(w.ok){const C=await w.json();return localStorage.setItem("adminToken",C.access_token),i(!0),!0}else return!1}catch(w){return console.error("Login error:",w),!1}},f=()=>{localStorage.removeItem("adminToken"),i(!1)};v.useEffect(()=>{u()},[]);const p={isAuthenticated:n,isLoading:o,login:d,logout:f,verifyToken:u};return g.jsx(fP.Provider,{value:p,children:e})},pP=v.lazy(()=>Zn(()=>import("./index-Dx7kXGv5.js"),__vite__mapDeps([0,1]))),mP=v.lazy(()=>Zn(()=>import("./index-DjbXFoDc.js"),__vite__mapDeps([2,3,4,5,6]))),gP=v.lazy(()=>Zn(()=>import("./AdminPage-QC43WsfP.js"),__vite__mapDeps([7,3,8]))),vP=v.lazy(()=>Zn(()=>import("./index-B4LyeOKz.js"),__vite__mapDeps([9,3,4,5,10])));class yP extends v.Component{constructor(n){super(n),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,i){console.error("Error caught by boundary:",n,i)}render(){return this.state.hasError?g.jsxs("div",{style:{padding:"20px",textAlign:"center"},children:[g.jsx("h2",{children:"Something went wrong"}),g.jsx("p",{children:"Please refresh the page to try again."}),g.jsx("button",{onClick:()=>window.location.reload(),children:"Refresh Page"})]}):this.props.children}}const wi=e=>{const n=e();return n.catch(()=>{}),n},wP=()=>{"requestIdleCallback"in window?requestIdleCallback(()=>{wi(()=>Zn(()=>import("./index-Dx7kXGv5.js"),__vite__mapDeps([0,1]))),wi(()=>Zn(()=>import("./index-DjbXFoDc.js"),__vite__mapDeps([2,3,4,5,6]))),wi(()=>Zn(()=>import("./AdminPage-QC43WsfP.js"),__vite__mapDeps([7,3,8]))),wi(()=>Zn(()=>import("./index-B4LyeOKz.js"),__vite__mapDeps([9,3,4,5,10])))}):setTimeout(()=>{wi(()=>Zn(()=>import("./index-Dx7kXGv5.js"),__vite__mapDeps([0,1]))),wi(()=>Zn(()=>import("./index-DjbXFoDc.js"),__vite__mapDeps([2,3,4,5,6]))),wi(()=>Zn(()=>import("./AdminPage-QC43WsfP.js"),__vite__mapDeps([7,3,8]))),wi(()=>Zn(()=>import("./index-B4LyeOKz.js"),__vite__mapDeps([9,3,4,5,10])))},1e3)},xP=vx([{element:g.jsx(LT,{}),children:[{path:"/",element:g.jsx(Fg,{})},{path:"/upload",element:g.jsx(Fg,{})},{path:"/analytics",element:g.jsx(v.Suspense,{fallback:g.jsx("div",{children:"Loading Analytics..."}),children:g.jsx(pP,{})})},{path:"/explore",element:g.jsx(v.Suspense,{fallback:g.jsx("div",{children:"Loading Explore..."}),children:g.jsx(mP,{})})},{path:"/help",element:g.jsx(dP,{})},{path:"/admin",element:g.jsx(v.Suspense,{fallback:g.jsx("div",{children:"Loading Admin..."}),children:g.jsx(gP,{})})},{path:"/map/:mapId",element:g.jsx(v.Suspense,{fallback:g.jsx("div",{children:"Loading Map Details..."}),children:g.jsx(vP,{})})}]}],{basename:"/"});function CP(){const[e,n]=v.useState([]);v.useEffect(()=>{wP()},[]);const i=v.useCallback(f=>{n(p=>Bx([...p,f],y=>y.name)??p)},[n]),o=v.useCallback(f=>{n(p=>{const y=p.findIndex(C=>C.name===f);if(y===-1)return p;const w=[...p];return w.splice(y,1),w})},[n]),s=v.useCallback((f,p)=>{n(y=>{const w=y.findIndex(m=>m.name===f);if(w===-1)return y;const C=[...y];return C[w]={...C[w],...p},C})},[n]),u=v.useMemo(()=>({alerts:e,addAlert:i,removeAlert:o,updateAlert:s}),[e,i,o,s]),d=v.useMemo(()=>({languageNamespaceStatus:{},setLanguageNamespaceStatus:()=>{},currentLanguage:"en",setCurrentLanguage:()=>{},strings:{},setStrings:()=>{},registerNamespace:()=>{}}),[]);return g.jsx(yP,{children:g.jsx(Fx.Provider,{value:u,children:g.jsx(i0.Provider,{value:d,children:g.jsx(hP,{children:g.jsx(Vj,{children:g.jsx(Nx,{router:xP})})})})})})}function SP(){return g.jsx(CP,{})}console.log("React version at runtime:",v.version,"createContext exists?",!!v.createContext);V1.createRoot(document.getElementById("root")).render(g.jsx(v.StrictMode,{children:g.jsx(SP,{})}));export{bC as A,Ko as B,EP as C,qj as D,TP as E,uf as F,Zn as G,Qi as H,V as I,Wi as J,bP as K,bT as L,Qj as M,Gf as N,Tt as O,jC as P,PP as Q,u0 as R,TC as S,c0 as T,jP as U,Mg as V,fP as W,_P as X,zg as Y,$o as _,$e as a,Mt as b,DP as c,OP as d,NP as e,SC as f,s0 as g,LP as h,MP as i,g as j,sr as k,qx as l,FE as m,Ue as n,Oe as o,Zx as p,Ga as q,v as r,l0 as s,i0 as t,Dx as u,PC as v,MC as w,cs as x,kP as y,ar as z};
py_backend/static/assets/{jszip.min-C3B0d4UO.js β†’ jszip.min-Bux5isNr.js} RENAMED
@@ -1,4 +1,4 @@
1
- import{X as bt,Y as It}from"./index-BCz4bkWK.js";function vt(yt){throw new Error('Could not dynamically require "'+yt+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var kt={exports:{}};/*!
2
 
3
  JSZip v3.10.1 - A JavaScript class for generating and reading zip files
4
  <http://stuartk.com/jszip>
 
1
+ import{X as bt,Y as It}from"./index-RA4UIF3R.js";function vt(yt){throw new Error('Could not dynamically require "'+yt+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var kt={exports:{}};/*!
2
 
3
  JSZip v3.10.1 - A JavaScript class for generating and reading zip files
4
  <http://stuartk.com/jszip>
py_backend/static/assets/{useAdmin-LSEnRjVv.js β†’ useAdmin-k5gw6w_T.js} RENAMED
@@ -1 +1 @@
1
- import{r,W as e}from"./index-BCz4bkWK.js";const o=()=>{const t=r.useContext(e);if(t===void 0)throw new Error("useAdmin must be used within an AdminProvider");return t};export{o as u};
 
1
+ import{r,W as e}from"./index-RA4UIF3R.js";const o=()=>{const t=r.useContext(e);if(t===void 0)throw new Error("useAdmin must be used within an AdminProvider");return t};export{o as u};
py_backend/static/index.html CHANGED
@@ -42,7 +42,7 @@
42
  });
43
  }
44
  </script>
45
- <script type="module" crossorigin src="/assets/index-BCz4bkWK.js"></script>
46
  <link rel="stylesheet" crossorigin href="/assets/index-FBu17hMI.css">
47
  </head>
48
  <body>
 
42
  });
43
  }
44
  </script>
45
+ <script type="module" crossorigin src="/assets/index-RA4UIF3R.js"></script>
46
  <link rel="stylesheet" crossorigin href="/assets/index-FBu17hMI.css">
47
  </head>
48
  <body>