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

              

              

              

              

              

              

              

              

              

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

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

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

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              
                <>
                    <p className={'block font-bold mb-2'}>Nodes</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>NodeType</th>
                                
                                
                                
                                
                                
                                    <th>XPosition</th>
                                
                                
                                
                                    <th>YPosition</th>
                                
                                
                                
                                    <th>ConfidenceLevel</th>
                                
                                
                                
                                    <th>AIGenerated</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {mind_maps.nodes && Array.isArray(mind_maps.nodes) &&
                              mind_maps.nodes.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/map_nodes/map_nodes-view/?id=${item.id}`)}>
                                  
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                  
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="node_type">
                                        { item.node_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="x_position">
                                        { item.x_position }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="y_position">
                                        { item.y_position }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="confidence_level">
                                        { item.confidence_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ai_generated">
                                        { dataFormatter.booleanFormatter(item.ai_generated) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!mind_maps?.nodes?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
              

              

              
              

              

              

              

              

              

              

              

              

              

              

              
                <>
                    <p className={'block font-bold mb-2'}>Edges</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                    <th>FromNodeKey</th>
                                
                                
                                
                                    <th>ToNodeKey</th>
                                
                                
                                
                                    <th>RelationType</th>
                                
                                
                                
                                
                                
                                    <th>Strength</th>
                                
                                
                                
                                    <th>AIGenerated</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {mind_maps.edges && Array.isArray(mind_maps.edges) &&
                              mind_maps.edges.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/map_edges/map_edges-view/?id=${item.id}`)}>
                                  
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                  
                                    
                                    
                                    
                                    <td data-label="from_node_key">
                                        { item.from_node_key }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="to_node_key">
                                        { item.to_node_key }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="relation_type">
                                        { item.relation_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="strength">
                                        { item.strength }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ai_generated">
                                        { dataFormatter.booleanFormatter(item.ai_generated) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!mind_maps?.edges?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
              

              

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Map_nodes MindMap</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>NodeType</th>
                                
                                
                                
                                
                                
                                <th>XPosition</th>
                                
                                
                                
                                <th>YPosition</th>
                                
                                
                                
                                <th>ConfidenceLevel</th>
                                
                                
                                
                                <th>AIGenerated</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {mind_maps.map_nodes_mind_map && Array.isArray(mind_maps.map_nodes_mind_map) &&
                              mind_maps.map_nodes_mind_map.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/map_nodes/map_nodes-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="node_type">
                                        { item.node_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="x_position">
                                        { item.x_position }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="y_position">
                                        { item.y_position }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="confidence_level">
                                        { item.confidence_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ai_generated">
                                        { dataFormatter.booleanFormatter(item.ai_generated) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!mind_maps?.map_nodes_mind_map?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Map_edges MindMap</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>FromNodeKey</th>
                                
                                
                                
                                <th>ToNodeKey</th>
                                
                                
                                
                                <th>RelationType</th>
                                
                                
                                
                                
                                
                                <th>Strength</th>
                                
                                
                                
                                <th>AIGenerated</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {mind_maps.map_edges_mind_map && Array.isArray(mind_maps.map_edges_mind_map) &&
                              mind_maps.map_edges_mind_map.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/map_edges/map_edges-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="from_node_key">
                                        { item.from_node_key }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="to_node_key">
                                        { item.to_node_key }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="relation_type">
                                        { item.relation_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="strength">
                                        { item.strength }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ai_generated">
                                        { dataFormatter.booleanFormatter(item.ai_generated) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!mind_maps?.map_edges_mind_map?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Mind_mapsView;