'use client' import { useState, useEffect } from 'react' import { Search, Check, X, Loader2, Calendar, Building2, Server, Plus, AlertTriangle, Clock, Lock, Crosshair, ArrowRight, Sparkles } from 'lucide-react' import { api } from '@/lib/api' import { useStore } from '@/lib/store' import Link from 'next/link' import clsx from 'clsx' interface CheckResult { domain: string status: string is_available: boolean registrar: string | null expiration_date: string | null name_servers: string[] | null error_message: string | null } const PLACEHOLDERS = [ 'crypto.ai', 'hotel.zurich', 'startup.io', 'finance.xyz', 'meta.com', 'shop.app' ] export function DomainChecker() { const [domain, setDomain] = useState('') const [loading, setLoading] = useState(false) const [result, setResult] = useState(null) const [error, setError] = useState(null) const { isAuthenticated } = useStore() const [isFocused, setIsFocused] = useState(false) // Typing effect state const [placeholder, setPlaceholder] = useState('') const [placeholderIndex, setPlaceholderIndex] = useState(0) const [charIndex, setCharIndex] = useState(0) const [isDeleting, setIsDeleting] = useState(false) const [isPaused, setIsPaused] = useState(false) // Typing effect logic useEffect(() => { if (isFocused || domain) return // Stop animation when user interacts const currentWord = PLACEHOLDERS[placeholderIndex] const typeSpeed = isDeleting ? 50 : 100 const pauseTime = 2000 if (isPaused) { const timeout = setTimeout(() => { setIsPaused(false) setIsDeleting(true) }, pauseTime) return () => clearTimeout(timeout) } const timeout = setTimeout(() => { if (!isDeleting) { // Typing if (charIndex < currentWord.length) { setPlaceholder(currentWord.substring(0, charIndex + 1)) setCharIndex(prev => prev + 1) } else { // Finished typing, pause before deleting setIsPaused(true) } } else { // Deleting if (charIndex > 0) { setPlaceholder(currentWord.substring(0, charIndex - 1)) setCharIndex(prev => prev - 1) } else { // Finished deleting, move to next word setIsDeleting(false) setPlaceholderIndex((prev) => (prev + 1) % PLACEHOLDERS.length) } } }, typeSpeed) return () => clearTimeout(timeout) }, [charIndex, isDeleting, isPaused, placeholderIndex, isFocused, domain]) const handleCheck = async (e: React.FormEvent) => { e.preventDefault() if (!domain.trim()) return setLoading(true) setError(null) setResult(null) try { const res = await api.checkDomain(domain) setResult(res) } catch (err) { setError(err instanceof Error ? err.message : 'Unable to check domain') } finally { setLoading(false) } } const formatDate = (dateStr: string | null) => { if (!dateStr) return null return new Date(dateStr).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', }) } const getDaysUntilExpiration = (dateStr: string | null) => { if (!dateStr) return null const expDate = new Date(dateStr) const now = new Date() const diffTime = expDate.getTime() - now.getTime() const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) return diffDays } return (
{/* Search Form */}
{/* Glow effect container - always visible, stronger on focus */}
{/* Input container */}
{/* Tech Corners */}
setDomain(e.target.value)} onFocus={() => setIsFocused(true)} onBlur={() => setIsFocused(false)} placeholder={isFocused ? "Enter domain..." : `Search ${placeholder}|`} className="w-full px-5 sm:px-7 py-5 sm:py-6 pr-32 sm:pr-40 bg-transparent rounded-none text-base sm:text-lg text-white placeholder:text-white/40 focus:outline-none transition-colors font-mono tracking-tight" />
{/* Error State */} {error && (

{error}

)} {/* Result Card */} {result && (
{result.is_available ? ( /* ========== AVAILABLE DOMAIN ========== */
{/* Inner Content */}
Available
// IMMEDIATE_DEPLOY

{result.domain}

Ready for immediate acquisition.

Status Market Open
Acquire Asset
) : ( /* ========== TAKEN DOMAIN ========== */
Locked

{result.domain}

{/* Details Grid */}
Registrar {result.registrar || 'Unknown'}
Expires {formatDate(result.expiration_date) || 'Unknown'}
Target this asset? Monitor Status
)}
)}
) }