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

const initialValues = {
  thyme_id: '',

  name: '',

  office: '',

  address: '',

  city: '',

  post_code: '',

  country: '',

  country_txt: '',

  phone_number: '',

  website: '',

  currency: '',

  curious_customer_id: '',

  account_manager: '',

  agency: '',

  inclusive_amends: false,

  early_payment_discount: '',

  client_id_link: '',

  public_url: '',

  all_brands: [],

  production_fee: '',

  insurance_fee: '',

  xero_id: '',
};

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

  const handleSubmit = async (data) => {
    await dispatch(create(data));
    await router.push('/clients/clients-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='Thyme Id'>
                <Field name='thyme_id' placeholder='Thyme Id' />
              </FormField>

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

              <FormField label='Office'>
                <Field name='office' placeholder='Office' />
              </FormField>

              <FormField label='Address'>
                <Field name='address' placeholder='Address' />
              </FormField>

              <FormField label='City'>
                <Field name='city' placeholder='City' />
              </FormField>

              <FormField label='Post Code'>
                <Field name='post_code' placeholder='Post Code' />
              </FormField>

              <FormField label='Country' labelFor='country'>
                <Field
                  name='country'
                  id='country'
                  component={SelectField}
                  options={[]}
                  itemRef={'countries'}
                ></Field>
              </FormField>

              <FormField label='Country Txt'>
                <Field name='country_txt' placeholder='Country Txt' />
              </FormField>

              <FormField label='Phone Number'>
                <Field name='phone_number' placeholder='Phone Number' />
              </FormField>

              <FormField label='Website'>
                <Field name='website' placeholder='Website' />
              </FormField>

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

              <FormField label='Curious Customer Id'>
                <Field
                  name='curious_customer_id'
                  placeholder='Curious Customer Id'
                />
              </FormField>

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

              <FormField label='Agency'>
                <Field name='agency' placeholder='Agency' />
              </FormField>

              <FormField label='Inclusive Amends' labelFor='inclusive_amends'>
                <Field
                  name='inclusive_amends'
                  id='inclusive_amends'
                  component={SwitchField}
                ></Field>
              </FormField>

              <FormField label='Early Payment Discount'>
                <Field
                  type='number'
                  name='early_payment_discount'
                  placeholder='Early Payment Discount'
                />
              </FormField>

              <FormField label='Client Id Link'>
                <Field name='client_id_link' placeholder='Client Id Link' />
              </FormField>

              <FormField label='Public Url'>
                <Field name='public_url' placeholder='Public Url' />
              </FormField>

              <FormField label='All Brands' labelFor='all_brands'>
                <Field
                  name='all_brands'
                  id='all_brands'
                  itemRef={'brands'}
                  options={[]}
                  component={SelectFieldMany}
                ></Field>
              </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='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('/clients/clients-list')}
                />
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  );
};

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

export default ClientsNew;
