import { mdiChartTimelineVariant } 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 { SwitchField } from '../../components/SwitchField'

import { SelectField } from '../../components/SelectField'
import {RichTextField} from "../../components/RichTextField";

import { create } from '../../stores/quotes/quotesSlice'
import { useAppDispatch } from '../../stores/hooks'
import { useRouter } from 'next/router'

const initialValues = {

    name: '',

    status: '',

    quote_title: '',

    client: '',

    brand: '',

    campaign: '',

    total_quoted: '',

    estimated_profit: '',

    created_date: '',

    last_modified_date: '',

}

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

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

  <FormField
      label="Status"
  >
      <Field
          name="status"
          placeholder="Status"
      />
  </FormField>

  <FormField
      label="Quote Title"
  >
      <Field
          name="quote_title"
          placeholder="Quote Title"
      />
  </FormField>

  <FormField label="Client" labelFor="client">
      <Field name="client" id="client" component={SelectField} options={[]} itemRef={'clients'}></Field>
  </FormField>

  <FormField label="Brand" labelFor="brand">
      <Field name="brand" id="brand" component={SelectField} options={[]} itemRef={'brands'}></Field>
  </FormField>

  <FormField label="Campaign Name" labelFor="campaign">
      <Field name="campaign" id="campaign" component={SelectField} options={[]} itemRef={'campaigns'}></Field>
  </FormField>

    <FormField
        label="Total Quoted"
    >
        <Field
            type="number"
            name="total_quoted"
            placeholder="Total Quoted"
        />
    </FormField>

    <FormField
        label="Estimated Profit"
    >
        <Field
            type="number"
            name="estimated_profit"
            placeholder="Estimated Profit"
        />
    </FormField>

  <FormField
      label="Created Date"
  >
      <Field
          type="datetime-local"
          name="created_date"
          placeholder="Created Date"
      />
  </FormField>

  <FormField
      label="Last Modified Date"
  >
      <Field
          type="datetime-local"
          name="last_modified_date"
          placeholder="Last Modified Date"
      />
  </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('/quotes/quotes-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

QuotesNew.getLayout = function getLayout(page: ReactElement) {
  return (
      <LayoutAuthenticated>
          {page}
      </LayoutAuthenticated>
  )
}

export default QuotesNew
