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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    company: '',
    
    
    
    
    agreement_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    driver: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    vehicle: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    agreement_type: 'rental',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    billing_frequency: 'daily',
    
    
    
    
    
    
    
    daily_rate: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    weekly_rate: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    monthly_rate: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    deposit_required: false,
    
    
    
    
    
    
    
    
    
    deposit_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    start_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    end_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    recurring_invoice_enabled: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    created_on: '',
    
    
    
    
    
    
    
    
    
}


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





















  <FormField label="Company" labelFor="company">
      <Field name="company" id="company" component={SelectField} options={[]} itemRef={'companies'}></Field>
  </FormField>









  <FormField
      label="AgreementNumber"
  >
      <Field
          name="agreement_number"
          placeholder="AgreementNumber"
      />
  </FormField>













































  <FormField label="Driver" labelFor="driver">
      <Field name="driver" id="driver" component={SelectField} options={[]} itemRef={'drivers'}></Field>
  </FormField>



























  <FormField label="Vehicle" labelFor="vehicle">
      <Field name="vehicle" id="vehicle" component={SelectField} options={[]} itemRef={'vehicles'}></Field>
  </FormField>























  <FormField label="AgreementType" labelFor="agreement_type">
      <Field name="agreement_type" id="agreement_type" component="select">
      
        <option value="rental">rental</option>
      
        <option value="lease">lease</option>
      
      </Field>
  </FormField>



























  <FormField label="BillingFrequency" labelFor="billing_frequency">
      <Field name="billing_frequency" id="billing_frequency" component="select">
      
        <option value="daily">daily</option>
      
        <option value="weekly">weekly</option>
      
        <option value="monthly">monthly</option>
      
      </Field>
  </FormField>



















    <FormField
        label="DailyRate"
    >
        <Field
            type="number"
            name="daily_rate"
            placeholder="DailyRate"
        />
    </FormField>



























    <FormField
        label="WeeklyRate"
    >
        <Field
            type="number"
            name="weekly_rate"
            placeholder="WeeklyRate"
        />
    </FormField>



























    <FormField
        label="MonthlyRate"
    >
        <Field
            type="number"
            name="monthly_rate"
            placeholder="MonthlyRate"
        />
    </FormField>





































  <FormField label='DepositRequired' labelFor='deposit_required'>
      <Field
          name='deposit_required'
          id='deposit_required'
          component={SwitchField}
      ></Field>
  </FormField>

















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































  <FormField
      label="StartDate"
  >
      <Field
          type="datetime-local"
          name="start_date"
          placeholder="StartDate"
      />
  </FormField>



























  <FormField
      label="EndDate"
  >
      <Field
          type="datetime-local"
          name="end_date"
          placeholder="EndDate"
      />
  </FormField>

































  <FormField label='RecurringInvoiceEnabled' labelFor='recurring_invoice_enabled'>
      <Field
          name='recurring_invoice_enabled'
          id='recurring_invoice_enabled'
          component={SwitchField}
      ></Field>
  </FormField>

























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="active">active</option>
      
        <option value="paused">paused</option>
      
        <option value="ended">ended</option>
      
        <option value="cancelled">cancelled</option>
      
      </Field>
  </FormField>















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



































  <FormField
      label="CreatedOn"
  >
      <Field
          type="datetime-local"
          name="created_on"
          placeholder="CreatedOn"
      />
  </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('/agreements/agreements-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default AgreementsNew
