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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    alert_type: 'inventory_low',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    severity: 'info',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'open',
    
    
    
    
    
    
    
    title_text: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    message: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    triggered_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    acknowledged_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    resolved_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    acknowledged_by_user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    related_plant: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    related_machine: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    related_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    related_lot: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    related_inspection: '',
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/alerts/alerts-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="AlertType" labelFor="alert_type">
      <Field name="alert_type" id="alert_type" component="select">
      
        <option value="inventory_low">inventory_low</option>
      
        <option value="machine_down">machine_down</option>
      
        <option value="qa_failure">qa_failure</option>
      
        <option value="maintenance_overdue">maintenance_overdue</option>
      
        <option value="order_late">order_late</option>
      
        <option value="temperature_high">temperature_high</option>
      
        <option value="certificate_missing">certificate_missing</option>
      
      </Field>
  </FormField>



























  <FormField label="Severity" labelFor="severity">
      <Field name="severity" id="severity" component="select">
      
        <option value="info">info</option>
      
        <option value="warning">warning</option>
      
        <option value="critical">critical</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="open">open</option>
      
        <option value="acknowledged">acknowledged</option>
      
        <option value="resolved">resolved</option>
      
      </Field>
  </FormField>













  <FormField
      label="Title"
  >
      <Field
          name="title_text"
          placeholder="Title"
      />
  </FormField>































      <FormField label='Message' hasTextareaHeight>
          <Field
              name='message'
              id='message'
              component={RichTextField}
          ></Field>
      </FormField>

































  <FormField
      label="TriggeredAt"
  >
      <Field
          type="datetime-local"
          name="triggered_at"
          placeholder="TriggeredAt"
      />
  </FormField>



























  <FormField
      label="AcknowledgedAt"
  >
      <Field
          type="datetime-local"
          name="acknowledged_at"
          placeholder="AcknowledgedAt"
      />
  </FormField>



























  <FormField
      label="ResolvedAt"
  >
      <Field
          type="datetime-local"
          name="resolved_at"
          placeholder="ResolvedAt"
      />
  </FormField>



































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



























  <FormField label="RelatedPlant" labelFor="related_plant">
      <Field name="related_plant" id="related_plant" component={SelectField} options={[]} itemRef={'plants'}></Field>
  </FormField>



























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



























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



























  <FormField label="RelatedLot" labelFor="related_lot">
      <Field name="related_lot" id="related_lot" component={SelectField} options={[]} itemRef={'inventory_lots'}></Field>
  </FormField>



























  <FormField label="RelatedInspection" labelFor="related_inspection">
      <Field name="related_inspection" id="related_inspection" component={SelectField} options={[]} itemRef={'inspections'}></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('/alerts/alerts-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default AlertsNew
