import ParticipantDetails from "@/components/ui/ParticipantDeatails"; import ShowInfo from "@/components/ui/ShowInfo"; import { useSeasonCount, useSeasonDates, useSeasonParticipants, } from "@/hooks/useSeason"; import { useShow } from "@/hooks/useShow"; import * as Haptics from "expo-haptics"; import { router, useLocalSearchParams } from "expo-router"; import React from "react"; import { ActivityIndicator, Dimensions, Image, ScrollView, StyleSheet, Text, TouchableOpacity, View, } from "react-native"; import styles from "./stackStyles/showDetailStyles"; export default function ShowDetails() { const { id, logoUri } = useLocalSearchParams(); const showId = Number(id); const logoUriString = Array.isArray(logoUri) ? logoUri[0] : logoUri; const [selectedParticipants, setSelectedParticipants] = React.useState(true); const [selectedSeason, setSelectedSeason] = React.useState(1); const { data: show, isLoading: showLoading } = useShow(showId); const { data: seasonCount = 0, isLoading: seasonCountLoading } = useSeasonCount(showId); const { data: participants, isLoading: pLoading, isError: pError, } = useSeasonParticipants(showId, selectedSeason); const { data: dates } = useSeasonDates(showId, selectedSeason); const startDate = dates?.startDate; const sortedParticipants = React.useMemo(() => { return [...participants].sort((a, b) => a.name.localeCompare(b.name, "de", { sensitivity: "base" }), ); }, [participants]); React.useEffect(() => { if (seasonCount > 0 && selectedSeason > seasonCount) { setSelectedSeason(1); } }, [seasonCount, selectedSeason]); const formattedStartDate = React.useMemo(() => { if (!startDate) return ""; const d = new Date(startDate); if (isNaN(d.getTime())) return ""; return d.toLocaleDateString("de-DE", { day: "2-digit", month: "long", year: "numeric", }); }, [startDate]); const handleOpenParticipant = React.useCallback( (p: { id: number; name: string; imageUri?: string }) => { router.push({ pathname: "/participant", params: { participantId: p.id, name: p.name, imageUri: p.imageUri || "", originShowId: String(showId), originSeason: String(selectedSeason), }, }); }, [showId, selectedSeason], ); const isInitialLoading = showLoading || seasonCountLoading; return ( {isInitialLoading ? ( ) : ( {logoUriString ? ( ) : null} {formattedStartDate ? ( {formattedStartDate} ) : null} setSelectedParticipants(true)} style={{ backgroundColor: selectedParticipants ? "rgba(25,158,219,0.2)" : "transparent", borderRadius: 20, borderWidth: selectedParticipants ? StyleSheet.hairlineWidth : 0, borderColor: "rgba(25,158,219,0.4)", }} > Teilnehmer setSelectedParticipants(false)} style={{ backgroundColor: !selectedParticipants ? "rgba(25,158,219,0.2)" : "transparent", borderRadius: 20, borderWidth: !selectedParticipants ? StyleSheet.hairlineWidth : 0, borderColor: "rgba(25,158,219,0.4)", }} > Details {selectedParticipants ? ( <> Staffeln {Array.from({ length: seasonCount }, (_, idx) => idx + 1).map( (season) => ( { setSelectedSeason(season); Haptics.impactAsync( Haptics.ImpactFeedbackStyle.Light, ); }} > {season} ), )} {pError && ( {pError} )} {pLoading && ( )} {!pLoading && !pError && participants.length === 0 && ( Keine Teilnehmer. )} {!pLoading && sortedParticipants.map((p) => ( handleOpenParticipant(p)} > {p.name} ))} ) : ( )} )} ); }