import Link from 'next/link'; import React, { useState } from 'react'; import { format } from 'date-fns'; import { es } from 'date-fns/locale'; import Coin from '../../common/Coin'; import RoundedLink from '../../common/RoundedLink'; import ArrowRight from '../../icons/ArrowRight'; import Challenge from '../../icons/Challenge'; import Closure from '../../icons/Closure'; import Formation from '../../icons/Formation'; import Trivial from '../../icons/Trivial'; import GoBackArrow from '../../icons/GoBackArrow'; import { Phases } from '../../../model/common'; import { RingProps } from '../../../model/components/ring'; import { Activity, Ring, Routes } from '../../../model/rings'; import PhaseItem from './PhaseItem'; import ClinicCase from '../../icons/ClinicCase'; import Event from '../../icons/Event'; const CurrentRingDetail: React.FC = ({ ring, user }) => { const { order, duration, title, description, challenge, training, trivial, closure, clinicCase, } = ring; const { answers, team: { ringScores }, } = user; const currentScore = ringScores?.find( (score) => (score.ring as Ring).id === ring.id, )?.score; const phaseIndex = answers?.find((ans) => ans.ring.id === ring.id)?.phase || 0; const [currentPhase, setCurrentPhase] = useState( Math.min(phaseIndex, 3), ); const isLastRing = ring.order === 5; const phases: Activity[] = [ training.info, trivial.info, isLastRing ? clinicCase.info : challenge.info, closure.info, ]; const phase = phases[currentPhase]; let disabled = false; if (isLastRing && currentPhase > 2) { const startDate = new Date(phase.startDate); const endDate = new Date(phase.endDate); const today = new Date(); disabled = startDate >= today || endDate <= today; } const { description: activityDescription, title: activityTitle, startDate, endDate, value, } = phase; const startDateObject = new Date(startDate); const endDateObject = new Date(endDate); let route = Routes[currentPhase]; if (isLastRing && currentPhase === 2) { // eslint-disable-next-line prefer-destructuring route = Routes[4]; } if (isLastRing && currentPhase === 3) { // eslint-disable-next-line prefer-destructuring route = Routes[5]; } return (

{`Anillo ${order} | Duración aprox. ${duration} hora`}

{title}

Puntuación actual anillo

{currentScore || 0} pts

{description}

setCurrentPhase(0)} currentPhaseNumber={phaseIndex} phaseNumber={0} icon={} points={1} selected={currentPhase === 0} /> setCurrentPhase(1)} currentPhaseNumber={phaseIndex} phaseNumber={1} icon={} points={5} disabled={phaseIndex !== 1} selected={currentPhase === 1} /> setCurrentPhase(2)} currentPhaseNumber={phaseIndex} phaseNumber={2} icon={ isLastRing ? ( ) : ( ) } points={1} disabled={phaseIndex !== 2} selected={currentPhase === 2} /> setCurrentPhase(3)} currentPhaseNumber={phaseIndex} phaseNumber={3} icon={ isLastRing ? ( ) : ( ) } disabled={phaseIndex < 3} selected={currentPhase === 3} />

{`Del ${format( startDateObject, "d 'de' MMMM", { locale: es }, )} al ${format(endDateObject, "d 'de' MMMM", { locale: es, })}`}

{activityTitle}

{activityDescription}

{`${value} pto${ value !== 1 ? 's' : '' } x participante / Nº Miembros`}

{!disabled ? ( } title="Jugar" /> ) : null}
); }; export default CurrentRingDetail;