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/qa_checklists/qa_checklistsSlice'
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 Qa_checklistsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { qa_checklists } = useAppSelector((state) => state.qa_checklists)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ChecklistType</p>
                    <p>{qa_checklists?.checklist_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

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

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Qa_checklist_items QAChecklist</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>SequenceNumber</th>
                                
                                
                                
                                <th>CheckName</th>
                                
                                
                                
                                <th>ValueType</th>
                                
                                
                                
                                <th>LowerLimit</th>
                                
                                
                                
                                <th>UpperLimit</th>
                                
                                
                                
                                <th>Instructions</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {qa_checklists.qa_checklist_items_qa_checklist && Array.isArray(qa_checklists.qa_checklist_items_qa_checklist) &&
                              qa_checklists.qa_checklist_items_qa_checklist.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/qa_checklist_items/qa_checklist_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="sequence_number">
                                        { item.sequence_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="check_name">
                                        { item.check_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="value_type">
                                        { item.value_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="lower_limit">
                                        { item.lower_limit }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="upper_limit">
                                        { item.upper_limit }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="instructions">
                                        { item.instructions }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!qa_checklists?.qa_checklist_items_qa_checklist?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Qa_checklistsView;