import{j as o}from"./vendor-ui-CUslpDkL.js";import{r as D}from"./vendor-react-Dg0Tra3e.js";import{s as W,u as Q,a as ee,C,B as g,G as te,b as ne}from"./index-CJqEbhJN.js";import{u as se}from"./vendor-query-CN1EccJz.js";import{S as re,a as ae,b as oe,c as ie,d as le}from"./select-BEyVJtLw.js";import{R as y}from"./refresh-cw-CVvHhQZs.js";import{F as ce}from"./filter-B-pqD9on.js";import{g as ue,f as fe}from"./format-BrSaXzvW.js";import{p as de}from"./parseISO-BuBF7yQQ.js";import"./vendor-supabase-yzuDJZPy.js";import"./vendor-motion-CiNtJfg1.js";import"./index-CSX6DdY0.js";function me(){return Object.assign({},ue())}function he(){return se({queryKey:["schedule"],queryFn:async()=>{const e=new Date,t=new Date(e.getFullYear(),e.getMonth(),e.getDate()),n=new Date(e.getTime()+7*24*60*60*1e3),{data:s,error:r}=await W.from("episodes").select(`
          id,
          show_id,
          title,
          air_datetime_utc,
          shows:show_id (
            title_english,
            title_romaji,
            poster_url,
            status
          )
        `).gte("air_datetime_utc",t.toISOString()).lte("air_datetime_utc",n.toISOString()).order("air_datetime_utc",{ascending:!0});if(r)throw r;return s.map(i=>({id:i.id,show_id:i.show_id,title:i.title,air_datetime_utc:i.air_datetime_utc,show:i.shows}))}})}async function xe(){const e=await W.functions.invoke("sync-schedules",{method:"POST"});if(e.error)throw e.error;return e.data}function U(e,t,n){const s=me(),r=we(e,n.timeZone,n.locale??s.locale);return"formatToParts"in r?pe(r,t):ge(r,t)}function pe(e,t){const n=e.formatToParts(t);for(let s=n.length-1;s>=0;--s)if(n[s].type==="timeZoneName")return n[s].value}function ge(e,t){const n=e.format(t).replace(/\u200E/g,""),s=/ [\w-+ ]+$/.exec(n);return s?s[0].substr(1):""}function we(e,t,n){return new Intl.DateTimeFormat(n?[n.code,"en-US"]:void 0,{timeZone:t,timeZoneName:e})}function Ne(e,t){const n=je(t);return"formatToParts"in n?De(n,e):ye(n,e)}const Te={year:0,month:1,day:2,hour:3,minute:4,second:5};function De(e,t){try{const n=e.formatToParts(t),s=[];for(let r=0;r<n.length;r++){const a=Te[n[r].type];a!==void 0&&(s[a]=parseInt(n[r].value,10))}return s}catch(n){if(n instanceof RangeError)return[NaN];throw n}}function ye(e,t){const n=e.format(t),s=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(n);return[parseInt(s[3],10),parseInt(s[1],10),parseInt(s[2],10),parseInt(s[4],10),parseInt(s[5],10),parseInt(s[6],10)]}const I={},z=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:"America/New_York",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(new Date("2014-06-25T04:00:00.123Z")),Ie=z==="06/25/2014, 00:00:00"||z==="‎06‎/‎25‎/‎2014‎ ‎00‎:‎00‎:‎00";function je(e){return I[e]||(I[e]=Ie?new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:e,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}):new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:e,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),I[e]}function R(e,t,n,s,r,a,i){const c=new Date(0);return c.setUTCFullYear(e,t,n),c.setUTCHours(s,r,a,i),c}const E=36e5,be=6e4,j={timezone:/([Z+-].*)$/,timezoneZ:/^(Z)$/,timezoneHH:/^([+-]\d{2})$/,timezoneHHMM:/^([+-])(\d{2}):?(\d{2})$/};function O(e,t,n){if(!e)return 0;let s=j.timezoneZ.exec(e);if(s)return 0;let r,a;if(s=j.timezoneHH.exec(e),s)return r=parseInt(s[1],10),F(r)?-(r*E):NaN;if(s=j.timezoneHHMM.exec(e),s){r=parseInt(s[2],10);const i=parseInt(s[3],10);return F(r,i)?(a=Math.abs(r)*E+i*be,s[1]==="+"?-a:a):NaN}if(_e(e)){t=new Date(t||Date.now());const i=n?t:Me(t),c=_(i,e);return-(n?c:ve(t,c,e))}return NaN}function Me(e){return R(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}function _(e,t){const n=Ne(e,t),s=R(n[0],n[1]-1,n[2],n[3]%24,n[4],n[5],0).getTime();let r=e.getTime();const a=r%1e3;return r-=a>=0?a:1e3+a,s-r}function ve(e,t,n){let r=e.getTime()-t;const a=_(new Date(r),n);if(t===a)return t;r-=a-t;const i=_(new Date(r),n);return a===i?a:Math.max(a,i)}function F(e,t){return-23<=e&&e<=23&&(t==null||0<=t&&t<=59)}const Z={};function _e(e){if(Z[e])return!0;try{return new Intl.DateTimeFormat(void 0,{timeZone:e}),Z[e]=!0,!0}catch{return!1}}const Oe=60*1e3,Ye={X:function(e,t,n){const s=b(n.timeZone,e);if(s===0)return"Z";switch(t){case"X":return H(s);case"XXXX":case"XX":return x(s);case"XXXXX":case"XXX":default:return x(s,":")}},x:function(e,t,n){const s=b(n.timeZone,e);switch(t){case"x":return H(s);case"xxxx":case"xx":return x(s);case"xxxxx":case"xxx":default:return x(s,":")}},O:function(e,t,n){const s=b(n.timeZone,e);switch(t){case"O":case"OO":case"OOO":return"GMT"+Se(s,":");case"OOOO":default:return"GMT"+x(s,":")}},z:function(e,t,n){switch(t){case"z":case"zz":case"zzz":return U("short",e,n);case"zzzz":default:return U("long",e,n)}}};function b(e,t){const n=e?O(e,t,!0)/Oe:t?.getTimezoneOffset()??0;if(Number.isNaN(n))throw new RangeError("Invalid time zone specified: "+e);return n}function w(e,t){const n=e<0?"-":"";let s=Math.abs(e).toString();for(;s.length<t;)s="0"+s;return n+s}function x(e,t=""){const n=e>0?"-":"+",s=Math.abs(e),r=w(Math.floor(s/60),2),a=w(Math.floor(s%60),2);return n+r+t+a}function H(e,t){return e%60===0?(e>0?"-":"+")+w(Math.abs(e)/60,2):x(e,t)}function Se(e,t=""){const n=e>0?"-":"+",s=Math.abs(e),r=Math.floor(s/60),a=s%60;return a===0?n+String(r):n+String(r)+t+w(a,2)}function $(e){const t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return t.setUTCFullYear(e.getFullYear()),+e-+t}const Ce=/(Z|[+-]\d{2}(?::?\d{2})?| UTC| [a-zA-Z]+\/[a-zA-Z_]+(?:\/[a-zA-Z_]+)?)$/,M=36e5,k=6e4,Ue=2,d={dateTimePattern:/^([0-9W+-]+)(T| )(.*)/,datePattern:/^([0-9W+-]+)(.*)/,plainTime:/:/,YY:/^(\d{2})$/,YYY:[/^([+-]\d{2})$/,/^([+-]\d{3})$/,/^([+-]\d{4})$/],YYYY:/^(\d{4})/,YYYYY:[/^([+-]\d{4})/,/^([+-]\d{5})/,/^([+-]\d{6})/],MM:/^-(\d{2})$/,DDD:/^-?(\d{3})$/,MMDD:/^-?(\d{2})-?(\d{2})$/,Www:/^-?W(\d{2})$/,WwwD:/^-?W(\d{2})-?(\d{1})$/,HH:/^(\d{2}([.,]\d*)?)$/,HHMM:/^(\d{2}):?(\d{2}([.,]\d*)?)$/,HHMMSS:/^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,timeZone:Ce};function G(e,t={}){if(arguments.length<1)throw new TypeError("1 argument required, but only "+arguments.length+" present");if(e===null)return new Date(NaN);const n=t.additionalDigits==null?Ue:Number(t.additionalDigits);if(n!==2&&n!==1&&n!==0)throw new RangeError("additionalDigits must be 0, 1 or 2");if(e instanceof Date||typeof e=="object"&&Object.prototype.toString.call(e)==="[object Date]")return new Date(e.getTime());if(typeof e=="number"||Object.prototype.toString.call(e)==="[object Number]")return new Date(e);if(Object.prototype.toString.call(e)!=="[object String]")return new Date(NaN);const s=ze(e),{year:r,restDateString:a}=Ee(s.date,n),i=Fe(a,r);if(i===null||isNaN(i.getTime()))return new Date(NaN);if(i){const c=i.getTime();let m=0,u;if(s.time&&(m=Ze(s.time),m===null||isNaN(m)))return new Date(NaN);if(s.timeZone||t.timeZone){if(u=O(s.timeZone||t.timeZone,new Date(c+m)),isNaN(u))return new Date(NaN)}else u=$(new Date(c+m)),u=$(new Date(c+m+u));return new Date(c+m+u)}else return new Date(NaN)}function ze(e){const t={};let n=d.dateTimePattern.exec(e),s;if(n?(t.date=n[1],s=n[3]):(n=d.datePattern.exec(e),n?(t.date=n[1],s=n[2]):(t.date=null,s=e)),s){const r=d.timeZone.exec(s);r?(t.time=s.replace(r[1],""),t.timeZone=r[1].trim()):t.time=s}return t}function Ee(e,t){if(e){const n=d.YYY[t],s=d.YYYYY[t];let r=d.YYYY.exec(e)||s.exec(e);if(r){const a=r[1];return{year:parseInt(a,10),restDateString:e.slice(a.length)}}if(r=d.YY.exec(e)||n.exec(e),r){const a=r[1];return{year:parseInt(a,10)*100,restDateString:e.slice(a.length)}}}return{year:null}}function Fe(e,t){if(t===null)return null;let n,s,r;if(!e||!e.length)return n=new Date(0),n.setUTCFullYear(t),n;let a=d.MM.exec(e);if(a)return n=new Date(0),s=parseInt(a[1],10)-1,L(t,s)?(n.setUTCFullYear(t,s),n):new Date(NaN);if(a=d.DDD.exec(e),a){n=new Date(0);const i=parseInt(a[1],10);return ke(t,i)?(n.setUTCFullYear(t,0,i),n):new Date(NaN)}if(a=d.MMDD.exec(e),a){n=new Date(0),s=parseInt(a[1],10)-1;const i=parseInt(a[2],10);return L(t,s,i)?(n.setUTCFullYear(t,s,i),n):new Date(NaN)}if(a=d.Www.exec(e),a)return r=parseInt(a[1],10)-1,P(r)?A(t,r):new Date(NaN);if(a=d.WwwD.exec(e),a){r=parseInt(a[1],10)-1;const i=parseInt(a[2],10)-1;return P(r,i)?A(t,r,i):new Date(NaN)}return null}function Ze(e){let t,n,s=d.HH.exec(e);if(s)return t=parseFloat(s[1].replace(",",".")),v(t)?t%24*M:NaN;if(s=d.HHMM.exec(e),s)return t=parseInt(s[1],10),n=parseFloat(s[2].replace(",",".")),v(t,n)?t%24*M+n*k:NaN;if(s=d.HHMMSS.exec(e),s){t=parseInt(s[1],10),n=parseInt(s[2],10);const r=parseFloat(s[3].replace(",","."));return v(t,n,r)?t%24*M+n*k+r*1e3:NaN}return null}function A(e,t,n){t=t||0,n=n||0;const s=new Date(0);s.setUTCFullYear(e,0,4);const r=s.getUTCDay()||7,a=t*7+n+1-r;return s.setUTCDate(s.getUTCDate()+a),s}const He=[31,28,31,30,31,30,31,31,30,31,30,31],$e=[31,29,31,30,31,30,31,31,30,31,30,31];function B(e){return e%400===0||e%4===0&&e%100!==0}function L(e,t,n){if(t<0||t>11)return!1;if(n!=null){if(n<1)return!1;const s=B(e);if(s&&n>$e[t]||!s&&n>He[t])return!1}return!0}function ke(e,t){if(t<1)return!1;const n=B(e);return!(n&&t>366||!n&&t>365)}function P(e,t){return!(e<0||e>52||t!=null&&(t<0||t>6))}function v(e,t,n){return!(e<0||e>=25||t!=null&&(t<0||t>=60)||n!=null&&(n<0||n>=60))}const Ae=/([xXOz]+)|''|'(''|[^'])+('|$)/g;function Le(e,t,n={}){t=String(t);const s=t.match(Ae);if(s){const r=G(n.originalDate||e,n);t=s.reduce(function(a,i){if(i[0]==="'")return a;const c=a.indexOf(i),m=a[c-1]==="'",u=a.replace(i,"'"+Ye[i[0]](r,i,n)+"'");return m?u.substring(0,c-1)+u.substring(c+1):u},t)}return fe(e,t,n)}function Pe(e,t,n){e=G(e,n);const s=O(t,e,!0),r=new Date(e.getTime()-s),a=new Date(0);return a.setFullYear(r.getUTCFullYear(),r.getUTCMonth(),r.getUTCDate()),a.setHours(r.getUTCHours(),r.getUTCMinutes(),r.getUTCSeconds(),r.getUTCMilliseconds()),a}function Xe(e,t,n,s){return s={...s,timeZone:t,originalDate:e},Le(Pe(e,t,{timeZone:s.timeZone}),n,s)}const X=[{value:"local",label:"Local Time",offset:""},{value:"America/Los_Angeles",label:"Pacific (PT)",offset:"UTC-8"},{value:"America/Denver",label:"Mountain (MT)",offset:"UTC-7"},{value:"America/Chicago",label:"Central (CT)",offset:"UTC-6"},{value:"America/New_York",label:"Eastern (ET)",offset:"UTC-5"},{value:"Europe/London",label:"London (GMT)",offset:"UTC+0"},{value:"Europe/Paris",label:"Paris (CET)",offset:"UTC+1"},{value:"Asia/Tokyo",label:"Tokyo (JST)",offset:"UTC+9"},{value:"Asia/Seoul",label:"Seoul (KST)",offset:"UTC+9"},{value:"Australia/Sydney",label:"Sydney (AEDT)",offset:"UTC+11"}];function rt(){const{t:e}=Q(),[t,n]=D.useState("all"),[s,r]=D.useState("local"),{data:a=[],isLoading:i,refetch:c}=he(),{toast:m}=ee(),[u,Y]=D.useState(!1),K=()=>s==="local"?Intl.DateTimeFormat().resolvedOptions().timeZone:s,S=async()=>{Y(!0);try{await xe(),m({title:e("schedule.syncSchedule"),description:e("schedule.loadingSchedule")}),setTimeout(()=>{c(),m({title:e("schedule.syncSchedule"),description:e("schedule.loadingSchedule")})},3e3)}catch(l){console.error("Sync error:",l),m({title:e("common.error"),description:e("common.error"),variant:"destructive"})}finally{Y(!1)}},N=(l,h)=>{const f=de(l);return Xe(f,K(),h)},q=(()=>{const l=new Map;for(const h of a){const f=N(h.air_datetime_utc,"yyyy-MM-dd"),p=`${h.show_id}-${f}`;if(!l.has(p))l.set(p,h);else{const J=l.get(p);new Date(h.air_datetime_utc)<new Date(J.air_datetime_utc)&&l.set(p,h)}}return Array.from(l.values()).sort((h,f)=>new Date(h.air_datetime_utc).getTime()-new Date(f.air_datetime_utc).getTime())})().reduce((l,h)=>{const f=N(h.air_datetime_utc,"EEEE, MMM d");return l[f]||(l[f]=[]),l[f].push(h),l},{}),V=s==="local"?e("schedule.localTime"):X.find(l=>l.value===s)?.label||e("schedule.localTime");return o.jsx("div",{className:"min-h-screen px-4 py-8 md:py-12",children:o.jsxs("div",{className:"mx-auto max-w-6xl",children:[o.jsxs("div",{className:"mb-8",children:[o.jsxs("div",{className:"flex items-center justify-between mb-4 flex-wrap gap-4",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(C,{className:"w-10 h-10 text-primary"}),o.jsx("h1",{className:"text-4xl font-bold",children:e("schedule.title")})]}),o.jsxs(g,{onClick:S,disabled:u,className:"rounded-full neon-glow-pink bg-gradient-to-r from-primary to-secondary",children:[o.jsx(y,{className:`w-4 h-4 mr-2 ${u?"animate-spin":""}`}),e(u?"schedule.syncing":"schedule.syncSchedule")]})]}),o.jsxs("p",{className:"text-muted-foreground text-lg",children:[e("schedule.description")," ",V,"."]})]}),o.jsxs("div",{className:"mb-8 flex flex-wrap items-center gap-4 justify-between",children:[o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsx(ce,{className:"w-5 h-5 text-muted-foreground"}),o.jsxs("div",{className:"flex gap-2",children:[o.jsx(g,{size:"sm",variant:t==="all"?"default":"outline",onClick:()=>n("all"),className:t==="all"?"neon-glow-pink":"glass-card",children:e("common.allShows")}),o.jsx(g,{size:"sm",variant:t==="following"?"default":"outline",onClick:()=>n("following"),className:t==="following"?"neon-glow-blue":"glass-card",children:e("common.following")})]})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(te,{className:"w-5 h-5 text-muted-foreground"}),o.jsxs(re,{value:s,onValueChange:r,children:[o.jsx(ae,{className:"w-[200px] glass-card border-primary/30",children:o.jsx(oe,{placeholder:"Select timezone"})}),o.jsx(ie,{className:"glass-card border-primary/30",children:X.map(l=>o.jsx(le,{value:l.value,children:o.jsxs("span",{className:"flex items-center justify-between gap-2 w-full",children:[o.jsx("span",{children:l.value==="local"?e("schedule.localTime"):l.label}),l.offset&&o.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:l.offset})]})},l.value))})]})]})]}),i&&o.jsxs("div",{className:"text-center py-20",children:[o.jsx(y,{className:"w-12 h-12 mx-auto mb-4 animate-spin text-primary"}),o.jsx("p",{className:"text-muted-foreground",children:e("schedule.loadingSchedule")})]}),!i&&a.length===0&&o.jsxs("div",{className:"text-center py-20",children:[o.jsx(C,{className:"w-16 h-16 mx-auto mb-4 text-muted-foreground"}),o.jsx("h3",{className:"text-xl font-semibold mb-2",children:e("schedule.noUpcoming")}),o.jsx("p",{className:"text-muted-foreground mb-6",children:e("schedule.clickSync")}),o.jsxs(g,{onClick:S,disabled:u,className:"rounded-full neon-glow-pink bg-gradient-to-r from-primary to-secondary",children:[o.jsx(y,{className:`w-4 h-4 mr-2 ${u?"animate-spin":""}`}),e("schedule.syncNow")]})]}),!i&&a.length>0&&o.jsx("div",{className:"space-y-8",children:Object.entries(q).map(([l,h])=>o.jsxs("div",{children:[o.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[o.jsx("div",{className:"h-[2px] w-12 neon-shimmer"}),o.jsx("h2",{className:"text-2xl font-bold text-primary",children:l}),o.jsx("div",{className:"h-[2px] flex-1 neon-shimmer"})]}),o.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:h.map(f=>{const T=f.show?.title_english||f.show?.title_romaji||"Unknown Show";return o.jsxs("div",{className:"glass-card-hover p-4 flex gap-4 group cursor-pointer",children:[o.jsxs("div",{className:"relative w-20 h-28 flex-shrink-0 rounded-lg overflow-hidden",children:[o.jsx("img",{src:f.show?.poster_url||"https://images.unsplash.com/photo-1578632767115-351597cf2477?w=200&h=300&fit=crop",alt:T,className:"w-full h-full object-cover transition-transform duration-500 group-hover:scale-110"}),o.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-card/80 to-transparent"})]}),o.jsxs("div",{className:"flex flex-col justify-between flex-1",children:[o.jsxs("div",{children:[o.jsx("h3",{className:"font-semibold text-lg mb-1 group-hover:text-primary transition-colors line-clamp-2",children:T}),o.jsx("p",{className:"text-sm text-muted-foreground",children:f.title})]}),o.jsxs("div",{className:"flex items-center gap-2 text-sm text-secondary font-mono",children:[o.jsx(ne,{className:"w-4 h-4"}),N(f.air_datetime_utc,"h:mm a")]})]})]},f.id)})})]},l))})]})})}export{rt as default};