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/compliance_categories/compliance_categoriesSlice'
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";

import {hasPermission} from "../../helpers/userPermissions";


const Compliance_categoriesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { compliance_categories } = useAppSelector((state) => state.compliance_categories)
    
    const { currentUser } = useAppSelector((state) => state.auth);
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>CategoryName</p>
                    <p>{compliance_categories?.category_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>CategoryType</p>
                    <p>{compliance_categories?.category_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>organizations</p>
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{compliance_categories?.organizations?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Compliance_templates Category</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>TemplateName</th>
                                
                                
                                
                                <th>Code</th>
                                
                                
                                
                                <th>Frequency</th>
                                
                                
                                
                                <th>DueDayOfMonth</th>
                                
                                
                                
                                <th>DueMonthOfYear</th>
                                
                                
                                
                                <th>GraceDays</th>
                                
                                
                                
                                <th>AppliesToBusinessType</th>
                                
                                
                                
                                <th>AppliesToIndustry</th>
                                
                                
                                
                                <th>AppliesToState</th>
                                
                                
                                
                                <th>MinEmployeeCount</th>
                                
                                
                                
                                <th>MaxEmployeeCount</th>
                                
                                
                                
                                <th>RiskLevel</th>
                                
                                
                                
                                <th>LegalReference</th>
                                
                                
                                
                                
                                
                                <th>Active</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {compliance_categories.compliance_templates_category && Array.isArray(compliance_categories.compliance_templates_category) &&
                              compliance_categories.compliance_templates_category.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/compliance_templates/compliance_templates-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="template_name">
                                        { item.template_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="frequency">
                                        { item.frequency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="due_day_of_month">
                                        { item.due_day_of_month }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="due_month_of_year">
                                        { item.due_month_of_year }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="grace_days">
                                        { item.grace_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="applies_to_business_type">
                                        { item.applies_to_business_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="applies_to_industry">
                                        { item.applies_to_industry }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="applies_to_state">
                                        { item.applies_to_state }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="min_employee_count">
                                        { item.min_employee_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_employee_count">
                                        { item.max_employee_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="risk_level">
                                        { item.risk_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="legal_reference">
                                        { item.legal_reference }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!compliance_categories?.compliance_templates_category?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Compliance_categoriesView;