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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    document: '',
    
    
    
    
    revision: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    version_status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    author: '',
    
    
    
    
    
    
    
    
    
    submitted_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    approved_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    effective_at: '',
    
    
    
    
    
    
    
    
    
    
    
    change_summary: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    version_content: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    version_files: [],
    
    
    
    
    
    
    hash_checksum: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}


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





















  <FormField label="Document" labelFor="document">
      <Field name="document" id="document" component={SelectField} options={[]} itemRef={'documents'}></Field>
  </FormField>









  <FormField
      label="Revision"
  >
      <Field
          name="revision"
          placeholder="Revision"
      />
  </FormField>









































  <FormField label="VersionStatus" labelFor="version_status">
      <Field name="version_status" id="version_status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="in_review">in_review</option>
      
        <option value="approved">approved</option>
      
        <option value="effective">effective</option>
      
        <option value="superseded">superseded</option>
      
        <option value="obsolete">obsolete</option>
      
      </Field>
  </FormField>































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



















  <FormField
      label="SubmittedAt"
  >
      <Field
          type="datetime-local"
          name="submitted_at"
          placeholder="SubmittedAt"
      />
  </FormField>



























  <FormField
      label="ApprovedAt"
  >
      <Field
          type="datetime-local"
          name="approved_at"
          placeholder="ApprovedAt"
      />
  </FormField>



























  <FormField
      label="EffectiveAt"
  >
      <Field
          type="datetime-local"
          name="effective_at"
          placeholder="EffectiveAt"
      />
  </FormField>



















    <FormField label="ChangeSummary" hasTextareaHeight>
        <Field name="change_summary" as="textarea" placeholder="ChangeSummary" />
    </FormField>





























      <FormField label='VersionContent' hasTextareaHeight>
          <Field
              name='version_content'
              id='version_content'
              component={RichTextField}
          ></Field>
      </FormField>














































  <FormField>
      <Field
          label='VersionFiles'
          color='info'
          icon={mdiUpload}
          path={'document_versions/version_files'}
          name='version_files'
          id='version_files'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></Field>
  </FormField>




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

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

export default Document_versionsNew
