PageSourceSearch

https://minigolf-sankt-georgen.lovable.app/assets/spiel.spiel._id-rVlDISq4.js

js minigolf-sankt-georgen.lovable.app collected 2026-10-03 03:34:42 UTC 8,517 bytes, 1 lines download raw bytes

1import{a5 as C,r as x,d as g,t as b,j as e,L as R}from"./index-CrlHD_rY.js";import{B as j}from"./button-C9mq-HB0.js";import{T as q}from"./trophy-B3uB_7rq.js";import{c as I}from"./createLucideIcon-D7E4aMTN.js";import{C as z}from"./chevron-right-DEaequSu.js";import{S as A}from"./sparkles-CC5roFfQ.js";import{C as D}from"./circle-check-BA4l3Wbt.js";import"./utils-CsI7vFqD.js";import"./clsx-B-dksMZM.js";const G=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],K=I("chevron-left",G);const O=[["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"M16 14v6",key:"1j4efv"}],["path",{d:"M8 14v6",key:"17c4r9"}],["path",{d:"M12 16v6",key:"c8a4gj"}]],T=I("cloud-rain",O);function B(o,y,c){const p=o.map(t=>{const n=t.scores.reduce((h,u)=>h+u.strokes,0),a=t.scores.filter(h=>h.strokes===1).length;let l=0;return y==="bonus_ace"&&(l=a),{playerId:t.id,name:t.name,userId:t.userId,totalStrokes:n,bonusPoints:l,holesInOne:a,finalScore:n-l,rank:0}});if(y==="match_play"){const t={};o.forEach(n=>t[n.id]=0);for(let n=1;n<=c;n++){let a=1/0,l=[];for(const h of o){const u=h.scores.find(N=>N.hole===n)?.strokes;u!=null&&(u<a?(a=u,l=[h.id]):u===a&&l.push(h.id))}l.length===1&&(t[l[0]]=(t[l[0]]??0)+1)}p.forEach(n=>{n.finalScore=-(t[n.playerId]??0)})}return p.sort((t,n)=>t.finalScore-n.finalScore),p.forEach((t,n)=>{t.rank=n+1}),p}function ee(){const{id:o}=C.useParams(),{user:y}=C.useRouteContext(),[c,p]=x.useState(null),[t,n]=x.useState([]),[a,l]=x.useState(1),[h,u]=x.useState(!0),[N,_]=x.useState(!1),[k,v]=x.useState(null),[S,E]=x.useState(!1);if(x.useEffect(()=>{(async()=>{const{data:s}=await g.from("games").select("*").eq("id",o).maybeSingle();if(!s){b.error("Spiel nicht gefunden");return}p(s);const{data:d}=await g.from("game_players").select("id, user_id, guest_name, position").eq("game_id",o).order("position"),{data:i}=await g.from("scores").select("*").eq("game_id",o),f=(d??[]).map(r=>({id:r.id,userId:r.user_id,name:r.guest_name??"Ich",position:r.position,scores:(i??[]).filter(m=>m.game_player_id===r.id).map(m=>({hole:m.hole_number,strokes:m.strokes}))}));n(f);let w=1;for(let r=1;r<=s.hole_count;r++)if(f.some(m=>!m.scores.find(M=>M.hole===r))){w=r;break}l(w),u(!1),s.status==="completed"&&v(B(f,s.mode,s.hole_count))})()},[o]),h)return e.jsx("div",{className:"mx-auto max-w-3xl px-4 py-10",children:"Lade Spiel..."});if(!c)return null;const L=async(s,d)=>{const i=s.scores.find(r=>r.hole===a),f=t.map(r=>r.id===s.id?{...r,scores:i?r.scores.map(m=>m.hole===a?{...m,strokes:d}:m):[...r.scores,{hole:a,strokes:d}]}:r);n(f);const{error:w}=await g.from("scores").upsert({game_id:o,game_player_id:s.id,hole_number:a,strokes:d},{onConflict:"game_player_id,hole_number"});w&&b.error("Konnte Score nicht speichern – Eintragungen sind nur mit gültigem QR-Check-in und bis 21:00 Uhr möglich.")},P=t.every(s=>s.scores.length===c.hole_count),F=async()=>{_(!0);try{const{error:s}=await g.rpc("finalize_game",{_game_id:o});if(s)throw s;v(B(t,c.mode,c.hole_count)),b.success("Spiel beendet! 🏆 XP, Badges & Treuestempel wurden allen verknüpften Konten gutgeschrieben.")}catch(s){const d=s?.message??"";b.error(d.includes("closed_for_today")?"Ab 21:00 Uhr sind keine Eintragungen mehr möglich.":d.includes("not_unlocked")?"Freischaltung abgelaufen oder verbraucht. Bitte erneut vor Ort einchecken.":d.includes("incomplete")?"Es fehlen noch Schläge – bitte alle Bahnen ausfüllen.":d||"Fehler beim Beenden")}finally{_(!1)}};return k?e.jsxs("div",{className:"mx-auto max-w-2xl px-4 py-8 sm:px-6",children:[e.jsxs("div",{className:"rounded-3xl bg-gradient-sunset p-8 text-center text-white shadow-pop",children:[e.jsx(q,{className:"mx-auto h-12 w-12"}),e.jsx("p",{className:"mt-3 text-sm uppercase tracking-wider opacity-90",children:"Spielende"}),e.jsxs("h1",{className:"mt-1 font-display text-4xl font-bold",children:["🏆 ",k[0].name," gewinnt!"]})]}),e.jsx("div",{className:"mt-6 overflow-hidden rounded-3xl border border-border bg-card shadow-soft",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-muted/40",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-bold uppercase tracking-wider text-muted-foreground",children:"Rang"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-bold uppercase tracking-wider text-muted-foreground",children:"Spieler"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-bold uppercase tracking-wider text-muted-foreground",children:"Schläge"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-bold uppercase tracking-wider text-muted-foreground",children:"Aces"})]})}),e.jsx("tbody",{children:k.map(s=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsxs("td",{className:"px-4 py-3 font-display font-bold",children:[s.rank,"."]}
1),e.jsx("td",{className:"px-4 py-3",children:s.name}),e.jsxs("td",{className:"px-4 py-3 text-right font-display font-bold",children:[s.totalStrokes,s.bonusPoints>0&&e.jsxs("span",{className:"text-primary",children:[" (−",s.bonusPoints,")"]})]}),e.jsx("td",{className:"px-4 py-3 text-right",children:s.holesInOne})]},s.playerId))})]})}),e.jsxs("div",{className:"mt-6 rounded-3xl border border-border bg-card p-5 shadow-soft",children:[e.jsxs("h2",{className:"flex items-center gap-2 font-display text-base font-bold",children:[e.jsx(T,{className:"h-5 w-5 text-secondary"})," Habt ihr im Regen gespielt?"]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Dann sichere dir das Badge „Regenkönig:in“ – nur echte Wetterfeste bekommen es."}),e.jsx(j,{variant:"outline",disabled:S,onClick:async()=>{const{error:s}=await g.rpc("claim_rain_badge",{_game_id:o});if(s)return b.error("Badge konnte nicht vergeben werden.");E(!0),b.success("Badge „Regenkönig:in“ freigeschaltet! 🌧️")},className:"mt-3 rounded-full",children:S?"Badge erhalten 🌧️":"Ja, wir haben im Regen gespielt"})]}),e.jsxs("div",{className:"mt-6 flex flex-col gap-2 sm:flex-row",children:[e.jsx(j,{asChild:!0,className:"flex-1 rounded-full",children:e.jsx(R,{to:"/spiel/dashboard",children:"Zum Dashboard"})}),e.jsx(j,{asChild:!0,variant:"outline",className:"flex-1 rounded-full",children:e.jsx(R,{to:"/spiel/neues-spiel",children:"Nochmal spielen"})})]})]}):e.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-6 sm:px-6 sm:py-10",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:$(c.mode)}),e.jsxs("h1",{className:"font-display text-3xl font-bold",children:["Bahn ",a," / ",c.hole_count]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{variant:"outline",size:"icon",disabled:a===1,onClick:()=>l(a-1),children:e.jsx(K,{})}),e.jsx(j,{variant:"outline",size:"icon",disabled:a===c.hole_count,onClick:()=>l(a+1),children:e.jsx(z,{})})]})]}),e.jsx("div",{className:"mt-2 h-2 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-gradient-grass",style:{width:`${a/c.hole_count*100}%`}})}),e.jsx("div",{className:"mt-6 space-y-3",children:t.map(s=>{const d=s.scores.find(i=>i.hole===a)?.strokes;return e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-4 shadow-soft",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"font-display text-lg font-bold",children:[s.name,s.userId===y.id&&" (Du)"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Gesamt: ",e.jsx("span",{className:"font-display font-bold text-foreground",children:s.scores.reduce((i,f)=>i+f.strokes,0)})]})]}),e.jsx("div",{className:"mt-3 grid grid-cols-7 gap-1.5",children:[1,2,3,4,5,6,7].map(i=>e.jsxs("button",{onClick:()=>L(s,i),className:`relative aspect-square rounded-xl font-display text-lg font-bold transition-all ${d===i?i===1?"bg-gradient-sunset text-white shadow-sun":"bg-primary text-primary-foreground shadow-soft":"bg-muted text-foreground hover:bg-muted/70"}`,children:[i,i===1&&d===1&&e.jsx(A,{className:"absolute -right-1 -top-1 h-4 w-4 text-accent"})]},i))})]},s.id)})}),P&&e.jsx(j,{onClick:F,disabled:N,size:"lg",className:"mt-8 w-full rounded-full bg-gradient-sunset text-base font-bold shadow-sun hover:opacity-90",children:N?"...":e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"mr-2 h-5 w-5"})," Spiel beenden & auswerten"]})})]})}function $(o){return o==="classic"?"Klassisch":o==="bonus_ace"?"Bonus-Ace":"Match Play"}export{ee as component};

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.