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/items/itemsSlice'
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 ItemsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { items } = useAppSelector((state) => state.items)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ItemName</p>
                    <p>{items?.item_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ItemCode</p>
                    <p>{items?.item_code}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ItemType</p>
                    <p>{items?.item_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>UOM</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{items?.uom?.uom_name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='LotTracked'>
                    <SwitchField
                      field={{name: 'lot_tracked', value: items?.lot_tracked}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='SerialTracked'>
                    <SwitchField
                      field={{name: 'serial_tracked', value: items?.serial_tracked}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>StandardCost</p>
                  <p>{items?.standard_cost || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>DefaultPurchasePrice</p>
                  <p>{items?.default_purchase_price || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>DefaultSalePrice</p>
                  <p>{items?.default_sale_price || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>ShelfLife(Days)</p>
                  <p>{items?.shelf_life_days || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>ReorderPoint</p>
                  <p>{items?.reorder_point || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>ReorderQuantity</p>
                  <p>{items?.reorder_qty || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

              

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

                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Lots Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>LotCode</th>
                                
                                
                                
                                <th>SupplierLotCode</th>
                                
                                
                                
                                
                                
                                <th>ReceivedAt</th>
                                
                                
                                
                                <th>ManufacturedAt</th>
                                
                                
                                
                                <th>ExpiresAt</th>
                                
                                
                                
                                <th>QualityStatus</th>
                                
                                
                                
                                <th>CertificateNumber</th>
                                
                                
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.lots_item && Array.isArray(items.lots_item) &&
                              items.lots_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/lots/lots-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="lot_code">
                                        { item.lot_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="supplier_lot_code">
                                        { item.supplier_lot_code }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="received_at">
                                        { dataFormatter.dateTimeFormatter(item.received_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="manufactured_at">
                                        { dataFormatter.dateTimeFormatter(item.manufactured_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expires_at">
                                        { dataFormatter.dateTimeFormatter(item.expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quality_status">
                                        { item.quality_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="certificate_number">
                                        { item.certificate_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.lots_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Inventory_transactions Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>TransactionNumber</th>
                                
                                
                                
                                <th>TransactionAt</th>
                                
                                
                                
                                <th>TransactionType</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                
                                
                                <th>UnitCost</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Reference</th>
                                
                                
                                
                                <th>Reason</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.inventory_transactions_item && Array.isArray(items.inventory_transactions_item) &&
                              items.inventory_transactions_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/inventory_transactions/inventory_transactions-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="transaction_number">
                                        { item.transaction_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="transaction_at">
                                        { dataFormatter.dateTimeFormatter(item.transaction_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="transaction_type">
                                        { item.transaction_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="unit_cost">
                                        { item.unit_cost }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reference">
                                        { item.reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reason">
                                        { item.reason }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.inventory_transactions_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Boms ParentItem</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>BOMName</th>
                                
                                
                                
                                <th>BOMCode</th>
                                
                                
                                
                                <th>BOMStatus</th>
                                
                                
                                
                                <th>Revision</th>
                                
                                
                                
                                <th>EffectiveFrom</th>
                                
                                
                                
                                <th>EffectiveTo</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.boms_parent_item && Array.isArray(items.boms_parent_item) &&
                              items.boms_parent_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/boms/boms-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="bom_name">
                                        { item.bom_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bom_code">
                                        { item.bom_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bom_status">
                                        { item.bom_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="revision">
                                        { item.revision }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="effective_from">
                                        { dataFormatter.dateTimeFormatter(item.effective_from) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="effective_to">
                                        { dataFormatter.dateTimeFormatter(item.effective_to) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.boms_parent_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Bom_lines ComponentItem</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>QuantityPer</th>
                                
                                
                                
                                
                                
                                <th>ScrapFactor</th>
                                
                                
                                
                                <th>IssueMethod</th>
                                
                                
                                
                                <th>LineNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.bom_lines_component_item && Array.isArray(items.bom_lines_component_item) &&
                              items.bom_lines_component_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/bom_lines/bom_lines-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="quantity_per">
                                        { item.quantity_per }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="scrap_factor">
                                        { item.scrap_factor }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="issue_method">
                                        { item.issue_method }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_notes">
                                        { item.line_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.bom_lines_component_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Work_orders Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>WorkOrderNumber</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>PlannedQuantity</th>
                                
                                
                                
                                <th>CompletedQuantity</th>
                                
                                
                                
                                
                                
                                <th>ScheduledStart</th>
                                
                                
                                
                                <th>ScheduledEnd</th>
                                
                                
                                
                                <th>ActualStart</th>
                                
                                
                                
                                <th>ActualEnd</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.work_orders_item && Array.isArray(items.work_orders_item) &&
                              items.work_orders_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/work_orders/work_orders-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="work_order_number">
                                        { item.work_order_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="planned_quantity">
                                        { item.planned_quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="completed_quantity">
                                        { item.completed_quantity }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="scheduled_start">
                                        { dataFormatter.dateTimeFormatter(item.scheduled_start) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="scheduled_end">
                                        { dataFormatter.dateTimeFormatter(item.scheduled_end) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="actual_start">
                                        { dataFormatter.dateTimeFormatter(item.actual_start) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="actual_end">
                                        { dataFormatter.dateTimeFormatter(item.actual_end) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.work_orders_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Material_issue_lines ComponentItem</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                
                                
                                <th>LineStatus</th>
                                
                                
                                
                                <th>LineNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.material_issue_lines_component_item && Array.isArray(items.material_issue_lines_component_item) &&
                              items.material_issue_lines_component_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/material_issue_lines/material_issue_lines-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="line_status">
                                        { item.line_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_notes">
                                        { item.line_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.material_issue_lines_component_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Receipt_lines Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                
                                
                                <th>UnitCost</th>
                                
                                
                                
                                <th>QualityStatus</th>
                                
                                
                                
                                <th>LineNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.receipt_lines_item && Array.isArray(items.receipt_lines_item) &&
                              items.receipt_lines_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/receipt_lines/receipt_lines-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="unit_cost">
                                        { item.unit_cost }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quality_status">
                                        { item.quality_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_notes">
                                        { item.line_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.receipt_lines_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Shipment_lines Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                
                                
                                <th>LineNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.shipment_lines_item && Array.isArray(items.shipment_lines_item) &&
                              items.shipment_lines_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/shipment_lines/shipment_lines-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="line_notes">
                                        { item.line_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.shipment_lines_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Qa_inspection_plans Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>PlanName</th>
                                
                                
                                
                                <th>PlanCode</th>
                                
                                
                                
                                
                                
                                <th>InspectionType</th>
                                
                                
                                
                                <th>SamplingMethod</th>
                                
                                
                                
                                <th>SampleSize</th>
                                
                                
                                
                                <th>PlanStatus</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.qa_inspection_plans_item && Array.isArray(items.qa_inspection_plans_item) &&
                              items.qa_inspection_plans_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/qa_inspection_plans/qa_inspection_plans-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="plan_name">
                                        { item.plan_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="plan_code">
                                        { item.plan_code }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="inspection_type">
                                        { item.inspection_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sampling_method">
                                        { item.sampling_method }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sample_size">
                                        { item.sample_size }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="plan_status">
                                        { item.plan_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.qa_inspection_plans_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Qa_inspections Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>InspectionNumber</th>
                                
                                
                                
                                <th>InspectionType</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ScheduledAt</th>
                                
                                
                                
                                <th>PerformedAt</th>
                                
                                
                                
                                
                                
                                <th>SampleSize</th>
                                
                                
                                
                                <th>DefectCount</th>
                                
                                
                                
                                <th>Disposition</th>
                                
                                
                                
                                <th>Summary</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.qa_inspections_item && Array.isArray(items.qa_inspections_item) &&
                              items.qa_inspections_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/qa_inspections/qa_inspections-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="inspection_number">
                                        { item.inspection_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="inspection_type">
                                        { item.inspection_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="scheduled_at">
                                        { dataFormatter.dateTimeFormatter(item.scheduled_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="performed_at">
                                        { dataFormatter.dateTimeFormatter(item.performed_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="sample_size">
                                        { item.sample_size }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="defect_count">
                                        { item.defect_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="disposition">
                                        { item.disposition }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="summary">
                                        { item.summary }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.qa_inspections_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Nonconformances Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>NCNumber</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Severity</th>
                                
                                
                                
                                <th>Source</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ReportedAt</th>
                                
                                
                                
                                
                                
                                <th>ProblemDescription</th>
                                
                                
                                
                                <th>Disposition</th>
                                
                                
                                
                                <th>ContainmentAction</th>
                                
                                
                                
                                <th>RootCause</th>
                                
                                
                                
                                <th>CorrectiveAction</th>
                                
                                
                                
                                <th>DueAt</th>
                                
                                
                                
                                <th>ClosedAt</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.nonconformances_item && Array.isArray(items.nonconformances_item) &&
                              items.nonconformances_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/nonconformances/nonconformances-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="nc_number">
                                        { item.nc_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="severity">
                                        { item.severity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="source">
                                        { item.source }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reported_at">
                                        { dataFormatter.dateTimeFormatter(item.reported_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="problem_description">
                                        { item.problem_description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="disposition">
                                        { item.disposition }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="containment_action">
                                        { item.containment_action }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="root_cause">
                                        { item.root_cause }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="corrective_action">
                                        { item.corrective_action }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="due_at">
                                        { dataFormatter.dateTimeFormatter(item.due_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="closed_at">
                                        { dataFormatter.dateTimeFormatter(item.closed_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.nonconformances_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                

                <BaseDivider />

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

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

export default ItemsView;