
import React, { useState } from 'react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';

interface LoginFormProps {
  onSubmit?: (email: string, password: string) => Promise<void> | void;
  isLoading?: boolean;
  defaultEmail?: string;
  defaultPassword?: string;
}

const LoginForm: React.FC<LoginFormProps> = ({ onSubmit, isLoading: externalLoading, defaultEmail, defaultPassword }) => {
  const [email, setEmail] = useState(defaultEmail ?? '');
  const [password, setPassword] = useState(defaultPassword ?? '');
  const [isLoading, setIsLoading] = useState(externalLoading ?? false);

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();
    setIsLoading(true);
    try {
      await onSubmit?.(email, password);
    } finally {
      setIsLoading(false);
    }
  };

  return (
    <div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-primary/20 to-secondary/20">
      <Card className="w-full max-w-md">
        <CardHeader>
          <img src="/Logo.png" alt="Logo" className="mx-auto mb-2 h-24 w-40 object-contain dark:invert dark:brightness-125" />
          <CardTitle className="text-2xl font-bold text-center">Login Erforderlich</CardTitle>
        </CardHeader>
        <CardContent>
          <form onSubmit={handleSubmit} className="space-y-4">
            <div className="space-y-2">
              <Label htmlFor="email">Email</Label>
              <Input
                id="email"
                type="email"
                placeholder="bitte E-Mail Adresse eingeben"
                value={email}
                onChange={(e) => setEmail(e.target.value)}
                required
              />
            </div>
            <div className="space-y-2">
              <Label htmlFor="password">Password</Label>
              <Input
                id="password"
                type="password"
                placeholder="bitte Passwort eingeben"
                value={password}
                onChange={(e) => setPassword(e.target.value)}
                required
              />
            </div>
            <Button 
              type="submit" 
              className="w-full" 
              disabled={isLoading}
            >
              {isLoading ? "Signing in..." : "Weiter"}
            </Button>
          </form>
        </CardContent>
      </Card>
    </div>
  );
};

export default LoginForm;
