import{S as q,q as B,v as p,w as T,x,y as N,z as j,A as H,B as ee,C as E,D as te,E as se,F as z,G as Z,r as u,H as J,a as re,u as ae,c as ie,j as l,L as $,s as O}from"./index-D8rt4Ouv.js";import{B as ne}from"./button-BKWwiobZ.js";var oe=class extends q{constructor(e,t){super(),this.options=t,this.#s=e,this.#a=null,this.#r=B(),this.bindMethods(),this.setOptions(t)}#s;#e=void 0;#p=void 0;#t=void 0;#n;#l;#r;#a;#m;#u;#d;#o;#c;#i;#f=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#e.addObserver(this),W(this.#e,this.options)?this.#h():this.updateResult(),this.#v())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Q(this.#e,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Q(this.#e,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#x(),this.#R(),this.#e.removeObserver(this)}setOptions(e){const t=this.options,s=this.#e;if(this.options=this.#s.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof p(this.options.enabled,this.#e)!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#w(),this.#e.setOptions(this.options),t._defaulted&&!T(this.options,t)&&this.#s.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#e,observer:this});const r=this.hasListeners();r&&V(this.#e,s,this.options,t)&&this.#h(),this.updateResult(),r&&(this.#e!==s||p(this.options.enabled,this.#e)!==p(t.enabled,this.#e)||x(this.options.staleTime,this.#e)!==x(t.staleTime,this.#e))&&this.#y();const a=this.#b();r&&(this.#e!==s||p(this.options.enabled,this.#e)!==p(t.enabled,this.#e)||a!==this.#i)&&this.#g(a)}getOptimisticResult(e){const t=this.#s.getQueryCache().build(this.#s,e),s=this.createResult(t,e);return he(this,s)&&(this.#t=s,this.#l=this.options,this.#n=this.#e.state),s}getCurrentResult(){return this.#t}trackResult(e,t){return new Proxy(e,{get:(s,r)=>(this.trackProp(r),t?.(r),r==="promise"&&(this.trackProp("data"),!this.options.experimental_prefetchInRender&&this.#r.status==="pending"&&this.#r.reject(new Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(s,r))})}trackProp(e){this.#f.add(e)}getCurrentQuery(){return this.#e}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){const t=this.#s.defaultQueryOptions(e),s=this.#s.getQueryCache().build(this.#s,t);return s.fetch().then(()=>this.createResult(s,t))}fetch(e){return this.#h({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#t))}#h(e){this.#w();let t=this.#e.fetch(this.options,e);return e?.throwOnError||(t=t.catch(N)),t}#y(){this.#x();const e=x(this.options.staleTime,this.#e);if(j.isServer()||this.#t.isStale||!H(e))return;const s=ee(this.#t.dataUpdatedAt,e)+1;this.#o=E.setTimeout(()=>{this.#t.isStale||this.updateResult()},s)}#b(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(this.#e):this.options.refetchInterval)??!1}#g(e){this.#R(),this.#i=e,!(j.isServer()||p(this.options.enabled,this.#e)===!1||!H(this.#i)||this.#i===0)&&(this.#c=E.setInterval(()=>{(this.options.refetchIntervalInBackground||te.isFocused())&&this.#h()},this.#i))}#v(){this.#y(),this.#g(this.#b())}#x(){this.#o!==void 0&&(E.clearTimeout(this.#o),this.#o=void 0)}#R(){this.#c!==void 0&&(E.clearInterval(this.#c),this.#c=void 0)}createResult(e,t){const s=this.#e,r=this.options,a=this.#t,o=this.#n,i=this.#l,y=e!==s?e.state:this.#p,{state:c}=e;let n={...c},g=!1,h;if(t._optimisticResults){const f=this.hasListeners(),v=!f&&W(e,t),S=f&&V(e,s,t,r);(v||S)&&(n={...n,...se(c.data,e.options)}),t._optimisticResults==="isRestoring"&&(n.fetchStatus="idle")}let{error:w,errorUpdatedAt:D,status:b}=n;h=n.data;let L=!1;if(t.placeholderData!==void 0&&h===void 0&&b==="pending"){let f;a?.isPlaceholderData&&t.placeholderData===i?.placeholderData?(f=a.data,L=!0):f=typeof t.placeholderData=="function"?t.placeholderData(this.#d?.state.data,this.#d):t.placeholderData,f!==void 0&&(b="success",h=z(a?.data,f,t),g=!0)}if(t.select&&h!==void 0&&!L)if(a&&h===o?.data&&t.select===this.#m)h=this.#u;else try{this.#m=t.select,h=t.select(h),h=z(a?.data,h,t),this.#u=h,this.#a=null}catch(f){this.#a=f}this.#a&&(w=this.#a,h=this.#u,D=Date.now(),b="error");const _=n.fetchStatus==="fetching",M=b==="pending",I=b==="error",F=M&&_,U=h!==void 0,m={status:b,fetchStatus:n.fetchStatus,isPending:M,isSuccess:b==="success",isError:I,isInitialLoading:F,isLoading:F,data:h,dataUpdatedAt:n.dataUpdatedAt,error:w,errorUpdatedAt:D,failureCount:n.fetchFailureCount,failureReason:n.fetchFailureReason,errorUpdateCount:n.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:n.dataUpdateCount>y.dataUpdateCount||n.errorUpdateCount>y.errorUpdateCount,isFetching:_,isRefetching:_&&!M,isLoadingError:I&&!U,isPaused:n.fetchStatus==="paused",isPlaceholderData:g,isRefetchError:I&&U,isStale:P(e,t),refetch:this.refetch,promise:this.#r,isEnabled:p(t.enabled,e)!==!1};if(this.options.experimental_prefetchInRender){const f=m.data!==void 0,v=m.status==="error"&&!f,S=k=>{v?k.reject(m.error):f&&k.resolve(m.data)},A=()=>{const k=this.#r=m.promise=B();S(k)},C=this.#r;switch(C.status){case"pending":e.queryHash===s.queryHash&&S(C);break;case"fulfilled":(v||m.data!==C.value)&&A();break;case"rejected":(!v||m.error!==C.reason)&&A();break}}return m}updateResult(){const e=this.#t,t=this.createResult(this.#e,this.options);if(this.#n=this.#e.state,this.#l=this.options,this.#n.data!==void 0&&(this.#d=this.#e),T(t,e))return;this.#t=t;const s=()=>{if(!e)return!0;const{notifyOnChangeProps:r}=this.options,a=typeof r=="function"?r():r;if(a==="all"||!a&&!this.#f.size)return!0;const o=new Set(a??this.#f);return this.options.throwOnError&&o.add("error"),Object.keys(this.#t).some(i=>{const d=i;return this.#t[d]!==e[d]&&o.has(d)})};this.#S({listeners:s()})}#w(){const e=this.#s.getQueryCache().build(this.#s,this.options);if(e===this.#e)return;const t=this.#e;this.#e=e,this.#p=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#v()}#S(e){Z.batch(()=>{e.listeners&&this.listeners.forEach(t=>{t(this.#t)}),this.#s.getQueryCache().notify({query:this.#e,type:"observerResultsUpdated"})})}};function ce(e,t){return p(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&p(t.retryOnMount,e)===!1)}function W(e,t){return ce(e,t)||e.state.data!==void 0&&Q(e,t,t.refetchOnMount)}function Q(e,t,s){if(p(t.enabled,e)!==!1&&x(t.staleTime,e)!=="static"){const r=typeof s=="function"?s(e):s;return r==="always"||r!==!1&&P(e,t)}return!1}function V(e,t,s,r){return(e!==t||p(r.enabled,e)===!1)&&(!s.suspense||e.state.status!=="error")&&P(e,s)}function P(e,t){return p(t.enabled,e)!==!1&&e.isStaleByTime(x(t.staleTime,e))}function he(e,t){return!T(e.getCurrentResult(),t)}var X=u.createContext(!1),le=()=>u.useContext(X);X.Provider;function ue(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var de=u.createContext(ue()),fe=()=>u.useContext(de),pe=(e,t,s)=>{const r=s?.state.error&&typeof e.throwOnError=="function"?J(e.throwOnError,[s.state.error,s]):e.throwOnError;(e.suspense||e.experimental_prefetchInRender||r)&&(t.isReset()||(e.retryOnMount=!1))},me=e=>{u.useEffect(()=>{e.clearReset()},[e])},ye=({result:e,errorResetBoundary:t,throwOnError:s,query:r,suspense:a})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(a&&e.data===void 0||J(s,[e.error,r])),be=e=>{if(e.suspense){const s=a=>a==="static"?a:Math.max(a??1e3,1e3),r=e.staleTime;e.staleTime=typeof r=="function"?(...a)=>s(r(...a)):s(r),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3))}},ge=(e,t)=>e.isLoading&&e.isFetching&&!t,ve=(e,t)=>e?.suspense&&t.isPending,G=(e,t,s)=>t.fetchOptimistic(e).catch(()=>{s.clearReset()});function xe(e,t,s){const r=le(),a=fe(),o=re(),i=o.defaultQueryOptions(e);o.getDefaultOptions().queries?._experimental_beforeQuery?.(i);const d=o.getQueryCache().get(i.queryHash);i._optimisticResults=r?"isRestoring":"optimistic",be(i),pe(i,a,d),me(a);const y=!o.getQueryCache().get(i.queryHash),[c]=u.useState(()=>new t(o,i)),n=c.getOptimisticResult(i),g=!r&&e.subscribed!==!1;if(u.useSyncExternalStore(u.useCallback(h=>{const w=g?c.subscribe(Z.batchCalls(h)):N;return c.updateResult(),w},[c,g]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),u.useEffect(()=>{c.setOptions(i)},[i,c]),ve(i,n))throw G(i,c,a);if(ye({result:n,errorResetBoundary:a,throwOnError:i.throwOnError,query:d,suspense:i.suspense}))throw n.error;return o.getDefaultOptions().queries?._experimental_afterQuery?.(i,n),i.experimental_prefetchInRender&&!j.isServer()&&ge(n,r)&&(y?G(i,c,a):d?.promise)?.catch(N).finally(()=>{c.updateResult()}),i.notifyOnChangeProps?n:c.trackResult(n)}function Ae(e,t){return xe(e,oe)}const Y=(...e)=>e.filter((t,s,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===s).join(" ").trim();const Re=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();const we=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,s,r)=>r?r.toUpperCase():s.toLowerCase());const K=e=>{const t=we(e);return t.charAt(0).toUpperCase()+t.slice(1)};var Se={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const Ce=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};const ke=u.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:s=2,absoluteStrokeWidth:r,className:a="",children:o,iconNode:i,...d},y)=>u.createElement("svg",{ref:y,...Se,width:t,height:t,stroke:e,strokeWidth:r?Number(s)*24/Number(t):s,className:Y("lucide",a),...!o&&!Ce(d)&&{"aria-hidden":"true"},...d},[...i.map(([c,n])=>u.createElement(c,n)),...Array.isArray(o)?o:[o]]));const R=(e,t)=>{const s=u.forwardRef(({className:r,...a},o)=>u.createElement(ke,{ref:o,iconNode:t,className:Y(`lucide-${Re(K(e))}`,`lucide-${e}`,r),...a}));return s.displayName=K(e),s};const Ee=[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 14h.01",key:"6423bh"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 18h.01",key:"lrp35t"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M16 18h.01",key:"kzsmim"}]],Oe=R("calendar-days",Ee);const _e=[["path",{d:"M17.596 12.768a2 2 0 1 0 2.829-2.829l-1.768-1.767a2 2 0 0 0 2.828-2.829l-2.828-2.828a2 2 0 0 0-2.829 2.828l-1.767-1.768a2 2 0 1 0-2.829 2.829z",key:"9m4mmf"}],["path",{d:"m2.5 21.5 1.4-1.4",key:"17g3f0"}],["path",{d:"m20.1 3.9 1.4-1.4",key:"1qn309"}],["path",{d:"M5.343 21.485a2 2 0 1 0 2.829-2.828l1.767 1.768a2 2 0 1 0 2.829-2.829l-6.364-6.364a2 2 0 1 0-2.829 2.829l1.768 1.767a2 2 0 0 0-2.828 2.829z",key:"1t2c92"}],["path",{d:"m9.6 14.4 4.8-4.8",key:"6umqxw"}]],Me=R("dumbbell",_e);const Ie=[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]],Te=R("layout-dashboard",Ie);const Ne=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],je=R("log-out",Ne);const Qe=[["path",{d:"M10 14.66v1.626a2 2 0 0 1-.976 1.696A5 5 0 0 0 7 21.978",key:"1n3hpd"}],["path",{d:"M14 14.66v1.626a2 2 0 0 0 .976 1.696A5 5 0 0 1 17 21.978",key:"rfe1zi"}],["path",{d:"M18 9h1.5a1 1 0 0 0 0-5H18",key:"7xy6bh"}],["path",{d:"M4 22h16",key:"57wxv0"}],["path",{d:"M6 9a6 6 0 0 0 12 0V3a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1z",key:"1mhfuq"}],["path",{d:"M6 9H4.5a1 1 0 0 1 0-5H6",key:"tex48p"}]],Pe=R("trophy",Qe),De=[{to:"/dashboard",label:"Dashboard",icon:Te},{to:"/seasons",label:"Seasons",icon:Pe},{to:"/games",label:"Games",icon:Oe},{to:"/practices",label:"Practices",icon:Me}];function Be({children:e}){const{user:t,loading:s,signOut:r}=ae(),a=ie();return u.useEffect(()=>{!s&&!t&&a.navigate({to:"/login",replace:!0})},[s,a,t]),s?l.jsx("div",{className:"min-h-screen bg-background"}):t?l.jsxs("div",{className:"min-h-screen bg-background flex flex-col",children:[l.jsx("header",{className:"border-b border-border bg-sidebar/80 backdrop-blur sticky top-0 z-30",children:l.jsxs("div",{className:"max-w-6xl mx-auto px-4 h-16 flex items-center justify-between",children:[l.jsxs($,{to:"/dashboard",className:"flex items-center gap-2",children:[l.jsx("div",{className:"h-3 w-3 rounded-full bg-primary"}),l.jsx("span",{className:"font-display text-2xl tracking-widest",children:"CROSSE"})]}),l.jsx(ne,{variant:"ghost",size:"sm",onClick:async()=>{await r(),a.navigate({to:"/login"})},children:l.jsx(je,{className:"h-4 w-4"})})]})}),l.jsx("main",{className:"flex-1 max-w-6xl w-full mx-auto px-4 py-6 pb-28",children:e}),l.jsx("nav",{className:"fixed bottom-0 inset-x-0 border-t border-border bg-sidebar/95 backdrop-blur z-30",children:l.jsx("div",{className:"max-w-6xl mx-auto px-2 grid grid-cols-4",children:De.map(({to:o,label:i,icon:d})=>l.jsxs($,{to:o,className:"flex flex-col items-center justify-center gap-1 py-3 text-xs text-muted-foreground",activeProps:{className:"flex flex-col items-center justify-center gap-1 py-3 text-xs text-primary"},children:[l.jsx(d,{className:"h-5 w-5"}),l.jsx("span",{className:"font-display tracking-wider",children:i})]},o))})})]}):l.jsx("div",{className:"min-h-screen bg-background"})}const He=e=>e.team_score>e.opponent_score?"W":e.team_score<e.opponent_score?"L":"T";async function ze(){const{data:e,error:t}=await O.from("seasons").select("*").order("year",{ascending:!1});if(t)throw t;return e}async function $e(){const{data:e,error:t}=await O.from("games").select("*").order("game_date",{ascending:!1});if(t)throw t;return e}async function We(){const{data:e,error:t}=await O.from("practices").select("*").order("practice_date",{ascending:!1});if(t)throw t;return e}async function Ve(){const{data:e,error:t}=await O.from("tournaments").select("*").order("start_date",{ascending:!1,nullsFirst:!1});if(t)throw t;return e}function Ge(e,t){if(!e.tournament_id)return!0;const s=t.find(r=>r.id===e.tournament_id);return s?s.count_in_record:!0}export{Be as A,Oe as C,Me as D,Pe as T,ze as a,$e as b,R as c,Ve as d,Ge as e,We as f,He as r,Ae as u};
