import { useLocalStorage } from "@/hooks/useLocalStorage" import { PREF } from "@/utils/const" import ChargedButton from "../ChargedButton"; import { usePermissions } from "@/hooks/usePermission"; import styles from "@/css/Intro.module.css"; import { ChangeEvent, InputEvent, MouseEvent, MouseEventHandler, PointerEvent, useRef, useState } from "react"; import Image from "next/image"; import PermissionCheck from "../PermissionCheck"; import { PermissionStateResult } from "@/utils/permissions"; import StyledContainer from "../StyledContainer"; import OldButton from "../OldButton"; import OldTextInput from "../OldTextInput"; const MIN_PLAYERS = 2; const MAX_PLAYERS = 8; export default function Intro() { const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0"); const [ rewatchScreen, setRewatchScreen ] = useState(false); const [ enterPlayerCount, setEnterPlayerCount ] = useState(false); const [ videoEnded, setVideoEnded ] = useState(false); const [ videoPaused, setVideoPaused ] = useState(false); const introVideoRef = useRef(null); const [ granted, setGranted ] = useState(false); const [ , setPlayerCount ] = useLocalStorage(PREF.playerCount, ""); const [ playerCountStr, setPlayerCountStr] = useState(""); const validPlayerCount = (number: number) => { return !isNaN(number) && (number <= MAX_PLAYERS && number >= MIN_PLAYERS); }; const handleVideoClick = (e: PointerEvent): boolean => { e.currentTarget.play(); return true; }; const handlePermissions = (gps: PermissionStateResult, cam: PermissionStateResult) => { setGranted(gps === "granted" && cam === "granted"); }; const handleChange = (event: ChangeEvent): boolean => { const value = event.target.value; let parsedValue = Number.parseInt(value); if (isNaN(parsedValue)) { if (value.length > 0) { event.preventDefault(); return false; } } parsedValue = Math.min(MAX_PLAYERS, Math.max(MIN_PLAYERS, parsedValue)); setPlayerCountStr(parsedValue.toString()); return true; }; return (
Background { !enterPlayerCount || !granted ?
{ setRewatchScreen(false); setEnterPlayerCount(true); }} style={{margin: "auto", marginTop: "3rem"}} disabled={!granted} >WEITER
: !rewatchScreen ?

Spieleranzahl

Wie viele Abenteurer seid ihr?



{ setPlayerCount(playerCountStr); setRewatchScreen(true); }} holdDuration={500} disabled={!validPlayerCount(Number.parseInt(playerCountStr))}> Halten, um das Video anzusehen!
:
{ !videoEnded && videoPaused ?
Pause Icon
: null } { videoEnded ?
{ if (introVideoRef.current) { introVideoRef.current.pause(); introVideoRef.current.currentTime = 0; introVideoRef.current.play(); setVideoEnded(false); } }}>Video wiederholen? { setStep("2"); }}>Wir sind bereit!
: null }
}
) }