File size: 7,012 Bytes
587459d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3e44c7
587459d
 
 
 
 
 
 
 
d3e44c7
587459d
 
 
 
 
 
 
 
d3e44c7
587459d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3e44c7
587459d
 
 
 
 
 
 
 
 
d3e44c7
 
587459d
d3e44c7
587459d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3e44c7
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"use client";

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

export function CinematicPreloader() {
  const { t, language } = useLanguage();
  const audio = useSplitFlapAudio();
  const [isVisible, setIsVisible] = useState(false);
  const [progress, setProgress] = useState(0);
  const [logs, setLogs] = useState<string[]>([]);
  const [stage, setStage] = useState(0);

  useEffect(() => {
    const init = setTimeout(() => {
      // Check session storage to show only once per session
      const hasSeenPreloader = sessionStorage.getItem("hubapi_preloader_seen");
      if (hasSeenPreloader === "true") {
        setIsVisible(false);
        return;
      }
      setIsVisible(true);
    }, 0);

    return () => clearTimeout(init);
  }, []);

  useEffect(() => {
    if (!isVisible) return;

    // Simulate step-by-step logs loading in correct language
    const logsEn = [
      "CONNECTING TO NEURAL MESH GATEWAY...",
      "ESTABLISHING HOSTINGER SECURE HANDSHAKE...",
      "INITIALIZING THREE.JS WEBGL PARTICLE SYSTEM...",
      "SYNCHRONIZING LATENCY METRICS AT EDGE NODES...",
      "TUNING INTELLIGENT MODEL ROUTERS...",
      "GATEWAY STABLE. SECURING NEURAL CHANNEL...",
    ];

    const logsAr = [
      "جاري الاتصال بـالبوابة العصبية العالمية...",
      "بدء المصافحة الآمنة مع خوادم HOSTINGER...",
      "تهيئة نظام الجسيمات ثلاثي الأبعاد WebGL...",
      "مزامنة مقاييس زمن الاستجابة في بوابات الحافة...",
      "تحسين موجهات الذكاء الاصطناعي التلقائية...",
      "البوابة مستقرة. تأمين القناة العصبية...",
    ];

    const currentLogs = language === "ar" ? logsAr : logsEn;

    if (stage < currentLogs.length) {
      const timer = setTimeout(() => {
        setLogs((prev) => [...prev, `${currentLogs[stage]} [OK]`]);
        setStage((prev) => prev + 1);

        // Play subtle click audio if not muted
        if (audio && !audio.isMuted) {
          audio.playClick();
        }
      }, 400);
      return () => clearTimeout(timer);
    }
  }, [isVisible, stage, language, audio]);

  useEffect(() => {
    if (!isVisible) return;

    const interval = setInterval(() => {
      setProgress((prev) => {
        if (prev >= 100) {
          clearInterval(interval);
          setTimeout(() => {
            // Dismiss preloader
            setIsVisible(false);
            sessionStorage.setItem("hubapi_preloader_seen", "true");
            // Play satisfying final release chime
            if (audio && !audio.isMuted) {
              audio.playClick(); // Click as fallback
            }
          }, 600);
          return 100;
        }
        // Accelerate progress based on stages loaded
        const increment = stage === 6 ? 15 : Math.floor(Math.random() * 8) + 4;
        return Math.min(prev + increment, 100);
      });
    }, 200);

    return () => clearInterval(interval);
  }, [isVisible, stage, audio]);

  return (
    <AnimatePresence>
      {isVisible && (
        <motion.div
          initial={{ opacity: 1 }}
          exit={{
            opacity: 0,
            y: -50,
            transition: { duration: 0.8, ease: [0.76, 0, 0.24, 1] },
          }}
          className="fixed inset-0 z-[9999] bg-black flex flex-col items-center justify-center p-6 select-none font-mono text-xs overflow-hidden"
        >
          {/* Subtle glowing grid background */}
          <div className="absolute inset-0 bg-[linear-gradient(to_right,#80808012_1px,transparent_1px),linear-gradient(to_bottom,#80808012_1px,transparent_1px)] bg-[size:40px_40px] pointer-events-none opacity-20" />
          <div className="absolute w-[500px] h-[500px] bg-primary/5 rounded-full blur-[100px] pointer-events-none" />

          <div className="w-full max-w-lg space-y-8 relative z-10">
            {/* Header Glitch Title */}
            <div className="flex flex-col items-center text-center space-y-2">
              <motion.div
                initial={{ scale: 0.9, opacity: 0 }}
                animate={{ scale: 1, opacity: 1 }}
                transition={{ duration: 0.5 }}
                className="w-12 h-12 border border-primary/40 rounded flex items-center justify-center relative shadow-[0_0_15px_rgba(var(--primary-rgb),0.2)]"
              >
                <div className="absolute w-3 h-3 bg-primary rounded-full animate-pulse shadow-[0_0_10px_var(--primary-glow)]" />
              </motion.div>
              <h2 className="font-fast-hand text-3xl tracking-widest text-foreground mt-4">
                HUBAPI
              </h2>
              <p className="text-[10px] text-muted-foreground/60 tracking-[0.2em] uppercase">
                {t("loading")}
              </p>
            </div>

            {/* Terminal Live Diagnostics */}
            <div className="h-44 p-5 rounded border border-white/5 bg-secondary/15 backdrop-blur-md overflow-hidden flex flex-col justify-end text-[10px] sm:text-xs text-primary/80 leading-relaxed font-mono">
              <div className="space-y-1.5 overflow-y-auto max-h-full pr-2">
                {logs.map((log, index) => (
                  <motion.div
                    key={index}
                    initial={{ opacity: 0, x: -10 }}
                    animate={{ opacity: 1, x: 0 }}
                    transition={{ duration: 0.3 }}
                    className="flex justify-between items-center gap-4"
                  >
                    <span>{log.split(" [OK]")[0]}</span>
                    <span className="text-primary font-bold">✓ DONE</span>
                  </motion.div>
                ))}
                {stage < 6 && (
                  <div className="flex items-center gap-1.5">
                    <span className="w-1 h-3 bg-primary animate-pulse" />
                    <span className="text-muted-foreground/60">...</span>
                  </div>
                )}
              </div>
            </div>

            {/* Progress Bar Container */}
            <div className="space-y-2">
              <div className="flex justify-between text-[10px] tracking-widest text-muted-foreground/60">
                <span>SYSTEM_INITIALIZATION</span>
                <span className="font-bold text-primary">{progress}%</span>
              </div>
              <div className="relative w-full h-1.5 bg-secondary/25 border border-white/5 rounded-full overflow-hidden">
                <motion.div
                  className="h-full bg-gradient-to-r from-primary to-amber-500 shadow-[0_0_10px_var(--primary-glow)]"
                  style={{ width: `${progress}%` }}
                />
              </div>
            </div>
          </div>
        </motion.div>
      )}
    </AnimatePresence>
  );
}