import type { Metadata } from "next";

import "./globals.css";



import type { Viewport } from "next";

export const viewport: Viewport = {
  themeColor: "#111b21",
};

export const metadata: Metadata = {
  title: "JUMPA.ID | Enterprise Video Conference",
  description: "Secure B2B WebRTC Gateway",
  manifest: "/manifest.json",
  appleWebApp: {
    capable: true,
    statusBarStyle: "black-translucent",
    title: "JUMPA VC",
  },
};

import crypto from "crypto";

import { OmniSyncProvider } from "../components/OmniSyncProvider";

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  // TSM Versioning Format: [TSM.ID].hh.mm.ss.DD.MM.YYYY.XXXX
  const date = new Date();
  const format2 = (n: number) => n.toString().padStart(2, '0');
  const hh = format2(date.getUTCHours());
  const mm = format2(date.getUTCMinutes());
  const ss = format2(date.getUTCSeconds());
  const DD = format2(date.getUTCDate());
  const MM = format2(date.getUTCMonth() + 1);
  const YYYY = date.getUTCFullYear();
  const XXXX = crypto.randomBytes(2).toString('hex').toUpperCase();
  const tsmVersion = `[TSM.ID].${hh}.${mm}.${ss}.${DD}.${MM}.${YYYY}.${XXXX}`;

  return (
    <html lang="id">
      <head>
        <link rel="manifest" href="/manifest.json" />
        <link rel="apple-touch-icon" href="/icon512_maskable.png" />
        <script dangerouslySetInnerHTML={{__html: `
          // PKX NUCLEAR CACHE BUSTER: Unregister all Service Workers & clear all caches
          if ('serviceWorker' in navigator) {
            navigator.serviceWorker.getRegistrations().then(function(registrations) {
              for (var i = 0; i < registrations.length; i++) {
                registrations[i].unregister();
              }
            });
          }
          if ('caches' in window) {
            caches.keys().then(function(names) {
              for (var i = 0; i < names.length; i++) {
                caches.delete(names[i]);
              }
            });
          }
        `}} />
      </head>
      <body className={`antialiased font-sans bg-[#050B14] text-white`}>
        <OmniSyncProvider initialLocale="id">
          {children}
          {/* TSM PERMANENT WATERMARK */}
          <div className="fixed bottom-1 right-1 z-[9999] opacity-30 pointer-events-none select-none">
            <span className="text-[8px] font-mono text-white tracking-widest drop-shadow-[0_0_5px_rgba(255,255,255,0.8)]">
              {tsmVersion}
            </span>
          </div>
        </OmniSyncProvider>
      </body>
    </html>
  );
}
