"use client"

import { useState } from "react"
import { useRouter } from "next/navigation"
import { Network, Eye, EyeOff, Globe, Moon, Sun } from "lucide-react"
import { useTheme } from "next-themes"
import { useLanguage } from "@/hooks/use-language"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"

export default function LoginPage() {
  const router = useRouter()
  const { theme, setTheme } = useTheme()
  const { locale, setLocale, t } = useLanguage()
  const [showPassword, setShowPassword] = useState(false)
  const [email, setEmail] = useState("admin@demoisp.com")
  const [password, setPassword] = useState("demo123")
  const [loading, setLoading] = useState(false)

  const handleLogin = async (e: React.FormEvent) => {
    e.preventDefault()
    setLoading(true)
    // Simulate login
    setTimeout(() => {
      setLoading(false)
      router.push("/dashboard")
    }, 800)
  }

  return (
    <div className="relative flex min-h-screen items-center justify-center overflow-hidden bg-gradient-to-br from-slate-900 via-blue-950 to-slate-900 p-4">
      {/* Background effects */}
      <div className="absolute inset-0 bg-[url('/grid.svg')] bg-center opacity-20" />
      <div className="absolute left-1/2 top-0 h-[500px] w-[500px] -translate-x-1/2 rounded-full bg-blue-500/20 blur-[120px]" />
      <div className="absolute bottom-0 right-0 h-[400px] w-[400px] rounded-full bg-cyan-500/10 blur-[100px]" />

      {/* Theme & Language controls */}
      <div className="absolute right-4 top-4 flex gap-2">
        <Button
          variant="ghost"
          size="sm"
          onClick={() => setLocale(locale === "en" ? "bn" : "en")}
          className="text-slate-300 hover:bg-white/10 hover:text-white"
        >
          <Globe className="mr-1.5 h-4 w-4" />
          {locale === "en" ? "বাংলা" : "English"}
        </Button>
        <Button
          variant="ghost"
          size="icon"
          onClick={() => setTheme(theme === "dark" ? "light" : "dark")}
          className="text-slate-300 hover:bg-white/10 hover:text-white"
        >
          <Sun className="h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
          <Moon className="absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
        </Button>
      </div>

      <Card className="relative z-10 w-full max-w-md border-slate-700/50 bg-slate-900/80 shadow-2xl backdrop-blur-xl">
        <CardHeader className="space-y-4 text-center">
          <div className="mx-auto flex h-14 w-14 items-center justify-center rounded-2xl bg-gradient-to-br from-blue-600 to-cyan-500 shadow-lg shadow-blue-500/30">
            <Network className="h-7 w-7 text-white" />
          </div>
          <div>
            <CardTitle className="text-2xl font-bold text-white">
              {t("appName")}
            </CardTitle>
            <CardDescription className="mt-1 text-slate-400">
              {t("companyName")}
            </CardDescription>
          </div>
        </CardHeader>

        <CardContent>
          <form onSubmit={handleLogin} className="space-y-5">
            <div className="space-y-2">
              <label className="text-sm font-medium text-slate-300">
                {t("email")}
              </label>
              <input
                type="email"
                value={email}
                onChange={(e) => setEmail(e.target.value)}
                className="w-full rounded-lg border border-slate-700 bg-slate-800/50 px-4 py-2.5 text-sm text-white placeholder:text-slate-500 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"
                placeholder="your@company.com"
                required
              />
            </div>

            <div className="space-y-2">
              <label className="text-sm font-medium text-slate-300">
                {t("password")}
              </label>
              <div className="relative">
                <input
                  type={showPassword ? "text" : "password"}
                  value={password}
                  onChange={(e) => setPassword(e.target.value)}
                  className="w-full rounded-lg border border-slate-700 bg-slate-800/50 px-4 py-2.5 pr-10 text-sm text-white placeholder:text-slate-500 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"
                  placeholder="••••••••"
                  required
                />
                <button
                  type="button"
                  onClick={() => setShowPassword(!showPassword)}
                  className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-200"
                >
                  {showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
                </button>
              </div>
            </div>

            <div className="flex items-center justify-between text-sm">
              <label className="flex items-center gap-2 text-slate-400">
                <input type="checkbox" className="rounded border-slate-600 bg-slate-800" />
                {t("rememberMe")}
              </label>
              <a href="#" className="text-blue-400 hover:text-blue-300">
                {t("forgotPassword")}
              </a>
            </div>

            <Button
              type="submit"
              className="w-full bg-gradient-to-r from-blue-600 to-cyan-500 py-2.5 font-semibold shadow-lg shadow-blue-500/25 hover:from-blue-500 hover:to-cyan-400"
              disabled={loading}
            >
              {loading ? "Signing in..." : t("login")}
            </Button>
          </form>

          <div className="mt-6 rounded-lg border border-slate-700/50 bg-slate-800/30 p-3 text-center text-xs text-slate-400">
            <p className="font-medium text-slate-300">Demo Credentials</p>
            <p className="mt-1">admin@demoisp.com / demo123</p>
          </div>
        </CardContent>
      </Card>

      <p className="absolute bottom-4 text-center text-xs text-slate-500">
        © 2026 Global Fair Communications Ltd. All rights reserved.
      </p>
    </div>
  )
}
