import { supabase } from '../supabaseClient';
import React, { useState } from 'react';
import { motion } from 'framer-motion'; // Import motion for the button
// You might need this icon if it's not globally available
const SpinnerIcon = () => ;
export default function AdminSettings() {
const [newAdminEmail, setNewAdminEmail] = useState('');
const [password, setPassword] = useState('');
const [loading, setLoading] = useState(false);
const handleTransferRequest = async (e) => {
e.preventDefault();
setLoading(true);
try {
const { data: { user } } = await supabase.auth.getUser();
if (!user) throw new Error("You must be logged in.");
const { error: signInError } = await supabase.auth.signInWithPassword({
email: user.email,
password: password,
});
if (signInError) {
throw new Error("Incorrect password. Please try again.");
}
const { error: invokeError } = await supabase.functions.invoke('initiate-admin-transfer', {
body: { newAdminEmail: newAdminEmail },
});
if (invokeError) throw invokeError;
alert(`An invitation to become the new admin has been sent to ${newAdminEmail}.`);
setNewAdminEmail('');
setPassword('');
} catch (error) {
alert(`Error: ${error.message}`);
} finally {
setLoading(false);
}
};
return (
);
}