import { mdiChartTimelineVariant, mdiUpload } from '@mdi/js'
import Head from 'next/head'
import React, { ReactElement, useEffect, useState } from 'react'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import dayjs from "dayjs";

import CardBox from '../../components/CardBox'
import LayoutAuthenticated from '../../layouts/Authenticated'
import SectionMain from '../../components/SectionMain'
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton'
import { getPageTitle } from '../../config'

import { Field, Form, Formik } from 'formik'
import FormField from '../../components/FormField'
import BaseDivider from '../../components/BaseDivider'
import BaseButtons from '../../components/BaseButtons'
import BaseButton from '../../components/BaseButton'
import FormCheckRadio from '../../components/FormCheckRadio'
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup'
import FormFilePicker from '../../components/FormFilePicker'
import FormImagePicker from '../../components/FormImagePicker'
import { SelectField } from "../../components/SelectField";
import { SelectFieldMany } from "../../components/SelectFieldMany";
import { SwitchField } from '../../components/SwitchField'
import {RichTextField} from "../../components/RichTextField";

import { update, fetch } from '../../stores/six_hat_sessions/six_hat_sessionsSlice'
import { useAppDispatch, useAppSelector } from '../../stores/hooks'
import { useRouter } from 'next/router'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";



const EditSix_hat_sessions = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()
  const initVals = {
      
    
    'session_name': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    

    

    

    
    campaign: null,
    

    
    
    

    

    

    

    

    

    

    

    

    

    

    
    ad_project: null,
    

    
    
    

    
    prompt_context: '',
    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    
    white_hat_notes: '',
    

    

    

    

    

    

    

    

    

    

    
    
    

    

    
    red_hat_notes: '',
    

    

    

    

    

    

    

    

    

    

    
    
    

    

    
    black_hat_notes: '',
    

    

    

    

    

    

    

    

    

    

    
    
    

    

    
    yellow_hat_notes: '',
    

    

    

    

    

    

    

    

    

    

    
    
    

    

    
    green_hat_notes: '',
    

    

    

    

    

    

    

    

    

    

    
    
    

    

    
    blue_hat_notes: '',
    

    

    

    

    

    

    

    

    

    

    
    
    
  }
  const [initialValues, setInitialValues] = useState(initVals)

  const { six_hat_sessions } = useAppSelector((state) => state.six_hat_sessions)
  

  const { six_hat_sessionsId } = router.query

  useEffect(() => {
    dispatch(fetch({ id: six_hat_sessionsId }))
  }, [six_hat_sessionsId])

  useEffect(() => {
    if (typeof six_hat_sessions === 'object') {
      setInitialValues(six_hat_sessions)
    }
  }, [six_hat_sessions])

  useEffect(() => {
      if (typeof six_hat_sessions === 'object') {

          const newInitialVal = {...initVals};

          Object.keys(initVals).forEach(el => newInitialVal[el] = (six_hat_sessions)[el])

          setInitialValues(newInitialVal);
      }
  }, [six_hat_sessions])

  const handleSubmit = async (data) => {
    await dispatch(update({ id: six_hat_sessionsId, data }))
    await router.push('/six_hat_sessions/six_hat_sessions-list')
  }

  return (
    <>
      <Head>
        <title>{getPageTitle('Edit six_hat_sessions')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={'Edit six_hat_sessions'} main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            enableReinitialize
            initialValues={initialValues}
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>


  
    <FormField
        label="SessionName"
    >
        <Field
            name="session_name"
            placeholder="SessionName"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  

  

  
  
    <FormField label='Campaign' labelFor='campaign'>
        <Field
            name='campaign'
            id='campaign'
            component={SelectField}
            options={initialValues.campaign}
            itemRef={'campaigns'}
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
            showField={'campaign_name'}
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        ></Field>
    </FormField>
    

  

  

    

  



  

  

  

  

  

  

  

  

  

  
  
    <FormField label='AdProject' labelFor='ad_project'>
        <Field
            name='ad_project'
            id='ad_project'
            component={SelectField}
            options={initialValues.ad_project}
            itemRef={'ad_projects'}
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
            showField={'project_name'}
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        ></Field>
    </FormField>
    

  

  

    

  



  

  
    <FormField label="PromptContext" hasTextareaHeight>
        <Field name="prompt_context" as="textarea" placeholder="PromptContext" />
    </FormField>
  

  

  

  

  

  

  

  

  

  

    

  



  

  

  
    <FormField label='WhiteHatNotes' hasTextareaHeight>
        <Field
            name='white_hat_notes'
            id='white_hat_notes'
            component={RichTextField}
        ></Field>
    </FormField>
  

  

  

  

  

  

  

  

  

    

  



  

  

  
    <FormField label='RedHatNotes' hasTextareaHeight>
        <Field
            name='red_hat_notes'
            id='red_hat_notes'
            component={RichTextField}
        ></Field>
    </FormField>
  

  

  

  

  

  

  

  

  

    

  



  

  

  
    <FormField label='BlackHatNotes' hasTextareaHeight>
        <Field
            name='black_hat_notes'
            id='black_hat_notes'
            component={RichTextField}
        ></Field>
    </FormField>
  

  

  

  

  

  

  

  

  

    

  



  

  

  
    <FormField label='YellowHatNotes' hasTextareaHeight>
        <Field
            name='yellow_hat_notes'
            id='yellow_hat_notes'
            component={RichTextField}
        ></Field>
    </FormField>
  

  

  

  

  

  

  

  

  

    

  



  

  

  
    <FormField label='GreenHatNotes' hasTextareaHeight>
        <Field
            name='green_hat_notes'
            id='green_hat_notes'
            component={RichTextField}
        ></Field>
    </FormField>
  

  

  

  

  

  

  

  

  

    

  



  

  

  
    <FormField label='BlueHatNotes' hasTextareaHeight>
        <Field
            name='blue_hat_notes'
            id='blue_hat_notes'
            component={RichTextField}
        ></Field>
    </FormField>
  

  

  

  

  

  

  

  

  

    

  


  

              <BaseDivider />
              <BaseButtons>
                <BaseButton type="submit" color="info" label="Submit" />
                <BaseButton type="reset" color="info" outline label="Reset" />
                <BaseButton type='reset' color='danger' outline label='Cancel' onClick={() => router.push('/six_hat_sessions/six_hat_sessions-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default EditSix_hat_sessions
