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/safety_policies/safety_policiesSlice'
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 Safety_policiesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { safety_policies } = useAppSelector((state) => state.safety_policies)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PolicyName</p>
                    <p>{safety_policies?.policy_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>EnforcementMode</p>
                    <p>{safety_policies?.enforcement_mode ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Scope</p>
                    <p>{safety_policies?.scope ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='CitationRequired'>
                    <SwitchField
                      field={{name: 'citation_required', value: safety_policies?.citation_required}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Sandbox_scenarios SafetyPolicy</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>
                            {safety_policies.sandbox_scenarios_safety_policy && Array.isArray(safety_policies.sandbox_scenarios_safety_policy) &&
                              safety_policies.sandbox_scenarios_safety_policy.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>
                        {!safety_policies?.sandbox_scenarios_safety_policy?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                

                <BaseDivider />

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

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

export default Safety_policiesView;