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/artist_profiles/artist_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";

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


const Artist_profilesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { artist_profiles } = useAppSelector((state) => state.artist_profiles)
    
    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 artist_profiles')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View artist_profiles')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/artist_profiles/artist_profiles-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

              

              

              

              

              

              

              

              

              

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

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Profiletype</p>
                    <p>{artist_profiles?.profile_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Legalname</p>
                    <p>{artist_profiles?.legal_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Country</p>
                    <p>{artist_profiles?.country}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>City</p>
                    <p>{artist_profiles?.city}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Taxresidency</p>
                    <p>{artist_profiles?.tax_residency}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Payoutcurrency</p>
                    <p>{artist_profiles?.payout_currency}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>WebsiteURL</p>
                    <p>{artist_profiles?.website_url}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>VKURL</p>
                    <p>{artist_profiles?.vk_url}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>YouTubeURL</p>
                    <p>{artist_profiles?.youtube_url}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TikTokURL</p>
                    <p>{artist_profiles?.tiktok_url}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>InstagramURL</p>
                    <p>{artist_profiles?.instagram_url}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Releases Artistprofile</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>
                            {artist_profiles.releases_artist_profile && Array.isArray(artist_profiles.releases_artist_profile) &&
                              artist_profiles.releases_artist_profile.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>
                        {!artist_profiles?.releases_artist_profile?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Pitch_requests Artistprofile</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Pitchtitle</th>
                                
                                
                                
                                
                                
                                <th>Mood</th>
                                
                                
                                
                                <th>Similarartists</th>
                                
                                
                                
                                <th>Achievements</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Submittedat</th>
                                
                                
                                
                                <th>Decidedat</th>
                                
                                
                                
                                <th>Decisionnotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {artist_profiles.pitch_requests_artist_profile && Array.isArray(artist_profiles.pitch_requests_artist_profile) &&
                              artist_profiles.pitch_requests_artist_profile.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/pitch_requests/pitch_requests-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="pitch_title">
                                        { item.pitch_title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="mood">
                                        { item.mood }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="similar_artists">
                                        { item.similar_artists }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="achievements">
                                        { item.achievements }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.submitted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="decided_at">
                                        { dataFormatter.dateTimeFormatter(item.decided_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="decision_notes">
                                        { item.decision_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!artist_profiles?.pitch_requests_artist_profile?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Royalty_reports Artistprofile</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Periodstartat</th>
                                
                                
                                
                                <th>Periodendat</th>
                                
                                
                                
                                <th>Sourcetype</th>
                                
                                
                                
                                
                                
                                <th>Sourcereference</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Errordetails</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {artist_profiles.royalty_reports_artist_profile && Array.isArray(artist_profiles.royalty_reports_artist_profile) &&
                              artist_profiles.royalty_reports_artist_profile.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/royalty_reports/royalty_reports-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="period_start_at">
                                        { dataFormatter.dateTimeFormatter(item.period_start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_end_at">
                                        { dataFormatter.dateTimeFormatter(item.period_end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="source_type">
                                        { item.source_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="source_reference">
                                        { item.source_reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="error_details">
                                        { item.error_details }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!artist_profiles?.royalty_reports_artist_profile?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Analytics_daily Artistprofile</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Metricdate</th>
                                
                                
                                
                                <th>Streams</th>
                                
                                
                                
                                <th>Uniquelisteners</th>
                                
                                
                                
                                <th>Saves</th>
                                
                                
                                
                                <th>Likes</th>
                                
                                
                                
                                <th>Shares</th>
                                
                                
                                
                                <th>Country</th>
                                
                                
                                
                                <th>City</th>
                                
                                
                                
                                <th>Trafficsource</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {artist_profiles.analytics_daily_artist_profile && Array.isArray(artist_profiles.analytics_daily_artist_profile) &&
                              artist_profiles.analytics_daily_artist_profile.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/analytics_daily/analytics_daily-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="metric_date">
                                        { dataFormatter.dateTimeFormatter(item.metric_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="streams">
                                        { item.streams }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unique_listeners">
                                        { item.unique_listeners }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="saves">
                                        { item.saves }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="likes">
                                        { item.likes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="shares">
                                        { item.shares }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="country">
                                        { item.country }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="city">
                                        { item.city }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="traffic_source">
                                        { item.traffic_source }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!artist_profiles?.analytics_daily_artist_profile?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Artist_profilesView;