import { mdiAccount, mdiChartTimelineVariant, mdiMail, mdiUpload } from '@mdi/js'
import Head from 'next/head'
import React, { ReactElement } from 'react'
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 { SwitchField } from '../../components/SwitchField'

import { SelectField } from '../../components/SelectField'
import { SelectFieldMany } from "../../components/SelectFieldMany";
import {RichTextField} from "../../components/RichTextField";

import { create } from '../../stores/appointments/appointmentsSlice'
import { useAppDispatch } from '../../stores/hooks'
import { useRouter } from 'next/router'
import moment from 'moment';

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    patient: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    city_doctor: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    rural_doctor: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    medical_camp: '',
    
    
    
    
    
    
    
    
    
    scheduled_start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    scheduled_end_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    appointment_type: 'in_person',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'requested',
    
    
    
    
    
    
    
    
    reason_for_visit: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    meeting_link: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    meeting_room: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}


const AppointmentsNew = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()

    
    
    // get from url params
    const { dateRangeStart, dateRangeEnd } = router.query
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/appointments/appointments-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    scheduled_start_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    scheduled_end_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="Patient" labelFor="patient">
      <Field name="patient" id="patient" component={SelectField} options={[]} itemRef={'patients'}></Field>
  </FormField>



























  <FormField label="CityDoctor" labelFor="city_doctor">
      <Field name="city_doctor" id="city_doctor" component={SelectField} options={[]} itemRef={'city_doctors'}></Field>
  </FormField>



























  <FormField label="RuralDoctor" labelFor="rural_doctor">
      <Field name="rural_doctor" id="rural_doctor" component={SelectField} options={[]} itemRef={'rural_doctors'}></Field>
  </FormField>



























  <FormField label="MedicalCamp" labelFor="medical_camp">
      <Field name="medical_camp" id="medical_camp" component={SelectField} options={[]} itemRef={'medical_camps'}></Field>
  </FormField>



















  <FormField
      label="ScheduledStartAt"
  >
      <Field
          type="datetime-local"
          name="scheduled_start_at"
          placeholder="ScheduledStartAt"
      />
  </FormField>



























  <FormField
      label="ScheduledEndAt"
  >
      <Field
          type="datetime-local"
          name="scheduled_end_at"
          placeholder="ScheduledEndAt"
      />
  </FormField>































  <FormField label="AppointmentType" labelFor="appointment_type">
      <Field name="appointment_type" id="appointment_type" component="select">
      
        <option value="in_person">in_person</option>
      
        <option value="telemedicine">telemedicine</option>
      
        <option value="camp_visit">camp_visit</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="requested">requested</option>
      
        <option value="confirmed">confirmed</option>
      
        <option value="in_progress">in_progress</option>
      
        <option value="completed">completed</option>
      
        <option value="cancelled">cancelled</option>
      
        <option value="no_show">no_show</option>
      
      </Field>
  </FormField>















    <FormField label="ReasonForVisit" hasTextareaHeight>
        <Field name="reason_for_visit" as="textarea" placeholder="ReasonForVisit" />
    </FormField>

























  <FormField
      label="MeetingLink"
  >
      <Field
          name="meeting_link"
          placeholder="MeetingLink"
      />
  </FormField>



























  <FormField
      label="MeetingRoom"
  >
      <Field
          name="meeting_room"
          placeholder="MeetingRoom"
      />
  </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('/appointments/appointments-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default AppointmentsNew
