1import{r as o,j as e,B as N}from"./index-e0L57TBH.js";import{u as C,g as S,s as _,f as $}from"./useGameTimer-CBZevxH9.js";import{R as E}from"./rotate-ccw-B3UTK1LQ.js";const b={easy:{cols:4,rows:3},medium:{cols:4,rows:4},hard:{cols:6,rows:6}},I=["ð","ð","ð","ð","ð","ð","ð","ð¥","ð¥","ð½","ð","ð¶ï¸","ð»","ð¸","ð","â","â¡","ð¥","ð","ð","ð","ð¯","ð¨","ðµ"];function w(a){const d=[...a];for(let s=d.length-1;s>0;s--){const l=Math.floor(Math.random()*(s+1));[d[s],d[l]]=[d[l],d[s]]}return d}function k(a){const{cols:d,rows:s}=b[a],l=d*s/2,n=w(I).slice(0,l);return w([...n,...n])}function G(){const[a,d]=o.useState("medium"),[s,l]=o.useState(()=>k("medium")),[n,u]=o.useState([]),[c,p]=o.useState(new Set),[x,j]=o.useState(0),i=C(),[T,M]=o.useState(()=>{try{return JSON.parse(localStorage.getItem("ozg_memory_best")||'{"easy":0,"medium":0,"hard":0}')}catch{return{easy:0,medium:0,hard:0}}}),[f,y]=o.useState(()=>S("memory_medium")),{cols:B}=b[a],h=c.size===s.length&&s.length>0;o.useEffect(()=>{h&&(i.stop(),y(_(`memory_${a}`,i.seconds)),M(t=>{if(t[a]&&t[a]<=x)return t;const r={...t,[a]:x};return localStorage.setItem("ozg_memory_best",JSON.stringify(r)),r}))},[h]),o.useEffect(()=>{if(n.length!==2)return;const[t,r]=n;if(s[t]===s[r])p(m=>
1new Set([...m,t,r])),u([]);else{const m=setTimeout(()=>u([]),800);return()=>clearTimeout(m)}},[n,s]);const z=t=>{h||c.has(t)||n.includes(t)||n.length===2||(i.start(),n.length===1&&j(r=>r+1),u([...n,t]))},v=(t=a)=>{d(t),l(k(t)),u([]),p(new Set),j(0),i.reset(),y(S(`memory_${t}`))},g=$;return e.jsxs("div",{className:"w-full max-w-lg mx-auto",children:[e.jsx("div",{className:"flex gap-2 mb-3 flex-wrap justify-center",children:Object.keys(b).map(t=>e.jsx(N,{size:"sm",variant:a===t?"default":"outline",onClick:()=>v(t),children:t},t))}),e.jsxs("div",{className:"grid grid-cols-5 gap-1.5 mb-3 text-center text-sm",children:[e.jsxs("div",{className:"bg-muted rounded-lg py-1.5",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Moves"}),e.jsx("div",{className:"font-bold tabular-nums",children:x})]}),e.jsxs("div",{className:"bg-muted rounded-lg py-1.5",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Time"}),e.jsx("div",{className:"font-bold tabular-nums",children:g(i.seconds)})]}),e.jsxs("div",{className:"bg-muted rounded-lg py-1.5",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Matched"}),e.jsxs("div",{className:"font-bold tabular-nums",children:[c.size/2,"/",s.length/2]})]}),e.jsxs("div",{className:"bg-muted rounded-lg py-1.5",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Best time"}),e.jsx("div",{className:"font-bold tabular-nums",children:f?g(f):"â"})]}),e.jsxs("div",{className:"bg-muted rounded-lg py-1.5",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Best moves"}),e.jsx("div",{className:"font-bold tabular-nums",children:T[a]||"â"})]})]}),e.jsx("div",{className:"grid gap-2",style:{gridTemplateColumns:`repeat(${B}, minmax(0, 1fr))`},children:s.map((t,r)=>{const m=n.includes(r)||c.has(r);return e.jsx("button",{onClick:()=>z(r),className:"aspect-square rounded-lg relative",style:{perspective:"600px"},"aria-label":`Card ${r+1}`,children:e.jsxs("div",{className:"absolute inset-0 transition-transform duration-500",style:{transformStyle:"preserve-3d",transform:m?"rotateY(180deg)":"rotateY(0)"},children:[e.jsx("div",{className:"absolute inset-0 rounded-lg bg-gradient-to-br from-primary to-primary/60 flex items-center justify-center text-2xl text-primary-foreground shadow",style:{backfaceVisibility:"hidden"},children:"?"}),e.jsx("div",{className:`absolute inset-0 rounded-lg bg-card border-2 flex items-center justify-center text-3xl md:text-4xl shadow ${c.has(r)?"border-primary":"border-muted"}`,style:{backfaceVisibility:"hidden",transform:"rotateY(180deg)"},children:t})]})},r)})}),h&&e.jsxs("div",{className:"mt-4 p-4 bg-primary/10 border border-primary rounded-lg text-center",children:[e.jsxs("div",{className:"font-bold text-lg mb-1",children:["ð Cleared in ",x," moves · ",g(i.seconds),f?` · best ${g(f)}`:""]}),e.jsxs(N,{onClick:()=>v(),className:"mt-2",children:[e.jsx(E,{className:"h-4 w-4 mr-2"}),"Play again"]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground mt-3",children:"Flip two cards to find a matching pair."})]})}export{G as default};
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.