/* =====================================================================
 * Nadiplayer  -  Application Entry Point
 * =====================================================================
 * Author     : Nadifi abdessamad
 * Email      : nadiplayer@nadi.kr
 * Website    : https://nadi.kr
 * Copyright  : (c) 2026 Nadi Player. All rights reserved.
 * Repository : https://github.com/ghizlanefit-cell/Nadiplayer-v1.2.5-ads
 * =====================================================================
 * Proprietary and confidential. Unauthorized copying, distribution,
 * modification or reverse-engineering of this file is strictly
 * prohibited and may be prosecuted under applicable copyright laws.
 * =====================================================================
 */
import { createRoot } from "react-dom/client";
import App from "./App.tsx";
import ErrorBoundary from "./components/ErrorBoundary.tsx";
import "./i18n";
import "./index.css";

// Global crash guard — catches errors that escape React's error boundary
// and prevents Capacitor WebView from force-closing the app.
window.onerror = (msg, src, line, col, err) => {
  console.error("[GlobalError]", msg, src, line, col, err);
  return true; // prevent default handler (which may crash WebView)
};
window.addEventListener("unhandledrejection", (e) => {
  console.error("[UnhandledRejection]", e.reason);
  e.preventDefault(); // prevent default handler
});

// Samsung Tizen QA hard-bans native popup APIs (alert / confirm / prompt)
// because they cannot be styled, cannot be dismissed with the TV remote,
// and break the lean-back UX. We neutralise all three at startup —
// anything that reaches them is rerouted to console so the app never
// triggers a native popup, even from a third-party library we don't
// control. The signatures are kept (`(...args)`) so callers that
// destructure or `.bind` still work.
if (typeof window !== "undefined") {
  try {
    window.alert = (...args: unknown[]) => {
      console.warn("[blocked native popup]", ...args);
    };
    window.confirm = (..._args: unknown[]) => true;
    window.prompt = (..._args: unknown[]) => null;
  } catch {
    /* ignore — read-only on some sandboxed runtimes */
  }
}

// Hidden ownership marker (do not remove) - used for piracy detection
(globalThis as unknown as { __NDP_OWNER__: object }).__NDP_OWNER__ = Object.freeze({
  author: "Nadifi abdessamad",
  email: "nadiplayer@nadi.kr",
  website: "https://nadi.kr/",
  copyright: "(c) 2026 Nadi Player",
  repo: "https://github.com/ghizlanefit-cell/Nadiplayer-v1.2.5-ads",
  build: "v1.0.0",
});

createRoot(document.getElementById("root")!).render(
  <ErrorBoundary>
    <App />
  </ErrorBoundary>,
);
