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/pay_types/pay_typesSlice'
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 Pay_typesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { pay_types } = useAppSelector((state) => state.pay_types)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PayMethod</p>
                    <p>{pay_types?.pay_method ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>HourlyRate</p>
                  <p>{pay_types?.hourly_rate || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>CommissionRate</p>
                  <p>{pay_types?.commission_rate || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Employee_pay_types PayType</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Active</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {pay_types.employee_pay_types_pay_type && Array.isArray(pay_types.employee_pay_types_pay_type) &&
                              pay_types.employee_pay_types_pay_type.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/employee_pay_types/employee_pay_types-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="active">
                                        { dataFormatter.booleanFormatter(item.active) }
                                    </td>
</tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!pay_types?.employee_pay_types_pay_type?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Job_logs PayType</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>WorkDate</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>HoursConducted</th>
                                
                                
                                
                                <th>ClientPaid</th>
                                
                                
                                
                                <th>WorkmansCompensationClass</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>OdometerStart</th>
                                
                                
                                
                                <th>OdometerEnd</th>
                                
                                
                                
                                <th>JobAddress</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>NotesToAdmin</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {pay_types.job_logs_pay_type && Array.isArray(pay_types.job_logs_pay_type) &&
                              pay_types.job_logs_pay_type.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/job_logs/job_logs-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="work_date">
                                        { dataFormatter.dateTimeFormatter(item.work_date) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="hours_conducted">
                                        { item.hours_conducted }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="client_paid">
                                        { item.client_paid }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="workers_comp_class">
                                        { item.workers_comp_class }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="odometer_start">
                                        { item.odometer_start }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="odometer_end">
                                        { item.odometer_end }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="job_address">
                                        { item.job_address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes_to_admin">
                                        { item.notes_to_admin }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!pay_types?.job_logs_pay_type?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                

                <BaseDivider />

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

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

export default Pay_typesView;