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 = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    organization: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    vendor: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    award: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    project: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    budget_line: '',
    
    
    
    
    contract_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    title: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    contract_type: 'works',
    
    
    
    
    
    
    
    contract_value: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    currency: 'CDF',
    
    
    
    
    
    
    
    
    
    
    
    
    start_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    end_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    retention_percent: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    penalty_rate_percent: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    signed_at: '',
    
    
    
    
    
    
    
    
    
}


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_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="Organization" labelFor="organization">
      <Field name="organization" id="organization" component={SelectField} options={[]} itemRef={'organizations'}></Field>
  </FormField>



























  <FormField label="Vendor" labelFor="vendor">
      <Field name="vendor" id="vendor" component={SelectField} options={[]} itemRef={'vendors'}></Field>
  </FormField>



























  <FormField label="Award" labelFor="award">
      <Field name="award" id="award" component={SelectField} options={[]} itemRef={'awards'}></Field>
  </FormField>



























  <FormField label="Project" labelFor="project">
      <Field name="project" id="project" component={SelectField} options={[]} itemRef={'projects'}></Field>
  </FormField>



























  <FormField label="BudgetLine" labelFor="budget_line">
      <Field name="budget_line" id="budget_line" component={SelectField} options={[]} itemRef={'budget_lines'}></Field>
  </FormField>









  <FormField
      label="ContractNumber"
  >
      <Field
          name="contract_number"
          placeholder="ContractNumber"
      />
  </FormField>



























  <FormField
      label="ContractTitle"
  >
      <Field
          name="title"
          placeholder="ContractTitle"
      />
  </FormField>









































  <FormField label="ContractType" labelFor="contract_type">
      <Field name="contract_type" id="contract_type" component="select">
      
        <option value="works">works</option>
      
        <option value="goods">goods</option>
      
        <option value="services">services</option>
      
        <option value="consulting">consulting</option>
      
        <option value="grant_agreement">grant_agreement</option>
      
      </Field>
  </FormField>



















    <FormField
        label="ContractValue"
    >
        <Field
            type="number"
            name="contract_value"
            placeholder="ContractValue"
        />
    </FormField>



































  <FormField label="Currency" labelFor="currency">
      <Field name="currency" id="currency" component="select">
      
        <option value="CDF">CDF</option>
      
        <option value="USD">USD</option>
      
      </Field>
  </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="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="under_review">under_review</option>
      
        <option value="active">active</option>
      
        <option value="suspended">suspended</option>
      
        <option value="completed">completed</option>
      
        <option value="terminated">terminated</option>
      
        <option value="expired">expired</option>
      
        <option value="closed">closed</option>
      
      </Field>
  </FormField>



















    <FormField
        label="RetentionPercent"
    >
        <Field
            type="number"
            name="retention_percent"
            placeholder="RetentionPercent"
        />
    </FormField>



























    <FormField
        label="PenaltyRatePercent"
    >
        <Field
            type="number"
            name="penalty_rate_percent"
            placeholder="PenaltyRatePercent"
        />
    </FormField>































  <FormField
      label="SignedAt"
  >
      <Field
          type="datetime-local"
          name="signed_at"
          placeholder="SignedAt"
      />
  </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
