import React, { createContext, useState, useContext } from 'react';

const TeacherFormContext = createContext();

export const useTeacherForm = () => useContext(TeacherFormContext);

export const TeacherFormProvider = ({ children, initialTeacher }) => {
  const [formData, setFormData] = useState(() => ({
    last_name: initialTeacher.last_name || '',
    first_name: initialTeacher.first_name || '',
    email: initialTeacher.email || '',
    specialities: initialTeacher.specialities || [],
    associated_profile: initialTeacher.associated_profile || '',
    droit: {
      label: initialTeacher.droit?.label || '',
      id: initialTeacher.droit?.id || 0,
    },
  }));

  return (
    <TeacherFormContext.Provider value={{ formData, setFormData }}>
      {children}
    </TeacherFormContext.Provider>
  );
};
