// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later // @source: https://gitlab.com/soapbox-pub/ditto/-/tree/f0a3877c import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{J as t,P as n,Ri as r,Sr as i,Yt as a,_n as o,a as s,br as c,bt as l,lr as u,mi as d,qi as f,wi as p}from"./lucide-icons-BdRF0moN.js";import{t as m}from"./jsx-runtime-By8HlURe.js";import{t as h}from"./useAppContext-Ughdk2-Z.js";import{t as g}from"./useLanguage-yd3vEXqu.js";import{t as _}from"./utils-BFSTDHdM.js";import{c as v,n as y}from"./chunk-62JRHF6Z-yJW_vgm4.js";import{t as b}from"./input-CM5Fnyvy.js";import{t as x}from"./skeleton-CVls4GW9.js";import{t as S}from"./WikipediaIcon-Dvm9f9D4.js";import{t as C}from"./wikimedia-CCPyM-j2.js";import{J as w,w as T}from"./index-CYEZWNq6.js";import{t as E}from"./useWikipediaFeatured-CTWYChC1.js";var D=e(f(),1),O=m(),k={featured:{label:`Featured`,icon:(0,O.jsx)(t,{className:`size-3.5`})},mostread:{label:`Trending`,icon:(0,O.jsx)(n,{className:`size-3.5`})},news:{label:`In the News`,icon:(0,O.jsx)(a,{className:`size-3.5`})},onthisday:{label:`On This Day`,icon:(0,O.jsx)(d,{className:`size-3.5`})}},A=[`featured`,`mostread`,`news`,`onthisday`];function j(e,t){return e.content_urls?.desktop?.page??`https://${t}.wikipedia.org/wiki/${e.title}`}function M(e){return`/i/${encodeURIComponent(e)}`}function N(e,t){return M(j(e,t))}function P(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}K`:String(e)}function F(e,t=150){return e.length<=t?e:e.slice(0,t).replace(/\s+\S*$/,``)+`…`}function I(e,t){let[n,r]=(0,D.useState)(A[0]),i=(0,D.useRef)(!1);return(0,D.useEffect)(()=>{let n=`-${(t.current?.offsetHeight??48)+8}px 0px -60% 0px`,a=new IntersectionObserver(e=>{if(i.current)return;let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top);if(t.length>0){let e=t[0].target.getAttribute(`data-section`);e&&r(e)}},{rootMargin:n,threshold:0});for(let t of A){let n=e[t].current;n&&a.observe(n)}return()=>a.disconnect()},[e,t]),{active:n,scrollTo:(0,D.useCallback)(n=>{let a=e[n].current;if(!a)return;let o=t.current?.offsetHeight??48,s=a.getBoundingClientRect().top+window.scrollY-o-8;i.current=!0,r(n),window.scrollTo({top:s,behavior:`smooth`}),setTimeout(()=>{i.current=!1},800)},[e,t])}}function L({section:e,active:t,onClick:n}){let r=k[e],i=(0,D.useRef)(null);return(0,D.useEffect)(()=>{t&&i.current&&i.current.scrollIntoView({behavior:`smooth`,inline:`center`,block:`nearest`})},[t]),(0,O.jsxs)(`button`,{ref:i,type:`button`,onClick:n,className:_(`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-sm font-medium transition-all duration-200 whitespace-nowrap shrink-0`,t?`bg-primary text-primary-foreground shadow-sm`:`bg-secondary/60 text-muted-foreground hover:bg-secondary hover:text-foreground`),children:[r.icon,r.label]})}function R({page:e,badge:t,badgeIcon:n}){let{locale:r}=g();return(0,O.jsxs)(y,{to:N(e,r),className:`group block rounded-2xl border border-border overflow-hidden bg-card hover:border-primary/30 transition-all duration-300 hover:shadow-lg hover:shadow-primary/5`,children:[(0,O.jsxs)(`div`,{className:`relative aspect-[4/3] overflow-hidden bg-gradient-to-br from-blue-500/10 to-indigo-500/10`,children:[e.thumbnail?(0,O.jsx)(`img`,{src:e.thumbnail.source,alt:e.normalizedtitle,loading:`lazy`,className:`absolute inset-0 w-full h-full object-cover group-hover:scale-105 transition-transform duration-500`,onError:e=>{e.currentTarget.style.display=`none`},decoding:`async`}):(0,O.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,O.jsx)(S,{className:`size-10 text-muted-foreground/20`})}),t&&(0,O.jsxs)(`div`,{className:`absolute top-2 right-2 px-2 py-0.5 rounded-md bg-black/60 backdrop-blur-sm text-white text-xs font-medium flex items-center gap-1`,children:[n,t]})]}),(0,O.jsxs)(`div`,{className:`p-3 space-y-1`,children:[(0,O.jsx)(`h3`,{className:`font-semibold text-sm leading-tight group-hover:text-primary transition-colors line-clamp-1`,children:e.normalizedtitle??e.titles?.normalized??e.title.replace(/_/g,` `)}),(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2`,children:e.description??F(e.extract)})]})]})}function z({page:e}){let{locale:n}=g();return(0,O.jsxs)(y,{to:N(e,n),className:`group block rounded-2xl border border-border overflow-hidden bg-card hover:border-primary/30 transition-all duration-300 hover:shadow-lg hover:shadow-primary/5`,children:[(0,O.jsx)(`div`,{className:`relative aspect-[16/9] overflow-hidden bg-gradient-to-br from-amber-500/10 to-orange-500/10`,children:e.thumbnail?(0,O.jsx)(`img`,{src:C(e.thumbnail.source,960,e.originalimage?.width),alt:e.normalizedtitle,loading:`lazy`,decoding:`async`,className:`absolute inset-0 w-full h-full object-cover group-hover:scale-105 transition-transform duration-500`,onError:e=>{e.currentTarget.style.display=`none`}}):(0,O.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,O.jsx)(t,{className:`size-12 text-muted-foreground/20`})})}),(0,O.jsxs)(`div`,{className:`p-4 space-y-2`,children:[(0,O.jsx)(`h3`,{className:`font-bold text-base leading-tight group-hover:text-primary transition-colors`,children:e.normalizedtitle??e.titles?.normalized??e.title.replace(/_/g,` `)}),(0,O.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed line-clamp-3`,children:F(e.extract,280)})]})]})}function B({event:e}){let{locale:t}=g(),n=e.pages[0];return(0,O.jsx)(`div`,{className:`rounded-2xl border border-border overflow-hidden bg-card`,children:(0,O.jsxs)(`div`,{className:`flex items-start gap-3 p-4`,children:[(0,O.jsx)(`div`,{className:`shrink-0 px-2.5 py-1 rounded-lg bg-primary/10 text-primary text-xs font-bold tabular-nums`,children:e.year}),(0,O.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-2`,children:[(0,O.jsx)(`p`,{className:`text-sm leading-relaxed`,children:e.text}),n&&(0,O.jsxs)(y,{to:N(n,t),className:`inline-flex items-center gap-1.5 text-xs text-primary hover:underline`,children:[(0,O.jsx)(p,{className:`size-3`}),n.normalizedtitle??n.title.replace(/_/g,` `)]})]}),n?.thumbnail&&(0,O.jsx)(y,{to:N(n,t),className:`shrink-0`,children:(0,O.jsx)(`img`,{src:n.thumbnail.source,alt:``,className:`w-14 h-14 rounded-lg object-cover`,loading:`lazy`,onError:e=>{e.currentTarget.style.display=`none`},decoding:`async`})})]})})}function V({item:e}){let{locale:t}=g(),n=(0,D.useMemo)(()=>e.story.replace(//g,``).replace(/<\/?[^>]+(>|$)/g,``).trim(),[e.story]),r=e.links[0];return(0,O.jsx)(`div`,{className:`rounded-2xl border border-border overflow-hidden bg-card`,children:(0,O.jsxs)(`div`,{className:`flex items-start gap-3 p-4`,children:[(0,O.jsx)(`div`,{className:`shrink-0 mt-0.5`,children:(0,O.jsx)(a,{className:`size-4 text-primary`})}),(0,O.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-2`,children:[(0,O.jsx)(`p`,{className:`text-sm leading-relaxed`,children:n}),r&&(0,O.jsxs)(y,{to:N(r,t),className:`inline-flex items-center gap-1.5 text-xs text-primary hover:underline`,children:[(0,O.jsx)(p,{className:`size-3`}),r.normalizedtitle??r.title.replace(/_/g,` `)]})]}),r?.thumbnail&&(0,O.jsx)(y,{to:N(r,t),className:`shrink-0`,children:(0,O.jsx)(`img`,{src:r.thumbnail.source,alt:``,className:`w-14 h-14 rounded-lg object-cover`,loading:`lazy`,onError:e=>{e.currentTarget.style.display=`none`},decoding:`async`})})]})})}function H(){let e=v(),t=(0,D.useRef)(null),n=(0,D.useRef)(null),[r,i]=(0,D.useState)(``),[a,c]=(0,D.useState)(``),[u,d]=(0,D.useState)(!1),f=(0,D.useRef)(void 0),{data:p,isFetching:m}=w(a),h=(0,D.useCallback)(e=>{i(e),clearTimeout(f.current),f.current=setTimeout(()=>{c(e.trim())},300)},[]);(0,D.useEffect)(()=>()=>clearTimeout(f.current),[]),(0,D.useEffect)(()=>{(a.length>=2&&p&&p.length>0||a.length>=2&&p&&p.length===0&&!m)&&d(!0)},[a,p,m]),(0,D.useEffect)(()=>{function e(e){n.current&&!n.current.contains(e.target)&&d(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let g=(0,D.useCallback)(n=>{i(``),c(``),d(!1),t.current?.blur(),e(M(n.url))},[e]),_=(0,D.useCallback)(()=>{i(``),c(``),d(!1),t.current?.focus()},[]),y=(0,D.useCallback)(e=>{e.key===`Escape`&&(d(!1),t.current?.blur()),e.key===`Enter`&&p&&p.length>0&&(e.preventDefault(),g(p[0]))},[p,g]);return(0,O.jsxs)(`div`,{ref:n,className:`relative px-4 pb-3`,children:[(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(l,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground pointer-events-none`}),(0,O.jsx)(b,{ref:t,type:`text`,placeholder:`Search Wikipedia...`,value:r,onChange:e=>h(e.target.value),onFocus:()=>{a.length>=2&&d(!0)},onKeyDown:y,className:`pl-9 pr-9 h-9 text-base md:text-sm rounded-full`}),r?(0,O.jsx)(`button`,{type:`button`,onClick:_,className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded-full text-muted-foreground hover:text-foreground hover:bg-secondary transition-colors`,children:(0,O.jsx)(s,{className:`size-3.5`})}):null]}),u&&a.length>=2&&(0,O.jsxs)(`div`,{className:`absolute left-4 right-4 top-full mt-1 z-50 bg-popover border border-border rounded-lg shadow-lg overflow-hidden`,children:[m&&(!p||p.length===0)?(0,O.jsx)(`div`,{className:`divide-y divide-border`,children:Array.from({length:4}).map((e,t)=>(0,O.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5`,children:[(0,O.jsx)(x,{className:`w-10 h-10 rounded shrink-0`}),(0,O.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-1`,children:[(0,O.jsx)(x,{className:`h-3.5 w-3/4`}),(0,O.jsx)(x,{className:`h-3 w-1/2`})]})]},t))}):p&&p.length>0?(0,O.jsx)(`div`,{className:`divide-y divide-border max-h-80 overflow-y-auto`,children:p.map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`flex items-center gap-3 px-3 py-2.5 w-full text-left hover:bg-secondary/60 transition-colors`,onClick:()=>g(e),children:[e.thumbnail?(0,O.jsx)(`img`,{src:e.thumbnail,alt:``,className:`w-10 h-10 rounded object-cover bg-secondary shrink-0`,loading:`lazy`,decoding:`async`}):(0,O.jsx)(`div`,{className:`w-10 h-10 rounded bg-gradient-to-br from-blue-500/10 to-indigo-500/10 flex items-center justify-center shrink-0`,children:(0,O.jsx)(S,{className:`size-4 text-muted-foreground/50`})}),(0,O.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,O.jsx)(`p`,{className:`text-sm font-medium truncate`,children:e.title}),(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:e.description})]})]},e.title))}):(0,O.jsxs)(`div`,{className:`px-4 py-6 text-center text-sm text-muted-foreground`,children:[`No results found for “`,a,`”`]}),m&&p&&p.length>0&&(0,O.jsx)(`div`,{className:`flex justify-center py-2 border-t border-border`,children:(0,O.jsx)(o,{className:`size-4 animate-spin text-muted-foreground`})})]})]})}function U({icon:e,title:t,subtitle:n}){return(0,O.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,O.jsx)(`div`,{className:`size-7 rounded-lg bg-primary/10 flex items-center justify-center`,children:e}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h2`,{className:`text-sm font-bold leading-tight`,children:t}),n&&(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]})]})}function W(){return(0,O.jsxs)(`div`,{className:`px-4 pt-4 pb-4 space-y-6`,children:[(0,O.jsxs)(`div`,{className:`rounded-2xl border border-border overflow-hidden bg-card`,children:[(0,O.jsx)(x,{className:`aspect-[16/9] w-full`}),(0,O.jsxs)(`div`,{className:`p-4 space-y-2`,children:[(0,O.jsx)(x,{className:`h-5 w-2/3`}),(0,O.jsx)(x,{className:`h-4 w-full`}),(0,O.jsx)(x,{className:`h-4 w-4/5`})]})]}),(0,O.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sidebar:grid-cols-3`,children:Array.from({length:6}).map((e,t)=>(0,O.jsxs)(`div`,{className:`rounded-2xl border border-border overflow-hidden bg-card`,children:[(0,O.jsx)(x,{className:`aspect-[4/3] w-full`}),(0,O.jsxs)(`div`,{className:`p-3 space-y-1`,children:[(0,O.jsx)(x,{className:`h-4 w-3/4`}),(0,O.jsx)(x,{className:`h-3 w-full`})]})]},t))}),(0,O.jsx)(`div`,{className:`space-y-3`,children:Array.from({length:3}).map((e,t)=>(0,O.jsx)(`div`,{className:`rounded-2xl border border-border p-4`,children:(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(x,{className:`w-10 h-6 rounded-lg`}),(0,O.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,O.jsx)(x,{className:`h-4 w-full`}),(0,O.jsx)(x,{className:`h-3 w-1/3`})]}),(0,O.jsx)(x,{className:`w-14 h-14 rounded-lg`})]})},t))})]})}function G(){let{config:e}=h(),{locale:o}=g(),{data:s,isLoading:l,isError:f}=E(),p=`https://${o}.wikipedia.org`;T({title:`Wikipedia | ${e.appName}`,description:`Explore today's featured Wikipedia content — trending articles, on this day, in the news, and more.`});let m=(0,D.useRef)(null),_=(0,D.useRef)(null),v=(0,D.useRef)(null),b=(0,D.useRef)(null),x=(0,D.useRef)(null),{active:C,scrollTo:w}=I({featured:_,mostread:v,news:b,onthisday:x},m),k=(0,D.useMemo)(()=>s?.mostread?.articles?s.mostread.articles.filter(e=>e.title!==`Main_Page`&&!e.title.startsWith(`Special:`)).slice(0,12):[],[s?.mostread?.articles]),j=(0,D.useMemo)(()=>s?.onthisday?s.onthisday.slice(0,8):[],[s?.onthisday]),M=(0,D.useMemo)(()=>s?.news??[],[s?.news]);return(0,O.jsxs)(`main`,{className:`pb-16 sidebar:pb-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-4 px-4 pt-4 pb-2`,children:[(0,O.jsx)(y,{to:`/`,className:`p-2 -ml-2 rounded-full hover:bg-secondary transition-colors sidebar:hidden`,children:(0,O.jsx)(r,{className:`size-5`})}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2.5 flex-1 min-w-0`,children:[(0,O.jsx)(`div`,{className:`size-8 rounded-lg bg-gradient-to-br from-blue-500/20 to-indigo-500/10 flex items-center justify-center`,children:(0,O.jsx)(S,{className:`size-4 text-blue-600 dark:text-blue-400`})}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h1`,{className:`text-xl font-bold leading-tight`,children:`Wikipedia`}),(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Today's featured content`})]})]}),(0,O.jsx)(`a`,{href:p,target:`_blank`,rel:`noopener noreferrer`,className:`p-2 rounded-full hover:bg-secondary transition-colors text-muted-foreground hover:text-foreground`,title:`Visit Wikipedia`,children:(0,O.jsx)(i,{className:`size-4`})})]}),(0,O.jsx)(H,{}),(0,O.jsx)(`div`,{ref:m,className:`sticky top-mobile-bar sidebar:top-0 bg-background/80 backdrop-blur-md z-10 border-b border-border`,children:(0,O.jsx)(`div`,{className:`flex gap-2 px-4 py-2.5 overflow-x-auto`,children:A.map(e=>(0,O.jsx)(L,{section:e,active:C===e,onClick:()=>w(e)},e))})}),l?(0,O.jsx)(W,{}):f?(0,O.jsxs)(`div`,{className:`px-4 pt-8 pb-16 text-center`,children:[(0,O.jsx)(u,{className:`size-10 mx-auto mb-3 text-muted-foreground/30`}),(0,O.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Couldn't load today's Wikipedia content. Try again later.`})]}):(0,O.jsxs)(`div`,{className:`px-4 pt-4 pb-4 space-y-6`,children:[s?.tfa&&(0,O.jsxs)(`div`,{ref:_,"data-section":`featured`,children:[(0,O.jsx)(U,{icon:(0,O.jsx)(t,{className:`size-3.5 text-amber-500`}),title:`Today's Featured Article`}),(0,O.jsx)(z,{page:s.tfa})]}),k.length>0&&(0,O.jsxs)(`div`,{ref:v,"data-section":`mostread`,children:[(0,O.jsx)(U,{icon:(0,O.jsx)(n,{className:`size-3.5 text-primary`}),title:`Trending`,subtitle:`Most read articles today`}),(0,O.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sidebar:grid-cols-3`,children:k.map(e=>(0,O.jsx)(R,{page:e,badge:e.views?P(e.views):void 0,badgeIcon:(0,O.jsx)(c,{className:`size-3`})},e.pageid))})]}),M.length>0&&(0,O.jsxs)(`div`,{ref:b,"data-section":`news`,children:[(0,O.jsx)(U,{icon:(0,O.jsx)(a,{className:`size-3.5 text-sky-500`}),title:`In the News`}),(0,O.jsx)(`div`,{className:`space-y-3`,children:M.map((e,t)=>(0,O.jsx)(V,{item:e},t))})]}),j.length>0&&(0,O.jsxs)(`div`,{ref:x,"data-section":`onthisday`,children:[(0,O.jsx)(U,{icon:(0,O.jsx)(d,{className:`size-3.5 text-violet-500`}),title:`On This Day`,subtitle:new Date().toLocaleDateString(o,{month:`long`,day:`numeric`})}),(0,O.jsx)(`div`,{className:`space-y-3`,children:j.map((e,t)=>(0,O.jsx)(B,{event:e},t))})]})]}),(0,O.jsx)(`div`,{className:`px-4 pb-8`,children:(0,O.jsx)(`div`,{className:`rounded-xl border border-dashed border-border bg-secondary/30 px-4 py-3 text-center`,children:(0,O.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Content provided by`,` `,(0,O.jsx)(`a`,{href:p,target:`_blank`,rel:`noopener noreferrer`,className:`underline underline-offset-2 hover:text-foreground transition-colors`,children:`Wikipedia`}),`, the free encyclopedia. Text is available under the`,` `,(0,O.jsx)(`a`,{href:`https://creativecommons.org/licenses/by-sa/4.0/`,target:`_blank`,rel:`noopener noreferrer`,className:`underline underline-offset-2 hover:text-foreground transition-colors`,children:`CC BY-SA 4.0`}),` `,`license.`]})})})]})}export{G as WikipediaPage}; // @license-end