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

const initialValues = {
    
    
    full_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    phone: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    email: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    city: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    preferred_contact_method: 'whatsapp',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    service: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    project: '',
    
    
    
    
    
    message: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachment_files: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    source: 'website_form',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    stage: 'new',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    assigned_user: '',
    
    
    
    
    
    
    
    
    
    requested_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    follow_up_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    consent_to_contact: false,
    
    
    
    
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/leads/leads-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="FullName"
  >
      <Field
          name="full_name"
          placeholder="FullName"
      />
  </FormField>



























  <FormField
      label="Phone"
  >
      <Field
          name="phone"
          placeholder="Phone"
      />
  </FormField>



























  <FormField
      label="Email"
  >
      <Field
          name="email"
          placeholder="Email"
      />
  </FormField>



























  <FormField
      label="City"
  >
      <Field
          name="city"
          placeholder="City"
      />
  </FormField>









































  <FormField label="PreferredContactMethod" labelFor="preferred_contact_method">
      <Field name="preferred_contact_method" id="preferred_contact_method" component="select">
      
        <option value="whatsapp">whatsapp</option>
      
        <option value="phone">phone</option>
      
        <option value="email">email</option>
      
      </Field>
  </FormField>































  <FormField label="InterestedService" labelFor="service">
      <Field name="service" id="service" component={SelectField} options={[]} itemRef={'services'}></Field>
  </FormField>



























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











    <FormField label="Message" hasTextareaHeight>
        <Field name="message" as="textarea" placeholder="Message" />
    </FormField>
















































  <FormField>
      <Field
          label='Attachments'
          color='info'
          icon={mdiUpload}
          path={'leads/attachment_files'}
          name='attachment_files'
          id='attachment_files'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></Field>
  </FormField>


















  <FormField label="Source" labelFor="source">
      <Field name="source" id="source" component="select">
      
        <option value="website_form">website_form</option>
      
        <option value="whatsapp_click">whatsapp_click</option>
      
        <option value="phone_click">phone_click</option>
      
        <option value="email_click">email_click</option>
      
        <option value="manual">manual</option>
      
      </Field>
  </FormField>



























  <FormField label="LeadStage" labelFor="stage">
      <Field name="stage" id="stage" component="select">
      
        <option value="new">new</option>
      
        <option value="contacted">contacted</option>
      
        <option value="qualified">qualified</option>
      
        <option value="proposal_sent">proposal_sent</option>
      
        <option value="won">won</option>
      
        <option value="lost">lost</option>
      
      </Field>
  </FormField>































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



















  <FormField
      label="RequestedAt"
  >
      <Field
          type="datetime-local"
          name="requested_at"
          placeholder="RequestedAt"
      />
  </FormField>



























  <FormField
      label="FollowUpAt"
  >
      <Field
          type="datetime-local"
          name="follow_up_at"
          placeholder="FollowUpAt"
      />
  </FormField>

































  <FormField label='ConsentToContact' labelFor='consent_to_contact'>
      <Field
          name='consent_to_contact'
          id='consent_to_contact'
          component={SwitchField}
      ></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('/leads/leads-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default LeadsNew
