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/brain_profiles/brain_profilesSlice'
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 Brain_profilesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { brain_profiles } = useAppSelector((state) => state.brain_profiles)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ProfileName</p>
                    <p>{brain_profiles?.profile_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ProfileCategory</p>
                    <p>{brain_profiles?.profile_category ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>CitationStrictness</p>
                  <p>{brain_profiles?.citation_strictness || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>CreativityLevel</p>
                  <p>{brain_profiles?.creativity_level || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>ComplianceStrictness</p>
                  <p>{brain_profiles?.compliance_strictness || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='IsActive'>
                    <SwitchField
                      field={{name: 'is_active', value: brain_profiles?.is_active}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Campaign_brain_configs BrainProfile</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>LayerName</th>
                                
                                
                                
                                <th>PriorityOrder</th>
                                
                                
                                
                                <th>IsEnabled</th>
                                
                                
                                
                                <th>InfluenceWeight</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {brain_profiles.campaign_brain_configs_brain_profile && Array.isArray(brain_profiles.campaign_brain_configs_brain_profile) &&
                              brain_profiles.campaign_brain_configs_brain_profile.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/campaign_brain_configs/campaign_brain_configs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="layer_name">
                                        { item.layer_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="priority_order">
                                        { item.priority_order }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_enabled">
                                        { dataFormatter.booleanFormatter(item.is_enabled) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="influence_weight">
                                        { item.influence_weight }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!brain_profiles?.campaign_brain_configs_brain_profile?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Brain_profilesView;