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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    project: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    verified_by_user: '',
    
    
    
    
    
    
    
    
    
    visit_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    verification_type: 'site_visit',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    outcome: 'pass',
    
    
    
    
    
    
    
    
    
    findings: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    actions_required: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    next_followup_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    photos: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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





















  <FormField label="Project" labelFor="project">
      <Field name="project" id="project" component={SelectField} options={[]} itemRef={'projects'}></Field>
  </FormField>



























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



















  <FormField
      label="VisitDate"
  >
      <Field
          type="datetime-local"
          name="visit_date"
          placeholder="VisitDate"
      />
  </FormField>































  <FormField label="VerificationType" labelFor="verification_type">
      <Field name="verification_type" id="verification_type" component="select">
      
        <option value="site_visit">site_visit</option>
      
        <option value="remote_validation">remote_validation</option>
      
        <option value="document_review">document_review</option>
      
        <option value="stakeholder_interview">stakeholder_interview</option>
      
      </Field>
  </FormField>



























  <FormField label="Outcome" labelFor="outcome">
      <Field name="outcome" id="outcome" component="select">
      
        <option value="pass">pass</option>
      
        <option value="partial">partial</option>
      
        <option value="fail">fail</option>
      
        <option value="follow_up_required">follow_up_required</option>
      
      </Field>
  </FormField>

















      <FormField label='Findings' hasTextareaHeight>
          <Field
              name='findings'
              id='findings'
              component={RichTextField}
          ></Field>
      </FormField>

























    <FormField label="ActionsRequired" hasTextareaHeight>
        <Field name="actions_required" as="textarea" placeholder="ActionsRequired" />
    </FormField>



































  <FormField
      label="NextFollow-upAt"
  >
      <Field
          type="datetime-local"
          name="next_followup_at"
          placeholder="NextFollow-upAt"
      />
  </FormField>







































  <FormField>
      <Field
          label='Photos'
          color='info'
          icon={mdiUpload}
          path={'field_verifications/photos'}
          name='photos'
          id='photos'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormImagePicker}
      ></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('/field_verifications/field_verifications-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Field_verificationsNew
