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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    tenant: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    farm: '',
    
    
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    objective: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    planned_start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    planned_end_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    actual_start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    actual_end_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    protocol_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    trial_sites: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    trial_entries: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


const TrialsNew = () => {
  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('/trials/trials-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    planned_start_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    planned_end_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="Tenant" labelFor="tenant">
      <Field name="tenant" id="tenant" component={SelectField} options={[]} itemRef={'tenants'}></Field>
  </FormField>



























  <FormField label="Farm" labelFor="farm">
      <Field name="farm" id="farm" component={SelectField} options={[]} itemRef={'farms'}></Field>
  </FormField>









  <FormField
      label="TrialName"
  >
      <Field
          name="name"
          placeholder="TrialName"
      />
  </FormField>



























  <FormField
      label="TrialCode"
  >
      <Field
          name="code"
          placeholder="TrialCode"
      />
  </FormField>































      <FormField label='Objective' hasTextareaHeight>
          <Field
              name='objective'
              id='objective'
              component={RichTextField}
          ></Field>
      </FormField>





































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="planned">planned</option>
      
        <option value="active">active</option>
      
        <option value="completed">completed</option>
      
        <option value="archived">archived</option>
      
      </Field>
  </FormField>























  <FormField
      label="PlannedStart"
  >
      <Field
          type="datetime-local"
          name="planned_start_at"
          placeholder="PlannedStart"
      />
  </FormField>



























  <FormField
      label="PlannedEnd"
  >
      <Field
          type="datetime-local"
          name="planned_end_at"
          placeholder="PlannedEnd"
      />
  </FormField>



























  <FormField
      label="ActualStart"
  >
      <Field
          type="datetime-local"
          name="actual_start_at"
          placeholder="ActualStart"
      />
  </FormField>



























  <FormField
      label="ActualEnd"
  >
      <Field
          type="datetime-local"
          name="actual_end_at"
          placeholder="ActualEnd"
      />
  </FormField>





















      <FormField label='ProtocolNotes' hasTextareaHeight>
          <Field
              name='protocol_notes'
              id='protocol_notes'
              component={RichTextField}
          ></Field>
      </FormField>











































    <FormField label='TrialSites' labelFor='trial_sites'>
        <Field
            name='trial_sites'
            id='trial_sites'
            itemRef={'trial_sites'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>



























    <FormField label='TrialEntries' labelFor='trial_entries'>
        <Field
            name='trial_entries'
            id='trial_entries'
            itemRef={'trial_entries'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>

























  <FormField label="organizations" labelFor="organizations">
      <Field name="organizations" id="organizations" component={SelectField} options={[]} itemRef={'organizations'}></Field>
  </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('/trials/trials-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default TrialsNew
