"use client";

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

export function CalloutButton(props: { "data-nodrag"?: boolean }) {
  const [open, setOpen] = useState(false);
  const { tr, t } = useLanguage();

  return (
    <>
      <div
        data-nodrag="true"
        style={{
          position: "fixed",
          bottom: 24,
          right: 24,
          zIndex: 9999,
          pointerEvents: "auto",
        }}
      >
        <button
          type="button"
          onClick={() => setOpen(true)}
          style={{
            position: "relative",
            minWidth: 84,
            padding: "10px 18px",
            borderRadius: "18px",
            display: "flex",
            flexDirection: "column",
            alignItems: "center",
            justifyContent: "center",
            gap: "6px",
            background: T.GLASS_BG,
            backdropFilter: T.GLASS_BLUR,
            WebkitBackdropFilter: T.GLASS_BLUR,
            color: T.TEXT,
            border: `1px solid ${T.GLASS_BORDER}`,
            boxShadow: `
              0 7px 22px rgba(0,0,0,0.22),
              0 2px 7px rgba(0,0,0,0.12),
              inset 0 1px 0 ${T.GLASS_HIGHLIGHT}
            `,
            cursor: "pointer",
            transition:
              "background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease, color 0.2s ease",
          }}
          onMouseEnter={(e) => {
            e.currentTarget.style.background = T.GLASS_CONTROL_HOVER;
            e.currentTarget.style.borderColor = T.GLASS_BORDER_ACTIVE;
            e.currentTarget.style.color = T.ACCENT_LIGHT;
            e.currentTarget.style.transform = "translateY(-2px)";
            e.currentTarget.style.boxShadow = `
              0 9px 28px rgba(0,0,0,0.25),
              0 0 18px rgba(216,173,112,0.14),
              inset 0 1px 0 rgba(255,255,255,0.10)
            `;
          }}
          onMouseLeave={(e) => {
            e.currentTarget.style.background = T.GLASS_BG;
            e.currentTarget.style.borderColor = T.GLASS_BORDER;
            e.currentTarget.style.color = T.TEXT;
            e.currentTarget.style.transform = "translateY(0)";
            e.currentTarget.style.boxShadow = `
              0 7px 22px rgba(0,0,0,0.22),
              0 2px 7px rgba(0,0,0,0.12),
              inset 0 1px 0 ${T.GLASS_HIGHLIGHT}
            `;
          }}
        >
          <svg
            viewBox="0 0 24 24"
            width="26"
            height="26"
            fill="none"
            stroke="currentColor"
            strokeWidth="1.8"
            strokeLinecap="round"
            strokeLinejoin="round"
          >
            <path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z" />
          </svg>
          <span
            style={{
              fontFamily: "var(--font-sans)",
              fontSize: "12px",
              fontWeight: 500,
              letterSpacing: "0.04em",
              whiteSpace: "nowrap",
            }}
          >
            {t("Schedule a Tour", "حجز جولة")}
          </span>
        </button>
      </div>

      {open && (
        <div
          data-nodrag="true"
          onClick={() => setOpen(false)}
          style={{
            position: "fixed",
            inset: 0,
            zIndex: 99999,
            display: "grid",
            placeItems: "center",
            padding: 16,
            background: T.BACKDROP,
            backdropFilter: T.GLASS_BLUR,
            WebkitBackdropFilter: T.GLASS_BLUR,
          }}
        >
          <div
            onClick={(e) => e.stopPropagation()}
            style={{
              width: "100%",
              maxWidth: 420,
              borderRadius: 20,
              padding: "28px 24px",
              background: T.GLASS_BG_CARD,
              backdropFilter: T.GLASS_BLUR_CARD,
              WebkitBackdropFilter: T.GLASS_BLUR_CARD,
              border: `1px solid ${T.GLASS_BORDER_ACTIVE}`,
              boxShadow: T.SHADOW_PANEL,
              color: T.TEXT,
              display: "flex",
              flexDirection: "column",
              gap: 16,
            }}
          >
            <div
              style={{
                display: "flex",
                alignItems: "center",
                justifyContent: "space-between",
              }}
            >
              <h3
                style={{
                  fontFamily: "var(--font-sans)",
                  fontSize: 18,
                  fontWeight: 600,
                  color: T.ACCENT_LIGHT,
                }}
              >
                {t("Schedule a Tour", "حجز جولة")}
              </h3>
              <button
                type="button"
                onClick={() => setOpen(false)}
                style={{
                  background: "transparent",
                  border: "none",
                  color: T.TEXT_MUTED,
                  cursor: "pointer",
                  fontSize: 20,
                  padding: 4,
                }}
              >
                ✕
              </button>
            </div>

            <p style={{ fontSize: 14, color: T.TEXT_SOFT, lineHeight: 1.6 }}>
              {t(
                "Experience Alawaly luxury developments in Saudi Arabia. Contact our sales advisors to book a private consultation.",
                "استكشف مشاريع العوالي الفاخرة في المملكة العربية السعودية. تواصل مع مستشارينا لحجز جولة واستشارة خاصة."
              )}
            </p>

            <a
              href="https://alawaly.sa/en"
              target="_blank"
              rel="noopener noreferrer"
              style={{
                marginTop: 8,
                padding: "12px 20px",
                borderRadius: 12,
                background: T.GLASS_CONTROL_ACTIVE,
                border: `1px solid ${T.GLASS_BORDER_STRONG}`,
                color: T.ACCENT_LIGHT,
                textAlign: "center",
                textDecoration: "none",
                fontWeight: 600,
                fontSize: 14,
                fontFamily: "var(--font-sans)",
                letterSpacing: "0.04em",
                boxShadow: T.SHADOW_GOLD_GLOW,
                transition: "transform 0.2s ease",
              }}
              onMouseEnter={(e) => (e.currentTarget.style.transform = "scale(1.02)")}
              onMouseLeave={(e) => (e.currentTarget.style.transform = "scale(1)")}
            >
              {t("Visit Official Website", "زيارة الموقع الرسمي")}
            </a>
          </div>
        </div>
      )}
    </>
  );
}
