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/withdrawal_requests/withdrawal_requestsSlice'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";
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 Withdrawal_requestsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { withdrawal_requests } = useAppSelector((state) => state.withdrawal_requests)
    

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

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>User</p>
                    
                    
                        <p>{withdrawal_requests?.user?.firstName ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Status</p>
                    <p>{withdrawal_requests?.status ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Coinsamount</p>
                  <p>{withdrawal_requests?.coins_amount || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Cashamount(UZS)</p>
                  <p>{withdrawal_requests?.cash_amount_uzs || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Payoutmethod</p>
                    <p>{withdrawal_requests?.payout_method ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Payoutdestination</p>
                    <p>{withdrawal_requests?.payout_destination}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Providerreference</p>
                    <p>{withdrawal_requests?.provider_reference}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              
                <FormField label='Multi Text' hasTextareaHeight>
                  <textarea className={'w-full'} disabled value={withdrawal_requests?.admin_note} />
                </FormField>
              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Payment_transactions Withdrawalrequest</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Provider</th>
                                
                                
                                
                                <th>Amount(UZS)</th>
                                
                                
                                
                                <th>Providertransactionreference</th>
                                
                                
                                
                                <th>Failurereason</th>
                                
                                
                                
                                <th>Initiatedat</th>
                                
                                
                                
                                <th>Finalizedat</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {withdrawal_requests.payment_transactions_withdrawal_request && Array.isArray(withdrawal_requests.payment_transactions_withdrawal_request) &&
                              withdrawal_requests.payment_transactions_withdrawal_request.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/payment_transactions/payment_transactions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="provider">
                                        { item.provider }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount_uzs">
                                        { item.amount_uzs }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="provider_transaction_reference">
                                        { item.provider_transaction_reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="failure_reason">
                                        { item.failure_reason }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="initiated_at">
                                        { dataFormatter.dateTimeFormatter(item.initiated_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="finalized_at">
                                        { dataFormatter.dateTimeFormatter(item.finalized_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!withdrawal_requests?.payment_transactions_withdrawal_request?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

Withdrawal_requestsView.getLayout = function getLayout(page: ReactElement) {
    return (
      <LayoutAuthenticated
        
        permission={'READ_WITHDRAWAL_REQUESTS'}
        
      >
          {page}
      </LayoutAuthenticated>
    )
}

export default Withdrawal_requestsView;