1import{d as D,a as u,S as G,b,p as v}from"./crosswordle_helpers-DUYixME-.js";import{b as U}from"./i18n-Cil1S7yA.js";const m=7,S="crosswordle_last_days_game_states";function I(e="7x7"){return`${S}_${e}`}function w(e="7x7"){try{const t=localStorage.getItem(I(e));return t?JSON.parse(t)||[]:[]}catch{return[]}}function T(e,t="7x7"){localStorage.setItem(I(t),JSON.stringify(e))}function A(e="7x7"){const t=new Date;t.setUTCHours(0,0,0,0);let r=w(e);r=r.filter(n=>{const a=new Date(n.date);return a.setUTCHours(0,0,0,0),Math.floor((t.getTime()-a.getTime())/(1e3*60*60*24))<m}),T(r,e)}async function L(e,t="7x7"){if(!e||!e.date||!e.gameId)return console.warn("Invalid gameData: missing required fields",e),Promise.reject(new Error("Invalid gameData"));if(!!!localStorage.getItem("heygg_user"))try{const n=w(t),a=new Date(e.date);a.setUTCHours(0,0,0,0);const o=new Date;if(o.setUTCHours(0,0,0,0),Math.floor((o.getTime()-a.getTime())/(1e3*60*60*24))>=m)return console.info("Skipping old gameData (older than 7 days)",e),!1;const s=n.filter(l=>l.gameId!==e.gameId);s.push(e);const i=s.sort((l,c)=>new Date(c.date).setUTCHours(0,0,0,0)-new Date(l.date).setUTCHours(0,0,0,0)).slice(0,m);return T(i,t),A(t),!0}catch(n){throw console.error("Failed to save gameData locally:",n),n}}async function E(e=null,t="7x7"){let n=new Date,a=0;const o=10;for(;a<o;){a++;const d=new Date(n),s=new Date(n);s.setDate(s.getDate()-50+1);const g=s.toISOString().split("T")[0],i=d.toISOString().split("T")[0],l=t==="7x7"?"daily":"daily:9x9";try{const c=await window.HeyGoodGame.Stats.fetchGameArchive("crosswordle",{level:l,start_date:g,end_date:i,limit:50});if(c!=null&&c.games){const h=c.games.sort((f,_)=>new Date(_.game_date)-new Date(f.game_date)).find(f=>!f.played&&f.level===l&&f.game_date!==e);if(h)return h.game_date;if(n.setDate(n.getDate()-50),n<new Date(t==="7x7"?G:b))break}}catch(c){console.error("Error fetching game archive:",c);break}}return null}async function y(e=null,t="7x7"){return new Promise((r,n)=>{const a=N(t),o=v(t);for(let d=1;d<=m;d++){const s=o-d;if(s<=0||s===e)continue;const i=U(t==="7x7"?"daily":"daily:9x9",s);a.find(c=>c.gameId===i)||r(s)}n(null)})}async function x(e=null,t="7x7"){const r=!!localStorage.getItem("heygg_user"),n=e?D(e,t):null;if(r)try{const a=await E(e,t);if(a)return{date:a,index:D(a,t),isLoggedIn:r,puzzleSize:t};try{const o=await y(n,t);return{date:u(o,t),index:o,isLoggedIn:r,puzzleSize:t}}catch(o){if(t==="9x9")return console.log("No unplayed 9x9 games found, falling back to 7x7"),await x(null,"7x7");throw o}}catch(a){console.error("Archive lookup failed, fallback to local:",a);try{const o=await y(n,t);return{date:u(o,t),index:o,isLoggedIn:r,puzzleSize:t}}catch(o){if(t==="9x9")return console.log("No unplayed 9x9 games found, falling back to 7x7"),await x(null,"7x7");throw o}}else try{const a=await y(n,t);return{date:u(a,t),index:a,isLoggedIn:r,puzzleSize:t}}catch(a){if(t==="9x9")return console.log("No unplayed 9x9 games found, falling back to 7x7"),await x(null,"7x7");throw a}}function N(e="7x7"){return w(e)}export{N as g,x as r,L as s};
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.