"use client";

import Link from "next/link";
import { useEffect, useState } from "react";

const VIDEO_URL =
  "https://res.cloudinary.com/djmddrfv2/video/upload/v1776867708/1776635758203726_mql5sn.mp4";

export default function ServiceStory() {
  const [isVideoOpen, setIsVideoOpen] = useState(false);

  useEffect(() => {
    if (!isVideoOpen) return;
    const onKeyDown = (e: KeyboardEvent) => {
      if (e.key === "Escape") setIsVideoOpen(false);
    };
    window.addEventListener("keydown", onKeyDown);
    document.body.style.overflow = "hidden";
    return () => {
      window.removeEventListener("keydown", onKeyDown);
      document.body.style.overflow = "";
    };
  }, [isVideoOpen]);

  return (
    <section
      id="home-story"
      className="relative overflow-hidden bg-gradient-to-b from-white via-[#fbf7f0] to-white pt-24 px-4 sm:px-6 lg:px-8"
    >
      <div
        aria-hidden
        className="pointer-events-none absolute -top-32 left-1/2 h-72 w-72 -translate-x-1/2 rounded-full bg-[#d6ac63]/10 blur-3xl"
      />
      <div
        aria-hidden
        className="pointer-events-none absolute -bottom-32 right-0 h-80 w-80 rounded-full bg-[#d6ac63]/10 blur-3xl"
      />

      <div className="relative mx-auto max-w-5xl">
        <div className="flex flex-col items-center text-center">
          <span className="inline-flex items-center gap-2 rounded-full border border-[#d6ac63]/40 bg-white/60 px-4 py-1.5 text-xs font-light uppercase tracking-wide text-[#d6ac63] backdrop-blur">
            <span className="h-1.5 w-1.5 rounded-full bg-[#d6ac63]" />
            Our Story
          </span>

          <p className="mt-8 max-w-4xl text-center font-light text-sm sm:text-base  tracking-wide text-black md:text-lg lg:text-xl ">
            Experience a sanctuary of success, intimacy, and celebration. At{" "}
            <span className="font-light text-black">Fauzan</span>, we are rooted
            in transformative luxury where guests immerse themselves in an elevated experience.
          </p>

          <button
            type="button"
            onClick={() => setIsVideoOpen(true)}
            className="group relative mt-12 inline-flex flex-col items-center gap-3"
            aria-label="Play service story video"
          >
            <span className="relative flex h-20 w-20 items-center justify-center">
              <span className="absolute inset-0 rounded-full bg-[#d6ac63]/20 transition-transform duration-500 group-hover:scale-110" />
              <span className="absolute inset-2 animate-ping rounded-full bg-[#d6ac63]/30" />
              <span className="relative flex h-16 w-16 items-center justify-center rounded-full bg-[#d6ac63] text-white shadow-lg shadow-[#d6ac63]/40 transition-all duration-300 group-hover:scale-105 group-hover:shadow-xl group-hover:shadow-[#d6ac63]/50">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  viewBox="0 0 24 24"
                  fill="currentColor"
                  className="ml-1 h-6 w-6"
                  aria-hidden
                >
                  <path d="M8 5v14l11-7-11-7z" />
                </svg>
              </span>
            </span>
            <span className="text-xs font-light uppercase tracking-wide text-gray-500 transition-colors group-hover:text-[#d6ac63]">
              Play Video
            </span>
          </button>

          <div className="mt-14 flex flex-col items-stretch justify-center gap-3 sm:flex-row sm:flex-wrap">
            <a
              href="/docs/doc_fauzan-riviera-fact-sheet.pdf"
              download
              className="group inline-flex uppercase tracking-wide items-center justify-center gap-2  border border-[#d6ac63] bg-white/70 px-6 py-3 text-[10px] lg:text-xs font-light text-black backdrop-blur transition-all duration-300 hover:bg-[#d6ac63] hover:text-white hover:shadow-lg hover:shadow-[#d6ac63]/30"
            >
              <svg
                xmlns="http://www.w3.org/2000/svg"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                strokeWidth="2"
                strokeLinecap="round"
                strokeLinejoin="round"
                className="h-4 w-4 transition-transform duration-300 group-hover:translate-y-0.5"
                aria-hidden
              >
                <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
                <polyline points="7 10 12 15 17 10" />
                <line x1="12" y1="15" x2="12" y2="3" />
              </svg>
              Fauzan Jersey Rivera
            </a>
            <a
              href="/docs/doc_fauzan-country-club-fact-sheet.pdf"
              download
              className="group inline-flex uppercase tracking-wide items-center justify-center gap-2  border border-[#d6ac63] bg-white/70 px-6 py-3 text-[10px] lg:text-xs font-light text-black backdrop-blur transition-all duration-300 hover:bg-[#d6ac63] hover:text-white hover:shadow-lg hover:shadow-[#d6ac63]/30"
            >
              <svg
                xmlns="http://www.w3.org/2000/svg"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                strokeWidth="2"
                strokeLinecap="round"
                strokeLinejoin="round"
                className="h-4 w-4 transition-transform duration-300 group-hover:translate-y-0.5"
                aria-hidden
              >
                <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
                <polyline points="7 10 12 15 17 10" />
                <line x1="12" y1="15" x2="12" y2="3" />
              </svg>
              Fauzan Country Club
            </a>
          </div>
        </div>

        <div
          className="mx-auto mt-20 h-px w-full max-w-4xl bg-gradient-to-r from-transparent via-[#d6ac63]/60 to-transparent"
          aria-hidden
        />
      </div>

      {isVideoOpen && (
        <div
          className="fixed inset-0 z-[70] flex items-center justify-center bg-black/80 p-4 backdrop-blur-md animate-in fade-in duration-300"
          onClick={() => setIsVideoOpen(false)}
          role="presentation"
        >
          <div
            className="relative w-full max-w-5xl overflow-hidden rounded-2xl bg-black shadow-2xl ring-1 ring-white/10"
            onClick={(e) => e.stopPropagation()}
            onKeyDown={(e) => e.stopPropagation()}
          >
            <button
              type="button"
              onClick={() => setIsVideoOpen(false)}
              className="absolute right-4 top-4 z-10 flex h-10 w-10 items-center justify-center rounded-full bg-white/10 text-white backdrop-blur-md transition-all duration-300 hover:bg-white/20 hover:scale-110"
              aria-label="Close video"
            >
              <svg
                xmlns="http://www.w3.org/2000/svg"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                strokeWidth="2"
                strokeLinecap="round"
                strokeLinejoin="round"
                className="h-5 w-5"
                aria-hidden
              >
                <line x1="18" y1="6" x2="6" y2="18" />
                <line x1="6" y1="6" x2="18" y2="18" />
              </svg>
            </button>
            <div className="aspect-video w-full">
              <video
                className="h-full w-full"
                src={VIDEO_URL}
                autoPlay
                controls
                playsInline
              />
            </div>
          </div>
        </div>
      )}
    </section>
  );
}
