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

const AddObject = () => {
  const auth = useAuth();
  const [title, setTitle] = useState('');
  const [description, setDescription] = useState('');

  const handleSubmit = async e => {
    e.preventDefault();
    try {
      await axios.post('/api/add-object', { title, description }); // сюда ваш endpoint
      alert("Объект успешно добавлен!");
    } catch (err) {
      console.error(err.response ? err.response.data : err.message);
    }
  };

  return (
    <div className="container">
      <h2>Добавить объект</h2>
      <form onSubmit={handleSubmit}>
        <input type="text" placeholder="Название" required onChange={(e) => setTitle(e.target.value)} /><br/><br/>
        <textarea rows="4" cols="50" placeholder="Описание" required onChange={(e) => setDescription(e.target.value)} /><br/><br/>
        <button type="submit">Добавить</button><br/><br/>
        <Link to="/dashboard">Вернуться в личный кабинет</Link>
      </form>
    </div>
  );
};

export default AddObject;