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/player_profiles/player_profilesSlice'
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 Player_profilesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { player_profiles } = useAppSelector((state) => state.player_profiles)
    

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

              

              

              

              

              

              

              

              

              

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

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Gender</p>
                    <p>{player_profiles?.gender ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>FirstName</p>
                    <p>{player_profiles?.first_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>LastName</p>
                    <p>{player_profiles?.last_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Level</p>
                  <p>{player_profiles?.level || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>ExperiencePoints</p>
                  <p>{player_profiles?.experience_points || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>MoneyBalance</p>
                  <p>{player_profiles?.money_balance || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>PIXBalance</p>
                  <p>{player_profiles?.pix_balance || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>CommunityReputation</p>
                  <p>{player_profiles?.reputation_score || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Npc_relationships PlayerProfile</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>RelationshipType</th>
                                
                                
                                
                                <th>FriendshipPoints</th>
                                
                                
                                
                                <th>TrustPoints</th>
                                
                                
                                
                                <th>LastInteractionAt</th>
                                
                                
                                
                                <th>IsUnlocked</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {player_profiles.npc_relationships_player_profile && Array.isArray(player_profiles.npc_relationships_player_profile) &&
                              player_profiles.npc_relationships_player_profile.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/npc_relationships/npc_relationships-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="relationship_type">
                                        { item.relationship_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="friendship_points">
                                        { item.friendship_points }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="trust_points">
                                        { item.trust_points }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_interaction_at">
                                        { dataFormatter.dateTimeFormatter(item.last_interaction_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_unlocked">
                                        { dataFormatter.booleanFormatter(item.is_unlocked) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!player_profiles?.npc_relationships_player_profile?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Farm_plots OwnerProfile</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Name</th>
                                
                                
                                
                                <th>WidthTiles</th>
                                
                                
                                
                                <th>HeightTiles</th>
                                
                                
                                
                                <th>IsIrrigated</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {player_profiles.farm_plots_owner_profile && Array.isArray(player_profiles.farm_plots_owner_profile) &&
                              player_profiles.farm_plots_owner_profile.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/farm_plots/farm_plots-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="width_tiles">
                                        { item.width_tiles }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="height_tiles">
                                        { item.height_tiles }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_irrigated">
                                        { dataFormatter.booleanFormatter(item.is_irrigated) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!player_profiles?.farm_plots_owner_profile?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Fishing_catches PlayerProfile</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>CaughtAt</th>
                                
                                
                                
                                <th>Weight</th>
                                
                                
                                
                                <th>Length</th>
                                
                                
                                
                                <th>QualityGrade</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {player_profiles.fishing_catches_player_profile && Array.isArray(player_profiles.fishing_catches_player_profile) &&
                              player_profiles.fishing_catches_player_profile.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/fishing_catches/fishing_catches-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="caught_at">
                                        { dataFormatter.dateTimeFormatter(item.caught_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="weight">
                                        { item.weight }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="length">
                                        { item.length }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quality_grade">
                                        { item.quality_grade }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!player_profiles?.fishing_catches_player_profile?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Player_profilesView;