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/verification_submissions/verification_submissionsSlice'
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 Verification_submissionsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { verification_submissions } = useAppSelector((state) => state.verification_submissions)
    

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

              

              

              

              

              

              

              

              

              

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

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BadgeType</p>
                    <p>{verification_submissions?.badge_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

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

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Verification_evidences Submission</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>EvidenceType</th>
                                
                                
                                
                                
                                
                                <th>URL</th>
                                
                                
                                
                                <th>CreatedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {verification_submissions.verification_evidences_submission && Array.isArray(verification_submissions.verification_evidences_submission) &&
                              verification_submissions.verification_evidences_submission.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/verification_evidences/verification_evidences-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="evidence_type">
                                        { item.evidence_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="url">
                                        { item.url }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="created_at_ts">
                                        { dataFormatter.dateTimeFormatter(item.created_at_ts) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!verification_submissions?.verification_evidences_submission?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Verification_submissionsView;