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

const initialValues = {
    
    
    material_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    material_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    material_type: 'raw',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    default_uom: '',
    
    
    
    
    standard_cost: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    standard_price: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    planning_method: 'make_to_stock',
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_lot_tracked: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_serial_tracked: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requires_inspection: false,
    
    
    
    
    
    
    
    
    
    
    
    
    shelf_life_days: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    preferred_supplier: '',
    
    
    
    
    
    
    specification: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'active',
    
    
    
    
    
    
}


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

    
    

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



























  <FormField
      label="MaterialName"
  >
      <Field
          name="material_name"
          placeholder="MaterialName"
      />
  </FormField>









































  <FormField label="MaterialType" labelFor="material_type">
      <Field name="material_type" id="material_type" component="select">
      
        <option value="raw">raw</option>
      
        <option value="component">component</option>
      
        <option value="subassembly">subassembly</option>
      
        <option value="finished_good">finished_good</option>
      
        <option value="consumable">consumable</option>
      
        <option value="spare_part">spare_part</option>
      
      </Field>
  </FormField>































  <FormField label="DefaultUoM" labelFor="default_uom">
      <Field name="default_uom" id="default_uom" component={SelectField} options={[]} itemRef={'units_of_measure'}></Field>
  </FormField>















    <FormField
        label="StandardCost"
    >
        <Field
            type="number"
            name="standard_cost"
            placeholder="StandardCost"
        />
    </FormField>



























    <FormField
        label="StandardPrice"
    >
        <Field
            type="number"
            name="standard_price"
            placeholder="StandardPrice"
        />
    </FormField>



































  <FormField label="PlanningMethod" labelFor="planning_method">
      <Field name="planning_method" id="planning_method" component="select">
      
        <option value="make_to_stock">make_to_stock</option>
      
        <option value="make_to_order">make_to_order</option>
      
      </Field>
  </FormField>





























  <FormField label='IsLotTracked' labelFor='is_lot_tracked'>
      <Field
          name='is_lot_tracked'
          id='is_lot_tracked'
          component={SwitchField}
      ></Field>
  </FormField>



























  <FormField label='IsSerialTracked' labelFor='is_serial_tracked'>
      <Field
          name='is_serial_tracked'
          id='is_serial_tracked'
          component={SwitchField}
      ></Field>
  </FormField>



























  <FormField label='RequiresInspection' labelFor='requires_inspection'>
      <Field
          name='requires_inspection'
          id='requires_inspection'
          component={SwitchField}
      ></Field>
  </FormField>

















    <FormField
        label="ShelfLifeDays"
    >
        <Field
            type="number"
            name="shelf_life_days"
            placeholder="ShelfLifeDays"
        />
    </FormField>







































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













      <FormField label='Specification' hasTextareaHeight>
          <Field
              name='specification'
              id='specification'
              component={RichTextField}
          ></Field>
      </FormField>














































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


















  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="active">active</option>
      
        <option value="inactive">inactive</option>
      
        <option value="obsolete">obsolete</option>
      
      </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('/materials/materials-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default MaterialsNew
