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/genres/genresSlice'
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";

import {hasPermission} from "../../helpers/userPermissions";


const GenresView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { genres } = useAppSelector((state) => state.genres)
    
    const { currentUser } = useAppSelector((state) => state.auth);
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Parentgenre</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{genres?.parent_genre?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Releases Primarygenre</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Releasetitle</th>
                                
                                
                                
                                <th>Releasetype</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Language</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Labelname</th>
                                
                                
                                
                                <th>Copyrightnotice</th>
                                
                                
                                
                                <th>Productionnotice</th>
                                
                                
                                
                                <th>UPC/EANcode</th>
                                
                                
                                
                                <th>UPCsource</th>
                                
                                
                                
                                <th>Releasedate</th>
                                
                                
                                
                                <th>Originalreleasedate</th>
                                
                                
                                
                                <th>Moderationstatus</th>
                                
                                
                                
                                <th>Moderationnotes</th>
                                
                                
                                
                                <th>Explicitcontent</th>
                                
                                
                                
                                <th>Licenseaccepted</th>
                                
                                
                                
                                <th>ContentIDenabled</th>
                                
                                
                                
                                <th>Contentmatchenabled</th>
                                
                                
                                
                                <th>Internalcatalogcode</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {genres.releases_primary_genre && Array.isArray(genres.releases_primary_genre) &&
                              genres.releases_primary_genre.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/releases/releases-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="release_type">
                                        { item.release_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="language">
                                        { item.language }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="label_name">
                                        { item.label_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="copyright_notice">
                                        { item.copyright_notice }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="production_notice">
                                        { item.production_notice }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="upc_code">
                                        { item.upc_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="upc_source">
                                        { item.upc_source }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="release_date">
                                        { dataFormatter.dateTimeFormatter(item.release_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="original_release_date">
                                        { dataFormatter.dateTimeFormatter(item.original_release_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="moderation_status">
                                        { item.moderation_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="moderation_notes">
                                        { item.moderation_notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="explicit_content">
                                        { dataFormatter.booleanFormatter(item.explicit_content) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="license_accepted">
                                        { dataFormatter.booleanFormatter(item.license_accepted) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="content_id_enabled">
                                        { dataFormatter.booleanFormatter(item.content_id_enabled) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="content_match_enabled">
                                        { dataFormatter.booleanFormatter(item.content_match_enabled) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="internal_catalog_code">
                                        { item.internal_catalog_code }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!genres?.releases_primary_genre?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                <>
                    <p className={'block font-bold mb-2'}>Releases Secondarygenre</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Releasetitle</th>
                                
                                
                                
                                <th>Releasetype</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Language</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Labelname</th>
                                
                                
                                
                                <th>Copyrightnotice</th>
                                
                                
                                
                                <th>Productionnotice</th>
                                
                                
                                
                                <th>UPC/EANcode</th>
                                
                                
                                
                                <th>UPCsource</th>
                                
                                
                                
                                <th>Releasedate</th>
                                
                                
                                
                                <th>Originalreleasedate</th>
                                
                                
                                
                                <th>Moderationstatus</th>
                                
                                
                                
                                <th>Moderationnotes</th>
                                
                                
                                
                                <th>Explicitcontent</th>
                                
                                
                                
                                <th>Licenseaccepted</th>
                                
                                
                                
                                <th>ContentIDenabled</th>
                                
                                
                                
                                <th>Contentmatchenabled</th>
                                
                                
                                
                                <th>Internalcatalogcode</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {genres.releases_secondary_genre && Array.isArray(genres.releases_secondary_genre) &&
                              genres.releases_secondary_genre.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/releases/releases-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="release_type">
                                        { item.release_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="language">
                                        { item.language }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="label_name">
                                        { item.label_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="copyright_notice">
                                        { item.copyright_notice }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="production_notice">
                                        { item.production_notice }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="upc_code">
                                        { item.upc_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="upc_source">
                                        { item.upc_source }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="release_date">
                                        { dataFormatter.dateTimeFormatter(item.release_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="original_release_date">
                                        { dataFormatter.dateTimeFormatter(item.original_release_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="moderation_status">
                                        { item.moderation_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="moderation_notes">
                                        { item.moderation_notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="explicit_content">
                                        { dataFormatter.booleanFormatter(item.explicit_content) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="license_accepted">
                                        { dataFormatter.booleanFormatter(item.license_accepted) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="content_id_enabled">
                                        { dataFormatter.booleanFormatter(item.content_id_enabled) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="content_match_enabled">
                                        { dataFormatter.booleanFormatter(item.content_match_enabled) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="internal_catalog_code">
                                        { item.internal_catalog_code }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!genres?.releases_secondary_genre?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Tracks Genre</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Tracktitle</th>
                                
                                
                                
                                <th>Tracknumber</th>
                                
                                
                                
                                <th>Version</th>
                                
                                
                                
                                
                                
                                <th>ISRCcode</th>
                                
                                
                                
                                <th>ISRCsource</th>
                                
                                
                                
                                
                                
                                <th>Durationseconds</th>
                                
                                
                                
                                <th>SamplerateHz</th>
                                
                                
                                
                                <th>Bitratekbps</th>
                                
                                
                                
                                <th>Audioformat</th>
                                
                                
                                
                                <th>Explicitcontent</th>
                                
                                
                                
                                <th>Lyrics</th>
                                
                                
                                
                                <th>Audiofingerprint</th>
                                
                                
                                
                                <th>Qualitystatus</th>
                                
                                
                                
                                <th>Qualitynotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {genres.tracks_genre && Array.isArray(genres.tracks_genre) &&
                              genres.tracks_genre.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/tracks/tracks-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="track_number">
                                        { item.track_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="version">
                                        { item.version }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="isrc_code">
                                        { item.isrc_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="isrc_source">
                                        { item.isrc_source }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="duration_seconds">
                                        { item.duration_seconds }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sample_rate_hz">
                                        { item.sample_rate_hz }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bitrate_kbps">
                                        { item.bitrate_kbps }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="audio_format">
                                        { item.audio_format }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="explicit_content">
                                        { dataFormatter.booleanFormatter(item.explicit_content) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="lyrics">
                                        { item.lyrics }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="audio_fingerprint">
                                        { item.audio_fingerprint }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quality_status">
                                        { item.quality_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quality_notes">
                                        { item.quality_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!genres?.tracks_genre?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default GenresView;