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_transactions/payment_transactionsSlice'
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_transactionsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { payment_transactions } = useAppSelector((state) => state.payment_transactions)

    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_transactions')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View payment_transactions')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/payment_transactions/payment_transactions-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>

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

                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>TransactionAmount</p>
                  <p>{payment_transactions?.transaction_amount || 'No data'}</p>
                </div>

                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>DeductAmount</p>
                  <p>{payment_transactions?.deduct_amount || 'No data'}</p>
                </div>

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

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

                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>RevenueAmount</p>
                  <p>{payment_transactions?.revenue_amount || 'No data'}</p>
                </div>

                <FormField label='SettlementDatetime'>
                    {payment_transactions.setlement_datetime ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={payment_transactions.setlement_datetime ?
                        new Date(
                          dayjs(payment_transactions.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'}>Type</p>
                    <p>{payment_transactions?.type ?? 'No data'}</p>
                </div>

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

                        <p>{payment_transactions?.payment?.remark ?? 'No data'}</p>

                </div>

                <BaseDivider />

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

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

export default Payment_transactionsView;
