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/authentication_attempts/authentication_attemptsSlice'
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";

import {hasPermission} from "../../helpers/userPermissions";


const Authentication_attemptsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { authentication_attempts } = useAppSelector((state) => state.authentication_attempts)
    
    const { currentUser } = useAppSelector((state) => state.auth);
    

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

              

              

              

              

              

              

              

              

              

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

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Authenticationmethod</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{authentication_attempts?.authentication_method?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

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

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>organizations</p>
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{authentication_attempts?.organizations?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Id_verification_artifacts Authenticationattempt</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>IDdocumenttype</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Qualitystatus</th>
                                
                                
                                
                                <th>Qualitynotes</th>
                                
                                
                                
                                <th>Facematchscore</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {authentication_attempts.id_verification_artifacts_authentication_attempt && Array.isArray(authentication_attempts.id_verification_artifacts_authentication_attempt) &&
                              authentication_attempts.id_verification_artifacts_authentication_attempt.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/id_verification_artifacts/id_verification_artifacts-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="id_document_type">
                                        { item.id_document_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="quality_status">
                                        { item.quality_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quality_notes">
                                        { item.quality_notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="match_score">
                                        { item.match_score }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!authentication_attempts?.id_verification_artifacts_authentication_attempt?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Bank_verifications Authenticationattempt</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Bankname</th>
                                
                                
                                
                                <th>Accountidentifier</th>
                                
                                
                                
                                <th>Expectedamount</th>
                                
                                
                                
                                <th>Reportedamount</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Verifiedat</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {authentication_attempts.bank_verifications_authentication_attempt && Array.isArray(authentication_attempts.bank_verifications_authentication_attempt) &&
                              authentication_attempts.bank_verifications_authentication_attempt.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/bank_verifications/bank_verifications-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="bank_name">
                                        { item.bank_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="account_identifier">
                                        { item.account_identifier }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expected_amount">
                                        { item.expected_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reported_amount">
                                        { item.reported_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="verified_at">
                                        { dataFormatter.dateTimeFormatter(item.verified_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!authentication_attempts?.bank_verifications_authentication_attempt?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Authentication_attemptsView;