import {useGetPatientsQuery} from "../../../Api/patientsApi.js";
import {useGetAppointmentTypesQuery} from "../../../Api/appointmentTypesApi.js";
import {useCreateScheduledAppointmentMutation} from "../../../Api/scheduledAppointmentsApi.js";


const useScheduledAppointmentFormModal = () => {
    const {
        data: patients = [],
        isLoading: isLoadingPatients,
        isError: isErrorPatients,
    } = useGetPatientsQuery(undefined, {
        pollingInterval: 20000,
    });

    const {
        data: appointmentTypes = [],
        isLoading: isLoadingAppointmentTypes,
        isError: isErrorAppointmentTypes,
    } = useGetAppointmentTypesQuery(undefined, {
        pollingInterval: 20000,
    });

    const [createScheduledAppointment, {isLoading: isCreating, isError: isErrorCreating}] = useCreateScheduledAppointmentMutation();

    return {
        patients,
        appointmentTypes,
        createScheduledAppointment,
        isLoading: isLoadingPatients || isLoadingAppointmentTypes || isCreating,
        isError: isErrorPatients || isErrorAppointmentTypes || isErrorCreating,
    };
};

export default useScheduledAppointmentFormModal;