Spaces:
Running
Running
| const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jszip.min-DHOAM-1s.js","assets/index-oPRJTRcN.js","assets/index-DkIjYZRi.css"])))=>i.map(i=>d[i]); | |
| import{H as Xe,v as Ye,j as a,N as X,n as T,r as g,x as ea,_ as ve,L as aa,z as E,I as se,J as ie,D as ta,K as sa,B as ia}from"./index-oPRJTRcN.js";import{u as na}from"./useAdmin-DytkUHQc.js";import{F as oa,E as ra}from"./ExportModal-CrJtybXx.js";const la="_tabSelector_usssr_1",ca="_imageContainer_usssr_12",da="_imagePlaceholder_usssr_33",ga="_metadataTags_usssr_45",ma="_metadataTag_usssr_45",ua="_captionContainer_usssr_67",pa="_captionText_usssr_74",fa="_gridLayout_usssr_131",ha="_detailsSection_usssr_155",_a="_loadingContainer_usssr_161",xa="_errorContainer_usssr_171",ya="_fullSizeModalOverlay_usssr_205",va="_fullSizeModalContent_usssr_219",wa="_ratingWarningContent_usssr_230",Ca="_ratingWarningTitle_usssr_236",ja="_ratingWarningText_usssr_243",Ia="_ratingWarningButtons_usssr_250",Na="_carouselContainer_usssr_365",ba="_carouselImageWrapper_usssr_370",Sa="_carouselImage_usssr_370",La="_carouselNavigation_usssr_393",Da="_carouselButton_usssr_405",ka="_carouselIndicators_usssr_429",Ma="_carouselIndicator_usssr_429",Ta="_carouselIndicatorActive_usssr_458",Fa="_singleImageContainer_usssr_488",Ea="_viewImageButtonContainer_usssr_494",p={tabSelector:la,imageContainer:ca,imagePlaceholder:da,metadataTags:ga,metadataTag:ma,captionContainer:ua,captionText:pa,gridLayout:fa,detailsSection:ha,loadingContainer:_a,errorContainer:xa,fullSizeModalOverlay:ya,fullSizeModalContent:va,ratingWarningContent:wa,ratingWarningTitle:Ca,ratingWarningText:ja,ratingWarningButtons:Ia,carouselContainer:Na,carouselImageWrapper:ba,carouselImage:Sa,carouselNavigation:La,carouselButton:Da,carouselIndicators:ka,carouselIndicator:Ma,carouselIndicatorActive:Ta,singleImageContainer:Fa,viewImageButtonContainer:Ea};function at(){const{mapId:u}=Xe(),y=Ye(),{isAuthenticated:ne}=na();console.log("MapDetailsPage: Current URL:",window.location.href),console.log("MapDetailsPage: Hash:",window.location.hash),console.log("MapDetailsPage: mapId from useParams:",u),console.log("MapDetailsPage: mapId type:",typeof u),console.log("MapDetailsPage: mapId length:",u?.length),console.log("MapDetailsPage: mapId value:",JSON.stringify(u));const we=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;if(!u||u==="undefined"||u==="null"||u.trim()===""||!we.test(u))return a.jsx(X,{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 = "',u,'" (type: ',typeof u,")"]}),a.jsx(T,{name:"back-to-explore",variant:"secondary",onClick:()=>y("/explore"),children:"Return to Explore"})]})});const[oe,Ce]=g.useState("mapDetails"),[e,Y]=g.useState(null),[W,P]=g.useState(!0),[re,O]=g.useState(null),[le,je]=g.useState([]),[ce,Ie]=g.useState([]),[de,Ne]=g.useState([]),[ge,be]=g.useState([]),[Se,Le]=g.useState([]),[De,ke]=g.useState(!1),[Me,Te]=g.useState(!1),[B,q]=g.useState(!1),[Fe,G]=g.useState(!1),[me,K]=g.useState(!1),[Ee,ee]=g.useState(!1),[Re,ae]=g.useState(!1),[Ra,$a]=g.useState("standard"),[R,Pa]=g.useState(80),[J,Aa]=g.useState(10),[za,Oa]=g.useState(10),[Ua,Wa]=g.useState(!0),[Ba,Ja]=g.useState(!0),[Z,Q]=g.useState(!1),[$e,ue]=g.useState(!1),[Pe,pe]=g.useState(null),[D,H]=g.useState([]),[A,z]=g.useState(0),[V,fe]=g.useState(!1),{search:d,setSearch:Ha,srcFilter:v,setSrcFilter:Va,catFilter:w,setCatFilter:qa,regionFilter:C,setRegionFilter:Ga,countryFilter:j,setCountryFilter:Ka,imageTypeFilter:I,setImageTypeFilter:Za,uploadTypeFilter:N,setUploadTypeFilter:Qa,showReferenceExamples:k,setShowReferenceExamples:Ae,clearAllFilters:ze}=ea(),Oe=[{key:"explore",label:"List"},{key:"mapDetails",label:"Carousel"}],he=g.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"),P(!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"),P(!1);return}console.log("fetchMapData: Making API call for id:",t),q(!0),P(!0);try{const f=await fetch(`/api/images/${t}`);if(!f.ok)throw new Error("Map not found");const s=await f.json();if(Y(s),s.all_image_ids&&s.all_image_ids.length>1)await _e(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 _e(r.all_image_ids):(H([s]),z(0))}else H([s]),z(0)}catch(l){console.error("Failed to fetch from grouped endpoint:",l),H([s]),z(0)}}else H([s]),z(0);await te(t)}catch(f){O(f instanceof Error?f.message:"Unknown error occurred")}finally{P(!1),q(!1)}},[]),_e=g.useCallback(async t=>{console.log("fetchAllImages called with imageIds:",t),fe(!0);try{const o=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()}),f=await Promise.all(o);H(f),z(0),console.log("fetchAllImages: Loaded",f.length,"images")}catch(o){console.error("fetchAllImages error:",o),O(o instanceof Error?o.message:"Failed to load all images")}finally{fe(!1)}},[]),Ue=g.useCallback(()=>{D.length>1&&z(t=>t>0?t-1:D.length-1)},[D.length]),We=g.useCallback(()=>{D.length>1&&z(t=>t<D.length-1?t+1:0)},[D.length]),Be=g.useCallback(t=>{t>=0&&t<D.length&&z(t)},[D.length]),xe=g.useCallback(t=>{const o=t||(D.length>0?D[A]:e);o&&(pe(o),ue(!0))},[D,A,e]),Je=g.useCallback(()=>{ue(!1),pe(null)},[]);g.useEffect(()=>{if(console.log("MapDetailsPage: mapId from useParams:",u),console.log("MapDetailsPage: mapId type:",typeof u),console.log("MapDetailsPage: mapId value:",u),!u||u==="undefined"||u==="null"||u.trim()===""||u===void 0||u===null){console.log("MapDetailsPage: Invalid mapId, setting error"),O("Map ID is required"),P(!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(u)){console.log("MapDetailsPage: Invalid UUID format:",u),O("Invalid Map ID format"),P(!1);return}console.log("MapDetailsPage: Fetching data for mapId:",u),he(u)},[u,he]),g.useEffect(()=>{if(!e||W||Z)return;if(!u||u==="undefined"||u==="null"||u.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(u)){console.log("Auto-navigation skipped: Invalid mapId format");return}(()=>{const f=!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=!v||e.source===v,l=!w||e.event_type===w,i=!C||e.countries.some(M=>M.r_code===C),r=!j||e.countries.some(M=>M.c_code===j),c=!I||e.image_type===I,n=!k||e.starred===!0,x=f&&s&&l&&i&&r&&c&&n;return console.log("Auto-navigation check:",{mapId:u,search:d,srcFilter:v,catFilter:w,regionFilter:C,countryFilter:j,imageTypeFilter:I,showReferenceExamples:k,matchesSearch:f,matchesSource:s,matchesCategory:l,matchesRegion:i,matchesCountry:r,matchesImageType:c,matchesReferenceExamples:n,matches:x}),x})()||(console.log("Current map does not match filters, looking for first matching item"),fetch("/api/images").then(f=>f.json()).then(f=>{console.log("Auto-navigation: Received images from API:",f.length),console.log("Auto-navigation: First few images:",f.slice(0,3).map(l=>({image_id:l.image_id,title:l.title})));const s=f.find(l=>{const i=!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=!v||l.source===v,c=!w||l.event_type===w,n=!C||l.countries?.some(m=>m.r_code===C),x=!j||l.countries?.some(m=>m.c_code===j),M=!I||l.image_type===I,S=!k||l.starred===!0;return i&&r&&c&&n&&x&&M&&S});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!==u&&(/^[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),y(`/map/${s.image_id}`)):console.error("Auto-navigation blocked: Invalid image_id format:",s.image_id))}).catch(console.error))},[e,d,v,w,C,j,I,k,u,y,W,Z]);const te=async t=>{if(!(!t||t==="undefined"||t==="null"||t.trim()===""))try{const o=await fetch("/api/images/grouped");if(o.ok){const s=(await o.json()).filter(i=>{const r=!d||i.title?.toLowerCase().includes(d.toLowerCase())||i.generated?.toLowerCase().includes(d.toLowerCase())||i.source?.toLowerCase().includes(d.toLowerCase())||i.event_type?.toLowerCase().includes(d.toLowerCase()),c=!v||i.source===v,n=!w||i.event_type===w,x=!C||i.countries?.some(_=>_.r_code===C),M=!j||i.countries?.some(_=>_.c_code===j),S=!I||i.image_type===I,m=!N||N==="single"&&(!i.image_count||i.image_count<=1)||N==="multiple"&&i.image_count&&i.image_count>1,b=!k||i.starred===!0;return r&&c&&n&&x&&M&&S&&m&&b}),l=s.findIndex(i=>i.image_id===t);ke(s.length>1&&l>0),Te(s.length>1&&l<s.length-1)}}catch(o){console.error("Failed to check navigation availability:",o)}},ye=async t=>{if(!B){q(!0);try{const o=await fetch("/api/images/grouped");if(o.ok){const f=await o.json(),s=f.filter(n=>{const x=!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()),M=!v||n.source===v,S=!w||n.event_type===w,m=!C||n.countries?.some($=>$.r_code===C),b=!j||n.countries?.some($=>$.c_code===j),_=!I||n.image_type===I,L=!N||N==="single"&&(!n.image_count||n.image_count<=1)||N==="multiple"&&n.image_count&&n.image_count>1,U=!k||n.starred===!0;return x&&M&&S&&m&&b&&_&&L&&U});if(s.findIndex(n=>n.image_id===u)===-1){const n=f.find(x=>x.image_id===u);n&&s.push(n)}const i=s.findIndex(n=>n.image_id===u);if(i===-1){console.error("Current image not found in filtered list");return}let r;t==="previous"?r=i>0?i-1:s.length-1:r=i<s.length-1?i+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),y(`/map/${c.image_id}`)):console.error("Carousel navigation blocked: Invalid image_id format:",c.image_id))}}catch(o){console.error("Failed to navigate to item:",o)}finally{q(!1)}}};g.useEffect(()=>{e&&u&&!W&&!Z&&te(u)},[e,u,d,v,w,C,j,I,N,k,W,Z,te]),g.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,o,f,s,l])=>{je(t),Ie(o),Ne(f),be(s),Le(l)}).catch(console.error)},[]);const He=async()=>{e&&G(!0)},Ve=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?Y(o=>o?{...o,starred:!o.starred}:null):console.error("Failed to toggle starred status")}catch(t){console.error("Error toggling starred status:",t)}},qe=async()=>{if(e){Q(!0);try{if(console.log("Deleting image with ID:",e.image_id),(await fetch(`/api/images/${e.image_id}`,{method:"DELETE"})).ok){Y(o=>o?{...o,starred:!o.starred}:null),G(!1);try{const o=await fetch("/api/images/grouped");if(o.ok){const s=(await o.json()).filter(i=>{const r=!d||i.title?.toLowerCase().includes(d.toLowerCase())||i.generated?.toLowerCase().includes(d.toLowerCase())||i.source?.toLowerCase().includes(d.toLowerCase())||i.event_type?.toLowerCase().includes(d.toLowerCase()),c=!v||i.source===v,n=!w||i.event_type===w,x=!C||i.countries?.some(_=>_.r_code===C),M=!j||i.countries?.some(_=>_.c_code===j),S=!I||i.image_type===I,m=!N||N==="single"&&(!i.image_count||i.image_count<=1)||N==="multiple"&&i.image_count&&i.image_count>1,b=!k||i.starred===!0;return r&&c&&n&&x&&M&&S&&m&&b}),l=s.filter(i=>i.image_id!==e.image_id);if(l.length>0){const i=s.findIndex(c=>c.image_id===e.image_id);let r;if(i===s.length-1?r=i-1:r=i,console.log("Navigation target:",{currentIndex:i,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),y(`/map/${c.image_id}`)):(console.error("Navigation blocked: Invalid image_id format:",c.image_id),y("/explore")):(console.error("Navigation blocked: Invalid image_id:",c?.image_id),y("/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),y(`/map/${l[0].image_id}`)):(console.error("Fallback navigation blocked: Invalid image_id format:",l[0].image_id),y("/explore")):(console.log("No valid remaining items, going to explore page"),y("/explore"))}else console.log("No remaining items, going to explore page"),y("/explore")}else y("/explore")}catch(o){console.error("Failed to navigate to next item:",o),y("/explore")}finally{Q(!1)}}else console.error("Delete failed"),Q(!1)}catch(t){console.error("Delete failed:",t),Q(!1)}}},h=g.useMemo(()=>{if(!e)return null;if(!d&&!v&&!w&&!C&&!j&&!I&&!N&&!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()),o=!v||e.source===v,f=!w||e.event_type===w,s=!C||e.countries.some(x=>x.r_code===C),l=!j||e.countries.some(x=>x.c_code===j),i=!I||e.image_type===I,r=!N||N==="single"&&(!e.image_count||e.image_count<=1)||N==="multiple"&&e.image_count&&e.image_count>1,c=!k||e.starred===!0,n=t&&o&&f&&s&&l&&i&&r&&c;return!n&&(d||v||w||C||j||I||N||k)?(setTimeout(()=>{Ge()},100),e):n?e:null},[e,d,v,w,C,j,I,N,k]),Ge=g.useCallback(async()=>{P(!0);try{const t=await fetch("/api/images/grouped");if(t.ok){const f=(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()),i=!v||s.source===v,r=!w||s.event_type===w,c=!C||s.countries?.some(m=>m.r_code===C),n=!j||s.countries?.some(m=>m.c_code===j),x=!I||s.image_type===I,M=!N||N==="single"&&(!s.image_count||s.image_count<=1)||N==="multiple"&&s.image_count&&s.image_count>1,S=!k||s.starred===!0;return l&&i&&r&&c&&n&&x&&M&&S});if(f.length>0){const s=f[0];s&&s.image_id&&y(`/map/${s.image_id}`)}else y("/explore")}}catch(t){console.error("Failed to navigate to matching image:",t),y("/explore")}finally{P(!1)}},[d,v,w,C,j,I,N,k,y]),Ke=()=>{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(",")}`;y(s);return}const o=`/upload?step=1&contribute=true&imageIds=${e.all_image_ids.join(",")}`;y(o)},F=(t,o)=>({image:`images/${o}`,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}}),Ze=async t=>{if(e){ee(!0),ae(!1);try{const o=(await ia(async()=>{const{default:r}=await import("./jszip.min-DHOAM-1s.js").then(c=>c.j);return{default:r}},__vite__mapDeps([0,1,2]))).default,f=new o;if(e.image_type==="crisis_map"){const r=f.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],x=n.map(async(m,b)=>{try{const _=await fetch(`/api/images/${m}/file`);if(!_.ok)throw new Error(`Failed to fetch image ${m}`);const L=await _.blob(),U=e.file_key.split(".").pop()||"jpg",$=`0001_${String(b+1).padStart(2,"0")}.${U}`;return c.file($,L),{success:!0,fileName:$,imageId:m}}catch(_){return console.error(`Failed to process image ${m}:`,_),{success:!1,fileName:"",imageId:m}}}),S=(await Promise.all(x)).filter(m=>m.success);if(S.length===0)throw new Error("No images could be processed");if(t==="fine-tuning"){const m=[],b=[],_=[],L=S.map(Qe=>`images/${Qe.fileName}`),U=Math.random(),$={image:L.length===1?L[0]:L,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?m.push($):U<(R+J)/100?b.push($):_.push($),r&&(r.file("train.jsonl",JSON.stringify(m,null,2)),r.file("test.jsonl",JSON.stringify(b,null,2)),r.file("val.jsonl",JSON.stringify(_,null,2)))}else{const m=S.map(_=>`images/${_.fileName}`),b={image:m.length===1?m[0]:m,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(b,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=f.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 x=await n.blob(),S=`0001.${e.file_key.split(".").pop()||"jpg"}`;if(c.file(S,x),t==="fine-tuning"){const m=[],b=[],_=[];if(String(e?.image_type)==="crisis_map"){const L=Math.random();L<R/100?m.push(F(e,"0001")):L<(R+J)/100?b.push(F(e,"0001")):_.push(F(e,"0001"))}else if(String(e?.image_type)==="drone_image"){const L=Math.random();L<R/100?m.push(F(e,"0001")):L<(R+J)/100?b.push(F(e,"0001")):_.push(F(e,"0001"))}r&&(r.file("train.jsonl",JSON.stringify(m,null,2)),r.file("test.jsonl",JSON.stringify(b,null,2)),r.file("val.jsonl",JSON.stringify(_,null,2)))}else{const m={image:`images/${S}`,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(m,null,2))}}catch(n){throw console.error(`Failed to process image ${e.image_id}:`,n),n}}else{const r=f.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 x=await n.blob(),S=`0001.${e.file_key.split(".").pop()||"jpg"}`;if(c.file(S,x),t==="fine-tuning"){const m=[],b=[],_=[];if(String(e?.image_type)==="crisis_map"){const L=Math.random();L<R/100?m.push(F(e,"0001")):L<(R+J)/100?b.push(F(e,"0001")):_.push(F(e,"0001"))}else if(String(e?.image_type)==="drone_image"){const L=Math.random();L<R/100?m.push(F(e,"0001")):L<(R+J)/100?b.push(F(e,"0001")):_.push(F(e,"0001"))}r&&(r.file("train.jsonl",JSON.stringify(m,null,2)),r.file("test.jsonl",JSON.stringify(b,null,2)),r.file("val.jsonl",JSON.stringify(_,null,2)))}else{const m={image:`images/${S}`,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(m,null,2))}}catch(n){throw console.error(`Failed to process image ${e.image_id}:`,n),n}}const s=await f.generateAsync({type:"blob"}),l=URL.createObjectURL(s),i=document.createElement("a");i.href=l,i.download=`dataset_${e.image_type}_${e.image_id}_${t}_${new Date().toISOString().split("T")[0]}.zip`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(l),console.log(`Exported ${e.image_type} dataset with 1 image in ${t} mode`),ae(!0)}catch(o){console.error("Export failed:",o),alert("Failed to export dataset. Please try again.")}finally{ee(!1)}}};return W?a.jsx(X,{children:a.jsx("div",{className:p.loadingContainer,children:a.jsxs("div",{className:"flex flex-col items-center gap-4",children:[a.jsx(ve,{className:"text-ifrcRed"}),a.jsx("div",{children:"Loading map details..."})]})})}):re||!e?a.jsx(X,{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:re||"Map not found"}),a.jsx(T,{name:"back-to-explore",variant:"secondary",onClick:()=>y("/explore"),children:"Return to Explore"})]})})}):a.jsxs(X,{children:[a.jsxs("div",{className:"max-w-7xl mx-auto",children:[a.jsxs("div",{className:p.tabSelector,children:[a.jsx(aa,{name:"map-details-view",value:oe,onChange:t=>{(t==="mapDetails"||t==="explore")&&(Ce(t),t==="explore"&&y("/explore"))},options:Oe,keySelector:t=>t.key,labelSelector:t=>t.label}),a.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[a.jsx(E,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:a.jsxs(T,{name:"reference-examples",variant:k?"primary":"secondary",onClick:()=>Ae(!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(T,{name:"export-dataset",variant:"secondary",onClick:()=>K(!0),children:"Export"})]})]}),a.jsx(oa,{sources:le,types:ce,regions:ge,countries:Se,imageTypes:de,isLoadingFilters:!1}),oe==="mapDetails"?a.jsx("div",{className:"relative",children:h?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:p.gridLayout,children:[a.jsxs(E,{heading:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{children:h.title||"Map Image"}),h.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||D.length>1?a.jsxs("div",{className:p.carouselContainer,children:[a.jsx("div",{className:p.carouselImageWrapper,children:V?a.jsxs("div",{className:p.imagePlaceholder,children:[a.jsx(ve,{className:"text-ifrcRed"}),a.jsx("div",{children:"Loading images..."})]}):D[A]?.image_url?a.jsx("img",{src:D[A].image_url,alt:D[A].file_key,className:p.carouselImage}):a.jsx("div",{className:p.imagePlaceholder,children:"No image available"})}),a.jsxs("div",{className:p.carouselNavigation,children:[a.jsx(T,{name:"previous-image",variant:"tertiary",size:1,onClick:Ue,disabled:V,className:p.carouselButton,children:a.jsx(se,{className:"w-4 h-4"})}),a.jsx("div",{className:p.carouselIndicators,children:D.map((t,o)=>a.jsx("button",{onClick:()=>Be(o),className:`${p.carouselIndicator} ${o===A?p.carouselIndicatorActive:""}`,disabled:V,children:o+1},o))}),a.jsx(T,{name:"next-image",variant:"tertiary",size:1,onClick:We,disabled:V,className:p.carouselButton,children:a.jsx(ie,{className:"w-4 h-4"})})]}),a.jsx("div",{className:p.viewImageButtonContainer,children:a.jsx(T,{name:"view-full-size-carousel",variant:"secondary",size:1,onClick:()=>xe(D[A]),disabled:V||!D[A]?.image_url,children:"View Image"})})]}):a.jsxs("div",{className:p.singleImageContainer,children:[h.image_url?a.jsx("img",{src:h.image_url,alt:h.file_key}):a.jsx("div",{className:p.imagePlaceholder,children:"No image available"}),a.jsx("div",{className:p.viewImageButtonContainer,children:a.jsx(T,{name:"view-full-size-single",variant:"secondary",size:1,onClick:()=>xe(h),disabled:!h.image_url,children:"View Image"})})]})}),a.jsx(E,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-md p-2",children:a.jsxs("div",{className:p.metadataTags,children:[h.image_type!=="drone_image"&&a.jsx("span",{className:p.metadataTag,children:le.find(t=>t.s_code===h.source)?.label||h.source}),a.jsx("span",{className:p.metadataTag,children:ce.find(t=>t.t_code===h.event_type)?.label||h.event_type}),a.jsx("span",{className:p.metadataTag,children:de.find(t=>t.image_type===h.image_type)?.label||h.image_type}),h.countries&&h.countries.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:p.metadataTag,children:ge.find(t=>t.r_code===h.countries[0].r_code)?.label||"Unknown Region"}),a.jsx("span",{className:p.metadataTag,children:h.countries.map(t=>t.label).join(", ")})]}),h.image_count&&h.image_count>1&&a.jsxs("span",{className:p.metadataTag,title:`Multi-upload with ${h.image_count} images`,children:["📷 ",h.image_count]}),(!h.image_count||h.image_count<=1)&&a.jsx("span",{className:p.metadataTag,title:"Single Upload",children:"Single"})]})})]}),a.jsx("div",{className:p.detailsSection,children:h.edited&&h.edited.includes("Description:")||h.generated&&h.generated.includes("Description:")?a.jsx(E,{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:(h.edited||h.generated||"").split(` | |
| `).map((t,o)=>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})},o))})})}):a.jsx(E,{heading:"Description",headingLevel:3,withHeaderBorder:!0,withInternalPadding:!0,spacing:"comfortable",children:a.jsx("div",{className:p.captionContainer,children:h.generated?a.jsx("div",{className:p.captionText,children:a.jsx("p",{children:h.edited||h.generated})}):a.jsx("p",{children:"— no caption yet —"})})})})]}),a.jsx("div",{className:"flex items-center justify-center mt-8",children:a.jsx(E,{withInternalPadding:!0,className:"bg-white/20 backdrop-blur-sm rounded-lg p-4",children:a.jsxs("div",{className:"flex items-center gap-4",children:[De&&a.jsx(E,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(T,{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:()=>ye("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(se,{className:"w-4 h-4"}),a.jsx(se,{className:"w-4 h-4"})]}),a.jsx("span",{className:"font-semibold",children:"Previous"})]})})}),ne&&a.jsx(E,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(T,{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:He,title:"Delete","aria-label":"Delete saved image",children:a.jsx(ta,{className:"w-4 h-4"})})}),a.jsx(E,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(T,{name:"contribute",onClick:Ke,children:"Contribute"})}),ne&&a.jsx(E,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(T,{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:Ve,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?"★":"☆"})})}),Me&&a.jsx(E,{withInternalPadding:!0,className:"rounded-md p-2",children:a.jsx(T,{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:()=>ye("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(ie,{className:"w-4 h-4"}),a.jsx(ie,{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(T,{name:"clear-filters",variant:"secondary",onClick:ze,children:"Clear Filters"})})]})}):null]}),Fe&&a.jsx("div",{className:p.fullSizeModalOverlay,onClick:()=>G(!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(T,{name:"confirm-delete",variant:"secondary",onClick:qe,children:"Delete"}),a.jsx(T,{name:"cancel-delete",variant:"tertiary",onClick:()=>G(!1),children:"Cancel"})]})]})})}),me&&a.jsx(ra,{isOpen:me,onClose:()=>{K(!1),ae(!1),ee(!1)},onExport:(t,o)=>{o.includes(e.image_type)&&Ze(t)},filteredCount:1,totalCount:1,hasFilters:!1,crisisMapsCount:e.image_type==="crisis_map"?1:0,droneImagesCount:e.image_type==="drone_image"?1:0,isLoading:Ee,exportSuccess:Re,variant:"single",onNavigateToList:()=>{K(!1),y("/explore")},onNavigateAndExport:()=>{K(!1),y("/explore?export=true")}}),a.jsx(sa,{isOpen:$e,imageUrl:Pe?.image_url||null,preview:null,selectedImageData:null,onClose:Je})]})}export{at as default}; | |