import { cookies } from 'next/headers';

import Puzzles from '@/ui/Puzzles';
import SWRFallback from '@/ui/SWRFallback';
import { getPuzzles } from '@/lib/puzzles';
import { notFound } from 'next/navigation';

export const metadata = {
  title: 'Puzzles'
};

export default async function Page() {
  const cookieStore = cookies();
  const token = cookieStore.get('token')!.value;

  const puzzles = await getPuzzles({ token });

  if (!puzzles) {
    notFound();
  }

  return (
    <section className="flex w-full flex-col space-y-6">
      <SWRFallback fallback={{ ['puzzles']: puzzles }}>
        <Puzzles token={token!} />
      </SWRFallback>
    </section>
  );
}
