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

const initialValues = {
    
    
    order_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    device: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    source: 'public_web',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'new',
    
    
    
    
    
    
    
    
    problem_description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    diagnosis_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    internal_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    estimated_cost: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    final_cost: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requires_deposit: false,
    
    
    
    
    
    
    
    
    
    deposit_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requested_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    received_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    estimated_ready_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    completed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivered_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    intake_photos: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
    
    
    
    
    
    
    
    whatsapp_notified: false,
    
    
    
    
    
    
    
    
}


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

    
    

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













































  <FormField label="Customer" labelFor="customer">
      <Field name="customer" id="customer" component={SelectField} options={[]} itemRef={'customers'}></Field>
  </FormField>



























  <FormField label="Device" labelFor="device">
      <Field name="device" id="device" component={SelectField} options={[]} itemRef={'devices'}></Field>
  </FormField>























  <FormField label="Source" labelFor="source">
      <Field name="source" id="source" component="select">
      
        <option value="public_web">public_web</option>
      
        <option value="qr">qr</option>
      
        <option value="chatbot">chatbot</option>
      
        <option value="admin_panel">admin_panel</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="new">new</option>
      
        <option value="diagnosing">diagnosing</option>
      
        <option value="awaiting_approval">awaiting_approval</option>
      
        <option value="approved">approved</option>
      
        <option value="in_repair">in_repair</option>
      
        <option value="ready_for_pickup">ready_for_pickup</option>
      
        <option value="delivered">delivered</option>
      
        <option value="cancelled">cancelled</option>
      
      </Field>
  </FormField>















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





























      <FormField label='DiagnosisNotes' hasTextareaHeight>
          <Field
              name='diagnosis_notes'
              id='diagnosis_notes'
              component={RichTextField}
          ></Field>
      </FormField>



























      <FormField label='InternalNotes' hasTextareaHeight>
          <Field
              name='internal_notes'
              id='internal_notes'
              component={RichTextField}
          ></Field>
      </FormField>





























    <FormField
        label="EstimatedCost"
    >
        <Field
            type="number"
            name="estimated_cost"
            placeholder="EstimatedCost"
        />
    </FormField>



























    <FormField
        label="FinalCost"
    >
        <Field
            type="number"
            name="final_cost"
            placeholder="FinalCost"
        />
    </FormField>





































  <FormField label='RequiresDeposit' labelFor='requires_deposit'>
      <Field
          name='requires_deposit'
          id='requires_deposit'
          component={SwitchField}
      ></Field>
  </FormField>

















    <FormField
        label="DepositAmount"
    >
        <Field
            type="number"
            name="deposit_amount"
            placeholder="DepositAmount"
        />
    </FormField>































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



























  <FormField
      label="ReceivedAt"
  >
      <Field
          type="datetime-local"
          name="received_at"
          placeholder="ReceivedAt"
      />
  </FormField>



























  <FormField
      label="EstimatedReadyAt"
  >
      <Field
          type="datetime-local"
          name="estimated_ready_at"
          placeholder="EstimatedReadyAt"
      />
  </FormField>



























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



























  <FormField
      label="DeliveredAt"
  >
      <Field
          type="datetime-local"
          name="delivered_at"
          placeholder="DeliveredAt"
      />
  </FormField>







































  <FormField>
      <Field
          label='IntakePhotos'
          color='info'
          icon={mdiUpload}
          path={'repair_orders/intake_photos'}
          name='intake_photos'
          id='intake_photos'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormImagePicker}
      ></Field>
  </FormField>




























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




















  <FormField label='WhatsAppNotified' labelFor='whatsapp_notified'>
      <Field
          name='whatsapp_notified'
          id='whatsapp_notified'
          component={SwitchField}
      ></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('/repair_orders/repair_orders-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Repair_ordersNew
