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

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Creator</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{tip_pages?.creator?.handle ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TipPageSlug</p>
                    <p>{tip_pages?.slug}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Headline</p>
                    <p>{tip_pages?.headline}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BackgroundType</p>
                    <p>{tip_pages?.background_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BackgroundValue</p>
                    <p>{tip_pages?.background_value}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>AccentColorHex</p>
                    <p>{tip_pages?.accent_color_hex}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>PresetAmount1</p>
                  <p>{tip_pages?.preset_amount_1 || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>PresetAmount2</p>
                  <p>{tip_pages?.preset_amount_2 || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>PresetAmount3</p>
                  <p>{tip_pages?.preset_amount_3 || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='AllowCustomAmount'>
                    <SwitchField
                      field={{name: 'allow_custom_amount', value: tip_pages?.allow_custom_amount}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>MinimumAmount</p>
                  <p>{tip_pages?.minimum_amount || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='TTSEnabled'>
                    <SwitchField
                      field={{name: 'tts_enabled', value: tip_pages?.tts_enabled}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TTSVoice</p>
                    <p>{tip_pages?.tts_voice}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='ShowSupporterFeed'>
                    <SwitchField
                      field={{name: 'show_supporter_feed', value: tip_pages?.show_supporter_feed}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Creator_profiles TipPage</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>
                            {tip_pages.creator_profiles_tip_page && Array.isArray(tip_pages.creator_profiles_tip_page) &&
                              tip_pages.creator_profiles_tip_page.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>
                        {!tip_pages?.creator_profiles_tip_page?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Tips TipPage</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                
                                
                                <th>IsAnonymous</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tip_pages.tips_tip_page && Array.isArray(tip_pages.tips_tip_page) &&
                              tip_pages.tips_tip_page.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/tips/tips-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_anonymous">
                                        { dataFormatter.booleanFormatter(item.is_anonymous) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tip_pages?.tips_tip_page?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Tip_pagesView;