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/brands/brandsSlice'
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 BrandsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { brands } = useAppSelector((state) => state.brands)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BrandName</p>
                    <p>{brands?.brand_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Industry</p>
                    <p>{brands?.industry}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PrimaryMarket</p>
                    <p>{brands?.primary_market}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BrandAssets</p>
                    {brands?.brand_assets?.length
                      ? dataFormatter.filesFormatter(brands.brand_assets).map(link => (
                        <button
                          key={link.publicUrl}
                          onClick={(e) => saveFile(e, link.publicUrl, link.name)}
                        >
                            {link.name}
                        </button>
                      )) : <p>No BrandAssets</p>
                    }
                </div>
              
              

                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Brand_voice_profiles Brand</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ProfileName</th>
                                
                                
                                
                                
                                
                                <th>DoSayExamples</th>
                                
                                
                                
                                <th>DontSayExamples</th>
                                
                                
                                
                                <th>EnglishVariant</th>
                                
                                
                                
                                <th>ReadingLevelTarget</th>
                                
                                
                                
                                <th>FormalityLevel</th>
                                
                                
                                
                                <th>EmpathyLevel</th>
                                
                                
                                
                                <th>EnergyLevel</th>
                                
                                
                                
                                <th>HumorLevel</th>
                                
                                
                                
                                <th>RiskTolerance</th>
                                
                                
                                
                                <th>ShowReasoningTrace</th>
                                
                                
                                
                                <th>IsDefault</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {brands.brand_voice_profiles_brand && Array.isArray(brands.brand_voice_profiles_brand) &&
                              brands.brand_voice_profiles_brand.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/brand_voice_profiles/brand_voice_profiles-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="profile_name">
                                        { item.profile_name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="do_say_examples">
                                        { item.do_say_examples }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="dont_say_examples">
                                        { item.dont_say_examples }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="english_variant">
                                        { item.english_variant }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reading_level_target">
                                        { item.reading_level_target }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="formality_level">
                                        { item.formality_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="empathy_level">
                                        { item.empathy_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="energy_level">
                                        { item.energy_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="humor_level">
                                        { item.humor_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="risk_tolerance">
                                        { item.risk_tolerance }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="show_reasoning_trace">
                                        { dataFormatter.booleanFormatter(item.show_reasoning_trace) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_default">
                                        { dataFormatter.booleanFormatter(item.is_default) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!brands?.brand_voice_profiles_brand?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Campaigns Brand</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>CampaignName</th>
                                
                                
                                
                                <th>CampaignType</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Objective</th>
                                
                                
                                
                                <th>PrimaryAudience</th>
                                
                                
                                
                                <th>BudgetAmount</th>
                                
                                
                                
                                <th>BudgetCurrency</th>
                                
                                
                                
                                <th>StartAt</th>
                                
                                
                                
                                <th>EndAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {brands.campaigns_brand && Array.isArray(brands.campaigns_brand) &&
                              brands.campaigns_brand.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/campaigns/campaigns-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="campaign_name">
                                        { item.campaign_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="campaign_type">
                                        { item.campaign_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="objective">
                                        { item.objective }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="primary_audience">
                                        { item.primary_audience }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="budget_amount">
                                        { item.budget_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="budget_currency">
                                        { item.budget_currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="start_at">
                                        { dataFormatter.dateTimeFormatter(item.start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_at">
                                        { dataFormatter.dateTimeFormatter(item.end_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!brands?.campaigns_brand?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default BrandsView;