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

const initialValues = {
    
    
    work_order_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    machine: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    work_type: 'preventive',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    priority: 'low',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'requested',
    
    
    
    
    
    
    
    
    
    
    
    
    requested_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    scheduled_start: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    scheduled_end: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    completed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requested_by: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    assigned_to: '',
    
    
    
    
    
    problem_description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    resolution_summary: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    labor_hours: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
}


const Maintenance_work_ordersNew = () => {
  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('/maintenance_work_orders/maintenance_work_orders-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: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    scheduled_end: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>



  <FormField
      label="WorkOrderNumber"
  >
      <Field
          name="work_order_number"
          placeholder="WorkOrderNumber"
      />
  </FormField>













































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























  <FormField label="WorkType" labelFor="work_type">
      <Field name="work_type" id="work_type" component="select">
      
        <option value="preventive">preventive</option>
      
        <option value="corrective">corrective</option>
      
        <option value="calibration">calibration</option>
      
        <option value="inspection">inspection</option>
      
      </Field>
  </FormField>



























  <FormField label="Priority" labelFor="priority">
      <Field name="priority" id="priority" component="select">
      
        <option value="low">low</option>
      
        <option value="medium">medium</option>
      
        <option value="high">high</option>
      
        <option value="critical">critical</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="requested">requested</option>
      
        <option value="approved">approved</option>
      
        <option value="scheduled">scheduled</option>
      
        <option value="in_progress">in_progress</option>
      
        <option value="completed">completed</option>
      
        <option value="cancelled">cancelled</option>
      
      </Field>
  </FormField>























  <FormField
      label="RequestedAt"
  >
      <Field
          type="datetime-local"
          name="requested_at"
          placeholder="RequestedAt"
      />
  </FormField>



























  <FormField
      label="ScheduledStart"
  >
      <Field
          type="datetime-local"
          name="scheduled_start"
          placeholder="ScheduledStart"
      />
  </FormField>



























  <FormField
      label="ScheduledEnd"
  >
      <Field
          type="datetime-local"
          name="scheduled_end"
          placeholder="ScheduledEnd"
      />
  </FormField>



























  <FormField
      label="CompletedAt"
  >
      <Field
          type="datetime-local"
          name="completed_at"
          placeholder="CompletedAt"
      />
  </FormField>



































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



























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











    <FormField label="ProblemDescription" hasTextareaHeight>
        <Field name="problem_description" as="textarea" placeholder="ProblemDescription" />
    </FormField>



























    <FormField label="ResolutionSummary" hasTextareaHeight>
        <Field name="resolution_summary" as="textarea" placeholder="ResolutionSummary" />
    </FormField>































    <FormField
        label="LaborHours"
    >
        <Field
            type="number"
            name="labor_hours"
            placeholder="LaborHours"
        />
    </FormField>












































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

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

export default Maintenance_work_ordersNew
