"use client";

import Link from "next/link";
import { useState } from "react";

export default function LoginPage() {
  const [isLoading, setIsLoading] = useState(false);

  const handleGoogleLogin = () => {
    setIsLoading(true);
    window.location.href = `${process.env.NEXT_PUBLIC_API_URL}/login/google`;
  };

  return (
    <div className="min-h-screen bg-white flex flex-col">
      {/* Header */}
      <div className="border-b border-gray-200">
        <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
          <Link href="/" className="flex items-center gap-2">
            <div className="w-8 h-8 bg-gradient-to-br from-pink-600 to-purple-600 rounded-lg flex items-center justify-center">
              <span className="text-white text-sm font-bold">RP</span>
            </div>
            <span className="font-semibold text-lg">RoleplayAI</span>
          </Link>
        </div>
      </div>

      {/* Main Content */}
      <div className="flex-1 flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
        <div className="w-full max-w-md">
          <div className="space-y-8">
            {/* Welcome Section */}
            <div className="space-y-2 text-center">
              <h1 className="text-4xl font-bold">Welcome Back</h1>
              <p className="text-gray-600">Sign in to continue to RoleplayAI</p>
            </div>

            {/* Google OAuth Button */}
            <div className="space-y-4">
              <button
                onClick={handleGoogleLogin}
                disabled={isLoading}
                className="w-full border-2 border-gray-200 rounded-xl py-3 px-4 font-medium hover:bg-gray-50 transition flex items-center justify-center gap-3 disabled:opacity-50"
              >
                <svg className="w-5 h-5" viewBox="0 0 24 24">
                  <path
                    fill="currentColor"
                    d="M12.545,10.239v3.821h5.445c-0.712,2.315-2.647,3.972-5.445,3.972c-3.332,0-6.033-2.701-6.033-6.032 c0-3.331,2.701-6.032,6.033-6.032c1.498,0,2.866,0.549,3.921,1.453l2.814-2.814C17.461,2.268,15.365,1,12.545,1 C6.477,1,1.54,5.952,1.54,12s4.938,11,11.005,11c6.071,0,11.067-4.975,11.067-11c0-0.713-0.092-1.405-0.196-2.067H12.545z"
                  />
                </svg>
                {isLoading ? "Signing in..." : "Continue with Google"}
              </button>
            </div>

            {/* Divider */}
            <div className="relative">
              <div className="absolute inset-0 flex items-center">
                <div className="w-full border-t border-gray-200"></div>
              </div>
              <div className="relative flex justify-center text-sm">
                <span className="px-2 bg-white text-gray-500">or</span>
              </div>
            </div>

            {/* Email Form */}
            <form className="space-y-4">
              <div>
                <label htmlFor="email" className="block text-sm font-medium mb-2">
                  Email Address
                </label>
                <input
                  type="email"
                  id="email"
                  placeholder="you@example.com"
                  className="w-full px-4 py-3 border-2 border-gray-200 rounded-xl focus:border-black focus:outline-none transition"
                  disabled
                />
                <p className="text-xs text-gray-500 mt-2">Email login coming soon</p>
              </div>
            </form>

            {/* Agreement Text */}
            <p className="text-center text-sm text-gray-600">
              By signing in, you agree to our{" "}
              <a href="#" className="text-black font-medium hover:underline">
                Terms of Service
              </a>{" "}
              and{" "}
              <a href="#" className="text-black font-medium hover:underline">
                Privacy Policy
              </a>
            </p>

            {/* Footer Links */}
            <div className="space-y-3 text-center text-sm">
              <p>
                Don't have an account?{" "}
                <a href="#" className="text-black font-medium hover:underline">
                  Sign up
                </a>
              </p>
              <p>
                <a href="/" className="text-gray-600 hover:text-black">
                  Back to Home
                </a>
              </p>
            </div>
          </div>

          {/* Trust Indicators */}
          <div className="mt-12 pt-8 border-t border-gray-200 space-y-6">
            <p className="text-center text-xs text-gray-500">TRUSTED BY</p>
            <div className="flex justify-center items-center gap-6 text-gray-400">
              <div className="text-center">
                <div className="text-2xl font-bold text-gray-600">10K+</div>
                <p className="text-xs">Users</p>
              </div>
              <div className="w-px h-8 bg-gray-200"></div>
              <div className="text-center">
                <div className="text-2xl font-bold text-gray-600">1000+</div>
                <p className="text-xs">Characters</p>
              </div>
              <div className="w-px h-8 bg-gray-200"></div>
              <div className="text-center">
                <div className="text-2xl font-bold text-gray-600">24/7</div>
                <p className="text-xs">Support</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}
