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/product_categories/product_categoriesSlice'
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 Product_categoriesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { product_categories } = useAppSelector((state) => state.product_categories)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Name</p>
                    <p>{product_categories?.name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='IsFeatured'>
                    <SwitchField
                      field={{name: 'is_featured', value: product_categories?.is_featured}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>SortOrder</p>
                  <p>{product_categories?.sort_order || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Products Category</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>
                            {product_categories.products_category && Array.isArray(product_categories.products_category) &&
                              product_categories.products_category.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>
                        {!product_categories?.products_category?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Product_categoriesView;