import { auth } from "@/auth";
import { redirect } from "next/navigation";
import Providers from "@/components/Providers";
import Sidebar from "@/components/Sidebar";
import { getDictionary, Locale } from "@/app/dictionaries";

export default async function DashboardLayout(
  props: {
    children: React.ReactNode;
    params: Promise<{ lang: string }>;
  }
) {
  const params = await props.params;

  const {
    children
  } = props;

  const session = await auth();
  if (!session) redirect(`/${params.lang}/login`);

  const dict = await getDictionary(params.lang as Locale);

  return (
    <Providers>
      <div className="app-layout">
        <Sidebar dict={dict.sidebar} lang={params.lang} />
        <div className="main-content">{children}</div>
      </div>
    </Providers>
  );
}
