/* ============================================================
   HÔTEL OMÉGA — WhatsApp Floating Action Button
   Trilingual pre-filled greeting; persistent + dismissable
   ============================================================ */

const WA_NUMBER = "594694203624"; // +594 694 20 36 24 — Hôtel Oméga

function WhatsAppFAB() {
  const [t, lang] = window.useT();
  const [hidden, setHidden] = React.useState(() => {
    try { return localStorage.getItem("omega-wa-dismissed") === "1"; } catch (_) { return false; }
  });
  const [hover, setHover] = React.useState(false);

  if (hidden) return null;

  const greeting = encodeURIComponent(t("wa.greeting"));
  const href = `https://wa.me/${WA_NUMBER}?text=${greeting}`;

  const dismiss = (e) => {
    e.preventDefault();
    e.stopPropagation();
    setHidden(true);
    try { localStorage.setItem("omega-wa-dismissed", "1"); } catch (_) {}
  };

  return (
    <div
      className="wa-fab"
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
    >
      {hover && (
        <div className="wa-fab-tooltip">
          <div className="wa-fab-tip-title">{t("wa.tipTitle")}</div>
          <div className="wa-fab-tip-sub">{t("wa.tipSub")}</div>
        </div>
      )}
      <a
        href={href}
        target="_blank"
        rel="noopener noreferrer"
        className="wa-fab-btn"
        aria-label="WhatsApp"
      >
        <svg viewBox="0 0 32 32" width="28" height="28" aria-hidden="true">
          <path
            fill="#fff"
            d="M16 3C9.4 3 4 8.4 4 15c0 2.4.7 4.6 1.9 6.5L4 29l7.7-1.8c1.8 1 3.9 1.5 6.3 1.5 6.6 0 12-5.4 12-12S22.6 3 16 3zm0 21.8c-2 0-3.9-.5-5.5-1.5l-.4-.2-4.5 1.1 1.2-4.4-.3-.4C5.4 18.3 4.8 16.7 4.8 15c0-5.6 4.6-10.2 10.2-10.2 2.7 0 5.3 1.1 7.2 3 1.9 1.9 3 4.5 3 7.2 0 5.6-4.6 10.2-10.2 10.2z"
          />
          <path
            fill="#fff"
            d="M22 17.6c-.3-.2-1.7-.9-2-1-.3-.1-.5-.2-.7.2-.2.3-.8 1-1 1.2-.2.2-.4.2-.6.1-.3-.2-1.2-.4-2.3-1.4-.9-.8-1.4-1.7-1.6-2-.2-.3 0-.5.1-.6.1-.1.3-.4.4-.5.1-.2.2-.3.3-.5.1-.2 0-.4 0-.5-.1-.2-.7-1.6-.9-2.2-.2-.6-.5-.5-.7-.5h-.6c-.2 0-.5.1-.8.4-.3.3-1 1-1 2.4 0 1.4 1 2.8 1.2 3 .1.2 2 3.1 4.9 4.3.7.3 1.2.5 1.7.6.7.2 1.3.2 1.8.1.6-.1 1.7-.7 2-1.4.2-.7.2-1.2.2-1.4-.1-.1-.3-.2-.6-.3z"
          />
        </svg>
      </a>
      <button
        className="wa-fab-close"
        onClick={dismiss}
        aria-label="Close"
        title={t("wa.dismiss")}
      >×</button>
    </div>
  );
}

window.WhatsAppFAB = WhatsAppFAB;
