import React, { ReactElement, useEffect } from 'react';
import Head from 'next/head'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import dayjs from "dayjs";
import {useAppDispatch, useAppSelector} from "../../stores/hooks";
import {useRouter} from "next/router";
import { fetch } from '../../stores/payment_revenues/payment_revenuesSlice'
import dataFormatter from '../../helpers/dataFormatter';
import LayoutAuthenticated from "../../layouts/Authenticated";
import {getPageTitle} from "../../config";
import SectionTitleLineWithButton from "../../components/SectionTitleLineWithButton";
import SectionMain from "../../components/SectionMain";
import CardBox from "../../components/CardBox";
import BaseButton from "../../components/BaseButton";
import BaseDivider from "../../components/BaseDivider";
import {mdiChartTimelineVariant} from "@mdi/js";
import {SwitchField} from "../../components/SwitchField";
import FormField from "../../components/FormField";

const Payment_revenuesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { payment_revenues } = useAppSelector((state) => state.payment_revenues)

    const { id } = router.query;

    function removeLastCharacter(str) {
      console.log(str,`str`)
      return str.slice(0, -1);
    }

    useEffect(() => {
        dispatch(fetch({ id }));
    }, [dispatch, id]);

    return (
      <>
          <Head>
              <title>{getPageTitle('View payment_revenues')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View payment_revenues')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/payment_revenues/payment_revenues-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>

                <FormField label='TransactionDate'>
                    {payment_revenues.transaction_date ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={payment_revenues.transaction_date ?
                        new Date(
                          dayjs(payment_revenues.transaction_date).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No TransactionDate</p>}
                </FormField>

                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>AdminFeeAmount</p>
                  <p>{payment_revenues?.admin_fee_amount || 'No data'}</p>
                </div>

                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>InterestAmount</p>
                  <p>{payment_revenues?.interest_amount || 'No data'}</p>
                </div>

                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>CommissionAmount</p>
                  <p>{payment_revenues?.commission_amount || 'No data'}</p>
                </div>

                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>ExpenseAmount</p>
                  <p>{payment_revenues?.expense_amount || 'No data'}</p>
                </div>

                <FormField label='SettlementDatetime'>
                    {payment_revenues.setlement_datetime ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={payment_revenues.setlement_datetime ?
                        new Date(
                          dayjs(payment_revenues.setlement_datetime).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No SettlementDatetime</p>}
                </FormField>

                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Branch</p>

                        <p>{payment_revenues?.branch?.name ?? 'No data'}</p>

                </div>

                <BaseDivider />

                <BaseButton
                    color='info'
                    label='Back'
                    onClick={() => router.push('/payment_revenues/payment_revenues-list')}
                />
              </CardBox>
          </SectionMain>
      </>
    );
};

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

export default Payment_revenuesView;
