import React, { useState } from 'react';
import axios from 'axios';

const AdminRegister = () => {
    const [name, setName] = useState('');
    const [email, setEmail] = useState('');
    const [password, setPassword] = useState('');

    const handleRegister = (e) => {
        e.preventDefault();
        axios.post('http://localhost:3001/admin/register', { name, email, password })
            .then(response => {
                alert('Admin registered successfully');
                // Redirect to login page or dashboard
            })
            .catch(error => {
                console.error('Error registering admin:', error);
            });
    };

    return (
        <div>
            <h1>Admin Register</h1>
            <form onSubmit={handleRegister}>
                <input type="text" value={name} onChange={(e) => setName(e.target.value)} placeholder="Name" required />
                <input type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="Email" required />
                <input type="password" value={password} onChange={(e) => setPassword(e.target.value)} placeholder="Password" required />
                <button type="submit">Register</button>
            </form>
        </div>
    );
};

export default AdminRegister;
