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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    organization: '',
    
    
    
    
    delivery_note_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sales_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    client: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    warehouse: '',
    
    
    
    
    
    
    
    
    
    issue_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivered_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    carrier_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tracking_reference: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    pdf_file: [],
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
}


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





















  <FormField label="Organization" labelFor="organization">
      <Field name="organization" id="organization" component={SelectField} options={[]} itemRef={'organizations'}></Field>
  </FormField>









  <FormField
      label="DeliveryNoteNumber"
  >
      <Field
          name="delivery_note_number"
          placeholder="DeliveryNoteNumber"
      />
  </FormField>













































  <FormField label="SalesOrder" labelFor="sales_order">
      <Field name="sales_order" id="sales_order" component={SelectField} options={[]} itemRef={'sales_orders'}></Field>
  </FormField>



























  <FormField label="Client" labelFor="client">
      <Field name="client" id="client" component={SelectField} options={[]} itemRef={'clients'}></Field>
  </FormField>



























  <FormField label="Warehouse" labelFor="warehouse">
      <Field name="warehouse" id="warehouse" component={SelectField} options={[]} itemRef={'warehouses'}></Field>
  </FormField>



















  <FormField
      label="IssueDate"
  >
      <Field
          type="datetime-local"
          name="issue_date"
          placeholder="IssueDate"
      />
  </FormField>



























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































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="issued">issued</option>
      
        <option value="delivered">delivered</option>
      
        <option value="canceled">canceled</option>
      
      </Field>
  </FormField>













  <FormField
      label="Carrier"
  >
      <Field
          name="carrier_name"
          placeholder="Carrier"
      />
  </FormField>



























  <FormField
      label="TrackingReference"
  >
      <Field
          name="tracking_reference"
          placeholder="TrackingReference"
      />
  </FormField>


















































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








      <FormField label='Notes' hasTextareaHeight>
          <Field
              name='notes'
              id='notes'
              component={RichTextField}
          ></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('/delivery_notes/delivery_notes-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Delivery_notesNew
