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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Programname</p>
                    <p>{cognitive_programs?.program_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Description</p>
                  {cognitive_programs.description
                    ? <p dangerouslySetInnerHTML={{__html: cognitive_programs.description}}/>
                    : <p>No data</p>
                  }
                </div>
              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Targetstage</p>
                    <p>{cognitive_programs?.target_stage ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

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

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Estimatedminutes</p>
                  <p>{cognitive_programs?.estimated_minutes || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Createdbyuser</p>
                    
                    
                        <p>{cognitive_programs?.created_by_user?.firstName ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Cognitive_exercises Program</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Exercisename</th>
                                
                                
                                
                                <th>Exercisetype</th>
                                
                                
                                
                                
                                
                                <th>Difficultylevel</th>
                                
                                
                                
                                <th>Maxscore</th>
                                
                                
                                
                                
                                
                                <th>Isactive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {cognitive_programs.cognitive_exercises_program && Array.isArray(cognitive_programs.cognitive_exercises_program) &&
                              cognitive_programs.cognitive_exercises_program.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/cognitive_exercises/cognitive_exercises-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="exercise_name">
                                        { item.exercise_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="exercise_type">
                                        { item.exercise_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="difficulty_level">
                                        { item.difficulty_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_score">
                                        { item.max_score }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!cognitive_programs?.cognitive_exercises_program?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Cognitive_sessions Program</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Startedat</th>
                                
                                
                                
                                <th>Endedat</th>
                                
                                
                                
                                <th>Completionstatus</th>
                                
                                
                                
                                <th>Totalscore</th>
                                
                                
                                
                                <th>Sessionnotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {cognitive_programs.cognitive_sessions_program && Array.isArray(cognitive_programs.cognitive_sessions_program) &&
                              cognitive_programs.cognitive_sessions_program.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/cognitive_sessions/cognitive_sessions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ended_at">
                                        { dataFormatter.dateTimeFormatter(item.ended_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="completion_status">
                                        { item.completion_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_score">
                                        { item.total_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="session_notes">
                                        { item.session_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!cognitive_programs?.cognitive_sessions_program?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Cognitive_programsView;