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/site_settings/site_settingsSlice'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";
import LayoutAuthenticated from "../../layouts/Authenticated";
import {getPageTitle} from "../../config";
import SectionTitleLineWithButton from "../../components/SectionTitleLineWithButton";
import SectionMain from "../../components/SectionMain";
import CardBox from "../../components/CardBox";
import BaseButton from "../../components/BaseButton";
import BaseDivider from "../../components/BaseDivider";
import {mdiChartTimelineVariant} from "@mdi/js";
import {SwitchField} from "../../components/SwitchField";
import FormField from "../../components/FormField";


const Site_settingsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { site_settings } = useAppSelector((state) => state.site_settings)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>StoreName</p>
                    <p>{site_settings?.store_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>DefaultLanguage</p>
                    <p>{site_settings?.default_language}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>DefaultCurrency</p>
                    <p>{site_settings?.default_currency}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='RTLEnabled'>
                    <SwitchField
                      field={{name: 'rtl_enabled', value: site_settings?.rtl_enabled}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>FooterBottomText</p>
                    <p>{site_settings?.footer_bottom_text}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='FooterPartnerBannerEnabled'>
                    <SwitchField
                      field={{name: 'footer_partner_banner_enabled', value: site_settings?.footer_partner_banner_enabled}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>FooterPartnerBannerURL</p>
                    <p>{site_settings?.footer_partner_banner_url}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Site_settingsView;