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

const initialValues = {
  name: '',

  rate_card_type: '',

  client: '',

  brand: '',

  status: '',

  currency: '',

  push_new_values: false,

  inherit_default_rate_card: false,

  service_count: '',

  discipline: '',

  output_channel: '',

  staff_skills: '',

  rate_card_owner: '',

  rate_card_id: '',

  markets: '',

  languages: '',

  valid_from: '',
  dateValid_from: '',

  valid_to: '',
  dateValid_to: '',

  version_number: '',

  commercial_owner: '',

  review_date: '',
  dateReview_date: '',

  assumptions: '',

  no_fixed_text: '',

  yes_fixed_text: '',
};

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

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

              <FormField label='Rate Card Type'>
                <Field name='rate_card_type' placeholder='Rate Card Type' />
              </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='Status'>
                <Field name='status' placeholder='Status' />
              </FormField>

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

              <FormField label='Push New Values' labelFor='push_new_values'>
                <Field
                  name='push_new_values'
                  id='push_new_values'
                  component={SwitchField}
                ></Field>
              </FormField>

              <FormField
                label='Inherit Default Rate Card'
                labelFor='inherit_default_rate_card'
              >
                <Field
                  name='inherit_default_rate_card'
                  id='inherit_default_rate_card'
                  component={SwitchField}
                ></Field>
              </FormField>

              <FormField label='Service Count'>
                <Field
                  type='number'
                  name='service_count'
                  placeholder='Service Count'
                />
              </FormField>

              <FormField label='Discipline'>
                <Field name='discipline' placeholder='Discipline' />
              </FormField>

              <FormField label='Output Channel'>
                <Field name='output_channel' placeholder='Output Channel' />
              </FormField>

              <FormField label='Staff Skills'>
                <Field name='staff_skills' placeholder='Staff Skills' />
              </FormField>

              <FormField label='Rate Card Owner'>
                <Field name='rate_card_owner' placeholder='Rate Card Owner' />
              </FormField>

              <FormField label='Rate Card Id'>
                <Field name='rate_card_id' placeholder='Rate Card Id' />
              </FormField>

              <FormField label='Markets'>
                <Field name='markets' placeholder='Markets' />
              </FormField>

              <FormField label='Languages'>
                <Field name='languages' placeholder='Languages' />
              </FormField>

              <FormField label='Valid From'>
                <Field type='date' name='valid_from' placeholder='Valid From' />
              </FormField>

              <FormField label='Valid To'>
                <Field type='date' name='valid_to' placeholder='Valid To' />
              </FormField>

              <FormField label='Version Number'>
                <Field name='version_number' placeholder='Version Number' />
              </FormField>

              <FormField label='Commercial Owner'>
                <Field name='commercial_owner' placeholder='Commercial Owner' />
              </FormField>

              <FormField label='Review Date'>
                <Field
                  type='date'
                  name='review_date'
                  placeholder='Review Date'
                />
              </FormField>

              <FormField label='Assumptions' hasTextareaHeight>
                <Field
                  name='assumptions'
                  as='textarea'
                  placeholder='Assumptions'
                />
              </FormField>

              <FormField label='No Fixed Text' hasTextareaHeight>
                <Field
                  name='no_fixed_text'
                  as='textarea'
                  placeholder='No Fixed Text'
                />
              </FormField>

              <FormField label='Yes Fixed Text' hasTextareaHeight>
                <Field
                  name='yes_fixed_text'
                  as='textarea'
                  placeholder='Yes Fixed Text'
                />
              </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('/brand_rate_cards/brand_rate_cards-list')
                  }
                />
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  );
};

Brand_rate_cardsNew.getLayout = function getLayout(page: ReactElement) {
  return (
    <LayoutAuthenticated permission={'CREATE_BRAND_RATE_CARDS'}>
      {page}
    </LayoutAuthenticated>
  );
};

export default Brand_rate_cardsNew;
