// src/pages/Login.js
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import useAuth from '../contexts/useAuth';

const Login = () => {
  const auth = useAuth();
  const [formData, setFormData] = useState({ email: '', password: '' });

  const handleSubmit = async e => {
    e.preventDefault();
    await auth.login(formData.email, formData.password);
  };

  return (
    <div className="container">
      <h2>Вход</h2>
      <form onSubmit={handleSubmit}>
        <input type="email" placeholder="Email" required onChange={(e) => setFormData({...formData, email: e.target.value})} />
        <input type="password" placeholder="Пароль" required onChange={(e) => setFormData({...formData, password: e.target.value})} />
        <button type="submit">Войти</button>
        <p>Нет аккаунта? <Link to="/register">Зарегистрируйтесь</Link></p>
      </form>
    </div>
  );
};

export default Login;