import type { GetServerSideProps } from 'next';
import { fetchFromApi } from '../../lib/serverFetch';

interface Category {
  slug: string;
}

export const getServerSideProps: GetServerSideProps = async ({ req }) => {
  const categories = await fetchFromApi<Category[]>(req, '/api/categories');
  const first = categories?.[0]?.slug;

  return {
    redirect: {
      destination: first ? `/parfemy/${first}` : '/',
      permanent: false,
    },
  };
};

export default function ParfemyIndex() {
  return null;
}
