import type { Metadata, Viewport } from "next";
import Script from "next/script";
import BackButtonGuard from "@/components/back-button-guard";
import "./globals.css";

export const metadata: Metadata = {
  title: "모모유통 | 유통관리 ERP",
  description: "모모유통 유통관리 ERP",
  manifest: "/manifest.json",
  applicationName: "모모유통 ERP",
  appleWebApp: {
    capable: true,
    title: "모모ERP",
    statusBarStyle: "default",
  },
  icons: {
    icon: [
      { url: "/icon-192.png", sizes: "192x192", type: "image/png" },
      { url: "/icon-512.png", sizes: "512x512", type: "image/png" },
    ],
    apple: [{ url: "/icon-180.png", sizes: "180x180", type: "image/png" }],
  },
};

export const viewport: Viewport = {
  themeColor: "#1f2937",
  width: "device-width",
  initialScale: 1,
  maximumScale: 1,
  userScalable: false,
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="ko" className="h-full antialiased">
      <head>
        <link
          rel="stylesheet"
          href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css"
        />
      </head>
      <body className="h-full">
        <BackButtonGuard />
        {children}
        <Script id="sw-register" strategy="afterInteractive">
          {`if ('serviceWorker' in navigator) {
  window.addEventListener('load', () => {
    navigator.serviceWorker.register('/sw.js').catch(() => {});
  });
}`}
        </Script>
      </body>
    </html>
  );
}
