//go:build !wasm
// +build !wasm

package main

import (
	"fmt"
	"image/color"
	"math"
	"strings"
	"time"

	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/text"
	"github.com/hajimehoshi/ebiten/v2/vector"
	"golang.org/x/image/font/basicfont"
)

// In Native: Nutze die normalen Draw-Funktionen

func (g *Game) drawMenu(screen *ebiten.Image) {
	g.DrawMenu(screen)
}

func (g *Game) drawLobby(screen *ebiten.Image) {
	g.DrawLobby(screen)
}

func (g *Game) drawLeaderboard(screen *ebiten.Image) {
	g.DrawLeaderboard(screen)
}

func (g *Game) drawPresentation(screen *ebiten.Image) {
	// Hintergrund: Retro Dunkelblau
	screen.Fill(color.RGBA{10, 15, 30, 255})

	// Animierte Scanlines / Raster-Effekt (Retro Style)
	for i := 0; i < ScreenHeight; i += 4 {
		vector.DrawFilledRect(screen, 0, float32(i), float32(ScreenWidth), 1, color.RGBA{0, 0, 0, 40}, false)
	}

	// Überschrift
	text.Draw(screen, "PRESENTATION MODE", basicfont.Face7x13, ScreenWidth/2-80, 50, color.RGBA{255, 255, 0, 255})
	vector.StrokeLine(screen, ScreenWidth/2-90, 60, ScreenWidth/2+90, 60, 2, color.RGBA{255, 255, 0, 255}, false)

	// Zitat groß in der Mitte
	if g.presQuote.Text != "" {
		quoteMsg := fmt.Sprintf("\"%s\"", g.presQuote.Text)
		authorMsg := fmt.Sprintf("- %s", g.presQuote.Author)
		
		g.DrawWrappedText(screen, quoteMsg, ScreenWidth/2, ScreenHeight/2-20, 600, color.White)
		text.Draw(screen, authorMsg, basicfont.Face7x13, ScreenWidth/2+100, ScreenHeight/2+50, color.RGBA{200, 200, 200, 255})
	}

	// Assets laufen unten durch
	for _, a := range g.presAssets {
		img, ok := g.assetsImages[a.AssetID]
		if !ok { continue }

		op := &ebiten.DrawImageOptions{}
		op.GeoM.Scale(a.Scale, a.Scale)
		op.GeoM.Translate(a.X, a.Y)
		
		bob := math.Sin(float64(time.Now().UnixMilli())/200.0) * 5.0
		op.GeoM.Translate(0, bob)

		screen.DrawImage(img, op)
	}

	// Draw connected players (no names)
	g.stateMutex.Lock()
	for _, p := range g.gameState.Players {
		if !p.IsAlive || p.Name == "PRESENTATION" {
			continue 
		}
		
		playerX := p.X
		playerY := p.Y

		if playerX > ScreenWidth {
			playerX = math.Mod(playerX, ScreenWidth)
		} else if playerX < 0 {
			playerX = ScreenWidth - math.Mod(-playerX, ScreenWidth)
		}

		img, ok := g.assetsImages["player"]
		if ok {
			op := &ebiten.DrawImageOptions{}
			op.GeoM.Translate(playerX, playerY)
			screen.DrawImage(img, op)
		}

		if p.State != "" && strings.HasPrefix(p.State, "EMOTE_") {
			emoteStr := p.State[6:]
			emoteMap := map[string]string{"1": "❤️", "2": "😂", "3": "😡", "4": "👍"}
			if emoji, ok := emoteMap[emoteStr]; ok {
				text.Draw(screen, emoji, basicfont.Face7x13, int(playerX+10), int(playerY-10), color.White)
			}
		}
	}
	g.stateMutex.Unlock()

	// Draw QR Code
	if g.presQRCode != nil {
		qrSize := 150.0
		qrW, _ := g.presQRCode.Size()
		scale := float64(qrSize) / float64(qrW)
		op := &ebiten.DrawImageOptions{}
		op.GeoM.Scale(scale, scale)
		op.GeoM.Translate(20, 20)
		screen.DrawImage(g.presQRCode, op)
		
		text.Draw(screen, "SCANNEN ZUM MITMACHEN!", basicfont.Face7x13, 20, 190, color.RGBA{255, 255, 0, 255})
	}

	text.Draw(screen, "DRÜCKE [F1] ZUM BEENDEN", basicfont.Face7x13, ScreenWidth-250, ScreenHeight-30, color.RGBA{255, 255, 255, 100})
}
