'use client';
import { zodResolver } from '@hookform/resolvers/zod';
import cookies from 'js-cookie';
import { notFound, useRouter } from 'next/navigation';
import { useContext, useState } from 'react';
import { useForm } from 'react-hook-form';
import { useSWRConfig } from 'swr';
import * as z from 'zod';
import { usePuzzle } from '@/lib/hooks/use-puzzles';
import { getURL } from '@/lib/utils';
import { Button } from '@/components/ui/Button';
import { Form, FormControl, FormField, FormItem, FormLabel } from '@/components/ui/Form';
import { Input } from '@/components/ui/Input';
import ToHTML from '@/components/ui/ToHTML';
import { UserContext } from '@/context/user';
import { type Puzzle } from '@/lib/puzzles';
import { Loader2 } from 'lucide-react';
import { Separator } from '@/components/ui/Separator';
type Granted = {
tries: number | null;
score?: number | null;
message?: string | null;
success?: boolean | null;
};
export default function Puzzle({ token, id }: { token: string; id: number }) {
const { data: me } = useContext(UserContext);
const { data: puzzle, isLoading } = usePuzzle({ token, id });
const router = useRouter();
if (!puzzle && isLoading) {
return <>>;
}
if (!puzzle) {
notFound();
}
// TODO : add a check to see if the user is in the group of the puzzle
if (me?.groups.length === 0) {
router.push('/dashboard/puzzles');
}
return (