File size: 2,528 Bytes
587459d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"use client";

import { useEffect, useState } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { ArrowUpRight } from "lucide-react";
import { useLanguage } from "@/components/LanguageContext";
import { useSplitFlapAudio } from "@/components/ui/split-flap-text";

export function FloatingCTA() {
  const { t } = useLanguage();
  const audio = useSplitFlapAudio();
  const [isVisible, setIsVisible] = useState(false);

  useEffect(() => {
    const handleScroll = () => {
      // Show button when user scrolls down more than 600px
      if (window.scrollY > 600) {
        setIsVisible(true);
      } else {
        setIsVisible(false);
      }
    };

    window.addEventListener("scroll", handleScroll, { passive: true });
    return () => {
      window.removeEventListener("scroll", handleScroll);
    };
  }, []);

  const handleClick = () => {
    // Play satisfying mechanical click sound
    if (audio && !audio.isMuted) {
      audio.playClick();
    }

    // Smooth scroll back to top to the waitlist input
    const inputElement = document.getElementById("email-input");
    if (inputElement) {
      inputElement.scrollIntoView({ behavior: "smooth", block: "center" });
      setTimeout(() => {
        inputElement.focus();
      }, 850);
    } else {
      window.scrollTo({ top: 0, behavior: "smooth" });
    }
  };

  return (
    <AnimatePresence>
      {isVisible && (
        <motion.button
          initial={{ opacity: 0, scale: 0.8, y: 20 }}
          animate={{ opacity: 1, scale: 1, y: 0 }}
          exit={{ opacity: 0, scale: 0.8, y: 20 }}
          whileHover={{ scale: 1.05 }}
          whileTap={{ scale: 0.95 }}
          onClick={handleClick}
          className="fixed bottom-6 right-6 sm:bottom-8 sm:right-8 z-40 flex items-center gap-2.5 px-5 h-12 rounded-full border border-primary/30 bg-primary/10 backdrop-blur-md text-primary font-mono text-[10px] font-bold tracking-widest shadow-[0_0_15px_var(--primary-glow)] hover:bg-primary/25 hover:border-primary/50 transition-all duration-300 focus-visible:outline-none"
        >
          <span className="relative flex h-2 w-2">
            <span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-primary opacity-75"></span>
            <span className="relative inline-flex rounded-full h-2 w-2 bg-primary"></span>
          </span>
          <span>{t("accessHubapi")}</span>
          <ArrowUpRight className="h-3.5 w-3.5" />
        </motion.button>
      )}
    </AnimatePresence>
  );
}