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/gdpr_consents/gdpr_consentsSlice'
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 Gdpr_consentsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { gdpr_consents } = useAppSelector((state) => state.gdpr_consents)
    

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

              

              

              

              

              

              

              

              

              
                <FormField label='TermsAccepted'>
                    <SwitchField
                      field={{name: 'terms_accepted', value: gdpr_consents?.terms_accepted}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='PrivacyPolicyAccepted'>
                    <SwitchField
                      field={{name: 'privacy_policy_accepted', value: gdpr_consents?.privacy_policy_accepted}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='MarketingEmailsOptIn'>
                    <SwitchField
                      field={{name: 'marketing_emails_opt_in', value: gdpr_consents?.marketing_emails_opt_in}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ConsentSource</p>
                    <p>{gdpr_consents?.consent_source ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ConsentVersion</p>
                    <p>{gdpr_consents?.consent_version}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>IPAddress</p>
                    <p>{gdpr_consents?.ip_address}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>UserAgent</p>
                    <p>{gdpr_consents?.user_agent}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>LawfulBasis</p>
                    <p>{gdpr_consents?.lawful_basis ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Guests GDPRConsent</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>Email</th>
                                
                                
                                
                                <th>Phone</th>
                                
                                
                                
                                <th>FirstName</th>
                                
                                
                                
                                <th>LastName</th>
                                
                                
                                
                                <th>DateofBirth</th>
                                
                                
                                
                                <th>Gender</th>
                                
                                
                                
                                <th>Nationality</th>
                                
                                
                                
                                <th>AddressLine1</th>
                                
                                
                                
                                <th>AddressLine2</th>
                                
                                
                                
                                <th>City</th>
                                
                                
                                
                                <th>State/Region</th>
                                
                                
                                
                                <th>PostalCode</th>
                                
                                
                                
                                <th>Country</th>
                                
                                
                                
                                <th>IdentityDocumentType</th>
                                
                                
                                
                                <th>IdentityDocumentNumber</th>
                                
                                
                                
                                <th>IdentityDocumentExpiresAt</th>
                                
                                
                                
                                <th>PIIVerified</th>
                                
                                
                                
                                <th>PIIVerifiedAt</th>
                                
                                
                                
                                <th>DataRetentionStatus</th>
                                
                                
                                
                                <th>AnonymizeAfterAt</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {gdpr_consents.guests_gdpr_consent && Array.isArray(gdpr_consents.guests_gdpr_consent) &&
                              gdpr_consents.guests_gdpr_consent.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/guests/guests-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phone">
                                        { item.phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="first_name">
                                        { item.first_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_name">
                                        { item.last_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="date_of_birth">
                                        { dataFormatter.dateTimeFormatter(item.date_of_birth) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gender">
                                        { item.gender }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="nationality">
                                        { item.nationality }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address_line1">
                                        { item.address_line1 }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address_line2">
                                        { item.address_line2 }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="city">
                                        { item.city }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="state_region">
                                        { item.state_region }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="postal_code">
                                        { item.postal_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="country">
                                        { item.country }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="identity_document_type">
                                        { item.identity_document_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="identity_document_number">
                                        { item.identity_document_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="identity_document_expires_at">
                                        { dataFormatter.dateTimeFormatter(item.identity_document_expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="pii_verified">
                                        { dataFormatter.booleanFormatter(item.pii_verified) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="pii_verified_at">
                                        { dataFormatter.dateTimeFormatter(item.pii_verified_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="data_retention_status">
                                        { item.data_retention_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="anonymize_after_at">
                                        { dataFormatter.dateTimeFormatter(item.anonymize_after_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!gdpr_consents?.guests_gdpr_consent?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Gdpr_consentsView;