import { mdiChartTimelineVariant, mdiUpload } from '@mdi/js'
import Head from 'next/head'
import React, { ReactElement, useEffect, useState } from 'react'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import dayjs from "dayjs";

import CardBox from '../../components/CardBox'
import LayoutAuthenticated from '../../layouts/Authenticated'
import SectionMain from '../../components/SectionMain'
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton'
import { getPageTitle } from '../../config'

import { Field, Form, Formik } from 'formik'
import FormField from '../../components/FormField'
import BaseDivider from '../../components/BaseDivider'
import BaseButtons from '../../components/BaseButtons'
import BaseButton from '../../components/BaseButton'
import FormCheckRadio from '../../components/FormCheckRadio'
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup'
import FormFilePicker from '../../components/FormFilePicker'
import FormImagePicker from '../../components/FormImagePicker'
import { SelectField } from "../../components/SelectField";
import { SelectFieldMany } from "../../components/SelectFieldMany";
import { SwitchField } from '../../components/SwitchField'
import {RichTextField} from "../../components/RichTextField";

import { update, fetch } from '../../stores/city_doctors/city_doctorsSlice'
import { useAppDispatch, useAppSelector } from '../../stores/hooks'
import { useRouter } from 'next/router'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";



const EditCity_doctors = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()
  const initVals = {
      
    

    

    

    

    

    

    

    

    

    

    

    
    user: null,
    

    
    
    
    'full_name': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'hospital_code': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'doctor_registration_no': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'specialization': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    
    years_experience: '',
    

    

    

    

    

    

    

    

    

    
    
    
    'qualification': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    availability_status: '',
    

    

    

    

    
    
    
    'consultation_fee': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'clinic_address': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'clinic_latitude': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'clinic_longitude': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
  }
  const [initialValues, setInitialValues] = useState(initVals)

  const { city_doctors } = useAppSelector((state) => state.city_doctors)
  

  const { city_doctorsId } = router.query

  useEffect(() => {
    dispatch(fetch({ id: city_doctorsId }))
  }, [city_doctorsId])

  useEffect(() => {
    if (typeof city_doctors === 'object') {
      setInitialValues(city_doctors)
    }
  }, [city_doctors])

  useEffect(() => {
      if (typeof city_doctors === 'object') {

          const newInitialVal = {...initVals};

          Object.keys(initVals).forEach(el => newInitialVal[el] = (city_doctors)[el])

          setInitialValues(newInitialVal);
      }
  }, [city_doctors])

  const handleSubmit = async (data) => {
    await dispatch(update({ id: city_doctorsId, data }))
    await router.push('/city_doctors/city_doctors-list')
  }

  return (
    <>
      <Head>
        <title>{getPageTitle('Edit city_doctors')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={'Edit city_doctors'} main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            enableReinitialize
            initialValues={initialValues}
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>


  

  

  

  

  

  

  

  

  

  
  
    <FormField label='User' labelFor='user'>
        <Field
            name='user'
            id='user'
            component={SelectField}
            options={initialValues.user}
            itemRef={'users'}
      
        
            showField={'firstName'}
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        ></Field>
    </FormField>
    

  

  

    

  



  
    <FormField
        label="FullName"
    >
        <Field
            name="full_name"
            placeholder="FullName"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="HospitalCode"
    >
        <Field
            name="hospital_code"
            placeholder="HospitalCode"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="DoctorRegistrationNo"
    >
        <Field
            name="doctor_registration_no"
            placeholder="DoctorRegistrationNo"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="Specialization"
    >
        <Field
            name="specialization"
            placeholder="Specialization"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="YearsExperience"
    >
        <Field
            type="number"
            name="years_experience"
            placeholder="YearsExperience"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="Qualification"
    >
        <Field
            name="qualification"
            placeholder="Qualification"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="AvailabilityStatus" labelFor="availability_status">
        <Field name="availability_status" id="availability_status" component="select">
          
            <option value="online">online</option>
          
            <option value="offline">offline</option>
          
            <option value="busy">busy</option>
          
            <option value="on_call">on_call</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  
    <FormField
        label="ConsultationFee"
    >
        <Field
            type="number"
            name="consultation_fee"
            placeholder="ConsultationFee"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="ClinicAddress"
    >
        <Field
            name="clinic_address"
            placeholder="ClinicAddress"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="ClinicLatitude"
    >
        <Field
            type="number"
            name="clinic_latitude"
            placeholder="ClinicLatitude"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="ClinicLongitude"
    >
        <Field
            type="number"
            name="clinic_longitude"
            placeholder="ClinicLongitude"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  


  

              <BaseDivider />
              <BaseButtons>
                <BaseButton type="submit" color="info" label="Submit" />
                <BaseButton type="reset" color="info" outline label="Reset" />
                <BaseButton type='reset' color='danger' outline label='Cancel' onClick={() => router.push('/city_doctors/city_doctors-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

EditCity_doctors.getLayout = function getLayout(page: ReactElement) {
  return (
      <LayoutAuthenticated
        
          permission={'UPDATE_CITY_DOCTORS'}
        
      >
          {page}
      </LayoutAuthenticated>
  )
}

export default EditCity_doctors
