// components/AdminPanel.js
'use client'
import { useState } from 'react'
import { useMutation } from '@tanstack/react-query'

export default function AdminPanel({ user }) {
    const [newAdmin, setNewAdmin] = useState({
        email: '',
        name: '',
        password: '',
        privileges: []
    })

    const { mutate: createAdmin, isLoading } = useMutation({
        mutationFn: (adminData) =>
            fetch('/api/admin/register', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify(adminData)
            }).then(res => res.json())
    })

    const handleSubmit = (e) => {
        e.preventDefault()
        createAdmin(newAdmin, {
            onSuccess: () => {
                alert('Admin created successfully')
                setNewAdmin({
                    email: '',
                    name: '',
                    password: '',
                    privileges: []
                })
            }
        })
    }

    return (
        <div className="bg-white p-6 rounded-lg shadow">
            <h2 className="text-xl font-semibold mb-4">Create New Admin</h2>
            <form onSubmit={handleSubmit} className="space-y-4">
                {/* Form fields for admin creation */}
            </form>

            {/* Other admin functionality */}
        </div>
    )
}