"use client";

import React from "react";
import { useLanguage } from "./LanguageContext";
import * as T from "@/lib/themeTokens";

export function Loader({
  message = "Loading map…",
}: {
  message?: string;
}) {
  const { tr } = useLanguage();

  return (
    <div
      style={{
        position: "fixed",
        inset: 0,
        zIndex: 9999,
        overflow: "hidden",
        display: "grid",
        placeItems: "center",
        padding: "max(16px, env(safe-area-inset-top))",
        background: T.BACKDROP,
        backdropFilter: "saturate(1.12) blur(6px)",
        WebkitBackdropFilter: "saturate(1.12) blur(6px)",
      }}
      role="status"
      aria-live="polite"
      aria-busy="true"
    >
      <div
        aria-hidden="true"
        style={{
          position: "absolute",
          inset: 0,
          pointerEvents: "none",
          background: T.GLASS_BG,
          opacity: 0.86,
        }}
      />
      <div
        aria-hidden="true"
        style={{
          position: "absolute",
          inset: 0,
          pointerEvents: "none",
          background:
            "radial-gradient(1200px 600px at 50% 120%, rgba(216,173,112,0.09), rgba(0,0,0,0) 60%)",
        }}
      />

      <div
        style={{
          position: "relative",
          display: "flex",
          flexDirection: "column",
          alignItems: "center",
          gap: 18,
          textAlign: "center",
          padding: "16px",
          minWidth: "min(90vw, 360px)",
        }}
      >
        <div className="hash-loader" aria-hidden="true">
          <div className="hash-bar-1" />
          <div className="hash-bar-2" />
        </div>

        <div
          style={{
            fontFamily: "var(--font-sans)",
            fontSize: "16px",
            color: T.ACCENT_LIGHT,
            letterSpacing: "0.08em",
            textTransform: "uppercase",
            textShadow: "0 2px 8px rgba(0,0,0,0.4)",
            fontWeight: 500,
          }}
        >
          {tr(message)}
        </div>
      </div>
    </div>
  );
}
