import { Metadata } from 'next';
import Navigation from '../Navigation';
import ImportTabsClient from './ImportTabsClient';
import { auth } from '../../auth';

type Props = {
  searchParams: Promise<{ tab?: string }>;
};

export async function generateMetadata({ searchParams }: Props): Promise<Metadata> {
  const { tab } = await searchParams;
  if (tab === 'recept') return { title: 'Importera recept' };
  return { title: 'Importera kvitto' };
}

export default async function ImportPage({ searchParams }: Props) {
  const { tab } = await searchParams;
  const activeTab = tab === 'recept' ? 'recept' : 'kvitto';
  const session = await auth();
  const isAdmin = (session?.user as any)?.role === 'admin';
  return (
    <>
      <Navigation />
      <ImportTabsClient activeTab={activeTab} isAdmin={isAdmin} />
    </>
  );
}
