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?.name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ItemNumber</p>
                    <p>{items?.item_number}</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'}>DefaultUoM</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{items?.default_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'}>DefaultWarehouse</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{items?.default_warehouse?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

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

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

              

              

              

              

              

              

              

              

              

              

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

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <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>RevisionStatus</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="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bom_code">
                                        { item.bom_code }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="revision_status">
                                        { item.revision_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>ScrapFactorPercent</th>
                                
                                
                                
                                <th>LineNumber</th>
                                
                                
                                
                                <th>ReferenceDesignator</th>
                                
                                
                                
                                <th>Notes</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_percent">
                                        { item.scrap_factor_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_number">
                                        { item.line_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reference_designator">
                                        { item.reference_designator }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.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'}>Routings Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>RoutingName</th>
                                
                                
                                
                                <th>RoutingCode</th>
                                
                                
                                
                                
                                
                                <th>RevisionStatus</th>
                                
                                
                                
                                <th>Revision</th>
                                
                                
                                
                                <th>EffectiveFrom</th>
                                
                                
                                
                                <th>EffectiveTo</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.routings_item && Array.isArray(items.routings_item) &&
                              items.routings_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/routings/routings-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="routing_code">
                                        { item.routing_code }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="revision_status">
                                        { item.revision_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?.routings_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Production_orders Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>OrderNumber</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>PlannedQuantity</th>
                                
                                
                                
                                <th>CompletedQuantity</th>
                                
                                
                                
                                <th>ScrappedQuantity</th>
                                
                                
                                
                                <th>PlannedStartAt</th>
                                
                                
                                
                                <th>PlannedEndAt</th>
                                
                                
                                
                                <th>ReleasedAt</th>
                                
                                
                                
                                <th>ClosedAt</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Priority</th>
                                
                                
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.production_orders_item && Array.isArray(items.production_orders_item) &&
                              items.production_orders_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/production_orders/production_orders-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="order_number">
                                        { item.order_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="planned_quantity">
                                        { item.planned_quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="completed_quantity">
                                        { item.completed_quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="scrapped_quantity">
                                        { item.scrapped_quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="planned_start_at">
                                        { dataFormatter.dateTimeFormatter(item.planned_start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="planned_end_at">
                                        { dataFormatter.dateTimeFormatter(item.planned_end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="released_at">
                                        { dataFormatter.dateTimeFormatter(item.released_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="closed_at">
                                        { dataFormatter.dateTimeFormatter(item.closed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="priority">
                                        { item.priority }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.production_orders_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Material_requirements Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>RequiredQuantity</th>
                                
                                
                                
                                <th>IssuedQuantity</th>
                                
                                
                                
                                
                                
                                <th>IssueMethod</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.material_requirements_item && Array.isArray(items.material_requirements_item) &&
                              items.material_requirements_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/material_requirements/material_requirements-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="required_quantity">
                                        { item.required_quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="issued_quantity">
                                        { item.issued_quantity }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="issue_method">
                                        { item.issue_method }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.material_requirements_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <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>LotNumber</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ManufacturedAt</th>
                                
                                
                                
                                <th>ReceivedAt</th>
                                
                                
                                
                                <th>ExpirationAt</th>
                                
                                
                                
                                <th>QualityStatus</th>
                                
                                
                                
                                <th>QuantityOnHand</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_number">
                                        { item.lot_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="manufactured_at">
                                        { dataFormatter.dateTimeFormatter(item.manufactured_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="received_at">
                                        { dataFormatter.dateTimeFormatter(item.received_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expiration_at">
                                        { dataFormatter.dateTimeFormatter(item.expiration_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quality_status">
                                        { item.quality_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity_on_hand">
                                        { item.quantity_on_hand }
                                    </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'}>Serial_numbers Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>SerialNumber</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>CreatedOn</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.serial_numbers_item && Array.isArray(items.serial_numbers_item) &&
                              items.serial_numbers_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/serial_numbers/serial_numbers-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="serial_number">
                                        { item.serial_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="created_on">
                                        { dataFormatter.dateTimeFormatter(item.created_on) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.serial_numbers_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>TransactionType</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                
                                
                                <th>TransactionAt</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Reference</th>
                                
                                
                                
                                <th>Notes</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_type">
                                        { item.transaction_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="transaction_at">
                                        { dataFormatter.dateTimeFormatter(item.transaction_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reference">
                                        { item.reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </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'}>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>ScheduledAt</th>
                                
                                
                                
                                <th>PerformedAt</th>
                                
                                
                                
                                
                                
                                <th>Result</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.inspections_item && Array.isArray(items.inspections_item) &&
                              items.inspections_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/inspections/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="scheduled_at">
                                        { dataFormatter.dateTimeFormatter(item.scheduled_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="performed_at">
                                        { dataFormatter.dateTimeFormatter(item.performed_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="result">
                                        { item.result }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.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>NCRNumber</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Severity</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Disposition</th>
                                
                                
                                
                                <th>ReportedAt</th>
                                
                                
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>RootCause</th>
                                
                                
                                
                                <th>CorrectiveAction</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="ncr_number">
                                        { item.ncr_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="severity">
                                        { item.severity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="disposition">
                                        { item.disposition }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reported_at">
                                        { dataFormatter.dateTimeFormatter(item.reported_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="root_cause">
                                        { item.root_cause }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="corrective_action">
                                        { item.corrective_action }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.nonconformances_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Quality_holds Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>HoldNumber</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>HoldStartedAt</th>
                                
                                
                                
                                <th>HoldReleasedAt</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Reason</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.quality_holds_item && Array.isArray(items.quality_holds_item) &&
                              items.quality_holds_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/quality_holds/quality_holds-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="hold_number">
                                        { item.hold_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="hold_started_at">
                                        { dataFormatter.dateTimeFormatter(item.hold_started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="hold_released_at">
                                        { dataFormatter.dateTimeFormatter(item.hold_released_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reason">
                                        { item.reason }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.quality_holds_item?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Documents Item</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>DocumentType</th>
                                
                                
                                
                                <th>DocumentNumber</th>
                                
                                
                                
                                <th>Revision</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>EffectiveFrom</th>
                                
                                
                                
                                <th>EffectiveTo</th>
                                
                                
                                
                                
                                
                                <th>Summary</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {items.documents_item && Array.isArray(items.documents_item) &&
                              items.documents_item.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/documents/documents-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="document_type">
                                        { item.document_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="document_number">
                                        { item.document_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="revision">
                                        { item.revision }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </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="summary">
                                        { item.summary }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!items?.documents_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;