import ChallengeCard from '@/components/ChallengeCard'
import PenaltyBanner from '@/components/PenalyBanner'
import { useDrawRandomChallengeMutation } from '@/hooks/mutations/useChallengeMutation'
import { useAuth } from '@/hooks/useAuth'
import { useChallengeActions } from '@/hooks/useChallengeActions'
import { useChallenges } from '@/hooks/useChallenges'
import { useGame } from '@/hooks/useGame'
import { FontAwesome6 } from '@expo/vector-icons'
import { useEffect, useMemo, useState } from 'react'
import { View } from 'react-native'
import { ActivityIndicator, Appbar, Banner, FAB, MD3Colors, Surface, Text, TouchableRipple } from 'react-native-paper'
function ChallengeScreenHeader() {
return <>
>
}
function ChallengeScreenBody() {
const auth = useAuth()
const game = useGame()
const challengeActions = useChallengeActions()
const challenges = useChallenges()
const currentChallengeAction = useMemo(() => {
if (!game.activeChallengeId)
return null
return challengeActions.challengeActions.find((action) => action.id === game.activeChallengeId)
}, [game, challengeActions])
const currentChallenge = useMemo(() => {
if (!currentChallengeAction)
return null
return challenges.challenges.find((challenge) => challenge.id === currentChallengeAction.challengeId)
}, [currentChallengeAction, challenges])
const [loading, setLoading] = useState(false)
const drawRandomChallengeMutation = useDrawRandomChallengeMutation({
auth,
onPostSuccess: () => setLoading(true),
})
useEffect(() => {
if (challengeActions)
setLoading(false)
}, [challengeActions])
return <>
{currentChallenge && }
{!currentChallenge && game.currentRunner && <>
Aucun défi en cours.
drawRandomChallengeMutation.mutate()}
variant='tertiary'
customSize={64} />
{loading && }
>}
}
style={{ backgroundColor: MD3Colors.secondary30 }}>
Vous êtes poursuiveuse, et n'avez donc pas de défi à accomplir.
>
}
export default function ChallengesScreen() {
return (
)
}