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/dialogue_topics/dialogue_topicsSlice'
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 Dialogue_topicsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { dialogue_topics } = useAppSelector((state) => state.dialogue_topics)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Title</p>
                    <p>{dialogue_topics?.title}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TopicType</p>
                    <p>{dialogue_topics?.topic_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='IsRepeatable'>
                    <SwitchField
                      field={{name: 'is_repeatable', value: dialogue_topics?.is_repeatable}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Dialogue_lines Topic</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>MoodTag</th>
                                
                                
                                
                                
                                
                                <th>Priority</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {dialogue_topics.dialogue_lines_topic && Array.isArray(dialogue_topics.dialogue_lines_topic) &&
                              dialogue_topics.dialogue_lines_topic.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/dialogue_lines/dialogue_lines-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="mood_tag">
                                        { item.mood_tag }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="priority">
                                        { item.priority }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!dialogue_topics?.dialogue_lines_topic?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Dialogue_topicsView;