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/beatmap_sets/beatmap_setsSlice'
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 Beatmap_setsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { beatmap_sets } = useAppSelector((state) => state.beatmap_sets)
    

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

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>OsuBeatmapsetNumeric</p>
                  <p>{beatmap_sets?.osu_beatmapset_numeric || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Title</p>
                    <p>{beatmap_sets?.title}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ArtistName</p>
                    <p>{beatmap_sets?.artist_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>CreatorUsername</p>
                    <p>{beatmap_sets?.creator_username}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>CreatorUserNumeric</p>
                  <p>{beatmap_sets?.creator_user_numeric || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Status</p>
                    <p>{beatmap_sets?.status ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>TotalPlaycount</p>
                  <p>{beatmap_sets?.total_playcount || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BackgroundImageUrl</p>
                    <p>{beatmap_sets?.background_image_url}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>CoverImageUrl</p>
                    <p>{beatmap_sets?.cover_image_url}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Beatmaps BeatmapSet</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>OsuBeatmapNumeric</th>
                                
                                
                                
                                <th>DifficultyName</th>
                                
                                
                                
                                <th>Mode</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Playcount</th>
                                
                                
                                
                                <th>Passcount</th>
                                
                                
                                
                                <th>StarRating</th>
                                
                                
                                
                                <th>Bpm</th>
                                
                                
                                
                                <th>LengthSeconds</th>
                                
                                
                                
                                <th>Cs</th>
                                
                                
                                
                                <th>Ar</th>
                                
                                
                                
                                <th>Od</th>
                                
                                
                                
                                <th>Hp</th>
                                
                                
                                
                                <th>LastSyncedAt</th>
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {beatmap_sets.beatmaps_beatmap_set && Array.isArray(beatmap_sets.beatmaps_beatmap_set) &&
                              beatmap_sets.beatmaps_beatmap_set.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/beatmaps/beatmaps-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="osu_beatmap_numeric">
                                        { item.osu_beatmap_numeric }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="difficulty_name">
                                        { item.difficulty_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="mode">
                                        { item.mode }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="playcount">
                                        { item.playcount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="passcount">
                                        { item.passcount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="star_rating">
                                        { item.star_rating }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bpm">
                                        { item.bpm }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="length_seconds">
                                        { item.length_seconds }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cs">
                                        { item.cs }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ar">
                                        { item.ar }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="od">
                                        { item.od }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="hp">
                                        { item.hp }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_synced_at">
                                        { dataFormatter.dateTimeFormatter(item.last_synced_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!beatmap_sets?.beatmaps_beatmap_set?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Beatmap_setsView;