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/jobs/jobsSlice'
import { useAppDispatch } from '../../stores/hooks'
import { useRouter } from 'next/router'

const initialValues = {

    name: '',

    job_number: '',

    job_name: '',

    status: 'New',

    client: '',

    brand: '',

    campaign: '',

    scheduled_completion_date: '',

    job_type: '',

    total_cost: '',

    invoiced: '',

    uninvoiced: '',

}

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

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

  <FormField
      label="Job Name"
  >
      <Field
          name="job_name"
          placeholder="Job Name"
      />
  </FormField>

  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">

        <option value="New">New</option>

        <option value="In Production">In Production</option>

        <option value="Completed">Completed</option>

        <option value="Cancelled">Cancelled</option>

      </Field>
  </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" labelFor="campaign">
      <Field name="campaign" id="campaign" component={SelectField} options={[]} itemRef={'campaigns'}></Field>
  </FormField>

  <FormField
      label="Scheduled Completion Date"
  >
      <Field
          type="datetime-local"
          name="scheduled_completion_date"
          placeholder="Scheduled Completion Date"
      />
  </FormField>

  <FormField
      label="Job Type"
  >
      <Field
          name="job_type"
          placeholder="Job Type"
      />
  </FormField>

    <FormField
        label="Total Cost"
    >
        <Field
            type="number"
            name="total_cost"
            placeholder="Total Cost"
        />
    </FormField>

    <FormField
        label="Invoiced"
    >
        <Field
            type="number"
            name="invoiced"
            placeholder="Invoiced"
        />
    </FormField>

    <FormField
        label="Uninvoiced"
    >
        <Field
            type="number"
            name="uninvoiced"
            placeholder="Uninvoiced"
        />
    </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('/jobs/jobs-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default JobsNew
