import{A as e,D as t,I as n,j as r,t as i,z as a}from"./jsx-runtime-ktpX_HJe.js";import{r as o}from"./Image-Cn5a1pql.js";import{t as s}from"./PeriodSelector-DA82l1SR.js";import{t as c}from"./color.esm-ZqnBw47-.js";var l=a(n(),1),u=i();function d({title:n,initialData:i,endpoint:a,render:d}){let f=`${n} - Koito`,p=t(),m=e(),h=r(),{firstActivity:g}=o(),_=new URLSearchParams(m.search),v=parseInt(_.get(`page`)||`1`,10),y=p.data?.[a]?p.data[a]:i,[b,x]=(0,l.useState)(`(--color-bg)`);(0,l.useEffect)(()=>{if((y?.items?.length??0)===0)return;let e=y.items[0]?.item?.image;e&&c(e.small,{amount:1}).then(e=>{x(`rgba(${e[0]},${e[1]},${e[2]},0.2)`)})},[y]);let S=_.get(`period`)??`day`,C=_.get(`year`),w=_.get(`month`),T=_.get(`week`),E=e=>{let t=new URLSearchParams(m.search);for(let n in e){let r=e[n];r===null?t.delete(n):t.set(n,r)}h(`/${a}?${t.toString()}`,{replace:!1})},D=e=>{E({period:e,page:`1`,year:null,month:null,week:null})},O=e=>{if(e==``){E({period:S,page:`1`,year:null,month:null,week:null});return}E({period:null,page:`1`,year:e})},k=e=>{E({period:null,page:`1`,year:C??new Date().getFullYear().toString(),month:e})},A=e=>{E({period:null,page:`1`,year:C??new Date().getFullYear().toString(),month:null,week:e})};(0,l.useEffect)(()=>{p.load(`/${a}?${_.toString()}`)},[m.search]);let j=e=>{let t=new URLSearchParams(m.search);t.set(`page`,String(e));let n=`/${a}?${t.toString()}`;p.load(n),h(n,{replace:!1})},M=()=>j(v+1),N=()=>j(v-1),P=new Date,F=g?.getFullYear()||P.setFullYear(P.getFullYear()-10),I=Array.from({length:P.getFullYear()-F+1},(e,t)=>`${new Date().getFullYear()-t}`),L=Array.from({length:12},(e,t)=>`${t+1}`),R=Array.from({length:53},(e,t)=>`${t+1}`);return(0,u.jsxs)(`div`,{className:`w-full min-h-screen`,style:{background:`linear-gradient(to bottom, ${b}, transparent 600px)`},children:[(0,u.jsx)(`title`,{children:f}),(0,u.jsx)(`meta`,{property:`og:title`,content:f}),(0,u.jsx)(`meta`,{name:`description`,content:f}),(0,u.jsxs)(`div`,{className:`w-(100%-3) sm:w-17/20 mx-auto ml-3 sm:ml-18 mt-6 sm:mt-12`,children:[(0,u.jsx)(`h1`,{children:n}),(0,u.jsxs)(`div`,{className:`flex flex-col items-start lg:flex-row sm:items-start gap-2 sm:gap-4`,children:[(0,u.jsx)(s,{current:S,setter:D,disableCache:!0}),(0,u.jsxs)(`div`,{className:`flex gap-3`,children:[(0,u.jsxs)(`select`,{value:C??``,onChange:e=>O(e.target.value),className:`px-2 py-1 rounded border border-gray-400`,children:[(0,u.jsx)(`option`,{value:``,children:`Year`}),I.map(e=>(0,u.jsx)(`option`,{value:e,children:e},e))]}),(0,u.jsxs)(`select`,{value:w??``,onChange:e=>k(e.target.value),className:`px-2 py-1 rounded border border-gray-400`,children:[(0,u.jsx)(`option`,{value:``,children:`Month`}),L.map(e=>(0,u.jsx)(`option`,{value:e,children:e},e))]}),(0,u.jsxs)(`select`,{value:T??``,onChange:e=>A(e.target.value),className:`px-2 py-1 rounded border border-gray-400`,children:[(0,u.jsx)(`option`,{value:``,children:`Week`}),R.map(e=>(0,u.jsx)(`option`,{value:e,children:e},e))]})]})]}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-color-fg-secondary`,children:(()=>{let e,t,n=P.getFullYear(),r=P.getMonth(),i=P.getDate();if(C&&w)e=new Date(parseInt(C),parseInt(w)-1,1),t=new Date(e),t.setMonth(e.getMonth()+1),t.setDate(0);else if(C&&T){let n=new Date(parseInt(C),0,1),r=parseInt(T);e=new Date(n),e.setDate(n.getDate()+(r-1)*7),t=new Date(e),t.setDate(e.getDate()+6)}else if(C)e=new Date(parseInt(C),0,1),t=new Date(parseInt(C),11,31);else switch(S){case`day`:e=new Date(P),t=new Date(P);break;case`week`:t=new Date(P),e=new Date(P),e.setDate(t.getDate()-6);break;case`month`:t=new Date(P),e=new Date(P),e=r===0?new Date(n-1,11,i):new Date(n,r-1,i);break;case`year`:t=new Date(P),e=new Date(n-1,r,i);break;case`all_time`:return`All Time`;default:return``}let a=new Intl.DateTimeFormat(void 0,{year:`numeric`,month:`long`,day:`numeric`});return`${a.format(e)} – ${a.format(t)}`})()}),(0,u.jsx)(`div`,{className:`mt-10 sm:mt-20 flex mx-auto justify-between`,children:d({data:y,page:v,onNext:M,onPrev:N})})]})]})}export{d as t};