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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    organization: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requisition: '',
    
    
    
    
    tender_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    title: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tender_type: 'open_tender',
    
    
    
    
    
    
    
    
    
    
    
    
    published_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    closing_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    opening_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    eligibility_criteria: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    submission_instructions: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


const TendersNew = () => {
  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('/tenders/tenders-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    published_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    closing_at: 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="Requisition" labelFor="requisition">
      <Field name="requisition" id="requisition" component={SelectField} options={[]} itemRef={'requisitions'}></Field>
  </FormField>









  <FormField
      label="TenderNumber"
  >
      <Field
          name="tender_number"
          placeholder="TenderNumber"
      />
  </FormField>



























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









































  <FormField label="TenderType" labelFor="tender_type">
      <Field name="tender_type" id="tender_type" component="select">
      
        <option value="open_tender">open_tender</option>
      
        <option value="restricted_tender">restricted_tender</option>
      
        <option value="consultation">consultation</option>
      
        <option value="rfq">rfq</option>
      
      </Field>
  </FormField>























  <FormField
      label="PublishedAt"
  >
      <Field
          type="datetime-local"
          name="published_at"
          placeholder="PublishedAt"
      />
  </FormField>



























  <FormField
      label="ClosingAt"
  >
      <Field
          type="datetime-local"
          name="closing_at"
          placeholder="ClosingAt"
      />
  </FormField>



























  <FormField
      label="OpeningAt"
  >
      <Field
          type="datetime-local"
          name="opening_at"
          placeholder="OpeningAt"
      />
  </FormField>































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="published">published</option>
      
        <option value="closed">closed</option>
      
        <option value="under_evaluation">under_evaluation</option>
      
        <option value="recommended">recommended</option>
      
        <option value="awarded">awarded</option>
      
        <option value="cancelled">cancelled</option>
      
      </Field>
  </FormField>















    <FormField label="EligibilityCriteria" hasTextareaHeight>
        <Field name="eligibility_criteria" as="textarea" placeholder="EligibilityCriteria" />
    </FormField>



























    <FormField label="SubmissionInstructions" hasTextareaHeight>
        <Field name="submission_instructions" as="textarea" placeholder="SubmissionInstructions" />
    </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('/tenders/tenders-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default TendersNew
