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/brand_voice_profiles/brand_voice_profilesSlice'
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 EditBrand_voice_profilesPage = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()
  const initVals = {
      
    

    

    

    

    

    

    

    

    

    

    

    
    brand: null,
    

    
    
    
    'profile_name': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    
    voice_description: '',
    

    

    

    

    

    

    

    

    

    

    
    
    

    
    do_say_examples: '',
    

    

    

    

    

    

    

    

    

    

    

    
    
    

    
    dont_say_examples: '',
    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    english_variant: '',
    

    

    

    

    
    
    

    

    

    
    reading_level_target: '',
    

    

    

    

    

    

    

    

    

    
    
    
    'formality_level': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'empathy_level': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'energy_level': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'humor_level': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'risk_tolerance': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    show_reasoning_trace: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    is_default: false,
    

    

    

    

    

    

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

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

  const { id } = router.query

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

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

  useEffect(() => {
      if (typeof brand_voice_profiles === 'object') {
          const newInitialVal = {...initVals};
          Object.keys(initVals).forEach(el => newInitialVal[el] = (brand_voice_profiles)[el])
          setInitialValues(newInitialVal);
      }
  }, [brand_voice_profiles])

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

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


  

  

  

  

  

  

  

  

  

  
  
    <FormField label='Brand' labelFor='brand'>
        <Field
            name='brand'
            id='brand'
            component={SelectField}
            options={initialValues.brand}
            itemRef={'brands'}
      
        
      
        
      
        
      
        
            showField={'brand_name'}
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        ></Field>
    </FormField>
    

  

  

    

  



  
    <FormField
        label="ProfileName"
    >
        <Field
            name="profile_name"
            placeholder="ProfileName"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  

  

  
    <FormField label='VoiceDescription' hasTextareaHeight>
        <Field
            name='voice_description'
            id='voice_description'
            component={RichTextField}
        ></Field>
    </FormField>
  

  

  

  

  

  

  

  

  

    

  



  

  
    <FormField label="DoSayExamples" hasTextareaHeight>
        <Field name="do_say_examples" as="textarea" placeholder="DoSayExamples" />
    </FormField>
  

  

  

  

  

  

  

  

  

  

    

  



  

  
    <FormField label="DontSayExamples" hasTextareaHeight>
        <Field name="dont_say_examples" as="textarea" placeholder="DontSayExamples" />
    </FormField>
  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="EnglishVariant" labelFor="english_variant">
        <Field name="english_variant" id="english_variant" component="select">
          
            <option value="en_au">en_au</option>
          
            <option value="en_us">en_us</option>
          
            <option value="en_uk">en_uk</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  
    <FormField
        label="ReadingLevelTarget"
    >
        <Field
            type="number"
            name="reading_level_target"
            placeholder="ReadingLevelTarget"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="FormalityLevel"
    >
        <Field
            type="number"
            name="formality_level"
            placeholder="FormalityLevel"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="EmpathyLevel"
    >
        <Field
            type="number"
            name="empathy_level"
            placeholder="EmpathyLevel"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="EnergyLevel"
    >
        <Field
            type="number"
            name="energy_level"
            placeholder="EnergyLevel"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="HumorLevel"
    >
        <Field
            type="number"
            name="humor_level"
            placeholder="HumorLevel"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="RiskTolerance"
    >
        <Field
            type="number"
            name="risk_tolerance"
            placeholder="RiskTolerance"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='ShowReasoningTrace' labelFor='show_reasoning_trace'>
        <Field
            name='show_reasoning_trace'
            id='show_reasoning_trace'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='IsDefault' labelFor='is_default'>
        <Field
            name='is_default'
            id='is_default'
            component={SwitchField}
        ></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('/brand_voice_profiles/brand_voice_profiles-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default EditBrand_voice_profilesPage
