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'}>Name</p>
                    <p>{brands?.name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Products Brand</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>Slug</th>
                                
                                
                                
                                <th>Subtitle</th>
                                
                                
                                
                                
                                
                                <th>ProductType</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                                
                                <th>IsBestSeller</th>
                                
                                
                                
                                <th>IsNewArrival</th>
                                
                                
                                
                                <th>BasePrice</th>
                                
                                
                                
                                <th>InventoryQuantity</th>
                                
                                
                                
                                <th>SKU</th>
                                
                                
                                
                                <th>RatingAverage</th>
                                
                                
                                
                                <th>RatingCount</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {brands.products_brand && Array.isArray(brands.products_brand) &&
                              brands.products_brand.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/products/products-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="slug">
                                        { item.slug }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="subtitle">
                                        { item.subtitle }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="product_type">
                                        { item.product_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_best_seller">
                                        { dataFormatter.booleanFormatter(item.is_best_seller) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_new_arrival">
                                        { dataFormatter.booleanFormatter(item.is_new_arrival) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="base_price">
                                        { item.base_price }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="inventory_quantity">
                                        { item.inventory_quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sku">
                                        { item.sku }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rating_average">
                                        { item.rating_average }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rating_count">
                                        { item.rating_count }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!brands?.products_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;