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/campaign_brain_configs/campaign_brain_configsSlice'
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 Campaign_brain_configsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { campaign_brain_configs } = useAppSelector((state) => state.campaign_brain_configs)
    

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

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Campaign</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{campaign_brain_configs?.campaign?.campaign_name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BrainProfile</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{campaign_brain_configs?.brain_profile?.profile_name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>LayerName</p>
                    <p>{campaign_brain_configs?.layer_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>PriorityOrder</p>
                  <p>{campaign_brain_configs?.priority_order || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='IsEnabled'>
                    <SwitchField
                      field={{name: 'is_enabled', value: campaign_brain_configs?.is_enabled}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>InfluenceWeight</p>
                  <p>{campaign_brain_configs?.influence_weight || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              
                <>
                    <p className={'block font-bold mb-2'}>EnabledSkillModules</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                    <th>ModuleName</th>
                                
                                
                                
                                    <th>ModuleType</th>
                                
                                
                                
                                
                                
                                    <th>EvidenceLevel</th>
                                
                                
                                
                                    <th>MethodSteps</th>
                                
                                
                                
                                    <th>RequiresCitations</th>
                                
                                
                                
                                    <th>IsActive</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {campaign_brain_configs.enabled_skill_modules && Array.isArray(campaign_brain_configs.enabled_skill_modules) &&
                              campaign_brain_configs.enabled_skill_modules.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/skill_modules/skill_modules-view/?id=${item.id}`)}>
                                  
                                    
                                    
                                    
                                    
                                    
                                    
                                  
                                    
                                    <td data-label="module_name">
                                        { item.module_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="module_type">
                                        { item.module_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="evidence_level">
                                        { item.evidence_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="method_steps">
                                        { item.method_steps }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="requires_citations">
                                        { dataFormatter.booleanFormatter(item.requires_citations) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!campaign_brain_configs?.enabled_skill_modules?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Sandbox_scenarios CampaignBrainConfig</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>ScenarioName</th>
                                
                                
                                
                                <th>ScenarioType</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>LastRunAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {campaign_brain_configs.sandbox_scenarios_campaign_brain_config && Array.isArray(campaign_brain_configs.sandbox_scenarios_campaign_brain_config) &&
                              campaign_brain_configs.sandbox_scenarios_campaign_brain_config.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/sandbox_scenarios/sandbox_scenarios-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="scenario_name">
                                        { item.scenario_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="scenario_type">
                                        { item.scenario_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_run_at">
                                        { dataFormatter.dateTimeFormatter(item.last_run_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!campaign_brain_configs?.sandbox_scenarios_campaign_brain_config?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                

                <BaseDivider />

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

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

export default Campaign_brain_configsView;