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

const initialValues = {
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    forecast_category: 'pipeline',
    
    
    
    
    
    
    
    
    
    
    
    
    expected_close_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    next_follow_up_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    closed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    priority: 'low',
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    pipeline: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    stage: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    company: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    primary_contact: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    owner: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    lead: '',
    
    
    
}


const DealsNew = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/deals/deals-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>



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

































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



































  <FormField label="ForecastCategory" labelFor="forecast_category">
      <Field name="forecast_category" id="forecast_category" component="select">
      
        <option value="pipeline">pipeline</option>
      
        <option value="best_case">best_case</option>
      
        <option value="commit">commit</option>
      
        <option value="closed_won">closed_won</option>
      
        <option value="closed_lost">closed_lost</option>
      
      </Field>
  </FormField>























  <FormField
      label="ExpectedCloseDate"
  >
      <Field
          type="datetime-local"
          name="expected_close_at"
          placeholder="ExpectedCloseDate"
      />
  </FormField>



























  <FormField
      label="NextFollow-upAt"
  >
      <Field
          type="datetime-local"
          name="next_follow_up_at"
          placeholder="NextFollow-upAt"
      />
  </FormField>



























  <FormField
      label="ClosedAt"
  >
      <Field
          type="datetime-local"
          name="closed_at"
          placeholder="ClosedAt"
      />
  </FormField>































  <FormField label="Priority" labelFor="priority">
      <Field name="priority" id="priority" component="select">
      
        <option value="low">low</option>
      
        <option value="medium">medium</option>
      
        <option value="high">high</option>
      
        <option value="urgent">urgent</option>
      
      </Field>
  </FormField>















    <FormField label="Description" hasTextareaHeight>
        <Field name="description" as="textarea" placeholder="Description" />
    </FormField>











































  <FormField label="Pipeline" labelFor="pipeline">
      <Field name="pipeline" id="pipeline" component={SelectField} options={[]} itemRef={'pipelines'}></Field>
  </FormField>



























  <FormField label="Stage" labelFor="stage">
      <Field name="stage" id="stage" component={SelectField} options={[]} itemRef={'pipeline_stages'}></Field>
  </FormField>



























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



























  <FormField label="PrimaryContact" labelFor="primary_contact">
      <Field name="primary_contact" id="primary_contact" component={SelectField} options={[]} itemRef={'contacts'}></Field>
  </FormField>



























  <FormField label="Owner" labelFor="owner">
      <Field name="owner" id="owner" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>



























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

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

export default DealsNew
