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/document_types/document_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 Document_typesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { document_types } = useAppSelector((state) => state.document_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 document_types')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View document_types')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/document_types/document_types-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

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

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Category</p>
                    <p>{document_types?.category ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Document_templates DocumentType</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>TemplateCode</th>
                                
                                
                                
                                <th>TemplateFamily</th>
                                
                                
                                
                                <th>Purpose</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Format</th>
                                
                                
                                
                                <th>Active</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {document_types.document_templates_document_type && Array.isArray(document_types.document_templates_document_type) &&
                              document_types.document_templates_document_type.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/document_templates/document_templates-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="template_name">
                                        { item.template_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="template_code">
                                        { item.template_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="template_family">
                                        { item.template_family }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="purpose">
                                        { item.purpose }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="format">
                                        { item.format }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="active">
                                        { dataFormatter.booleanFormatter(item.active) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!document_types?.document_templates_document_type?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Documents DocumentType</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>DocumentNumber</th>
                                
                                
                                
                                <th>CurrentRevision</th>
                                
                                
                                
                                <th>LifecycleStatus</th>
                                
                                
                                
                                <th>ControlLevel</th>
                                
                                
                                
                                <th>Confidentiality</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>EffectiveDate</th>
                                
                                
                                
                                <th>NextReviewDate</th>
                                
                                
                                
                                <th>Summary</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>TrainingRequired</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {document_types.documents_document_type && Array.isArray(document_types.documents_document_type) &&
                              document_types.documents_document_type.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/documents/documents-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="document_number">
                                        { item.document_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="current_revision">
                                        { item.current_revision }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="lifecycle_status">
                                        { item.lifecycle_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="control_level">
                                        { item.control_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="confidentiality">
                                        { item.confidentiality }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="effective_date">
                                        { dataFormatter.dateTimeFormatter(item.effective_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="next_review_date">
                                        { dataFormatter.dateTimeFormatter(item.next_review_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="summary">
                                        { item.summary }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="training_required">
                                        { dataFormatter.booleanFormatter(item.training_required) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!document_types?.documents_document_type?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Document_typesView;