1import{a as S,j as e}from"./index-B8j-9aKy.js";import{b as i}from"./vendor-react-BWjNeuN-.js";import{u as z,G as V}from"./GameShell-oaSlFUww.js";import{F as q}from"./flag-CJ0iNFQn.js";import"./NotFoundPage-fRqBHVvP.js";import"./circle-check-2tRLWn78.js";import"./heart-CBVLvJjs.js";import"./GameEditDialog-CFlo6OZu.js";import"./label-BmL1bEKx.js";import"./categorySlug-BTIspAdd.js";import"./pencil-bEuV4KQn.js";import"./chevron-right-7ZPkw_L-.js";const c=17.6,N=Math.sqrt(3)*c,T=2*c;function K(h,r){const f=h*N+(r&1?N/2:0)+c,p=r*T*.75+c;return{x:f,y:p}}function U(h,r,f=c-1.5){return Array.from({length:6},(p,t)=>{const o=Math.PI/180*(60*t-30);return`${h+f*Math.cos(o)},${r+f*Math.sin(o)}`}).join(" ")}const Y=19,Z=19,R=Y*N+N/2+c*2,B=Z*T*.75+T*.25+c*2,Q=["","#2563eb","#16a34a","#dc2626","#7e22ce","#b45309","#0891b2","#374151","#6b7280"];function fe(){const{loading:h,setLoading:r,scoreRefreshKey:f,refreshScores:p}=z(),[t,o]=i.useState(null),[m,k]=i.useState(!1),[d,_]=i.useState(null),[y,x]=i.useState(!1),C=i.useRef(null),w=i.useCallback(async()=>{r(!0),o(null),_(null),k(!1);try{const n=await S("/api/hexfield/start",{method:"POST"});_(n.sessionId),o(n)}finally{r(!1)}},[r]),G=i.useCallback(async(n,a)=>{if(!d||!t||(t==null?void 0:t.status)!=="playing"||y)return;const s=t==null?void 0:t.cells[a][n];if(s.state!=="revealed"&&!(s.state==="flagged"&&!m)){if(m){x(!0);try{const l=await S("/api/hexfield/flag",{method:"POST",body:JSON.stringify({sessionId:d,col:n,row:a})});o(l)}finally{x(!1)}return}x(!0);try{const l=await S("/api/hexfield/reveal",{method:"POST",body:JSON.stringify({sessionId:d,col:n,row:a})});o(l),(l.status==="won"||l.status==="game_over")&&p()}finally{x(!1)}}},[d,t,y,m,p]),F=i.useCallback(async(n,a,s)=>{if(s.preventDefault(),!(!d||!t||(t==null?void 0:t.status)!=="playing"||y||(t==null?void 0:t.cells[a][n]).state==="revealed")){x(!0);try{const u=await S("/api/hexfield/flag",{method:"POST",body:JSON.stringify({sessionId:d,col:n,row:a})});o(u)}finally{x(!1)}}},[d,t,y]);function H(n,a){C.current=setTimeout(()=>{F(n,a,{preventDefault:()=>{}})},500)}function A(){C.current&&clearTimeout(C.current)}i.useEffect(()=>{w()},[w]);const W=(t==null?void 0:t.cells.flat().filter(n=>n.state==="flagged").length)??0,L=((t==null?void 0:t.mineCount)??0)-(W??0),b=(t==null?void 0:t.status)!=="playing",$=e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"Clear every safe cell on the hexagonal grid without hitting a mine."}),e.jsxs("ul",{children:[e.jsx("li",{children:"Tap a cell to reveal it. A number shows how many of its neighbouring hexes contain mines."}),e.jsx("li",{children:"Use the number clues to deduce where the mines are hidden."}),e.jsxs("li",{children:["Turn on ",e.jsx("strong",{children:"Flag mode"})," and tap to flag a suspected mine."]}),e.jsx("li",{children:"Reveal a mine and it's game over. Clear all the safe cells to win."})]})]});return e.jsx(V,{scoreRefreshKey:f,fsMode:"portrait",rules:$,gameLoading:h,loadingContent:e.jsx("div",{className:"flex justify-center p-12",children:e.jsx("p",{className:"text-muted-foreground animate-pulse",children:"Loadingâ¦"})}),children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between w-full max-w-2xl mx-auto mb-2 px-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"ð£ "}),e.jsx("span",{className:"font-bold tabular-nums",children:L})]}),e.jsxs("div",{children:[t.status==="won"&&e.jsx("span",{className:"font-bold text-emerald-500",children:"ð You win!"}),t.status==="game_over"&&e.jsx("span",{className:"font-bold text-red-500",children:"ð¥ Boom!"}),t.status==="playing"&&e.jsx("span",{className:"text-muted-foreground text-xs",children:m?"ð© Flag mode":"Click to reveal"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Score "}),e.jsx("span",{className:"font-bold tabular-nums text-primary",children:t.score})]})]}),e.jsx("div",{className:"flex justify-center mb-2",children:e.jsxs("button",{onClick:()=>k(n=>!n),className:["flex items-center gap-1.5 rounded-lg px-4 py-1.5 text-sm font-medium transition-colors",m?"bg-red-600 text-white":"bg-secondary text-secondary-foreground hover:bg-accent"].join(" "),children:[e.jsx(q,{size:14}),m?"Flag mode ON":"Flag mode"]})}),e.jsx("div",{className:"flex justify-center w-full",children:e.jsx("svg",{width:R,height:B,viewBox:`0 0 ${R} ${B}`,className:"block select-none",style:{maxWidth:"100%",touchAction:"manipulation"},children:t.cells.map((n,a)=>n.map((s,l)=>{var P,E;const{x:u,y:g}=K(l,a),I=U(u,g),J=((P=t.hitMine)==null?void 0:P.row)===a&&((E=t.hitMine)==null?void 0:E.
1col)===l;if(s.state==="invalid")return null;let O="#d1d5db",M="#9ca3af",D=1;s.state==="revealed"?(O="#f3f4f6",M="#e5e7eb"):(s.state==="mine"||s.state==="wrong_flag")&&(O=J?"#dc2626":"#7f1d1d",M="#ef4444");let j=null;const v=c*.65;return s.state==="revealed"&&s.adjacent&&s.adjacent>0?j=e.jsx("text",{x:u,y:g,textAnchor:"middle",dominantBaseline:"central",fontSize:v,fontWeight:"bold",fill:Q[s.adjacent]??"#6b7280",children:s.adjacent}):s.state==="flagged"?j=e.jsx("text",{x:u,y:g,textAnchor:"middle",dominantBaseline:"central",fontSize:v,children:"ð©"}):s.state==="mine"?j=e.jsx("text",{x:u,y:g,textAnchor:"middle",dominantBaseline:"central",fontSize:v,children:"ð£"}):s.state==="wrong_flag"&&(j=e.jsx("text",{x:u,y:g,textAnchor:"middle",dominantBaseline:"central",fontSize:v,children:"â"})),e.jsxs("g",{onClick:()=>G(l,a),onContextMenu:X=>F(l,a,X),onTouchStart:()=>H(l,a),onTouchEnd:A,onTouchMove:A,style:{cursor:b?"default":"pointer"},children:[e.jsx("polygon",{points:I,fill:O,stroke:M,strokeWidth:D,className:!b&&s.state==="hidden"?"hover:brightness-95 transition-all":""}),j]},`${l}-${a}`)}))})}),b&&e.jsxs("div",{className:"mt-4 flex flex-col items-center gap-3",children:[t.status==="won"&&e.jsxs("p",{className:"text-lg font-bold text-emerald-500",children:[t.score," cells revealed!"]}),e.jsx("button",{onClick:w,className:"rounded-xl bg-primary px-8 py-2.5 text-sm font-semibold text-primary-foreground hover:bg-primary/90 transition-all hover:scale-105 active:scale-95",children:"Play Again"})]}),!b&&e.jsxs("p",{className:"mt-2 text-center text-xs text-muted-foreground",children:[t.revealedCount," / ",271-t.mineCount," safe cells revealed"]})," "]}):null})}export{fe 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.