๐Ÿ“ฆ aquaticcalf / non-euclidean-museum

๐Ÿ“„ data-terminal.tsx ยท 217 lines
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217"use client"

import { useState, useEffect, useRef } from "react"
import { motion, AnimatePresence } from "framer-motion"
import { Terminal, X, ChevronRight, Clock, Database, Download, Upload } from "lucide-react"

interface DataTerminalProps {
  isOpen: boolean
  onClose: () => void
  terminalData?: {
    title: string
    content: string[]
    accessLevel?: string
  }
}

export default function DataTerminal({
  isOpen,
  onClose,
  terminalData = {
    title: "VRTX TERMINAL",
    content: [
      "Initializing non-Euclidean data stream...",
      "Connecting to central neural network...",
      "Access granted to museum database.",
      "WARNING: Spatial anomalies detected in sector 7.",
      "Use caution when traversing non-Euclidean spaces.",
      "Reality distortion fields active in all exhibits.",
    ],
    accessLevel: "VISITOR",
  },
}: DataTerminalProps) {
  const [displayedLines, setDisplayedLines] = useState<string[]>([])
  const [cursorPosition, setCursorPosition] = useState(0)
  const [showCursor, setShowCursor] = useState(true)
  const [isTyping, setIsTyping] = useState(false)
  const terminalRef = useRef<HTMLDivElement>(null)

  // Auto-typing effect for terminal text
  useEffect(() => {
    if (isOpen && terminalData.content.length > 0) {
      setDisplayedLines([])
      setIsTyping(true)

      let currentLineIndex = 0
      let currentCharIndex = 0
      const typingInterval = setInterval(() => {
        if (currentLineIndex < terminalData.content.length) {
          const currentLine = terminalData.content[currentLineIndex]

          if (currentCharIndex <= currentLine.length) {
            setDisplayedLines((prev) => {
              const newLines = [...prev]
              newLines[currentLineIndex] = currentLine.substring(0, currentCharIndex)
              return newLines
            })
            currentCharIndex++
            setCursorPosition(currentCharIndex)
          } else {
            currentLineIndex++
            currentCharIndex = 0
            setCursorPosition(0)
          }
        } else {
          setIsTyping(false)
          clearInterval(typingInterval)
        }
      }, 30)

      return () => clearInterval(typingInterval)
    }
  }, [isOpen, terminalData])

  // Blinking cursor effect
  useEffect(() => {
    const cursorInterval = setInterval(() => {
      setShowCursor((prev) => !prev)
    }, 500)

    return () => clearInterval(cursorInterval)
  }, [])

  // Random UI glitch effects
  const [glitchX, setGlitchX] = useState(false)
  useEffect(() => {
    if (isOpen) {
      const glitchInterval = setInterval(() => {
        if (Math.random() > 0.9) {
          setGlitchX(true)
          setTimeout(() => setGlitchX(false), 150)
        }
      }, 3000)

      return () => clearInterval(glitchInterval)
    }
  }, [isOpen])

  // Get current time
  const [currentTime, setCurrentTime] = useState("")
  useEffect(() => {
    if (isOpen) {
      const timer = setInterval(() => {
        const date = new Date()
        setCurrentTime(date.toLocaleTimeString())
      }, 1000)
      return () => clearInterval(timer)
    }
  }, [isOpen])

  return (
    <AnimatePresence>
      {isOpen && (
        <div className="fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm z-50">
          <motion.div
            initial={{ scale: 0.9, opacity: 0 }}
            animate={{ scale: 1, opacity: 1 }}
            exit={{ scale: 0.9, opacity: 0 }}
            transition={{ type: "spring", stiffness: 300, damping: 30 }}
            className={`w-[600px] max-w-[90vw] h-[400px] max-h-[80vh] bg-black/80 backdrop-blur-md border border-cyan-500/50 ${glitchX ? "glitch-x" : ""}`}
          >
            {/* Terminal Header */}
            <div className="h-8 bg-cyan-900/30 border-b border-cyan-500/50 flex items-center justify-between px-3">
              <div className="flex items-center">
                <Terminal size={14} className="text-cyan-400 mr-2" />
                <span className="text-cyan-400 font-mono text-xs">{terminalData.title}</span>
              </div>
              <div className="flex items-center space-x-3">
                <Clock size={14} className="text-cyan-400" />
                <span className="text-cyan-400 font-mono text-xs">{currentTime}</span>
                <button onClick={onClose} className="text-cyan-400 hover:text-white focus:outline-none">
                  <X size={14} />
                </button>
              </div>
            </div>

            {/* Terminal Status Bar */}
            <div className="h-6 bg-cyan-900/20 border-b border-cyan-500/30 flex items-center justify-between px-3">
              <div className="flex items-center">
                <Database size={12} className="text-cyan-400 mr-1" />
                <span className="text-cyan-400 font-mono text-xs text-opacity-80">
                  ACCESS LEVEL: {terminalData.accessLevel}
                </span>
              </div>
              <div className="flex items-center space-x-2">
                <div className="flex items-center">
                  <Download size={10} className="text-cyan-400 mr-1" />
                  <span className="text-cyan-400 font-mono text-[10px]">1.2 MB/s</span>
                </div>
                <div className="flex items-center">
                  <Upload size={10} className="text-cyan-400 mr-1" />
                  <span className="text-cyan-400 font-mono text-[10px]">0.3 MB/s</span>
                </div>
              </div>
            </div>

            {/* Terminal Content */}
            <div
              ref={terminalRef}
              className="h-[calc(100%-56px)] p-4 font-mono text-xs text-cyan-400 overflow-y-auto terminal-scrollbar"
            >
              {displayedLines.map((line, index) => (
                <div key={index} className="mb-2 flex">
                  <span className="text-cyan-500 mr-2 opacity-70">
                    <ChevronRight size={14} />
                  </span>
                  <span>
                    {line}
                    {isTyping && index === displayedLines.length - 1 && (
                      <span className={`ml-px ${showCursor ? "opacity-100" : "opacity-0"}`}>_</span>
                    )}
                  </span>
                </div>
              ))}

              {!isTyping && (
                <div className="flex">
                  <span className="text-cyan-500 mr-2 opacity-70">
                    <ChevronRight size={14} />
                  </span>
                  <span className={showCursor ? "opacity-100" : "opacity-0"}>_</span>
                </div>
              )}
            </div>
          </motion.div>
        </div>
      )}

      <style jsx global>{`
        .terminal-scrollbar::-webkit-scrollbar {
          width: 6px;
        }
        
        .terminal-scrollbar::-webkit-scrollbar-track {
          background: rgba(0, 0, 0, 0.2);
        }
        
        .terminal-scrollbar::-webkit-scrollbar-thumb {
          background: rgba(0, 190, 255, 0.3);
        }
        
        .glitch-x {
          animation: glitch-x 0.2s ease-in-out;
        }
        
        @keyframes glitch-x {
          0% { transform: translate(0); }
          25% { transform: translate(-10px, 0); }
          50% { transform: translate(10px, 0); }
          75% { transform: translate(-5px, 0); }
          100% { transform: translate(0); }
        }
      `}</style>
    </AnimatePresence>
  )
}