import React, { useEffect } from "react";
import { useAddStudent } from "../api/student";

// Function to create a student object
const createStudent = () => {
  const randomNum = Math.floor(Math.random() * 10000); // Generate a random number

  return {
    id: 123 + randomNum, // Adjusted id for uniqueness
    username: `studentUsername${randomNum}`,
    password: `securePassword${randomNum}`,
    notes: "Some notes",
    nationality: "Hungarian",
    birth_place: "City",
    birthday: "2000-01-01",
    phone_number_2: "123456789",
    phone_number_1: "987654321",
    mother_name: "MotherName",
    father_name: "FatherName",
    last_name: `LastName${randomNum}`,
    first_name: `FirstName${randomNum}`,
    religion: "muslim",
    address: "123 Main St",
    father_job: "FatherJob",
    mother_phone_number: "111222333",
    father_phone_number: "444555666",
    mother_job: "MotherJob",
    edu_class_id: 1,
    sex: "male",
  };
};

const CreateUser = ({ number_of_user }: { number_of_user: number }) => {
  const { mutate } = useAddStudent();

  useEffect(() => {
    for (let index = 0; index < number_of_user; index++) {
      const newStudent = createStudent();

      // Call mutate to add the student
      mutate(newStudent);
    }
  }, [number_of_user, mutate]);

  return null; // or return some JSX if needed
};

export default CreateUser;
