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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    tenant: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    company: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    service_line: '',
    
    
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    contract_type: 'maintenance',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    billing_model: 'fixed_price',
    
    
    
    
    
    
    
    amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    currency: 'USD',
    
    
    
    
    
    
    
    
    
    
    
    
    start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    end_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    auto_renew: false,
    
    
    
    
    
    
    
    
    
    
    
    
    renewal_notice_days: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


const ContractsNew = () => {
  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('/contracts/contracts-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_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    end_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="Tenant" labelFor="tenant">
      <Field name="tenant" id="tenant" component={SelectField} options={[]} itemRef={'tenants'}></Field>
  </FormField>



























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



























  <FormField label="Serviceline" labelFor="service_line">
      <Field name="service_line" id="service_line" component={SelectField} options={[]} itemRef={'service_lines'}></Field>
  </FormField>









  <FormField
      label="Contractname"
  >
      <Field
          name="name"
          placeholder="Contractname"
      />
  </FormField>









































  <FormField label="Contracttype" labelFor="contract_type">
      <Field name="contract_type" id="contract_type" component="select">
      
        <option value="maintenance">maintenance</option>
      
        <option value="msa">msa</option>
      
        <option value="sow">sow</option>
      
        <option value="nda">nda</option>
      
        <option value="hosting">hosting</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>



























  <FormField label="Billingmodel" labelFor="billing_model">
      <Field name="billing_model" id="billing_model" component="select">
      
        <option value="fixed_price">fixed_price</option>
      
        <option value="time_material">time_material</option>
      
        <option value="recurring">recurring</option>
      
      </Field>
  </FormField>



















    <FormField
        label="Amount"
    >
        <Field
            type="number"
            name="amount"
            placeholder="Amount"
        />
    </FormField>



































  <FormField label="Currency" labelFor="currency">
      <Field name="currency" id="currency" component="select">
      
        <option value="USD">USD</option>
      
        <option value="CDF">CDF</option>
      
        <option value="EUR">EUR</option>
      
        <option value="XAF">XAF</option>
      
        <option value="XOF">XOF</option>
      
      </Field>
  </FormField>























  <FormField
      label="Startdate"
  >
      <Field
          type="datetime-local"
          name="start_at"
          placeholder="Startdate"
      />
  </FormField>



























  <FormField
      label="Enddate"
  >
      <Field
          type="datetime-local"
          name="end_at"
          placeholder="Enddate"
      />
  </FormField>

































  <FormField label='Autorenew' labelFor='auto_renew'>
      <Field
          name='auto_renew'
          id='auto_renew'
          component={SwitchField}
      ></Field>
  </FormField>

















    <FormField
        label="Renewalnoticedays"
    >
        <Field
            type="number"
            name="renewal_notice_days"
            placeholder="Renewalnoticedays"
        />
    </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="suspended">suspended</option>
      
        <option value="expired">expired</option>
      
        <option value="terminated">terminated</option>
      
      </Field>
  </FormField>















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











































  <FormField label="organizations" labelFor="organizations">
      <Field name="organizations" id="organizations" component={SelectField} options={[]} itemRef={'organizations'}></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('/contracts/contracts-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default ContractsNew
