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/products/productsSlice'
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";

import {hasPermission} from "../../helpers/userPermissions";


const ProductsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { products } = useAppSelector((state) => state.products)
    
    const { currentUser } = useAppSelector((state) => state.auth);
    

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

              

              

              

              

              

              

              

              

              

              
                {hasPermission(currentUser, 'READ_ORGANIZATIONS') && 
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Organization</p>
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{products?.organization?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                  } 
              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Code</p>
                    <p>{products?.sku}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Category</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{products?.category?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Unit</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{products?.unit?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>SalePriceHT</p>
                  <p>{products?.sale_price_ht || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>PurchasePriceHT</p>
                  <p>{products?.purchase_price_ht || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TaxRate</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{products?.tax_rate?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>StockOnHand</p>
                  <p>{products?.stock_on_hand || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>StockReserved</p>
                  <p>{products?.stock_reserved || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>ReorderLevel</p>
                  <p>{products?.reorder_level || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>WeightedAvgCost</p>
                  <p>{products?.weighted_avg_cost || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='TrackStock'>
                    <SwitchField
                      field={{name: 'track_stock', value: products?.track_stock}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Quote_items Product</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Designation</th>
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                <th>Unit</th>
                                
                                
                                
                                <th>UnitPriceHT</th>
                                
                                
                                
                                <th>DiscountPercent</th>
                                
                                
                                
                                <th>TaxRatePercent</th>
                                
                                
                                
                                <th>LineTotalHT</th>
                                
                                
                                
                                <th>LineTaxTotal</th>
                                
                                
                                
                                <th>LineTotalTTC</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {products.quote_items_product && Array.isArray(products.quote_items_product) &&
                              products.quote_items_product.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/quote_items/quote_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="designation">
                                        { item.designation }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_label">
                                        { item.unit_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_price_ht">
                                        { item.unit_price_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="discount_percent">
                                        { item.discount_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tax_rate_percent">
                                        { item.tax_rate_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total_ht">
                                        { item.line_total_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_tax_total">
                                        { item.line_tax_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total_ttc">
                                        { item.line_total_ttc }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!products?.quote_items_product?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Sales_order_items Product</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Designation</th>
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                <th>Unit</th>
                                
                                
                                
                                <th>UnitPriceHT</th>
                                
                                
                                
                                <th>DiscountPercent</th>
                                
                                
                                
                                <th>TaxRatePercent</th>
                                
                                
                                
                                <th>LineTotalHT</th>
                                
                                
                                
                                <th>LineTaxTotal</th>
                                
                                
                                
                                <th>LineTotalTTC</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {products.sales_order_items_product && Array.isArray(products.sales_order_items_product) &&
                              products.sales_order_items_product.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/sales_order_items/sales_order_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="designation">
                                        { item.designation }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_label">
                                        { item.unit_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_price_ht">
                                        { item.unit_price_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="discount_percent">
                                        { item.discount_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tax_rate_percent">
                                        { item.tax_rate_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total_ht">
                                        { item.line_total_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_tax_total">
                                        { item.line_tax_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total_ttc">
                                        { item.line_total_ttc }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!products?.sales_order_items_product?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Delivery_note_items Product</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Designation</th>
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                <th>Unit</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {products.delivery_note_items_product && Array.isArray(products.delivery_note_items_product) &&
                              products.delivery_note_items_product.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/delivery_note_items/delivery_note_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="designation">
                                        { item.designation }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_label">
                                        { item.unit_label }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!products?.delivery_note_items_product?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Invoice_items Product</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Designation</th>
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                <th>Unit</th>
                                
                                
                                
                                <th>UnitPriceHT</th>
                                
                                
                                
                                <th>DiscountPercent</th>
                                
                                
                                
                                <th>TaxRatePercent</th>
                                
                                
                                
                                <th>LineTotalHT</th>
                                
                                
                                
                                <th>LineTaxTotal</th>
                                
                                
                                
                                <th>LineTotalTTC</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {products.invoice_items_product && Array.isArray(products.invoice_items_product) &&
                              products.invoice_items_product.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/invoice_items/invoice_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="designation">
                                        { item.designation }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_label">
                                        { item.unit_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_price_ht">
                                        { item.unit_price_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="discount_percent">
                                        { item.discount_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tax_rate_percent">
                                        { item.tax_rate_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total_ht">
                                        { item.line_total_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_tax_total">
                                        { item.line_tax_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total_ttc">
                                        { item.line_total_ttc }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!products?.invoice_items_product?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Credit_note_items Product</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Designation</th>
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                <th>Unit</th>
                                
                                
                                
                                <th>UnitPriceHT</th>
                                
                                
                                
                                <th>TaxRatePercent</th>
                                
                                
                                
                                <th>LineTotalHT</th>
                                
                                
                                
                                <th>LineTaxTotal</th>
                                
                                
                                
                                <th>LineTotalTTC</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {products.credit_note_items_product && Array.isArray(products.credit_note_items_product) &&
                              products.credit_note_items_product.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/credit_note_items/credit_note_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="designation">
                                        { item.designation }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_label">
                                        { item.unit_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_price_ht">
                                        { item.unit_price_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tax_rate_percent">
                                        { item.tax_rate_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total_ht">
                                        { item.line_total_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_tax_total">
                                        { item.line_tax_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total_ttc">
                                        { item.line_total_ttc }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!products?.credit_note_items_product?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Purchase_order_items Product</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Designation</th>
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                <th>Unit</th>
                                
                                
                                
                                <th>UnitPriceHT</th>
                                
                                
                                
                                <th>TaxRatePercent</th>
                                
                                
                                
                                <th>LineTotalHT</th>
                                
                                
                                
                                <th>LineTaxTotal</th>
                                
                                
                                
                                <th>LineTotalTTC</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {products.purchase_order_items_product && Array.isArray(products.purchase_order_items_product) &&
                              products.purchase_order_items_product.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/purchase_order_items/purchase_order_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="designation">
                                        { item.designation }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_label">
                                        { item.unit_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_price_ht">
                                        { item.unit_price_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tax_rate_percent">
                                        { item.tax_rate_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total_ht">
                                        { item.line_total_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_tax_total">
                                        { item.line_tax_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total_ttc">
                                        { item.line_total_ttc }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!products?.purchase_order_items_product?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Stock_reception_items Product</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>QuantityReceived</th>
                                
                                
                                
                                <th>UnitCostHT</th>
                                
                                
                                
                                <th>ExpiryDate</th>
                                
                                
                                
                                <th>BatchCode</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {products.stock_reception_items_product && Array.isArray(products.stock_reception_items_product) &&
                              products.stock_reception_items_product.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/stock_reception_items/stock_reception_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="quantity_received">
                                        { item.quantity_received }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_cost_ht">
                                        { item.unit_cost_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expiry_date">
                                        { dataFormatter.dateTimeFormatter(item.expiry_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="batch_code">
                                        { item.batch_code }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!products?.stock_reception_items_product?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Stock_reservations Product</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>QuantityReserved</th>
                                
                                
                                
                                <th>ReservedAt</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {products.stock_reservations_product && Array.isArray(products.stock_reservations_product) &&
                              products.stock_reservations_product.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/stock_reservations/stock_reservations-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="quantity_reserved">
                                        { item.quantity_reserved }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reserved_at">
                                        { dataFormatter.dateTimeFormatter(item.reserved_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!products?.stock_reservations_product?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Stock_movements Product</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>MovedAt</th>
                                
                                
                                
                                <th>MovementType</th>
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                <th>UnitCostHT</th>
                                
                                
                                
                                <th>Reference</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {products.stock_movements_product && Array.isArray(products.stock_movements_product) &&
                              products.stock_movements_product.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/stock_movements/stock_movements-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="moved_at">
                                        { dataFormatter.dateTimeFormatter(item.moved_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="movement_type">
                                        { item.movement_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_cost_ht">
                                        { item.unit_cost_ht }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reference">
                                        { item.reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!products?.stock_movements_product?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Inventory_count_items Product</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>SystemQuantity</th>
                                
                                
                                
                                <th>CountedQuantity</th>
                                
                                
                                
                                <th>Difference</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {products.inventory_count_items_product && Array.isArray(products.inventory_count_items_product) &&
                              products.inventory_count_items_product.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/inventory_count_items/inventory_count_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="quantity_system">
                                        { item.quantity_system }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity_counted">
                                        { item.quantity_counted }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity_diff">
                                        { item.quantity_diff }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!products?.inventory_count_items_product?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                

                <BaseDivider />

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

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

export default ProductsView;