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/avatar_customizations/avatar_customizationsSlice'
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 Avatar_customizationsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { avatar_customizations } = useAppSelector((state) => state.avatar_customizations)
    

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

              

              

              

              

              

              

              

              

              

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

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ProfileName</p>
                    <p>{avatar_customizations?.profile_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BaseColor</p>
                    <p>{avatar_customizations?.base_color ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>CustomColorHex</p>
                    <p>{avatar_customizations?.custom_color_hex}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>FaceStyle</p>
                    <p>{avatar_customizations?.face_style ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PatternStyle</p>
                    <p>{avatar_customizations?.pattern_style ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PatternColor</p>
                    <p>{avatar_customizations?.pattern_color ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PatternCustomHex</p>
                    <p>{avatar_customizations?.pattern_custom_hex}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>HatStyle</p>
                    <p>{avatar_customizations?.hat_style ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Match_players AvatarCustomization</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>DisplayName</th>
                                
                                
                                
                                
                                
                                <th>PlayerStatus</th>
                                
                                
                                
                                <th>ScorePoints</th>
                                
                                
                                
                                <th>CorrectCount</th>
                                
                                
                                
                                <th>IncorrectCount</th>
                                
                                
                                
                                <th>YUXEarned</th>
                                
                                
                                
                                <th>RaceDistance(km)</th>
                                
                                
                                
                                <th>JoinedAt</th>
                                
                                
                                
                                <th>LeftAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {avatar_customizations.match_players_avatar_customization && Array.isArray(avatar_customizations.match_players_avatar_customization) &&
                              avatar_customizations.match_players_avatar_customization.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/match_players/match_players-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="display_name">
                                        { item.display_name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="player_status">
                                        { item.player_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="score_points">
                                        { item.score_points }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="correct_count">
                                        { item.correct_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="incorrect_count">
                                        { item.incorrect_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="yux_earned">
                                        { item.yux_earned }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="race_distance_km">
                                        { item.race_distance_km }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="joined_at">
                                        { dataFormatter.dateTimeFormatter(item.joined_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="left_at">
                                        { dataFormatter.dateTimeFormatter(item.left_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!avatar_customizations?.match_players_avatar_customization?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Avatar_customizationsView;