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

const initialValues = {
  client: '',

  name: '',

  rate_card_import: false,

  client_fixed_text: '',

  yes_fixed_text: '',

  default_client_contact: '',

  default_account_manager: '',

  default_sales: '',

  inherit_default_rate_card: false,

  link_rate_card: '',

  default_costs: '',

  production_fee: '',

  insurance_fee: '',

  temp: '',

  xero_id: '',
};

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

  const handleSubmit = async (data) => {
    await dispatch(create(data));
    await router.push('/brands/brands-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='Client' labelFor='client'>
                <Field
                  name='client'
                  id='client'
                  component={SelectField}
                  options={[]}
                  itemRef={'clients'}
                ></Field>
              </FormField>

              <FormField label='Name'>
                <Field name='name' placeholder='Name' />
              </FormField>

              <FormField label='Rate Card Import' labelFor='rate_card_import'>
                <Field
                  name='rate_card_import'
                  id='rate_card_import'
                  component={SwitchField}
                ></Field>
              </FormField>

              <FormField label='Client Fixed Text' hasTextareaHeight>
                <Field
                  name='client_fixed_text'
                  as='textarea'
                  placeholder='Client Fixed Text'
                />
              </FormField>

              <FormField label='Yes Fixed Text' hasTextareaHeight>
                <Field
                  name='yes_fixed_text'
                  as='textarea'
                  placeholder='Yes Fixed Text'
                />
              </FormField>

              <FormField label='Default Client Contact'>
                <Field
                  name='default_client_contact'
                  placeholder='Default Client Contact'
                />
              </FormField>

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

              <FormField label='Default Sales' labelFor='default_sales'>
                <Field
                  name='default_sales'
                  id='default_sales'
                  component={SelectField}
                  options={[]}
                  itemRef={'users'}
                ></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='Link Rate Card' labelFor='link_rate_card'>
                <Field
                  name='link_rate_card'
                  id='link_rate_card'
                  component={SelectField}
                  options={[]}
                  itemRef={'brand_rate_cards'}
                ></Field>
              </FormField>

              <FormField label='Default Costs'>
                <Field
                  type='number'
                  name='default_costs'
                  placeholder='Default Costs'
                />
              </FormField>

              <FormField label='Production Fee'>
                <Field
                  type='number'
                  name='production_fee'
                  placeholder='Production Fee'
                />
              </FormField>

              <FormField label='Insurance Fee'>
                <Field
                  type='number'
                  name='insurance_fee'
                  placeholder='Insurance Fee'
                />
              </FormField>

              <FormField label='Temp'>
                <Field name='temp' placeholder='Temp' />
              </FormField>

              <FormField label='Xero Id'>
                <Field name='xero_id' placeholder='Xero Id' />
              </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('/brands/brands-list')}
                />
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  );
};

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

export default BrandsNew;
