1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6553],{6553:(e,t,l)=>{l.d(t,{Ag:()=>v,E5:()=>W,FI:()=>D,HD:()=>C,Jh:()=>M,OO:()=>y,Sk:()=>b,Yg:()=>N,c9:()=>$,gY:()=>d,p3:()=>c,q0:()=>f,saveChallengeWeekSlot:()=>j,stashChallengeHubReturn:()=>p,t5:()=>_});var n=l(86727),r=l(67813),i=l(71835),u=l(3856);let s="__climbest_challenge_weekly_test__",a="climbest.challengeWeeklyTestPlan.v1",o="climbest.openChallengeHub.v1";function p(e){try{sessionStorage.setItem(o,JSON.stringify({weekKey:e}))}catch{}}function c(){try{let e=sessionStorage.getItem(o);if(!e)return null;sessionStorage.removeItem(o);let t=JSON.parse(e);return"string"==typeof t.weekKey&&t.weekKey?{weekKey:t.weekKey}:null}catch{return null}}function d(e){let t=(0,u.A)(e??void 0),l=t.isoWeek(),n=t.isoWeekYear();return`${n}-W${String(l).padStart(2,"0")}`}function y(e){return Array.from({length:(0,u.A)(`${e}-12-28`).isoWeek()},(t,l)=>`${e}-W${String(l+1).padStart(2,"0")}`)}function b(e){let t=/^(\d{4})-W(\d{2})$/.exec(e);if(!t)return null;let l=Number(t[1]),n=Number(t[2]);return!Number.isFinite(l)||!Number.isFinite(n)||n<1||n>53?null:{year:l,week:n}}function f(e){let t=b(e);return t?(0,u.A)(`${t.year}-01-04`).isoWeek(t.week).startOf("isoWeek"):null}function w(){return{weeks:{},publishedAt:null,publishedBy:null}}function h(e){return e&&"object"==typeof e?"string"!=typeof e.workoutId||"string"!=typeof e.title?null:{workoutId:e.workoutId,title:e.title,durationMin:"number"==typeof e.durationMin&&Number.isFinite(e.durationMin)?e.durationMin:null,blurb:"string"==typeof e.blurb?e.blurb:null}:null}function g(e){if(!e||"object"!=typeof e)return null;let t=e.challengeWeeklyTestPlan;if(t&&"object"==typeof t){let e=t.weeks,l={};if(e&&"object"==typeof e)for(let[t,n]of Object.entries(e)){let e=h(n);e&&(l[t]=e)}return{weeks:l,publishedAt:"string"==typeof t.publishedAt?new Date(t.publishedAt):null,publishedBy:"string"==typeof t.publishedBy?t.publishedBy:null}}let l=e.challengeWeeklyTest,n=h(l);return n?{weeks:{[d()]:n},publishedAt:"string"==typeof l.publishedAt?new Date(l.publishedAt):null,publishedBy:"string"==typeof l.publishedBy?l.publishedBy:null}:null}function k(e){try{localStorage.setItem(a,JSON.stringify({weeks:e.weeks,publishedAt:e.publishedAt?.toISOString()??null,publishedBy:e.publishedBy}))}catch{}}async function m(e,t){let l={challengeWeeklyTestPlan:{weeks:t.weeks,publishedAt:t.publishedAt?.toISOString()??null,publishedBy:t.publishedBy}};await (0,i.E7)({templateName:s,ownerId:e,payload:l})}let A=null,B=null,S=new Map,I=new Map;async function v(){if(A&&Date.now()-A.at<6e4)return A.value;if(B)return B;B=(async()=>{try{let e=await (0,i.nb)({templateName:s}),t=g(e);if(t)return k(t),t}catch{}return function(){try{let e=localStorage.getItem(a);if(!e){let e=localStorage.getItem("climbest.challengeWeeklyTest.v1");if(!e)return w();let t=JSON.parse(e),l=h(t);if(!l)return w();return{weeks:{[d()]:l},publishedAt:"string"==typeof t.publishedAt?new Date(t.publishedAt):null,publishedBy:"string"==typeof t.publishedBy?t.publishedBy:null}}let t=JSON.parse(e);if(t&&"object"==typeof t&&"weeks"in t){let e={};if(t.weeks&&"object"==typeof t.weeks)for(let[l,n]of Object.entries(t.weeks)){let t=h(n);t&&(e[l]=t)}return{weeks:e,publishedAt:"string"==typeof t.publishedAt?new Date(t.publishedAt):null,publishedBy:"string"==typeof t.publishedBy?t.publishedBy:null}}return g(t)??w()}catch{return w()}}()})();try{let e=await B;return A={at:Date.now(),value:e},e}finally{B=null}}async function _(e){let t=await v(),l=d(e),n=t.weeks[l];return n?{...n,weekKey:l,publishedAt:t.publishedAt??new Date,publishedBy:t.publishedBy??""}:null}function D(e){if(!A||Date.now()-A.at>=6e4)return null;let t=d(e),l=A.value.weeks[t];return l?{...l,weekKey:t,publishedAt:A.value.publishedAt??new Date,publishedBy:A.value.publishedBy??""}:null}function $(e){(async()=>{let t=await _(e);t?.workoutId&&W(t.workoutId)})().catch(()=>{})}function O(){A=null,B=null}async function W(e){if(!e)return null;let t=S.get(e);if(t&&Date.now()-t.at<6e4)return t.url;let l=I.get(e);if(l)return l;let i=(async()=>{try{let t=(0,n.createClient)(),{data:l,error:i}=await t.from("workouts").select("exercises").eq("id",e).maybeSingle();if(i||!l)return null;let u=Array.isArray(l.exercises)?l.exercises:[],s=u[0]?.exercise??null,a=s?.previewUrl?.trim();if(a)return a;let o=s?.uid?.trim();if(!o)return null;let{data:p}=await t.from("exercises").select("preview_url").eq("id",o).maybeSingle();return("string"==typeof p?.preview_url?(0,r.g)(p.preview_url.trim())??p.preview_url.trim():"")||null}catch{return null}})();I.set(e,i);try{let t=await i;return S.set(e,{at:Date.now(),url:t}),t}finally{I.delete(e)}}function N(e){let t=S.get(e);return!t||Date.now()-t.at>=6e4?null:t.url}async function C(e){if(!e)return!1;try{let t=await _();if(!t?.workoutId)return!1;let l=f(t.weekKey);if(!l)return!1;let r=l.startOf("day").toISOString(),i=l.add(7,"day").startOf("day").toISOString(),u=(0,n.createClient)(),{data:s,error:a}=await u.from("workout_history").select("id").eq("user_id",e).eq("workout_id",t.workoutId).not("completed_at","is",null).gte("completed_at",r).lt("completed_at",i).limit(1).maybeSingle();if(a)return!1;return!!s?.id}catch{return!1}}async function j(e){let t=await v(),l={workoutId:e.workoutId,title:e.title.trim()||"Challenge",durationMin:e.durationMin??null,blurb:e.blurb?.trim()||null},r=(0,n.createClient)();try{await r.from("workouts").update({is_public:!0}).eq("id",e.workoutId).eq("owner_id",e.publishedBy)}catch{}let i={weeks:{...t.weeks,[e.weekKey]:l},publishedAt:new Date,publishedBy:e.publishedBy};return k(i),O(),A={at:Date.now(),value:i},await m(e.publishedBy,i),i}async function M(e){let t={...(await v()).weeks};delete t[e.weekKey];let l={weeks:t,publishedAt:new Date,publishedBy:e.publishedBy};return k(l),O(),A={at:Date.now(),value:l},await m(e.publishedBy,l),l}},67813:(e,t,l)=>{l.d(t,{g:()=>r,w:()=>i});let n="/storage/v1/object/sign/";function r(e){if(!e)return;let t=e.trim();if(!t)return;let l="https://sb.climbest.app".trim();try{let e=new URL(t),r=e.pathname,i=e.search;if(r.startsWith(n)&&(r=r.replace(n,"/storage/v1/object/public/"),i=""),!l)return`${e.origin}${r}${i}`;let u=new URL(l);return`${u.origin}${r}${i}`}catch{return t}}function i(e){let t=r(e);if(!t)return;let l=t.split("/").pop()?.split(".")[0]??"";return l?t.includes("?")?`${t}&cv=${encodeURIComponent(l)}`:`${t}?cv=${encodeURIComponent(l)}`:t}}}]);
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.