"use client";

import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import ReactLenis from "lenis/react";
import NavbarLayoutFloatingOverlay from '@/components/navbar/NavbarLayoutFloatingOverlay/NavbarLayoutFloatingOverlay';
import Input from '@/components/form/Input';
import ButtonBounceEffect from '@/components/button/ButtonBounceEffect/ButtonBounceEffect';
import { useState } from 'react';
import { useRouter } from 'next/navigation';

export default function AdminLoginPage() {
  const [username, setUsername] = useState('');
  const [password, setPassword] = useState('');
  const router = useRouter();

  const handleLogin = (e: React.FormEvent) => {
    e.preventDefault();
    // Basic client-side validation for demonstration
    if (username === 'admin' && password === 'admin') {
      alert('Login successful! Redirecting to dashboard.');
      router.push('/admin/dashboard');
    } else {
      alert('Invalid credentials.');
    }
  };

  return (
    <ThemeProvider
        defaultButtonVariant="expand-hover"
        defaultTextAnimation="background-highlight"
        borderRadius="rounded"
        contentWidth="compact"
        sizing="mediumLargeSizeLargeTitles"
        background="blurBottom"
        cardStyle="gradient-radial"
        primaryButtonStyle="gradient"
        secondaryButtonStyle="layered"
        headingFontWeight="normal"
    >
      <ReactLenis root>
        <div id="nav" data-section="nav">
          <NavbarLayoutFloatingOverlay
            navItems={[
              { name: "Home", id: "#home" },
              { name: "About", id: "#about" },
              { name: "Features", id: "#features" },
              { name: "Solutions", id: "#solutions" },
              { name: "Pricing", id: "#pricing" },
              { name: "Testimonials", id: "#testimonials" },
              { name: "Contact", id: "#contact" },
              { name: "Admin Login", id: "/admin/login" },
            ]}
            brandName="ReservaFlow"
            button={{ text: "Start Free Trial", href: "#contact" }}
          />
        </div>

        <div className="flex min-h-screen items-center justify-center p-4 bg-background-accent">
          <div className="w-full max-w-md space-y-8 p-10 rounded-lg shadow-xl bg-card">
            <h2 className="text-center text-3xl font-extrabold text-foreground">
              Admin Login
            </h2>
            <form className="mt-8 space-y-6" onSubmit={handleLogin}>
              <div className="rounded-md shadow-sm -space-y-px">
                <div>
                  <label htmlFor="username" className="sr-only">Username</label>
                  <Input
                    id="username"
                    name="username"
                    type="text"
                    required
                    placeholder="Username"
                    value={username}
                    onChange={setUsername}
                    className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-foreground rounded-t-md focus:outline-none focus:ring-primary-cta focus:border-primary-cta focus:z-10 sm:text-sm"
                  />
                </div>
                <div>
                  <label htmlFor="password" className="sr-only">Password</label>
                  <Input
                    id="password"
                    name="password"
                    type="password"
                    required
                    placeholder="Password"
                    value={password}
                    onChange={setPassword}
                    className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-foreground rounded-b-md focus:outline-none focus:ring-primary-cta focus:border-primary-cta focus:z-10 sm:text-sm mt-4"
                  />
                </div>
              </div>

              <ButtonBounceEffect
                type="submit"
                text="Sign in"
                className="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-primary-cta hover:bg-primary-cta-hover focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-cta"
              />
            </form>
          </div>
        </div>
      </ReactLenis>
    </ThemeProvider>
  );
}