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

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>OwnerUser</p>
                    
                    
                        <p>{profile_styles?.owner_user?.firstName ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>StyleName</p>
                    <p>{profile_styles?.style_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>UsernameColorHex</p>
                    <p>{profile_styles?.username_color_hex}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BioFontFamily</p>
                    <p>{profile_styles?.bio_font_family}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              
                <FormField label='Multi Text' hasTextareaHeight>
                  <textarea className={'w-full'} disabled value={profile_styles?.panel_order_json} />
                </FormField>
              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ProfileLayout</p>
                    <p>{profile_styles?.profile_layout ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='ShowPronounsBadge'>
                    <SwitchField
                      field={{name: 'show_pronouns_badge', value: profile_styles?.show_pronouns_badge}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PronounsText</p>
                    <p>{profile_styles?.pronouns_text}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              
                <FormField label='Multi Text' hasTextareaHeight>
                  <textarea className={'w-full'} disabled value={profile_styles?.custom_css} />
                </FormField>
              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Creator_profiles ProfileStyle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Handle</th>
                                
                                
                                
                                <th>CreatorType</th>
                                
                                
                                
                                <th>IsVerified</th>
                                
                                
                                
                                <th>IsAdultCreator</th>
                                
                                
                                
                                <th>Slogan</th>
                                
                                
                                
                                
                                
                                <th>BusinessEmail</th>
                                
                                
                                
                                <th>SupportEmail</th>
                                
                                
                                
                                <th>PreferredLanguage</th>
                                
                                
                                
                                <th>CategoryTags(Comma-separated)</th>
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {profile_styles.creator_profiles_profile_style && Array.isArray(profile_styles.creator_profiles_profile_style) &&
                              profile_styles.creator_profiles_profile_style.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/creator_profiles/creator_profiles-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="handle">
                                        { item.handle }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="creator_type">
                                        { item.creator_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_verified">
                                        { dataFormatter.booleanFormatter(item.is_verified) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_adult_creator">
                                        { dataFormatter.booleanFormatter(item.is_adult_creator) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="slogan">
                                        { item.slogan }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="business_email">
                                        { item.business_email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="support_email">
                                        { item.support_email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="preferred_language">
                                        { item.preferred_language }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="category_tags">
                                        { item.category_tags }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!profile_styles?.creator_profiles_profile_style?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Profile_stylesView;