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

const initialValues = {
  name: '',

  rate_type: '',

  standard_service: '',

  department: '',

  service_text: '',

  rate: '',

  service_id: '',

  service_code: '',

  unit_type: '',

  cost: '',

  qty: '',

  currency: '',

  rate_gbp: '',

  rate_eur: '',

  rate_usd: '',

  yes_fixed_text: false,

  no_fixed_text: false,
};

const Default_activities_productsNew = () => {
  const router = useRouter();
  const dispatch = useAppDispatch();

  const handleSubmit = async (data) => {
    await dispatch(create(data));
    await router.push(
      '/default_activities_products/default_activities_products-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='Rate Type'>
                <Field name='rate_type' placeholder='Rate Type' />
              </FormField>

              <FormField label='Standard Service'>
                <Field name='standard_service' placeholder='Standard Service' />
              </FormField>

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

              <FormField label='Service Text'>
                <Field name='service_text' placeholder='Service Text' />
              </FormField>

              <FormField label='Rate'>
                <Field type='number' name='rate' placeholder='Rate' />
              </FormField>

              <FormField label='Service Id'>
                <Field name='service_id' placeholder='Service Id' />
              </FormField>

              <FormField label='Service Code'>
                <Field name='service_code' placeholder='Service Code' />
              </FormField>

              <FormField label='Unit Type'>
                <Field name='unit_type' placeholder='Unit Type' />
              </FormField>

              <FormField label='Cost'>
                <Field type='number' name='cost' placeholder='Cost' />
              </FormField>

              <FormField label='Qty'>
                <Field type='number' name='qty' placeholder='Qty' />
              </FormField>

              <FormField label='Currency'>
                <Field name='currency' placeholder='Currency' />
              </FormField>

              <FormField label='Rate Gbp'>
                <Field type='number' name='rate_gbp' placeholder='Rate Gbp' />
              </FormField>

              <FormField label='Rate Eur'>
                <Field type='number' name='rate_eur' placeholder='Rate Eur' />
              </FormField>

              <FormField label='Rate Usd'>
                <Field type='number' name='rate_usd' placeholder='Rate Usd' />
              </FormField>

              <FormField label='Yes Fixed Text' labelFor='yes_fixed_text'>
                <Field
                  name='yes_fixed_text'
                  id='yes_fixed_text'
                  component={SwitchField}
                ></Field>
              </FormField>

              <FormField label='No Fixed Text' labelFor='no_fixed_text'>
                <Field
                  name='no_fixed_text'
                  id='no_fixed_text'
                  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(
                      '/default_activities_products/default_activities_products-list',
                    )
                  }
                />
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  );
};

Default_activities_productsNew.getLayout = function getLayout(
  page: ReactElement,
) {
  return (
    <LayoutAuthenticated permission={'CREATE_DEFAULT_ACTIVITIES_PRODUCTS'}>
      {page}
    </LayoutAuthenticated>
  );
};

export default Default_activities_productsNew;
