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/ad_projects/ad_projectsSlice'
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 Ad_projectsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { ad_projects } = useAppSelector((state) => state.ad_projects)
    

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

              

              

              

              

              

              

              

              

              

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

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ProjectName</p>
                    <p>{ad_projects?.project_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Channel</p>
                    <p>{ad_projects?.channel ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

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

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BrandVoiceProfile</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{ad_projects?.brand_voice_profile?.profile_name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Six_hat_sessions AdProject</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>SessionName</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>PromptContext</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ad_projects.six_hat_sessions_ad_project && Array.isArray(ad_projects.six_hat_sessions_ad_project) &&
                              ad_projects.six_hat_sessions_ad_project.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/six_hat_sessions/six_hat_sessions-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="session_name">
                                        { item.session_name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="prompt_context">
                                        { item.prompt_context }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ad_projects?.six_hat_sessions_ad_project?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Ad_creatives AdProject</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>CreativeName</th>
                                
                                
                                
                                <th>CreativeFormat</th>
                                
                                
                                
                                
                                
                                <th>Headline</th>
                                
                                
                                
                                <th>DescriptionText</th>
                                
                                
                                
                                <th>CallToAction</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>TargetingNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ad_projects.ad_creatives_ad_project && Array.isArray(ad_projects.ad_creatives_ad_project) &&
                              ad_projects.ad_creatives_ad_project.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/ad_creatives/ad_creatives-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="creative_name">
                                        { item.creative_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="creative_format">
                                        { item.creative_format }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="headline">
                                        { item.headline }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description_text">
                                        { item.description_text }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="call_to_action">
                                        { item.call_to_action }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="targeting_notes">
                                        { item.targeting_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ad_projects?.ad_creatives_ad_project?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Generation_runs AdProject</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>RunType</th>
                                
                                
                                
                                <th>RequestedAt</th>
                                
                                
                                
                                <th>RunStatus</th>
                                
                                
                                
                                <th>InputPrompt</th>
                                
                                
                                
                                <th>ModelLabel</th>
                                
                                
                                
                                <th>Temperature</th>
                                
                                
                                
                                <th>RetrievedChunkCount</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ad_projects.generation_runs_ad_project && Array.isArray(ad_projects.generation_runs_ad_project) &&
                              ad_projects.generation_runs_ad_project.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/generation_runs/generation_runs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="run_type">
                                        { item.run_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="requested_at">
                                        { dataFormatter.dateTimeFormatter(item.requested_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="run_status">
                                        { item.run_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="input_prompt">
                                        { item.input_prompt }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="model_label">
                                        { item.model_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="temperature">
                                        { item.temperature }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="retrieved_chunk_count">
                                        { item.retrieved_chunk_count }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ad_projects?.generation_runs_ad_project?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Platform_metrics AdProject</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Platform</th>
                                
                                
                                
                                <th>MetricDate</th>
                                
                                
                                
                                <th>Spend</th>
                                
                                
                                
                                <th>Impressions</th>
                                
                                
                                
                                <th>Clicks</th>
                                
                                
                                
                                <th>Ctr</th>
                                
                                
                                
                                <th>Conversions</th>
                                
                                
                                
                                <th>Cpa</th>
                                
                                
                                
                                <th>Roas</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ad_projects.platform_metrics_ad_project && Array.isArray(ad_projects.platform_metrics_ad_project) &&
                              ad_projects.platform_metrics_ad_project.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/platform_metrics/platform_metrics-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="platform">
                                        { item.platform }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="metric_date">
                                        { dataFormatter.dateTimeFormatter(item.metric_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="spend">
                                        { item.spend }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="impressions">
                                        { item.impressions }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="clicks">
                                        { item.clicks }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ctr">
                                        { item.ctr }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="conversions">
                                        { item.conversions }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cpa">
                                        { item.cpa }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="roas">
                                        { item.roas }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ad_projects?.platform_metrics_ad_project?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                

                <BaseDivider />

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

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

export default Ad_projectsView;