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/units_of_measure/units_of_measureSlice'
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 Units_of_measureView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { units_of_measure } = useAppSelector((state) => state.units_of_measure)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>UoMCode</p>
                    <p>{units_of_measure?.code}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>UoMType</p>
                    <p>{units_of_measure?.uom_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Materials UnitofMeasure</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>MaterialCode</th>
                                
                                
                                
                                <th>MaterialName</th>
                                
                                
                                
                                <th>MaterialType</th>
                                
                                
                                
                                
                                
                                <th>StandardCost</th>
                                
                                
                                
                                <th>StandardLeadTimeDays</th>
                                
                                
                                
                                <th>LotTracked</th>
                                
                                
                                
                                <th>SerialTracked</th>
                                
                                
                                
                                <th>ReorderPoint</th>
                                
                                
                                
                                <th>ReorderQuantity</th>
                                
                                
                                
                                
                                
                                <th>Specification</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {units_of_measure.materials_uom && Array.isArray(units_of_measure.materials_uom) &&
                              units_of_measure.materials_uom.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/materials/materials-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="material_code">
                                        { item.material_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="material_type">
                                        { item.material_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="standard_cost">
                                        { item.standard_cost }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="standard_lead_time_days">
                                        { item.standard_lead_time_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="lot_tracked">
                                        { dataFormatter.booleanFormatter(item.lot_tracked) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="serial_tracked">
                                        { dataFormatter.booleanFormatter(item.serial_tracked) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reorder_point">
                                        { item.reorder_point }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reorder_quantity">
                                        { item.reorder_quantity }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="specification">
                                        { item.specification }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!units_of_measure?.materials_uom?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Units_of_measureView;