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