import { requireUserInServerComponent } from '@/lib/server/require-user-in-server-component';
import ConsentDialog from './(user)/_components/consent-dialog';
import { loadCurrentUserAccount } from './(user)/_lib/server/load-user-account';

export default async function HomeLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const user = await requireUserInServerComponent();
  const account = await loadCurrentUserAccount()

  if (account && account?.has_consent_anonymized_company_statistics === null) {
    return (
      <div className="container">
        <ConsentDialog userId={user.id} />
      </div>
    );
  }

  return <>{children}</>;
}
