// This layout is used to test the revalidation logic
// The layout itself will not create any cache entries
// It will just be used to render a page
// If the layout itself uses a fetch request, it will be handled the same way as if the page itself would use a fetch request
// The layout can be revalidated as well by using revalidatePath with the path of the layout file. However, this will not revalidate the subsequent fetch requests

import type { Metadata } from 'next';
import { Geist, Geist_Mono } from 'next/font/google';
import './globals.css';

const geistSans = Geist({
  variable: '--font-geist-sans',
  subsets: ['latin'],
});

const geistMono = Geist_Mono({
  variable: '--font-geist-mono',
  subsets: ['latin'],
});

export const metadata: Metadata = {
  title: 'Create Next App',
  description: 'Generated by create next app',
};

export default async function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  // let res;
  // try {
  //   res = await fetch(`https://httpbin.org/get`, {
  //     next: {
  //       revalidate: 15,
  //       tags: ['httpbin-layout-revalidate15'],
  //     },
  //   });
  // } catch (e) {
  //   // ECONNREFUSED is expected during build
  //   // eslint-disable-next-line @typescript-eslint/no-explicit-any
  //   if (((e as Error).cause as any)?.code !== 'ECONNREFUSED') {
  //     throw e;
  //   }
  // }

  // const data = res?.ok ? await res.json() : { origin: -1 };
  return (
    <html lang="en">
      <body
        className={`${geistSans.variable} ${geistMono.variable} antialiased`}
      >
        Layout TS: {Date.now()}
        {/* Layout counter: {data.origin} */}
        {children}
      </body>
    </html>
  );
}
