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

const initialValues = {
    
    
    movement_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    movement_type: 'receipt',
    
    
    
    
    
    
    
    
    
    
    
    
    movement_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    item: '',
    
    
    
    
    quantity: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    uom: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    from_location: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    to_location: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    lot: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    serial: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    work_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    supplier: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reason_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    performed_by: '',
    
    
    
    
    reference: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    documents: [],
    
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/inventory_movements/inventory_movements-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="MovementNumber"
  >
      <Field
          name="movement_number"
          placeholder="MovementNumber"
      />
  </FormField>









































  <FormField label="MovementType" labelFor="movement_type">
      <Field name="movement_type" id="movement_type" component="select">
      
        <option value="receipt">receipt</option>
      
        <option value="issue">issue</option>
      
        <option value="transfer">transfer</option>
      
        <option value="adjustment">adjustment</option>
      
        <option value="production_output">production_output</option>
      
        <option value="scrap">scrap</option>
      
        <option value="customer_shipment">customer_shipment</option>
      
        <option value="customer_return">customer_return</option>
      
      </Field>
  </FormField>























  <FormField
      label="MovementAt"
  >
      <Field
          type="datetime-local"
          name="movement_at"
          placeholder="MovementAt"
      />
  </FormField>



































  <FormField label="Item" labelFor="item">
      <Field name="item" id="item" component={SelectField} options={[]} itemRef={'items'}></Field>
  </FormField>















    <FormField
        label="Quantity"
    >
        <Field
            type="number"
            name="quantity"
            placeholder="Quantity"
        />
    </FormField>







































  <FormField label="UoM" labelFor="uom">
      <Field name="uom" id="uom" component={SelectField} options={[]} itemRef={'uoms'}></Field>
  </FormField>



























  <FormField label="FromLocation" labelFor="from_location">
      <Field name="from_location" id="from_location" component={SelectField} options={[]} itemRef={'locations'}></Field>
  </FormField>



























  <FormField label="ToLocation" labelFor="to_location">
      <Field name="to_location" id="to_location" component={SelectField} options={[]} itemRef={'locations'}></Field>
  </FormField>



























  <FormField label="Lot" labelFor="lot">
      <Field name="lot" id="lot" component={SelectField} options={[]} itemRef={'lots'}></Field>
  </FormField>



























  <FormField label="Serial" labelFor="serial">
      <Field name="serial" id="serial" component={SelectField} options={[]} itemRef={'serials'}></Field>
  </FormField>



























  <FormField label="WorkOrder" labelFor="work_order">
      <Field name="work_order" id="work_order" component={SelectField} options={[]} itemRef={'work_orders'}></Field>
  </FormField>



























  <FormField label="Supplier" labelFor="supplier">
      <Field name="supplier" id="supplier" component={SelectField} options={[]} itemRef={'suppliers'}></Field>
  </FormField>



























  <FormField label="Customer" labelFor="customer">
      <Field name="customer" id="customer" component={SelectField} options={[]} itemRef={'customers'}></Field>
  </FormField>



























  <FormField label="ReasonCode" labelFor="reason_code">
      <Field name="reason_code" id="reason_code" component={SelectField} options={[]} itemRef={'reason_codes'}></Field>
  </FormField>



























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









  <FormField
      label="Reference"
  >
      <Field
          name="reference"
          placeholder="Reference"
      />
  </FormField>





























    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </FormField>
















































  <FormField>
      <Field
          label='Documents'
          color='info'
          icon={mdiUpload}
          path={'inventory_movements/documents'}
          name='documents'
          id='documents'
          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('/inventory_movements/inventory_movements-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Inventory_movementsNew
