"use client"

import { useState, useEffect } from "react"

interface GlitchTextProps {
  text: string
  className?: string
}

export function GlitchText({ text, className = "" }: GlitchTextProps) {
  const [isGlitching, setIsGlitching] = useState(false)

  useEffect(() => {
    const interval = setInterval(() => {
      setIsGlitching(true)
      setTimeout(() => setIsGlitching(false), 200)
    }, 3000)

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

  return (
    <span className={`relative inline-block ${className}`}>
      <span className={isGlitching ? "animate-pulse" : ""}>{text}</span>
      {isGlitching && (
        <>
          <span
            className="absolute top-0 left-0 text-red-500/50 animate-pulse"
            style={{ clipPath: "inset(0 0 50% 0)", transform: "translateX(-2px)" }}
          >
            {text}
          </span>
          <span
            className="absolute top-0 left-0 text-cyan-500/50 animate-pulse"
            style={{ clipPath: "inset(50% 0 0 0)", transform: "translateX(2px)" }}
          >
            {text}
          </span>
        </>
      )}
    </span>
  )
}
