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/rank_tiers/rank_tiersSlice'
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 Rank_tiersView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { rank_tiers } = useAppSelector((state) => state.rank_tiers)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Minpoints</p>
                  <p>{rank_tiers?.min_points || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Maxpoints</p>
                  <p>{rank_tiers?.max_points || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Description</p>
                  {rank_tiers.description
                    ? <p dangerouslySetInnerHTML={{__html: rank_tiers.description}}/>
                    : <p>No data</p>
                  }
                </div>
              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>User_ranks Ranktier</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Rankpoints</th>
                                
                                
                                
                                <th>Updatedattime</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {rank_tiers.user_ranks_rank_tier && Array.isArray(rank_tiers.user_ranks_rank_tier) &&
                              rank_tiers.user_ranks_rank_tier.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/user_ranks/user_ranks-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="rank_points">
                                        { item.rank_points }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="updated_at_time">
                                        { dataFormatter.dateTimeFormatter(item.updated_at_time) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!rank_tiers?.user_ranks_rank_tier?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Rank_tiersView;