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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    production_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    routing_operation: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'not_started',
    
    
    
    
    
    
    
    
    
    
    
    
    scheduled_start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    scheduled_end_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    actual_start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    actual_end_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    machine: '',
    
    
    
    
    good_quantity: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    scrap_quantity: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    operator_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


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





















  <FormField label="ProductionOrder" labelFor="production_order">
      <Field name="production_order" id="production_order" component={SelectField} options={[]} itemRef={'production_orders'}></Field>
  </FormField>



























  <FormField label="RoutingOperation" labelFor="routing_operation">
      <Field name="routing_operation" id="routing_operation" component={SelectField} options={[]} itemRef={'routing_operations'}></Field>
  </FormField>























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="not_started">not_started</option>
      
        <option value="ready">ready</option>
      
        <option value="in_progress">in_progress</option>
      
        <option value="paused">paused</option>
      
        <option value="complete">complete</option>
      
        <option value="blocked">blocked</option>
      
      </Field>
  </FormField>























  <FormField
      label="ScheduledStartAt"
  >
      <Field
          type="datetime-local"
          name="scheduled_start_at"
          placeholder="ScheduledStartAt"
      />
  </FormField>



























  <FormField
      label="ScheduledEndAt"
  >
      <Field
          type="datetime-local"
          name="scheduled_end_at"
          placeholder="ScheduledEndAt"
      />
  </FormField>



























  <FormField
      label="ActualStartAt"
  >
      <Field
          type="datetime-local"
          name="actual_start_at"
          placeholder="ActualStartAt"
      />
  </FormField>



























  <FormField
      label="ActualEndAt"
  >
      <Field
          type="datetime-local"
          name="actual_end_at"
          placeholder="ActualEndAt"
      />
  </FormField>



































  <FormField label="Machine" labelFor="machine">
      <Field name="machine" id="machine" component={SelectField} options={[]} itemRef={'machines'}></Field>
  </FormField>















    <FormField
        label="GoodQuantity"
    >
        <Field
            type="number"
            name="good_quantity"
            placeholder="GoodQuantity"
        />
    </FormField>



























    <FormField
        label="ScrapQuantity"
    >
        <Field
            type="number"
            name="scrap_quantity"
            placeholder="ScrapQuantity"
        />
    </FormField>























    <FormField label="OperatorNotes" hasTextareaHeight>
        <Field name="operator_notes" as="textarea" placeholder="OperatorNotes" />
    </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('/production_operations/production_operations-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Production_operationsNew
