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/roles_catalog/roles_catalogSlice'
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 Roles_catalogView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { roles_catalog } = useAppSelector((state) => state.roles_catalog)
    

    const { id } = router.query;
    
    useEffect(() => {
        dispatch(fetch({ id }));
    }, [dispatch, id]);


    return (
      <>
          <Head>
              <title>{getPageTitle('Governance role details')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="Governance role details" main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/roles_catalog/roles_catalog-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Human review checklists</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>ChecklistName</th>
                                
                                
                                
                                <th>Purpose</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Instructions</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {roles_catalog.human_review_checklists_required_reviewer_role && Array.isArray(roles_catalog.human_review_checklists_required_reviewer_role) &&
                              roles_catalog.human_review_checklists_required_reviewer_role.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/human_review_checklists/human_review_checklists-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="purpose">
                                        { item.purpose }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="instructions">
                                        { item.instructions }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!roles_catalog?.human_review_checklists_required_reviewer_role?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Training_requirements Role</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Required</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {roles_catalog.training_requirements_role && Array.isArray(roles_catalog.training_requirements_role) &&
                              roles_catalog.training_requirements_role.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/training_requirements/training_requirements-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_required">
                                        { dataFormatter.booleanFormatter(item.is_required) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!roles_catalog?.training_requirements_role?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Roles_catalogView;
