import React, { useState, useEffect } from 'react';
import SpecialitiesSection from '@/components/Structure/Configuration/SpecialitiesSection';
import TeachersSection from '@/components/Structure/Configuration/TeachersSection';
import ClassesSection from '@/components/Structure/Configuration/ClassesSection';
import { ClassesProvider } from '@/context/ClassesContext';
import { BE_SCHOOL_SPECIALITIES_URL, BE_SCHOOL_TEACHERS_URL, BE_SCHOOL_SCHOOLCLASSES_URL } from '@/utils/Url';

const StructureManagement = ({ specialities, setSpecialities, teachers, setTeachers, classes, setClasses, handleCreate, handleEdit, handleDelete }) => {
  return (
    <div className="max-w-8xl mx-auto p-4 mt-6 space-y-8">
      <ClassesProvider>
        <div className="w-2/5 p-4 bg-white rounded-lg shadow-md">
          <SpecialitiesSection
            specialities={specialities}
            setSpecialities={setSpecialities}
            handleCreate={(newData) => handleCreate(`${BE_SCHOOL_SPECIALITIES_URL}`, newData, setSpecialities)}
            handleEdit={(id, updatedData) => handleEdit(`${BE_SCHOOL_SPECIALITIES_URL}`, id, updatedData, setSpecialities)}
            handleDelete={(id) => handleDelete(`${BE_SCHOOL_SPECIALITIES_URL}`, id, setSpecialities)}
          />
        </div>
        <div className="w-4/5 p-4 bg-white rounded-lg shadow-md">
          <TeachersSection
            teachers={teachers}
            setTeachers={setTeachers}
            specialities={specialities}
            handleCreate={(newData) => handleCreate(`${BE_SCHOOL_TEACHERS_URL}`, newData, setTeachers)}
            handleEdit={(id, updatedData) => handleEdit(`${BE_SCHOOL_TEACHERS_URL}`, id, updatedData, setTeachers)}
            handleDelete={(id) => handleDelete(`${BE_SCHOOL_TEACHERS_URL}`, id, setTeachers)}
          />
        </div>
        <div className="w-full p-4 bg-white rounded-lg shadow-md">
          <ClassesSection
            classes={classes}
            setClasses={setClasses}
            teachers={teachers}
            handleCreate={(newData) => handleCreate(`${BE_SCHOOL_SCHOOLCLASSES_URL}`, newData, setClasses)}
            handleEdit={(id, updatedData) => handleEdit(`${BE_SCHOOL_SCHOOLCLASSES_URL}`, id, updatedData, setClasses)}
            handleDelete={(id) => handleDelete(`${BE_SCHOOL_SCHOOLCLASSES_URL}`, id, setClasses)}
          />
        </div>
      </ClassesProvider>
    </div>
  );
};

export default StructureManagement;
