import { useState } from 'react';
import { useAuth } from '../../../stores/auth';

export default function Login() {
  const [value, setValue] = useState('');
  const setToken = useAuth(s => s.setToken);

  function handleSubmit(e: React.FormEvent) {
    e.preventDefault();
    if (value.trim()) {
      setToken(value.trim());
      window.location.href = '/admin';
    }
  }

  return (
    <div className="max-w-md mx-auto mt-20">
      <div className="glass p-12">
        <h1 className="text-3xl font-bold mb-6 text-mauve">Admin Login</h1>
        <p className="text-subtext0 mb-8">Enter your admin token to access the dashboard.</p>
        <form onSubmit={handleSubmit} className="space-y-6">
          <div>
            <label htmlFor="token" className="block text-sm font-medium text-subtext1 mb-2">Admin Token</label>
            <input
              type="password"
              id="token"
              required
              value={value}
              onChange={e => setValue(e.target.value)}
              className="w-full bg-crust border border-surface1 rounded-lg px-4 py-3 text-text focus:outline-none focus:border-mauve transition-colors"
              placeholder="••••••••••••"
            />
          </div>
          <button type="submit" className="w-full bg-mauve text-crust font-bold py-3 rounded-lg hover:bg-pink transition-colors">
            Login
          </button>
        </form>
      </div>
    </div>
  );
}
