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

              

              

              

              

              

              

              

              

              

              
                {hasPermission(currentUser, 'READ_ORGANIZATIONS') && 
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Organization</p>
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{ai_models?.organization?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                  } 
              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ModelType</p>
                    <p>{ai_models?.model_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Provider</p>
                    <p>{ai_models?.provider}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Version</p>
                    <p>{ai_models?.version}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

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

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Ai_embeddings AIModel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>VectorRef</th>
                                
                                
                                
                                <th>Dimensions</th>
                                
                                
                                
                                <th>EmbeddingType</th>
                                
                                
                                
                                <th>QualityScore</th>
                                
                                
                                
                                <th>IndexedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ai_models.ai_embeddings_ai_model && Array.isArray(ai_models.ai_embeddings_ai_model) &&
                              ai_models.ai_embeddings_ai_model.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/ai_embeddings/ai_embeddings-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="vector_ref">
                                        { item.vector_ref }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="dimensions">
                                        { item.dimensions }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="embedding_type">
                                        { item.embedding_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quality_score">
                                        { item.quality_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="indexed_at">
                                        { dataFormatter.dateTimeFormatter(item.indexed_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ai_models?.ai_embeddings_ai_model?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Face_detections AIModel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>BBoxX</th>
                                
                                
                                
                                <th>BBoxY</th>
                                
                                
                                
                                <th>BBoxWidth</th>
                                
                                
                                
                                <th>BBoxHeight</th>
                                
                                
                                
                                <th>Confidence</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ai_models.face_detections_ai_model && Array.isArray(ai_models.face_detections_ai_model) &&
                              ai_models.face_detections_ai_model.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/face_detections/face_detections-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="bbox_x">
                                        { item.bbox_x }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bbox_y">
                                        { item.bbox_y }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bbox_width">
                                        { item.bbox_width }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bbox_height">
                                        { item.bbox_height }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="confidence">
                                        { item.confidence }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ai_models?.face_detections_ai_model?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Selfie_references AIModel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>UploadedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ai_models.selfie_references_ai_model && Array.isArray(ai_models.selfie_references_ai_model) &&
                              ai_models.selfie_references_ai_model.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/selfie_references/selfie_references-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="uploaded_at">
                                        { dataFormatter.dateTimeFormatter(item.uploaded_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ai_models?.selfie_references_ai_model?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Ai_captions AIModel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>CaptionText</th>
                                
                                
                                
                                <th>Confidence</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ai_models.ai_captions_ai_model && Array.isArray(ai_models.ai_captions_ai_model) &&
                              ai_models.ai_captions_ai_model.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/ai_captions/ai_captions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="caption_text">
                                        { item.caption_text }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="confidence">
                                        { item.confidence }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ai_models?.ai_captions_ai_model?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Ai_modelsView;