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

const initialValues = {

    start_payment_date: '',

    payment_date: '',

    last_payment_paid_date: '',

    sort: '',

    deduct_amount: '',

    deduct_paid_amount: '',

    interval: '',

    interest_amount: '',

    commission_amount: '',

    total_amount: '',

    total_paid_amount: '',

    penalty_amount: '',

    pending_amount: '',

    cross_amount: '',

    remark: '',

    loan: '',

    status: '',

}

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

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/payments/payments-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="StartPaymentDate"
  >
      <Field
          type="datetime-local"
          name="start_payment_date"
          placeholder="StartPaymentDate"
      />
  </FormField>

  <FormField
      label="PaymentDate"
  >
      <Field
          type="datetime-local"
          name="payment_date"
          placeholder="PaymentDate"
      />
  </FormField>

  <FormField
      label="LastPaymentPaidDate"
  >
      <Field
          type="datetime-local"
          name="last_payment_paid_date"
          placeholder="LastPaymentPaidDate"
      />
  </FormField>

    <FormField
        label="Sort"
    >
        <Field
            type="number"
            name="sort"
            placeholder="Sort"
        />
    </FormField>

    <FormField
        label="DeductAmount"
    >
        <Field
            type="number"
            name="deduct_amount"
            placeholder="DeductAmount"
        />
    </FormField>

    <FormField
        label="DeductPaidAmount"
    >
        <Field
            type="number"
            name="deduct_paid_amount"
            placeholder="DeductPaidAmount"
        />
    </FormField>

    <FormField
        label="Interval"
    >
        <Field
            type="number"
            name="interval"
            placeholder="Interval"
        />
    </FormField>

    <FormField
        label="InterestAmount"
    >
        <Field
            type="number"
            name="interest_amount"
            placeholder="InterestAmount"
        />
    </FormField>

    <FormField
        label="CommissionAmount"
    >
        <Field
            type="number"
            name="commission_amount"
            placeholder="CommissionAmount"
        />
    </FormField>

    <FormField
        label="TotalAmount"
    >
        <Field
            type="number"
            name="total_amount"
            placeholder="TotalAmount"
        />
    </FormField>

    <FormField
        label="TotalPaidAmount"
    >
        <Field
            type="number"
            name="total_paid_amount"
            placeholder="TotalPaidAmount"
        />
    </FormField>

    <FormField
        label="PenaltyAmount"
    >
        <Field
            type="number"
            name="penalty_amount"
            placeholder="PenaltyAmount"
        />
    </FormField>

    <FormField
        label="PendingAmount"
    >
        <Field
            type="number"
            name="pending_amount"
            placeholder="PendingAmount"
        />
    </FormField>

    <FormField
        label="CrossAmount"
    >
        <Field
            type="number"
            name="cross_amount"
            placeholder="CrossAmount"
        />
    </FormField>

  <FormField
      label="Remark"
  >
      <Field
          name="remark"
          placeholder="Remark"
      />
  </FormField>

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

  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component={SelectField} options={[]} itemRef={'payment_status'}></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('/payments/payments-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default PaymentsNew
