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'}>Categoryname</p>
                    <p>{product_categories?.category_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Parentcategory</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{product_categories?.parent_category?.category_name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

                
                
                
                
                
                
                
                
                <>
                    <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>SKU</th>
                                
                                
                                
                                <th>Productname</th>
                                
                                
                                
                                <th>Brand</th>
                                
                                
                                
                                
                                
                                <th>Shortdescription</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Packsize</th>
                                
                                
                                
                                <th>Unitspercase</th>
                                
                                
                                
                                <th>Unitweight(lbs)</th>
                                
                                
                                
                                <th>Caseweight(lbs)</th>
                                
                                
                                
                                <th>Unitofmeasure</th>
                                
                                
                                
                                <th>MOQ(cases)</th>
                                
                                
                                
                                <th>Temperaturezone</th>
                                
                                
                                
                                <th>Productstatus</th>
                                
                                
                                
                                <th>Allergens</th>
                                
                                
                                
                                <th>Certifications</th>
                                
                                
                                
                                <th>Sampleeligible</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="sku">
                                        { item.sku }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="product_name">
                                        { item.product_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="brand">
                                        { item.brand }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="short_description">
                                        { item.short_description }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="pack_size">
                                        { item.pack_size }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="units_per_case">
                                        { item.units_per_case }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_weight_lbs">
                                        { item.unit_weight_lbs }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="case_weight_lbs">
                                        { item.case_weight_lbs }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="uom">
                                        { item.uom }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="moq_cases">
                                        { item.moq_cases }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="temperature_zone">
                                        { item.temperature_zone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="product_status">
                                        { item.product_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="allergens">
                                        { item.allergens }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="certifications">
                                        { item.certifications }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_sample_eligible">
                                        { dataFormatter.booleanFormatter(item.is_sample_eligible) }
                                    </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;