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/generation_outputs/generation_outputsSlice'
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 Generation_outputsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { generation_outputs } = useAppSelector((state) => state.generation_outputs)
    

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

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>GenerationRun</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{generation_outputs?.generation_run?.model_label ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>OutputType</p>
                    <p>{generation_outputs?.output_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>OutputTitle</p>
                    <p>{generation_outputs?.output_title}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='IsExported'>
                    <SwitchField
                      field={{name: 'is_exported', value: generation_outputs?.is_exported}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='ExportedAt'>
                    {generation_outputs.exported_at ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={generation_outputs.exported_at ?
                        new Date(
                          dayjs(generation_outputs.exported_at).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No ExportedAt</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Output_citations GenerationOutput</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>RelevanceScore</th>
                                
                                
                                
                                <th>CitationNote</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {generation_outputs.output_citations_generation_output && Array.isArray(generation_outputs.output_citations_generation_output) &&
                              generation_outputs.output_citations_generation_output.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/output_citations/output_citations-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="relevance_score">
                                        { item.relevance_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="citation_note">
                                        { item.citation_note }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!generation_outputs?.output_citations_generation_output?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Feedback_entries GenerationOutput</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>GivenAt</th>
                                
                                
                                
                                <th>OverallScore</th>
                                
                                
                                
                                <th>ComplianceScore</th>
                                
                                
                                
                                <th>BrandFitScore</th>
                                
                                
                                
                                <th>ConversionIntentScore</th>
                                
                                
                                
                                <th>EmpathyScore</th>
                                
                                
                                
                                <th>RiskBoldnessScore</th>
                                
                                
                                
                                <th>FreeformNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {generation_outputs.feedback_entries_generation_output && Array.isArray(generation_outputs.feedback_entries_generation_output) &&
                              generation_outputs.feedback_entries_generation_output.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/feedback_entries/feedback_entries-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="given_at">
                                        { dataFormatter.dateTimeFormatter(item.given_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="overall_score">
                                        { item.overall_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="compliance_score">
                                        { item.compliance_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="brand_fit_score">
                                        { item.brand_fit_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="conversion_intent_score">
                                        { item.conversion_intent_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="empathy_score">
                                        { item.empathy_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="risk_boldness_score">
                                        { item.risk_boldness_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="freeform_notes">
                                        { item.freeform_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!generation_outputs?.feedback_entries_generation_output?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Generation_outputsView;