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/job_requisitions/job_requisitionsSlice'
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 Job_requisitionsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { job_requisitions } = useAppSelector((state) => state.job_requisitions)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>RequestingDepartment</p>
                    <p>{job_requisitions?.requestingDept}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PositionTitle</p>
                    <p>{job_requisitions?.positionTitle}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>NumberOfVacancies</p>
                  <p>{job_requisitions?.numberOfVacancies || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>SalaryRangeFrom</p>
                  <p>{job_requisitions?.salaryRangeFrom || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>SalaryRangeTo</p>
                  <p>{job_requisitions?.salaryRangeTo || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='TargetStartDate'>
                    {job_requisitions.targetStartDate ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={job_requisitions.targetStartDate ?
                        new Date(
                          dayjs(job_requisitions.targetStartDate).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No TargetStartDate</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Status</p>
                    <p>{job_requisitions?.status ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ApprovedByManager</p>
                    
                    
                        <p>{job_requisitions?.approvedByManagerUser?.firstName ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ApprovedByHR</p>
                    
                    
                        <p>{job_requisitions?.approvedByHrUser?.firstName ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Applicants JobRequisition</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ApplicationDate</th>
                                
                                
                                
                                <th>FirstName</th>
                                
                                
                                
                                <th>LastName</th>
                                
                                
                                
                                <th>Email</th>
                                
                                
                                
                                <th>Mobile</th>
                                
                                
                                
                                <th>Source</th>
                                
                                
                                
                                
                                
                                <th>InterviewSchedule</th>
                                
                                
                                
                                <th>InterviewResult</th>
                                
                                
                                
                                <th>PsychTestResult</th>
                                
                                
                                
                                <th>MedicalResult</th>
                                
                                
                                
                                <th>BackgroundCheckResult</th>
                                
                                
                                
                                <th>JobOfferStatus</th>
                                
                                
                                
                                <th>ExpectedStartDate</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {job_requisitions.applicants_jobRequisition && Array.isArray(job_requisitions.applicants_jobRequisition) &&
                              job_requisitions.applicants_jobRequisition.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/applicants/applicants-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="applicationDate">
                                        { dataFormatter.dateTimeFormatter(item.applicationDate) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="firstName">
                                        { item.firstName }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="lastName">
                                        { item.lastName }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="mobile">
                                        { item.mobile }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="source">
                                        { item.source }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="interviewSchedule">
                                        { dataFormatter.dateTimeFormatter(item.interviewSchedule) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="interviewResult">
                                        { item.interviewResult }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="psychTestResult">
                                        { item.psychTestResult }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="medicalResult">
                                        { item.medicalResult }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="backgroundCheck">
                                        { item.backgroundCheck }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="jobOfferStatus">
                                        { item.jobOfferStatus }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expectedStartDate">
                                        { dataFormatter.dateTimeFormatter(item.expectedStartDate) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!job_requisitions?.applicants_jobRequisition?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Job_requisitionsView;