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

const initialValues = {
    
    
    quote_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    account: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    location: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requested_by: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    owner: '',
    
    
    
    
    
    
    
    
    
    requested_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    expires_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    quote_status: 'requested',
    
    
    
    
    
    
    
    quote_total: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
}


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

    
    

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













































  <FormField label="Account" labelFor="account">
      <Field name="account" id="account" component={SelectField} options={[]} itemRef={'accounts'}></Field>
  </FormField>



























  <FormField label="Location" labelFor="location">
      <Field name="location" id="location" component={SelectField} options={[]} itemRef={'locations'}></Field>
  </FormField>



























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



























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



















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



























  <FormField
      label="Expiresat"
  >
      <Field
          type="datetime-local"
          name="expires_at"
          placeholder="Expiresat"
      />
  </FormField>































  <FormField label="Quotestatus" labelFor="quote_status">
      <Field name="quote_status" id="quote_status" component="select">
      
        <option value="requested">requested</option>
      
        <option value="in_review">in_review</option>
      
        <option value="sent">sent</option>
      
        <option value="accepted">accepted</option>
      
        <option value="declined">declined</option>
      
        <option value="expired">expired</option>
      
      </Field>
  </FormField>



















    <FormField
        label="Quotetotal"
    >
        <Field
            type="number"
            name="quote_total"
            placeholder="Quotetotal"
        />
    </FormField>























    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </FormField>
















































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

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

export default QuotesNew
