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/users/usersSlice'
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 UsersView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { users } = useAppSelector((state) => state.users)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>First Name</p>
                    <p>{users?.firstName}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Last Name</p>
                    <p>{users?.lastName}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Phone Number</p>
                    <p>{users?.phoneNumber}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>E-Mail</p>
                    <p>{users?.email}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Avatar</p>
                    {users?.avatar?.length
                      ? (
                        <ImageField
                          name={'avatar'}
                          image={users?.avatar}
                          className='w-20 h-20'
                        />
                      ) : <p>No Avatar</p>
                    }
                </div>
              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>App Role</p>
                    
                    
                    
                    
                        <p>{users?.app_role?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              
                <>
                    <p className={'block font-bold mb-2'}>Custom Permissions</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                    <th>Name</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.custom_permissions && Array.isArray(users.custom_permissions) &&
                              users.custom_permissions.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/permissions/permissions-view/?id=${item.id}`)}>
                                  
                                    
                                    
                                  
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.custom_permissions?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
              

              

              
              

                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>User_sessions User</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>SessionToken</th>
                                
                                
                                
                                <th>SignedInAt</th>
                                
                                
                                
                                <th>ExpiresAt</th>
                                
                                
                                
                                <th>SignedOutAt</th>
                                
                                
                                
                                <th>IPAddress</th>
                                
                                
                                
                                <th>UserAgent</th>
                                
                                
                                
                                <th>RememberMe</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.user_sessions_user && Array.isArray(users.user_sessions_user) &&
                              users.user_sessions_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/user_sessions/user_sessions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="session_token">
                                        { item.session_token }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="signed_in_at">
                                        { dataFormatter.dateTimeFormatter(item.signed_in_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expires_at">
                                        { dataFormatter.dateTimeFormatter(item.expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="signed_out_at">
                                        { dataFormatter.dateTimeFormatter(item.signed_out_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ip_address">
                                        { item.ip_address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="user_agent">
                                        { item.user_agent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="remember_me">
                                        { dataFormatter.booleanFormatter(item.remember_me) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.user_sessions_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Referrals Referrer</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ReferralCode</th>
                                
                                
                                
                                <th>ReferredEmail</th>
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>InvitedAt</th>
                                
                                
                                
                                <th>SignedUpAt</th>
                                
                                
                                
                                <th>RewardedAt</th>
                                
                                
                                
                                <th>RewardDoodlecoins</th>
                                
                                
                                
                                <th>Note</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.referrals_referrer && Array.isArray(users.referrals_referrer) &&
                              users.referrals_referrer.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/referrals/referrals-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="referral_code">
                                        { item.referral_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="referred_email">
                                        { item.referred_email }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="invited_at">
                                        { dataFormatter.dateTimeFormatter(item.invited_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="signed_up_at">
                                        { dataFormatter.dateTimeFormatter(item.signed_up_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rewarded_at">
                                        { dataFormatter.dateTimeFormatter(item.rewarded_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reward_doodlecoins">
                                        { item.reward_doodlecoins }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="note">
                                        { item.note }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.referrals_referrer?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                <>
                    <p className={'block font-bold mb-2'}>Referrals ReferredUser</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ReferralCode</th>
                                
                                
                                
                                <th>ReferredEmail</th>
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>InvitedAt</th>
                                
                                
                                
                                <th>SignedUpAt</th>
                                
                                
                                
                                <th>RewardedAt</th>
                                
                                
                                
                                <th>RewardDoodlecoins</th>
                                
                                
                                
                                <th>Note</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.referrals_referred_user && Array.isArray(users.referrals_referred_user) &&
                              users.referrals_referred_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/referrals/referrals-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="referral_code">
                                        { item.referral_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="referred_email">
                                        { item.referred_email }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="invited_at">
                                        { dataFormatter.dateTimeFormatter(item.invited_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="signed_up_at">
                                        { dataFormatter.dateTimeFormatter(item.signed_up_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rewarded_at">
                                        { dataFormatter.dateTimeFormatter(item.rewarded_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reward_doodlecoins">
                                        { item.reward_doodlecoins }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="note">
                                        { item.note }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.referrals_referred_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Coin_code_redemptions User</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>RedeemedAt</th>
                                
                                
                                
                                <th>AmountDoodlecoins</th>
                                
                                
                                
                                <th>StatusMessage</th>
                                
                                
                                
                                <th>Successful</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.coin_code_redemptions_user && Array.isArray(users.coin_code_redemptions_user) &&
                              users.coin_code_redemptions_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/coin_code_redemptions/coin_code_redemptions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="redeemed_at">
                                        { dataFormatter.dateTimeFormatter(item.redeemed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount_doodlecoins">
                                        { item.amount_doodlecoins }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status_message">
                                        { item.status_message }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="successful">
                                        { dataFormatter.booleanFormatter(item.successful) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.coin_code_redemptions_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Wallet_transactions User</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>Direction</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>BalanceAfter</th>
                                
                                
                                
                                <th>Reason</th>
                                
                                
                                
                                <th>Reference</th>
                                
                                
                                
                                <th>OccurredAt</th>
                                
                                
                                
                                <th>Note</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.wallet_transactions_user && Array.isArray(users.wallet_transactions_user) &&
                              users.wallet_transactions_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/wallet_transactions/wallet_transactions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="direction">
                                        { item.direction }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="balance_after">
                                        { item.balance_after }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reason">
                                        { item.reason }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reference">
                                        { item.reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="occurred_at">
                                        { dataFormatter.dateTimeFormatter(item.occurred_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="note">
                                        { item.note }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.wallet_transactions_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Coin_conversions User</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>FromDoodlecoins</th>
                                
                                
                                
                                <th>ToSupercharged</th>
                                
                                
                                
                                <th>RateFrom</th>
                                
                                
                                
                                <th>RateTo</th>
                                
                                
                                
                                <th>ConvertedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.coin_conversions_user && Array.isArray(users.coin_conversions_user) &&
                              users.coin_conversions_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/coin_conversions/coin_conversions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="from_doodlecoins">
                                        { item.from_doodlecoins }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="to_supercharged">
                                        { item.to_supercharged }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rate_from">
                                        { item.rate_from }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rate_to">
                                        { item.rate_to }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="converted_at">
                                        { dataFormatter.dateTimeFormatter(item.converted_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.coin_conversions_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>User_memberships User</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>StartedAt</th>
                                
                                
                                
                                <th>NextBillingAt</th>
                                
                                
                                
                                <th>CancelledAt</th>
                                
                                
                                
                                <th>EndsAt</th>
                                
                                
                                
                                <th>PriceSupercharged</th>
                                
                                
                                
                                <th>PerksSnapshot</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.user_memberships_user && Array.isArray(users.user_memberships_user) &&
                              users.user_memberships_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/user_memberships/user_memberships-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="next_billing_at">
                                        { dataFormatter.dateTimeFormatter(item.next_billing_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cancelled_at">
                                        { dataFormatter.dateTimeFormatter(item.cancelled_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ends_at">
                                        { dataFormatter.dateTimeFormatter(item.ends_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="price_supercharged">
                                        { item.price_supercharged }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="perks_snapshot">
                                        { item.perks_snapshot }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.user_memberships_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Item_redemptions User</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>RedeemedAt</th>
                                
                                
                                
                                <th>CostDoodlecoins</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Note</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.item_redemptions_user && Array.isArray(users.item_redemptions_user) &&
                              users.item_redemptions_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/item_redemptions/item_redemptions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="redeemed_at">
                                        { dataFormatter.dateTimeFormatter(item.redeemed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cost_doodlecoins">
                                        { item.cost_doodlecoins }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="note">
                                        { item.note }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.item_redemptions_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Products CreatedByUser</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>ProductType</th>
                                
                                
                                
                                <th>Name</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                
                                
                                <th>PriceSupercharged</th>
                                
                                
                                
                                <th>ExpiresAt</th>
                                
                                
                                
                                <th>MaxPurchases</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>PublishedAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.products_created_by_user && Array.isArray(users.products_created_by_user) &&
                              users.products_created_by_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/products/products-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="product_type">
                                        { item.product_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="price_supercharged">
                                        { item.price_supercharged }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expires_at">
                                        { dataFormatter.dateTimeFormatter(item.expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_purchases">
                                        { item.max_purchases }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="published_at">
                                        { dataFormatter.dateTimeFormatter(item.published_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.products_created_by_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Product_purchases User</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>PurchasedAt</th>
                                
                                
                                
                                <th>PriceSupercharged</th>
                                
                                
                                
                                <th>AccessStatus</th>
                                
                                
                                
                                <th>AccessExpiresAt</th>
                                
                                
                                
                                <th>Note</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.product_purchases_user && Array.isArray(users.product_purchases_user) &&
                              users.product_purchases_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/product_purchases/product_purchases-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="purchased_at">
                                        { dataFormatter.dateTimeFormatter(item.purchased_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="price_supercharged">
                                        { item.price_supercharged }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="access_status">
                                        { item.access_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="access_expires_at">
                                        { dataFormatter.dateTimeFormatter(item.access_expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="note">
                                        { item.note }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.product_purchases_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Content_consumptions User</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Action</th>
                                
                                
                                
                                <th>StartedAt</th>
                                
                                
                                
                                <th>CompletedAt</th>
                                
                                
                                
                                <th>DurationSeconds</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.content_consumptions_user && Array.isArray(users.content_consumptions_user) &&
                              users.content_consumptions_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/content_consumptions/content_consumptions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="action">
                                        { item.action }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="completed_at">
                                        { dataFormatter.dateTimeFormatter(item.completed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="duration_seconds">
                                        { item.duration_seconds }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.content_consumptions_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Chat_rooms CreatedByUser</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>RoomType</th>
                                
                                
                                
                                <th>Name</th>
                                
                                
                                
                                <th>PrivateRoom</th>
                                
                                
                                
                                
                                
                                <th>CreatedAt</th>
                                
                                
                                
                                <th>LastMessageAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.chat_rooms_created_by_user && Array.isArray(users.chat_rooms_created_by_user) &&
                              users.chat_rooms_created_by_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/chat_rooms/chat_rooms-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="room_type">
                                        { item.room_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="private_room">
                                        { dataFormatter.booleanFormatter(item.private_room) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="created_at_time">
                                        { dataFormatter.dateTimeFormatter(item.created_at_time) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_message_at">
                                        { dataFormatter.dateTimeFormatter(item.last_message_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.chat_rooms_created_by_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Chat_memberships User</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>MemberRole</th>
                                
                                
                                
                                <th>JoinedAt</th>
                                
                                
                                
                                <th>LeftAt</th>
                                
                                
                                
                                <th>Muted</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.chat_memberships_user && Array.isArray(users.chat_memberships_user) &&
                              users.chat_memberships_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/chat_memberships/chat_memberships-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="member_role">
                                        { item.member_role }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="joined_at">
                                        { dataFormatter.dateTimeFormatter(item.joined_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="left_at">
                                        { dataFormatter.dateTimeFormatter(item.left_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="muted">
                                        { dataFormatter.booleanFormatter(item.muted) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.chat_memberships_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Chat_messages Sender</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>MessageText</th>
                                
                                
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                <th>EditedAt</th>
                                
                                
                                
                                <th>Deleted</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.chat_messages_sender && Array.isArray(users.chat_messages_sender) &&
                              users.chat_messages_sender.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/chat_messages/chat_messages-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="message_text">
                                        { item.message_text }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="edited_at">
                                        { dataFormatter.dateTimeFormatter(item.edited_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="deleted">
                                        { dataFormatter.booleanFormatter(item.deleted) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.chat_messages_sender?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Admin_audit_logs AdminUser</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Action</th>
                                
                                
                                
                                <th>EntityName</th>
                                
                                
                                
                                <th>EntityReference</th>
                                
                                
                                
                                <th>OccurredAt</th>
                                
                                
                                
                                <th>Details</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.admin_audit_logs_admin_user && Array.isArray(users.admin_audit_logs_admin_user) &&
                              users.admin_audit_logs_admin_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/admin_audit_logs/admin_audit_logs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="action">
                                        { item.action }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="entity_name">
                                        { item.entity_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="entity_reference">
                                        { item.entity_reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="occurred_at">
                                        { dataFormatter.dateTimeFormatter(item.occurred_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="details">
                                        { item.details }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.admin_audit_logs_admin_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                

                <BaseDivider />

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

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

export default UsersView;