import React from 'react';
import Link from 'next/link';
import {fetchData} from '@2fn/data';

export default function Category({data}) {
	return (
		<div>
			<div>
  {data.map(item => <Link href={`/recommendation/${item['id']}`} key={item['name']}><a><span>{item['name']}</span></a></Link>
  )}
</div>
		</div>
	);
}
	
export async function getStaticProps(context) {
  const id = context.params?.id;
  console.log('***id', id);
	const data = await fetchData(`recommendations?category.id=${id}`);
	return {
    props: { data },
    unstable_revalidate: 1,
	};
}
export async function getStaticPaths() {
    const data = await fetchData('categories');
    console.log('***data', data);
    return {
      paths: data.map(item => ({ params: {id: item['id'].toString()} })),
      fallback: true
    };
  }
