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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    tenant: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    company: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    deal: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    template: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    service_line: '',
    
    
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'planned',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivery_method: 'agile',
    
    
    
    
    
    
    
    
    
    
    
    
    start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    end_at: '',
    
    
    
    
    
    
    
    
    
    
    budget_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    budget_currency: 'USD',
    
    
    
    
    
    
    
    external_costs: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    estimated_hours: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    actual_hours: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    project_manager: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    risk_level: 'low',
    
    
    
    
    
    
    
    
    summary: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


const ProjectsNew = () => {
  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('/projects/projects-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="Deal" labelFor="deal">
      <Field name="deal" id="deal" component={SelectField} options={[]} itemRef={'deals'}></Field>
  </FormField>



























  <FormField label="Template" labelFor="template">
      <Field name="template" id="template" component={SelectField} options={[]} itemRef={'project_templates'}></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="Projectname"
  >
      <Field
          name="name"
          placeholder="Projectname"
      />
  </FormField>



























  <FormField
      label="Projectcode"
  >
      <Field
          name="code"
          placeholder="Projectcode"
      />
  </FormField>









































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="planned">planned</option>
      
        <option value="active">active</option>
      
        <option value="on_hold">on_hold</option>
      
        <option value="completed">completed</option>
      
        <option value="cancelled">cancelled</option>
      
      </Field>
  </FormField>



























  <FormField label="Deliverymethod" labelFor="delivery_method">
      <Field name="delivery_method" id="delivery_method" component="select">
      
        <option value="agile">agile</option>
      
        <option value="waterfall">waterfall</option>
      
        <option value="hybrid">hybrid</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="Budgetamount"
    >
        <Field
            type="number"
            name="budget_amount"
            placeholder="Budgetamount"
        />
    </FormField>



































  <FormField label="Budgetcurrency" labelFor="budget_currency">
      <Field name="budget_currency" id="budget_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="Externalcosts"
    >
        <Field
            type="number"
            name="external_costs"
            placeholder="Externalcosts"
        />
    </FormField>



























    <FormField
        label="Estimatedhours"
    >
        <Field
            type="number"
            name="estimated_hours"
            placeholder="Estimatedhours"
        />
    </FormField>



























    <FormField
        label="Actualhours"
    >
        <Field
            type="number"
            name="actual_hours"
            placeholder="Actualhours"
        />
    </FormField>







































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























  <FormField label="Risklevel" labelFor="risk_level">
      <Field name="risk_level" id="risk_level" component="select">
      
        <option value="low">low</option>
      
        <option value="medium">medium</option>
      
        <option value="high">high</option>
      
        <option value="critical">critical</option>
      
      </Field>
  </FormField>















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

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

export default ProjectsNew
