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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    material: '',
    
    
    
    
    revision_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    effective_from: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    effective_to: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    lifecycle_state: 'draft',
    
    
    
    
    
    
    
    
    
    change_summary: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    approved_by_user: '',
    
    
    
    
    
    
    
    
    
    approved_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    spec_files: [],
    
    
    
    
    
}


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





















  <FormField label="Material" labelFor="material">
      <Field name="material" id="material" component={SelectField} options={[]} itemRef={'materials'}></Field>
  </FormField>









  <FormField
      label="RevisionCode"
  >
      <Field
          name="revision_code"
          placeholder="RevisionCode"
      />
  </FormField>





































  <FormField
      label="EffectiveFrom"
  >
      <Field
          type="datetime-local"
          name="effective_from"
          placeholder="EffectiveFrom"
      />
  </FormField>



























  <FormField
      label="EffectiveTo"
  >
      <Field
          type="datetime-local"
          name="effective_to"
          placeholder="EffectiveTo"
      />
  </FormField>































  <FormField label="LifecycleState" labelFor="lifecycle_state">
      <Field name="lifecycle_state" id="lifecycle_state" component="select">
      
        <option value="draft">draft</option>
      
        <option value="released">released</option>
      
        <option value="obsolete">obsolete</option>
      
      </Field>
  </FormField>

















      <FormField label='ChangeSummary' hasTextareaHeight>
          <Field
              name='change_summary'
              id='change_summary'
              component={RichTextField}
          ></Field>
      </FormField>









































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



















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








































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

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

export default Material_revisionsNew
