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

const initialValues = {

    name: '',

    status: '',

    campaign_number: '',

    thyme_campaign_number: '',

    campaign_name: '',

    client: '',

    brand: '',

    scheduled_completion_date: '',

    account_manager: '',

    sales: '',

    billing_status: '',

    departments: '',

    created_by: '',

    total_cost: '',

    total_invoiced: '',

    uninvoiced: '',

    remaining_invoice_decimal: '',

    timing_project_id: '',

    timing_app_department_id: '',

    timing_id: '',

    client_details: '',

    sub_brand: '',

    start_date: '',

    admin_override: false,

    current_date: '',

    contact_info: '',

    client_contact: '',

    country: '',

    language: '',

    client_ref: '',

    client_job_number: '',

    invoice_number: '',

    revenue_code: '',

    created_date: '',

    last_updated_date: '',

    timing_app: '',

    organizations: '',

}

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

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

  <FormField
      label="Thyme Campaign Number"
  >
      <Field
          name="thyme_campaign_number"
          placeholder="Thyme Campaign Number"
      />
  </FormField>

  <FormField
      label="Campaign Name"
  >
      <Field
          name="campaign_name"
          placeholder="Campaign Name"
      />
  </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="Scheduled Completion Date"
  >
      <Field
          type="datetime-local"
          name="scheduled_completion_date"
          placeholder="Scheduled Completion Date"
      />
  </FormField>

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

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

  <FormField
      label="Billing Status"
  >
      <Field
          name="billing_status"
          placeholder="Billing Status"
      />
  </FormField>

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

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

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

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

    <FormField
        label="Uninvoiced"
    >
        <Field
            type="number"
            name="uninvoiced"
            placeholder="Uninvoiced"
        />
    </FormField>

    <FormField
        label="Remaining Invoice %"
    >
        <Field
            type="number"
            name="remaining_invoice_decimal"
            placeholder="Remaining Invoice %"
        />
    </FormField>

  <FormField
      label="TimingProjectID"
  >
      <Field
          name="timing_project_id"
          placeholder="TimingProjectID"
      />
  </FormField>

  <FormField
      label="TimingApp_DepartmentID"
  >
      <Field
          name="timing_app_department_id"
          placeholder="TimingApp_DepartmentID"
      />
  </FormField>

  <FormField
      label="TimingID"
  >
      <Field
          name="timing_id"
          placeholder="TimingID"
      />
  </FormField>

  <FormField
      label="Client Details"
  >
      <Field
          name="client_details"
          placeholder="Client Details"
      />
  </FormField>

  <FormField
      label="Sub Brand"
  >
      <Field
          name="sub_brand"
          placeholder="Sub Brand"
      />
  </FormField>

  <FormField
      label="Start Date"
  >
      <Field
          type="datetime-local"
          name="start_date"
          placeholder="Start Date"
      />
  </FormField>

  <FormField label='Admin Override' labelFor='admin_override'>
      <Field
          name='admin_override'
          id='admin_override'
          component={SwitchField}
      ></Field>
  </FormField>

  <FormField
      label="Current Date"
  >
      <Field
          type="datetime-local"
          name="current_date"
          placeholder="Current Date"
      />
  </FormField>

  <FormField
      label="Contact Info"
  >
      <Field
          name="contact_info"
          placeholder="Contact Info"
      />
  </FormField>

  <FormField
      label="Client Contact"
  >
      <Field
          name="client_contact"
          placeholder="Client Contact"
      />
  </FormField>

  <FormField
      label="Country"
  >
      <Field
          name="country"
          placeholder="Country"
      />
  </FormField>

  <FormField
      label="Language"
  >
      <Field
          name="language"
          placeholder="Language"
      />
  </FormField>

  <FormField
      label="Client Ref"
  >
      <Field
          name="client_ref"
          placeholder="Client Ref"
      />
  </FormField>

  <FormField
      label="Client Job Number"
  >
      <Field
          name="client_job_number"
          placeholder="Client Job Number"
      />
  </FormField>

  <FormField
      label="Invoice Number"
  >
      <Field
          name="invoice_number"
          placeholder="Invoice Number"
      />
  </FormField>

  <FormField
      label="Revenue Code"
  >
      <Field
          name="revenue_code"
          placeholder="Revenue Code"
      />
  </FormField>

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

  <FormField
      label="Last Updated Date"
  >
      <Field
          type="datetime-local"
          name="last_updated_date"
          placeholder="Last Updated Date"
      />
  </FormField>

  <FormField
      label="TimingApp"
  >
      <Field
          name="timing_app"
          placeholder="TimingApp"
      />
  </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('/campaigns/campaigns-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default CampaignsNew
