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 = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    organization: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    quote_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    issue_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    valid_until: '',
    
    
    
    
    
    
    
    
    
    
    currency_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    exchange_rate: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    subtotal_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tax_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    discount_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    total_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    terms_and_conditions: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    quote_lines: [],
    
    
}


const QuotesNew = () => {
  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('/quotes/quotes-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'),
                    valid_until: 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="Customer" labelFor="customer">
      <Field name="customer" id="customer" component={SelectField} options={[]} itemRef={'contacts'}></Field>
  </FormField>









  <FormField
      label="QuoteNumber"
  >
      <Field
          name="quote_number"
          placeholder="QuoteNumber"
      />
  </FormField>









































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="sent">sent</option>
      
        <option value="accepted">accepted</option>
      
        <option value="declined">declined</option>
      
        <option value="expired">expired</option>
      
        <option value="cancelled">cancelled</option>
      
      </Field>
  </FormField>























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



























  <FormField
      label="ValidUntil"
  >
      <Field
          type="datetime-local"
          name="valid_until"
          placeholder="ValidUntil"
      />
  </FormField>

















  <FormField
      label="CurrencyCode"
  >
      <Field
          name="currency_code"
          placeholder="CurrencyCode"
      />
  </FormField>

































    <FormField
        label="ExchangeRate"
    >
        <Field
            type="number"
            name="exchange_rate"
            placeholder="ExchangeRate"
        />
    </FormField>



























    <FormField
        label="SubtotalAmount"
    >
        <Field
            type="number"
            name="subtotal_amount"
            placeholder="SubtotalAmount"
        />
    </FormField>



























    <FormField
        label="TaxAmount"
    >
        <Field
            type="number"
            name="tax_amount"
            placeholder="TaxAmount"
        />
    </FormField>



























    <FormField
        label="DiscountAmount"
    >
        <Field
            type="number"
            name="discount_amount"
            placeholder="DiscountAmount"
        />
    </FormField>



























    <FormField
        label="TotalAmount"
    >
        <Field
            type="number"
            name="total_amount"
            placeholder="TotalAmount"
        />
    </FormField>

























      <FormField label='CustomerNotes' hasTextareaHeight>
          <Field
              name='customer_notes'
              id='customer_notes'
              component={RichTextField}
          ></Field>
      </FormField>



























      <FormField label='TermsandConditions' hasTextareaHeight>
          <Field
              name='terms_and_conditions'
              id='terms_and_conditions'
              component={RichTextField}
          ></Field>
      </FormField>











































    <FormField label='QuoteLines' labelFor='quote_lines'>
        <Field
            name='quote_lines'
            id='quote_lines'
            itemRef={'quote_lines'}
            options={[]}
            component={SelectFieldMany}>
        </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
