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

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

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

  return (
    <div className="container">
      <h2>Регистрация</h2>
      <form onSubmit={handleSubmit}>
        <input type="text" placeholder="Имя" required onChange={(e) => setFormData({...formData, name: e.target.value})} />
        <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="/login">Войти</Link></p>
      </form>
    </div>
  );
};

export default Register;