1import{u as Ie,b as rt,_ as st,r as a,j as r,L as He,ae as A,ab as It,a6 as Tt,D as Et,P as Pt,M as Lt,bm as Dt}from"./index-SfRhvKf7.js";import{P as Ot}from"./PageBreadCrumb-DJvkjCSc.js";import{u as _t,h as Ft,d as $t}from"./myRequestsBadges-CgnZufmW.js";import{g as Bt}from"./buttonStyles-B3V8uqct.js";import{S as Ye}from"./close-KMS4O4-C.js";import{S as ot}from"./pencil-DVePWa1x.js";import{S as Kt}from"./inbox-B5JRhvcJ.js";import{S as Gt}from"./funnel-B1JtbtOn.js";import{S as at}from"./camera-BwPkgJ9T.js";import{S as nt}from"./location2-Di5pvMbZ.js";import{m as Qt,h as Ut}from"./RequestService-DUDcHUju.js";import{T as ge}from"./TaxonomyService-rHPMNHt5.js";import"./firebase-TSw-wn12.js";import{R as zt,a as Re}from"./request-card-v3-skeleton-jhOiA_4R.js";import Ht from"./OpenDocumentCopyRequestsMapWidget-COr0Msp-.js";import{u as Yt}from"./useQuestionsListTranslation-CO_dlGne.js";import{n as Vt}from"./TranslationService-BWHQ5BpU.js";import{j as Jt}from"./api-DxQaTkkU.js";import{g as Wt}from"./ArchiveService-BEfy8p9J.js";import{S as Ve}from"./SearchableMultiSelect-C723LdFD.js";import{G as Xt}from"./GenealogyTopic-B40AyUIl.js";import"./calender-line-BET5OKKt.js";import"./pin-Denya4F3.js";import"./bank-CNkDLRjo.js";import"./useUserById-BNZiC8hR.js";import"./useTermLabels-B5MeO3zU.js";import"./useBids-D1fwK0QU.js";import"./ResearcherOfferLimitService-CNP8oHgl.js";import"./priceFormatting-TQRxgBeY.js";import"./request-BjJmmtz9.js";import"./DocumentType-DfzLkOxU.js";import"./format-C52v1Gph.js";import"./forumPriceBadge-tm6TIHdC.js";import"./repositoryCurrency-DOoHkR5x.js";import"./requestAuthorName-CpK6k-3N.js";import"./chevron-right-C3pavqAe.js";import"./worldMill-CLJuVFem.js";import"./QnABidService-B8LAO679.js";import"./serviceUrls-CUa-KURh.js";const Zt=()=>{const{t:e}=Ie(),{user:o}=rt(),{questions:n}=st(),{requests:d,loading:f}=_t(o?.uid??null),l=a.useMemo(()=>Ft(o?.uid,d,n),[o?.uid,d,n]),c=o&&!f&&l,y=a.useMemo(()=>$t(o?.uid,d,n),[o?.uid,d,n]);return r.jsxs("div",{className:"mb-4 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[r.jsx("div",{className:"max-w-2xl flex-1",children:r.jsx("p",{className:"text-lg text-gray-700 dark:text-gray-300 leading-relaxed",children:e("forum.intro","Ask the genealogy community for help, offer your expertise, or hire a local specialist to retrieve archive records")})}),r.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-shrink-0 sm:flex-row sm:items-center",children:[c&&r.jsx("div",{className:"forum-request-rainbow-border relative isolate overflow-hidden rounded-lg p-px",children:r.jsx(He,{to:"/my-requests",className:"relative z-10 block w-full sm:w-auto",children:r.jsxs("div",{className:"inline-flex h-11 w-full items-center justify-center gap-2 rounded-[calc(theme(borderRadius.lg)-1px)] bg-white px-5 text-sm font-medium leading-none text-gray-700 transition-all duration-150 hover:bg-green-50 hover:shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-green-500 focus-visible:ring-offset-2 focus-visible:ring-offset-white active:scale-[0.98] dark:bg-gray-900 dark:text-gray-200 dark:hover:bg-gray-900 sm:w-auto dark:focus-visible:ring-offset-gray-900",children:[e("menu.myRequests","My Requests"),y>0&&r.jsx("span",{className:"inline-flex items-center rounded-full bg-green-500 px-2 py-0.5 text-xs font-semibold leading-none text-white",children:y})]})})}),r.jsx(He,{to:"/requests-hub",className:Bt({variant:"gradient",size:"md",fullWidth:!0,className:"gap-2 hover:scale-105 sm:w-auto"}),children:e("forum.actions.postRequest","Post a Request")})]})]})},er=[{id:"questions",labelKey:"forum.filters.questions",defaultLabel:"Questions",Icon:ot,selectedBg:"bg-gradient-to-br from-blue-500 to-indigo-600",unselectedIcon:"text-indigo-400 dark:text-indigo-500"},{id:"requests",labelKey:"forum.filters.reprography",defaultLabel:"Reprography",Icon:at,selectedBg:"bg-gradient-to-br from-emerald-500 to-teal-600",unselectedIcon:"text-teal-400 dark:text-teal-500"},{id:"all",labelKey:"forum.filters.allRequests",defaultLabel:"All Requests",Icon:Kt,selectedBg:"bg-gray-900 dark:bg-gray-100",selectedText:"text-white dark:text-gray-900",unselectedIcon:"text-gray-500"}],tr=({contentFilter:e,onContentFilterChange:o,researchQuestionsMode:n,onResearchQuestionsModeChange:d,documentCopyMode:f,onDocumentCopyModeChange:l,scopeQualityFilter:c="all",onScopeQualityFilterChange:y,preferencesActive:R=!1,onPreferencesToggle:M,preferencesDisabled:h=!1,showUseProfileInterests:j=!1,onUseProfileInterests:N,isLoadingLocation:K=!1,hasNearbyArchives:he=!1})=>{const{t:m}
1=Ie(),[ye,I]=a.useState(!1),[v,q]=a.useState(!1),O=a.useRef(e);a.useEffect(()=>{e!==O.current&&(e==="questions"&&I(!1),e==="requests"&&q(!1),O.current=e)},[e]);const Y=e==="questions",k=e==="requests",w=e==="questions"&&!ye,T=e==="requests"&&!v;return r.jsxs("div",{className:"bg-white dark:bg-white/[0.03] border border-gray-200 dark:border-gray-800 rounded-xl mb-6 overflow-hidden",children:[r.jsx("div",{className:"flex items-center gap-2 px-3 py-3",children:er.map(u=>{const x=e===u.id,E="selectedText"in u?u.selectedText:"text-white";return r.jsxs("button",{onClick:()=>o(u.id),"aria-pressed":x,className:`flex items-center flex-shrink-0 rounded-full transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 ${x?`${u.selectedBg} ${E} py-2 pl-3 pr-4 gap-1.5`:"bg-gray-100 dark:bg-gray-800 p-2.5"}`,children:[r.jsx(u.Icon,{className:`h-4 w-4 flex-shrink-0 transition-colors duration-200 ${x?E??"text-white":u.unselectedIcon}`}),r.jsx("span",{className:`overflow-hidden whitespace-nowrap text-sm font-semibold transition-all duration-200 ${x?"max-w-[160px] opacity-100":"max-w-0 opacity-0"}`,children:m(u.labelKey,u.defaultLabel)})]},u.id)})}),r.jsx("div",{className:`overflow-hidden transition-all duration-200 ${w?"max-h-28 opacity-100":"max-h-0 opacity-0"}`,"aria-hidden":!w,children:r.jsxs("div",{className:"mx-3 mb-3 flex items-start gap-3 rounded-xl bg-indigo-50 dark:bg-indigo-950/30 border border-indigo-100 dark:border-indigo-900/40 px-4 py-3",children:[r.jsx(ot,{className:"h-8 w-8 text-indigo-500 dark:text-indigo-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm font-semibold text-indigo-700 dark:text-indigo-300",children:m("forum.filterHelper.questions.title","Questions")}),r.jsx("p",{className:"text-sm text-indigo-600 dark:text-indigo-400 mt-0.5",children:m("forum.filterHelper.questions.text","Questions are research requests where someone needs help with genealogical research.")})]}),r.jsx("button",{onClick:()=>I(!0),"aria-label":m("common.dismiss","Dismiss"),className:"flex-shrink-0 text-indigo-400 hover:text-indigo-600 dark:text-indigo-500 dark:hover:text-indigo-300 transition-colors",children:r.jsx(Ye,{className:"h-4 w-4"})})]})}),r.jsx("div",{className:`overflow-hidden transition-all duration-200 ${T?"max-h-28 opacity-100":"max-h-0 opacity-0"}`,"aria-hidden":!T,children:r.jsxs("div",{className:"mx-3 mb-3 flex items-start gap-3 rounded-xl bg-emerald-50 dark:bg-emerald-950/30 border border-emerald-100 dark:border-emerald-900/40 px-4 py-3",children:[r.jsx(at,{className:"h-8 w-8 text-emerald-500 dark:text-emerald-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm font-semibold text-emerald-700 dark:text-emerald-300",children:m("forum.filterHelper.reprography.title","Reprography")}),r.jsx("p",{className:"text-sm text-emerald-600 dark:text-emerald-400 mt-0.5",children:m("forum.filterHelper.reprography.text","Reprography requests ask for scans or photos of records held by a repository.")})]}),r.jsx("button",{onClick:()=>q(!0),"aria-label":m("common.dismiss","Dismiss"),className:"flex-shrink-0 text-emerald-400 hover:text-emerald-600 dark:text-emerald-500 dark:hover:text-emerald-300 transition-colors",children:r.jsx(Ye,{className:"h-4 w-4"})})]})}),r.jsx("div",{className:`overflow-hidden transition-all duration-200 ${Y?"max-h-20 opacity-100":"max-h-0 opacity-0"}`,"aria-hidden":!Y,children:r.jsxs("div",{className:"flex flex-wrap items-center gap-3 border-t border-gray-100 dark:border-gray-800 px-4 py-3",children:[r.jsxs("div",{role:"group","aria-label":m("forum.filters.status","Status"),className:"inline-flex rounded-lg border border-gray-200 bg-white p-0.5 dark:border-gray-700 dark:bg-gray-800/60",children:[r.jsx("button",{onClick:()=>d("open"),className:`px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${n==="open"?"bg-brand-100 text-brand-700 dark:bg-brand-500/25 dark:text-brand-200":"text-gray-700 hover:bg-gray-50 dark:text-gray-200 dark:hover:bg-gray-700"}`,"aria-pressed":n==="open",children:m("forum.filters.open","Open")}),r.jsx("button",{onClick:()=>d("all"),className:`px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${n==="all"?"bg-brand-100 text-brand-700 dark:bg-brand-500/25 dark:text-brand-200":"text-gray-700 hover:bg-gray-50 dark:text-gray-200 dark:hover:bg-gray-700"}`,"aria-pressed":n==="all",children:m("forum.filters.all","All")})]}),y&&r.jsx("div",{role:"group","aria-label":m("qna.scopeQuality","Scope Quality"),className:"inline-flex rounded-lg border border-gray-200 bg-white p-0.5 dark:border-gray-700 dark:bg-gray-800/60",children:["all","paid"].map(u=>{const x=u==="all"?m("forum.filters.all","All"):m("qna.filterPaidOffers","Paid Offers");return r.jsx("button",{onClick:()=>y(u),className:`px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${c===u?"bg-emerald-100 text-emerald-700 dark:bg-emerald-500/25 dark:text-emerald-200":"text-gray-700 hover:bg-gray-50 dark:text-gray-200 dark:hover:bg-gray-700"}`,"aria-pressed":c===u,children:x},u)})}),M&&r.jsxs("button",{onClick:M,disabled:h,className:`flex items-center gap-2 rounded-lg border px-3 py-1.5 text-sm font-medium transition-colors ${R?"border-brand-300 bg-brand-100 text-brand-700 hover:bg-brand-200 dark:border-brand-500/50 dark:bg-brand-500/30 dark:text-brand-100":"border-gray-200 bg-white text-gray-700 hover:bg-gray-50 dark:border-gray-700 dark:bg-gray-800/60 dark:text-gray-200 dark:hover:bg-gray-700"} ${h?"cursor-not-allowed opacity-60":""}`,title:h?m("forum.preferences.signInRequired","Sign in to use interest filters"):m("forum.preferences.tooltip","Set Research Question region and topic filters"),children:[r.jsx(Gt,{className:`h-4 w-4 ${R?"text-brand-600 dark:text-brand-400":""}`}),r.jsx("span",{children:m("forum.preferences.label","My Filters")})]}),j&&N&&r.jsx("button",{type:"button",onClick:N,className:"text-sm font-medium text-brand-600 underline-offset-4 hover:underline dark:text-brand-400",children:m("forum.preferences.useProfileInterests","Use my profile interests")})]})}),r.jsx("div",{className:`overflow-hidden transition-all duration-200 ${k?"max-h-20 opacity-100":"max-h-0 opacity-0"}`,"aria-hidden":!k,children:r.jsx("div",{className:"flex flex-wrap items-center gap-3 border-t border-gray-100 dark:border-gray-800 px-4 py-3",children:r.jsxs("div",{role:"group","aria-label":m("forum.filters.location","
1Location"),className:"inline-flex rounded-lg border border-gray-200 bg-white p-0.5 dark:border-gray-700 dark:bg-gray-800/60",children:[r.jsx("button",{onClick:()=>l("all"),className:`px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${f==="all"?"bg-emerald-100 text-emerald-700 dark:bg-emerald-500/25 dark:text-emerald-200":"text-gray-700 hover:bg-gray-50 dark:text-gray-200 dark:hover:bg-gray-700"}`,"aria-pressed":f==="all",children:m("forum.filters.allRequests","All Requests")}),r.jsxs("button",{onClick:()=>l("nearMe"),disabled:K,className:`near-me-attention-trigger inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${f==="nearMe"?"bg-emerald-100 text-emerald-700 dark:bg-emerald-500/25 dark:text-emerald-200":"text-gray-700 hover:bg-gray-50 dark:text-gray-200 dark:hover:bg-gray-700"} ${K?"cursor-wait opacity-70":""}`,"aria-pressed":f==="nearMe",title:m("forum.nearMe.tooltip","Show document requests from archives near you"),children:[K?r.jsx("span",{className:"inline-flex h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}):r.jsx(nt,{"data-testid":"near-me-icon",className:`h-4 w-4 ${f!=="nearMe"?"animate-near-me-compass":""} ${f==="nearMe"&&he?"text-emerald-600 dark:text-emerald-300":""}`}),r.jsx("span",{children:m("forum.nearMe.label","Near Me")})]})]})})})]})},Je="adsbygoogle-loader",rr=({publisherId:e,slotId:o,testMode:n=!1,className:d,style:f})=>{const l=a.useRef(null);return a.useEffect(()=>{if(A.log("[GoogleAdSenseAd] Component mounted",{publisherId:e?`${e.substring(0,15)}...`:"N/A",slotId:o?`${o.substring(0,10)}...`:"N/A",testMode:n,hasAdRef:!!l.current}),typeof window>"u")return;if(!e||!o||!l.current){A.warn("[GoogleAdSenseAd] Missing required props or ref",{hasPublisherId:!!e,hasSlotId:!!o,hasAdRef:!!l.current});return}const y=(()=>{const j=document.getElementById(Je);if(j)return j;const N=document.createElement("script");return N.id=Je,N.src=`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${e}`,N.async=!0,N.crossOrigin="anonymous",document.head.appendChild(N),N})(),R=()=>{if(l.current)try{A.log("[GoogleAdSenseAd] Pushing ad to adsbygoogle",{adsbyGoogleLength:window.adsbygoogle?.length??0}),l.current.innerHTML="",window.adsbygoogle=window.adsbygoogle||[],window.adsbygoogle.push({}),A.log("[GoogleAdSenseAd] Ad pushed successfully")}catch(j){A.error("[GoogleAdSenseAd] AdSense push error:",j)}};if(y.getAttribute("data-adsbygoogle-loaded")==="true"){R();return}const M=()=>{y.setAttribute("data-adsbygoogle-loaded","true"),R()},h=j=>{A.error("[GoogleAdSenseAd] Script failed to load:",j)};return y.addEventListener("load",M),y.addEventListener("error",h),()=>{y.removeEventListener("load",M),y.removeEventListener("error",h)}},[e,o,n]),!e||!o?null:r.jsx("ins",{ref:l,className:`adsbygoogle block ${d??""}`.trim(),style:{display:"block",minHeight:"250px",...f},"data-ad-client":e,"data-ad-slot":o,"data-ad-format":"auto","data-full-width-responsive":"true","data-adtest":n?"on":void 0})},H=20,We=.621371,pe=e=>{if(e instanceof Date)return e;if(e&&typeof e=="object"&&"toDate"in e&&typeof e.toDate=="function"){const o=e.toDate();return o instanceof Date?o:null}return null},je=e=>{const o=pe(e.createdAt);if(o)return o.getTime();const n=pe(e.dateSubmitted);if(n)return n.getTime();const d=pe(e.updatedAt);return d?d.getTime():0},sr=e=>{const o=Ut(e);return o?o.getTime():pe(e.createdAt)?.getTime()??0},Ae="forum_near_me_enabled",Xe="forum_near_me_coords",or="forum_research_question_filters_v1",ar=["research_region","region"],nr="topic",ir=new Set(["REQUESTED","ASSIGNED"]),Te=e=>{const o=e;return e.type==="REPROGRAPHY"&&!!o.archiveRepositoryId},Ze=e=>Te(e)?e.archiveRepositoryId:e.repositoryId??e.id,lr=e=>Te(e)&&e.archiveRepositoryName?.trim()?e.archiveRepositoryName.trim():e.repositoryName?.trim()?e.repositoryName.trim():"Unknown repository",dr=e=>!ir.has(e),B=e=>{if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){const o=Number(e);if(Number.isFinite(o))return o}return null},cr=e=>{const o=e,n=B(o.distanceKm)??B(o.distance_km);if(n!==null)return n;const d=B(o.distanceMiles)??B(o.distance_miles);if(d!==null)return d/We;const f=B(o.distance);return f===null?null:(typeof o.distanceUnit=="string"?o.distanceUnit.toLowerCase():"").startsWith("mi")?f/We:f},ur=(e,o)=>{const n=M=>M*Math.PI/180,f=n(o.latitude-e.latitude),l=n(o.longitude-e.longitude),c=n(e.latitude),y=n(o.latitude),R=Math.sin(f/2)*Math.sin(f/2)+Math.sin(l/2)*
1Math.sin(l/2)*Math.cos(c)*Math.cos(y);return 2*6371*Math.atan2(Math.sqrt(R),Math.sqrt(1-R))},mr=e=>{if(!e)return null;try{const o=JSON.parse(e),n=B(o.latitude),d=B(o.longitude);return n===null||d===null?null:{latitude:n,longitude:d}}catch{return null}},it=e=>`${or}:${e}`,fr=e=>{try{const o=localStorage.getItem(it(e));if(!o)return null;const n=JSON.parse(o);return!Array.isArray(n.regions)||!n.regions.every(d=>typeof d=="string")||!Array.isArray(n.topics)||!n.topics.every(d=>typeof d=="string")?null:{regions:n.regions,topics:n.topics}}catch{return null}},Me=(e,o)=>{try{localStorage.setItem(it(e),JSON.stringify(o))}catch{}},et=(e,o)=>{const n=new Set(e),d=new Set(o);return n.size===d.size&&Array.from(n).every(f=>d.has(f))},gr=e=>{const o=(e??"en").split("-")[0];return["en","fr","es","de","it","nl"].includes(o)?o:"en"},pr=e=>e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").replace(/^#+\s*/,"").trim().toLowerCase(),U=e=>{const o=pr(e);if(!o)return[];const n=o.replace(/\s+/g,"-").replace(/_+/g,"-"),d=o.replace(/[-_]+/g," ").replace(/\s+/g," ");return Array.from(new Set([o,n,d]))},Ce=(e,o)=>{for(const n of U(o.id))e.add(n);for(const n of U(o.slug))e.add(n);for(const n of Object.values(o.labels))for(const d of U(n))e.add(d)},tt=(e,o,n)=>{if(o.size===0)return!0;if(!e)return!1;const d=new Set;for(const c of U(e))d.add(c);const f=e.trim().toLowerCase(),l=n.get(f);l&&Ce(d,l);for(const c of d)if(o.has(c))return!0;return!1},hr=e=>e==="all"||e==="questions"||e==="requests"||e==="myActivity"?e:"all",rs=()=>{const{t:e,i18n:o}=Ie(),n=It(),{questions:d,loading:f}=st(),{user:l,firestoreUser:c,loading:y}=rt(),{isCountryAvailable:R,isRepositoryAvailable:M}=Tt(),{settings:h}=Et(),j=a.useMemo(()=>{const t=new URLSearchParams(n.search);return hr(t.get("filter"))},[n.search]),[N,K]=a.useState([]),[he,m]=a.useState(!0),[ye,I]=a.useState("all"),[v,q]=a.useState("open"),[O,Y]=a.useState("all"),[k,w]=a.useState("all"),[T,u]=a.useState(!1),[x,E]=a.useState(1);a.useEffect(()=>{switch(j){case"questions":I("questions"),q("open"),w("hide"),u(!1);break;case"requests":I("requests"),q("hide"),w("all"),u(!1);break;case"myActivity":I("myActivity"),q("open"),w("all"),u(!!l?.uid);break;case"all":default:I("all"),q("open"),w("all"),u(!1);break}},[j,l?.uid]);const[xe,be]=a.useState(!1),[V,Ee]=a.useState(()=>new Set),[ve,lt]=a.useState(()=>mr(localStorage.getItem(Xe))),[Pe,J]=a.useState(null),[Le,W]=a.useState(new Map),[dt,X]=a.useState(!1),[De,_]=a.useState(null),[ke,Oe]=a.useState(!1),[Z,ct]=a.useState([]),[ee,ut]=a.useState([]),[G,te]=a.useState([]),[Q,re]=a.useState([]),[mt,_e]=a.useState(null),we=a.useRef(null),[se,oe]=a.useState([]),[ae,ne]=a.useState([]);a.useEffect(()=>{let t=!0;return(async()=>{m(!0);try{const i=await Qt(l?.uid??null);t&&K(i)}catch(i){console.error("Failed to load forum requests",i),t&&K([])}finally{t&&m(!1)}})(),()=>{t=!1}},[l?.uid]),a.useEffect(()=>{c?.nearbyArchiveIds&&c.nearbyArchiveIds.length>0&&Ee(new Set(c.nearbyArchiveIds))},[c?.nearbyArchiveIds]);const P=a.useMemo(()=>c?.preferredResearchRegions??[],[c?.preferredResearchRegions]),L=a.useMemo(()=>c?.preferredResearchTopics??[],[c?.preferredResearchTopics]);a.useEffect(()=>{if(y)return;const t=l?.uid;if(!t){te([]),re([]),_e(null),we.current=null;return}if(c?.id!==t||we.current===t)return;const s=fr(t),i=s??{regions:P,topics:L};te(i.regions),re(i.topics),_e(t),we.current=t,s||Me(t,i)},[y,l?.uid,c?.id,P,L]);const Fe=a.useCallback(async()=>{Oe(!0),_(null);try{const t=[];for(const b of ar){const p=await ge.getVocabularyByKey(b);if(!p)continue;const z=await ge.listTerms(p.id,!1);t.push(...z.filter(Ct=>Ct.status==="active"))}const s=Array.from(new Map(t.map(b=>[b.id,b])).values()),i=await ge.getVocabularyByKey(nr);if(!i)throw new Error("Topic vocabulary unavailable");const g=await ge.listTerms(i.id,!1),C=new Set(Xt.map(b=>b.tag)),S=g.filter(b=>b.status==="active"&&C.has(b.slug));ct(s),ut(S)}catch(t){A.error("[Forum] Failed to load preference terms",t),_(e("forum.preferences.loadError","Could not load filter options."))}finally{Oe(!1)}},[e]);a.useEffect(()=>{Fe()},[Fe]);const $e=a.useCallback(async()=>xe?{success:!1}:navigator?.geolocation?(be(!0),J(null),await new Promise(t=>{navigator.geolocation.getCurrentPosition(s=>{const i={latitude:s.coords.latitude,longitude:s.coords.longitude};(async()=>{try{const S=(await Jt(i,100)).filter(M).map(b=>b.id).filter(b=>!!b);Ee(new Set(S)),lt(i),localStorage.setItem(Xe,JSON.stringify(i)),l?.uid&&await Dt(l.uid,S),w("nearMe"),localStorage.setItem(Ae,"true"),t({success:!0})}catch(C){A.error("[Forum] Error fetching nearby archives:",C),J(e("forum.nearMe.error","Could not find nearby archives. Please try again.")),t({success:!1})}finally{be(!1)}})()},s=>{A.error("[Forum] Error getting user location:",s),J(e("forum.nearMe.locationError","Could not access your location. Please enable location sharing and try again.")),be(!1),t({success:!1})},{enableHighAccuracy:!0,timeout:1e4})})):(J(e("forum.nearMe.notSupported","Your browser does not support location access.")),{success:!1}),[xe,M,e,l?.uid]),ft=a.useCallback(t=>{if(w(t),t==="nearMe"){localStorage.setItem(Ae,"true"),$e();return}localStorage.setItem(Ae,"false")},[$e]),gt=a.useCallback(t=>{switch(I(t),E(1),t){case"all":u(!1),q(s=>s==="hide"?"open":s),w(s=>s==="hide"?"all":s);break;case"questions":u(!1),w("hide"),q(s=>s==="hide"?"open":s);break;case"requests":u(!1),q("hide"),w(s=>s==="hide"?"all":s);break;case"myActivity":u(!0),q(s=>s==="hide"?"open":s),w(s=>s==="hide"?"all":s);break}},[]),pt=a.useCallback(()=>{l?.uid&&(oe(G),ne(Q),_(null),X(!0))},[l?.uid,G,Q]),ht=a.useCallback(()=>{oe([]),ne([]),_(null)},[]),yt=a.useCallback(()=>{l?.uid&&(_(null),te(se),re(ae),Me(l.uid,{regions:se,topics:ae}),X(!1))},[l?.uid,se,ae]),xt=a.useCallback(()=>{l?.uid&&(te(P),re(L),oe(P),ne(L),Me(l.uid,{regions:P,topics:L}))},[l?.uid,P,L]),bt=Vt(o.language)??"en",Be=Yt(d,bt,!1),ie=gr(o.language),Ke=a.useMemo(()=>{const t=d.map(i=>({id:i.id,type:"question",createdAtMs:sr(i),question:i})),s=N.map(i=>({id:i.id,type:"request",createdAtMs:je(i),request:i}));return[...t,...s].sort((i,g)=>g.createdAtMs-i.createdAtMs)},[d,N]),vt=a.useMemo(()=>Z.map(t=>({value:t.id,text:t.labels?.[ie]||t.labels?.en||t.slug})),[Z,ie]),kt=a.useMemo(()=>ee.map(t=>({value:t.id,text:t.labels?.[ie]||t.labels?.en||t.slug})),[ee,ie]),le=a.useMemo(()=>{const t=new Map;for(const s of Z)t.set(s.id.toLowerCase(),s),t.set(s.slug.toLowerCase(),s);return t},[Z]),de=a.useMemo(()=>{const t=new Map;for(const s of ee)t.set(s.id.toLowerCase(),s),t.set(s.slug.toLowerCase(),s);return t},[ee]),Ge=a.useMemo(()=>{const t=new Set;for(const s of G){for(const g of U(s))t.add(g);const i=le.get(s.toLowerCase());i&&Ce(t,i)}return t},[G,le]),Qe=a.useMemo(()=>{const t=new Set;for(const s of Q){for(const g of U(s))t.add(g);const i=de.get(s.toLowerCase());i&&Ce(t,i)}return t},[Q,de]),ce=G.length>0||Q.length>0,wt=P.length>0||L.length>0,St=et(G,P)&&et(Q,L),Nt=mt===l?.uid&&wt&&!St,qt=t=>t.archiveRepositoryId||void 0,D=a.useMemo(()=>Ke.filter(t=>{if(t.type==="question"){if(v==="hide"||v==="open"&&t.question.status!=="OPEN"&&!t.question.requestRejection||O==="paid"&&!t.question.openForPaidOffers)return!1;if(ce){const s=t.question.tags?.region,i=t.question.tags?.topic;if(!tt(s,Ge,le)||!tt(i,Qe,de))return!1}}else{if(t.request.status==="REJECTED"||k==="hide")return!1;if(k==="nearMe"){if(!R(t.request.countryISOA3??""))return!1;const s=qt(t.request);if(V.size===0||!s||!V.has(s))return!1}}return T?l?.uid?t.type==="question"?c?.role==="admin"||t.question.userId===l.uid:t.request.requestorId===l.uid||t.request.serviceProviderId===l.uid:!1:!0}
1),[Ke,l?.uid,c?.role,k,R,V,v,O,T,ce,Ge,Qe,le,de]);a.useEffect(()=>{E(1)},[v,k,O,T,ce]);const ue=a.useMemo(()=>D.flatMap(t=>{if(t.type!=="request")return[];const s=t.request;return t.request.type!=="REPROGRAPHY"||!s.archiveRepositoryId?[]:[t.request]}),[D]),F=v==="hide"&&k!=="hide";a.useEffect(()=>{if(!F){W(new Map);return}const t=Array.from(new Set(ue.map(g=>Ze(g)).filter(g=>!!g)));if(t.length===0){W(new Map);return}let s=!0;return(async()=>{try{const g=await Wt(t);if(!s)return;const C=new Map;g.forEach(S=>{C.set(S.id,S)}),W(C)}catch(g){A.error("[Forum] Failed to load archives for grouped document-copy view",g),s&&W(new Map)}})(),()=>{s=!1}},[F,ue]);const me=a.useMemo(()=>{if(!F)return[];const t=new Map;return D.forEach(s=>{if(s.type!=="request"||!Te(s.request))return;const i=Ze(s.request),g=t.get(i);if(g){g.requests.push(s.request);return}t.set(i,{repositoryName:lr(s.request),requests:[s.request]})}),Array.from(t.entries()).map(([s,i])=>{const g=[...i.requests].sort((p,z)=>je(z)-je(p)),C=g.every(p=>dr(p.status)),S=g.map(p=>cr(p)).filter(p=>p!==null&&Number.isFinite(p));if(S.length===0){const p=Le.get(s);p&&ve&&typeof p.latitude=="number"&&typeof p.longitude=="number"&&Number.isFinite(p.latitude)&&Number.isFinite(p.longitude)&&S.push(ur(ve,{latitude:p.latitude,longitude:p.longitude}))}const b=S.length>0?S.reduce((p,z)=>p+z,0)/S.length:null;return{repositoryId:s,repositoryName:i.repositoryName,requests:g,isClosed:C,averageDistanceKm:b}}).sort((s,i)=>s.isClosed!==i.isClosed?s.isClosed?-1:1:s.averageDistanceKm===null&&i.averageDistanceKm!==null?1:s.averageDistanceKm!==null&&i.averageDistanceKm===null?-1:s.averageDistanceKm!==null&&i.averageDistanceKm!==null?s.averageDistanceKm-i.averageDistanceKm:s.repositoryName.localeCompare(i.repositoryName))},[F,D,Le,ve]),Ue=F?me.length:D.length,$=Math.max(1,Math.ceil(Ue/H));a.useEffect(()=>{x>$&&E($)},[x,$]);const Rt=a.useMemo(()=>{const t=(x-1)*H;return D.slice(t,t+H)},[x,D]),jt=a.useMemo(()=>{const t=(x-1)*H;return me.slice(t,t+H)},[x,me]),At=a.useMemo(()=>T?e("forum.empty.myActivity","No activity found for your account."):v==="hide"&&k==="hide"?e("forum.empty.hidden","No filters active."):v==="hide"?k==="nearMe"?e("forum.nearMe.noNearbyRequests","No document requests found near your location."):e("forum.empty.requests","No document copy requests found."):k==="hide"?v==="open"?e("forum.empty.open","No open items found."):e("forum.empty.questions","No questions found."):v==="open"?e("forum.empty.open","No open items found."):e("forum.empty.all","No forum items found."),[T,v,k,e]),Se=f||he,Ne=!!h?.adsenseSlotId,fe=!!h?.adsEnabled,ze=!Se&&ue.length>0,qe=c?.role==="admin",Mt=F?me.length===0:D.length===0;return a.useEffect(()=>{A.log("[Forum] Ads Debug Info:",{adsEnabled:h?.adsEnabled,shouldShowAds:fe,adsConfigured:Ne,hasSlotId:!!h?.adsenseSlotId,slotId:h?.adsenseSlotId?`${h.adsenseSlotId.substring(0,10)}...`:"N/A",testMode:h?.adsenseTestMode,publisherIdNote:"Publisher ID is hardcoded in index.html",isAdmin:qe})},[h,fe,Ne,qe]),r.jsxs(r.Fragment,{children:[r.jsx(Pt,{title:e("menu.requests","Requests"),description:e("forum.description","Browse genealogy discussions and document copy requests in one unified forum feed.")}),r.jsx(Ot,{pageTitle:e("menu.requests","Requests")}),r.jsxs("div",{className:"space-y-6",children:[r.jsxs("div",{children:[r.jsx(Zt,{}),r.jsx(tr,{contentFilter:ye,onContentFilterChange:gt,researchQuestionsMode:v,onResearchQuestionsModeChange:q,documentCopyMode:k,onDocumentCopyModeChange:ft,scopeQualityFilter:O,onScopeQualityFilterChange:Y,preferencesActive:ce,onPreferencesToggle:pt,preferencesDisabled:!l,showUseProfileInterests:Nt,onUseProfileInterests:xt,isLoadingLocation:xe,hasNearbyArchives:V.size>0}),Pe&&r.jsx("div",{className:"mb-4 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-700 dark:border-amber-900/40 dark:bg-amber-900/10 dark:text-amber-300",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(nt,{className:"h-4 w-4 mt-0.5 flex-shrink-0"}),r.jsx("span",{children:Pe})]})}),r.jsx(Lt,{isOpen:dt,onClose:()=>{X(!1)},className:"max-w-2xl",children:r.jsxs("div",{className:"p-6 space-y-5",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:e("forum.preferences.setupTitle","Set up My Filters")}),r.jsx("p",{className:"mt-1 text-sm text-gray-600 dark:text-gray-300",children:e("forum.preferences.setupDescription","Choose regions and topics for your Research Question filters. These filters are separate from interests saved in your profile.")})]}),r.jsx(Ve,{label:e("forum.preferences.regionsLabel","Region(s)"),options:vt,defaultSelected:se,onChange:t=>{oe(t),_(null)},disabled:ke,placeholder:e("forum.preferences.regionsPlaceholder","Select one or more regions")}),r.jsx(Ve,{label:e("forum.preferences.topicsLabel","Topic(s)"),options:kt,defaultSelected:ae,onCh
1ange:t=>{ne(t),_(null)},disabled:ke,placeholder:e("forum.preferences.topicsPlaceholder","Select one or more topics")}),(De||ke)&&r.jsx("p",{className:"text-sm text-amber-600 dark:text-amber-400",children:De||e("forum.preferences.loadingTerms","Loading filters...")}),r.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[r.jsx("button",{type:"button",onClick:ht,className:"rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-60 dark:border-gray-700 dark:text-gray-200 dark:hover:bg-gray-800",children:e("common.reset","Reset")}),r.jsx("button",{type:"button",onClick:()=>X(!1),className:"rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-60 dark:border-gray-700 dark:text-gray-200 dark:hover:bg-gray-800",children:e("common.cancel","Cancel")}),r.jsx("button",{type:"button",onClick:yt,className:"inline-flex items-center gap-2 rounded-lg bg-brand-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-70",children:e("common.apply","Apply")})]})]})})]}),r.jsxs("div",{className:"flex flex-col md:flex-row gap-6",children:[r.jsxs("div",{className:"flex-1",children:[Se?r.jsx("div",{className:"space-y-3",children:Array.from({length:3},(t,s)=>r.jsx(zt,{loadingLabel:e("common.loading","Loading...")},s))}):Mt?r.jsx("div",{className:"p-6 text-center text-gray-500",children:At}):F?r.jsx("div",{className:"space-y-5",children:jt.map(t=>r.jsxs("section",{className:"space-y-3",children:[r.jsx("div",{className:"px-1 py-1",children:r.jsx("div",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:t.repositoryName})}),r.jsx("div",{className:"space-y-3",children:t.requests.map(s=>r.jsx(Re,{kind:"document",request:s},`request-${s.id}`))})]},t.repositoryId))}):r.jsx("div",{className:"space-y-3",children:Rt.map(t=>t.type==="question"?r.jsx(Re,{kind:"question",question:t.question,translatedTitle:Be.getTranslatedTitle(t.question.id),isTranslating:Be.isTranslating(t.question.id)},`question-${t.id}`):r.jsx(Re,{kind:"document",request:t.request},`request-${t.id}`))}),!Se&&Ue>0&&$>1&&r.jsxs("div",{className:"mt-6 flex items-center justify-between rounded-xl border border-gray-200 bg-white px-4 py-3 dark:border-gray-800 dark:bg-white/[0.03]",children:[r.jsx("button",{onClick:()=>E(t=>Math.max(1,t-1)),disabled:x===1,className:"rounded-lg border border-gray-200 px-3 py-1.5 text-sm text-gray-700 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-700 dark:text-gray-200 dark:hover:bg-gray-800",children:e("forum.pagination.previous","Previous")}),r.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-300",children:e("forum.pagination.page","Page {{current}} of {{total}}",{current:x,total:$})}),r.jsx("button",{onClick:()=>E(t=>Math.min($,t+1)),disabled:x===$,className:"rounded-lg border border-gray-200 px-3 py-1.5 text-sm text-gray-700 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-700 dark:text-gray-200 dark:hover:bg-gray-800",children:e("forum.pagination.next","Next")})]})]}),(ze||fe)&&r.jsxs("div",{className:"md:w-96 lg:w-[42rem] shrink-0 space-y-4",children:[ze&&r.jsx(Ht,{requests:ue}),fe&&r.jsxs("div",{className:"sticky top-24 border rounded-xl p-4 bg-white dark:bg-white/[0.03] dark:border-gray-800",children:[r.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 mb-2",children:e("common.advertisement","Advertisement")}),Ne?r.jsx(rr,{publisherId:h?.adsensePublisherId??"",slotId:h?.adsenseSlotId??"",testMode:h?.adsenseTestMode??!0,className:"mx-auto",style:{minHeight:"320px"}}):r.jsxs("div",{className:"bg-gray-100 dark:bg-gray-800 rounded-lg flex flex-col items-center justify-center gap-2 px-4 py-10 text-center",children:[r.jsx("span",{className:"text-gray-500 dark:text-gray-400 text-sm",children:e("common.adPlaceholder","Ad space reserved")}),qe&&r.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:e("forum.ads.configure","Configure AdSense Slot ID in Admin â Ads Setup to display live ads.")})]})]})]})]})]})]})};export{rs as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.