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/medications/medicationsSlice'
import { useAppDispatch } from '../../stores/hooks'
import { useRouter } from 'next/router'
import moment from 'moment';

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    user: '',
    
    
    
    
    medication_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    dose_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    dose_unit: 'mg',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    frequency_type: 'once_daily',
    
    
    
    
    
    
    
    
    
    
    frequency_interval_hours: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    frequency_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    route: 'oral',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    prescribing_provider: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    pharmacy: '',
    
    
    
    
    condition_treated: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    start_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    end_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    refill_reminder_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reminders_enabled: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_controlled_substance: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    medication_photos: [],
    
    
    
    
    
    
    instructions: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/medications/medications-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="User" labelFor="user">
      <Field name="user" id="user" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>









  <FormField
      label="MedicationName"
  >
      <Field
          name="medication_name"
          placeholder="MedicationName"
      />
  </FormField>

































    <FormField
        label="DoseAmount"
    >
        <Field
            type="number"
            name="dose_amount"
            placeholder="DoseAmount"
        />
    </FormField>



































  <FormField label="DoseUnit" labelFor="dose_unit">
      <Field name="dose_unit" id="dose_unit" component="select">
      
        <option value="mg">mg</option>
      
        <option value="ml">ml</option>
      
        <option value="mcg">mcg</option>
      
        <option value="g">g</option>
      
        <option value="units">units</option>
      
        <option value="puffs">puffs</option>
      
        <option value="drops">drops</option>
      
        <option value="sprays">sprays</option>
      
        <option value="patch">patch</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>



























  <FormField label="Frequency" labelFor="frequency_type">
      <Field name="frequency_type" id="frequency_type" component="select">
      
        <option value="once_daily">once_daily</option>
      
        <option value="twice_daily">twice_daily</option>
      
        <option value="three_times_daily">three_times_daily</option>
      
        <option value="every_x_hours">every_x_hours</option>
      
        <option value="weekly">weekly</option>
      
        <option value="monthly">monthly</option>
      
        <option value="as_needed">as_needed</option>
      
        <option value="custom">custom</option>
      
      </Field>
  </FormField>



















    <FormField
        label="EveryXHours"
    >
        <Field
            type="number"
            name="frequency_interval_hours"
            placeholder="EveryXHours"
        />
    </FormField>























    <FormField label="FrequencyNotes" hasTextareaHeight>
        <Field name="frequency_notes" as="textarea" placeholder="FrequencyNotes" />
    </FormField>







































  <FormField label="Route" labelFor="route">
      <Field name="route" id="route" component="select">
      
        <option value="oral">oral</option>
      
        <option value="topical">topical</option>
      
        <option value="inhaled">inhaled</option>
      
        <option value="injected">injected</option>
      
        <option value="sublingual">sublingual</option>
      
        <option value="nasal">nasal</option>
      
        <option value="rectal">rectal</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>































  <FormField label="PrescribingProvider" labelFor="prescribing_provider">
      <Field name="prescribing_provider" id="prescribing_provider" component={SelectField} options={[]} itemRef={'healthcare_providers'}></Field>
  </FormField>



























  <FormField label="Pharmacy" labelFor="pharmacy">
      <Field name="pharmacy" id="pharmacy" component={SelectField} options={[]} itemRef={'pharmacies'}></Field>
  </FormField>









  <FormField
      label="ConditionTreated"
  >
      <Field
          name="condition_treated"
          placeholder="ConditionTreated"
      />
  </FormField>





































  <FormField
      label="StartDate"
  >
      <Field
          type="datetime-local"
          name="start_date"
          placeholder="StartDate"
      />
  </FormField>



























  <FormField
      label="EndDate"
  >
      <Field
          type="datetime-local"
          name="end_date"
          placeholder="EndDate"
      />
  </FormField>



























  <FormField
      label="RefillReminderDate"
  >
      <Field
          type="datetime-local"
          name="refill_reminder_date"
          placeholder="RefillReminderDate"
      />
  </FormField>

































  <FormField label='RemindMetoTakeIt' labelFor='reminders_enabled'>
      <Field
          name='reminders_enabled'
          id='reminders_enabled'
          component={SwitchField}
      ></Field>
  </FormField>



























  <FormField label='ControlledSubstance' labelFor='is_controlled_substance'>
      <Field
          name='is_controlled_substance'
          id='is_controlled_substance'
          component={SwitchField}
      ></Field>
  </FormField>

































  <FormField>
      <Field
          label='MedicationPhotos'
          color='info'
          icon={mdiUpload}
          path={'medications/medication_photos'}
          name='medication_photos'
          id='medication_photos'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormImagePicker}
      ></Field>
  </FormField>







    <FormField label="Instructions" hasTextareaHeight>
        <Field name="instructions" as="textarea" placeholder="Instructions" />
    </FormField>



























    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </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('/medications/medications-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default MedicationsNew
