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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    machine: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    event_type: 'status_change',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'running',
    
    
    
    
    
    
    
    
    
    
    
    
    started_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ended_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    work_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reason_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reported_by: '',
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


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





















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























  <FormField label="EventType" labelFor="event_type">
      <Field name="event_type" id="event_type" component="select">
      
        <option value="status_change">status_change</option>
      
        <option value="downtime">downtime</option>
      
        <option value="maintenance">maintenance</option>
      
        <option value="setup">setup</option>
      
        <option value="changeover">changeover</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="running">running</option>
      
        <option value="idle">idle</option>
      
        <option value="down">down</option>
      
        <option value="maintenance">maintenance</option>
      
        <option value="offline">offline</option>
      
      </Field>
  </FormField>























  <FormField
      label="StartedAt"
  >
      <Field
          type="datetime-local"
          name="started_at"
          placeholder="StartedAt"
      />
  </FormField>



























  <FormField
      label="EndedAt"
  >
      <Field
          type="datetime-local"
          name="ended_at"
          placeholder="EndedAt"
      />
  </FormField>



































  <FormField label="WorkOrder" labelFor="work_order">
      <Field name="work_order" id="work_order" component={SelectField} options={[]} itemRef={'work_orders'}></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="ReportedBy" labelFor="reported_by">
      <Field name="reported_by" id="reported_by" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>











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

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

export default Machine_eventsNew
