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/private_profiles/private_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 EditPrivate_profilesPage = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()
  const initVals = {
      
    

    

    

    

    

    

    

    

    

    

    

    
    user: null,
    

    
    
    

    

    

    

    

    

    

    

    
    primary_role: '',
    

    

    

    

    
    
    

    
    goals_summary: '',
    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'focus_area': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'time_commitment': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    
    constraints_notes: '',
    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    
    ai_profile_draft: '',
    

    

    

    

    

    

    

    

    

    

    
    
    

    

    
    vision_statement: '',
    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    
    onboarding_completed_at: new Date(),
    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    linked_accounts_intent: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    

    

    

    

    
    resume_documents: [],
    
    
    

    

    

    

    

    

    

    

    

    

    

    

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

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

  const { id } = router.query

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

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

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

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

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


  

  

  

  

  

  

  

  

  

  
  
    <FormField label='User' labelFor='user'>
        <Field
            name='user'
            id='user'
            component={SelectField}
            options={initialValues.user}
            itemRef={'users'}
      
        
            showField={'firstName'}
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        ></Field>
    </FormField>
    

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="PrimaryRole" labelFor="primary_role">
        <Field name="primary_role" id="primary_role" component="select">
          
            <option value="student">student</option>
          
            <option value="career_changer">career_changer</option>
          
            <option value="professional">professional</option>
          
            <option value="job_seeker">job_seeker</option>
          
            <option value="founder">founder</option>
          
            <option value="manager">manager</option>
          
            <option value="other">other</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  
    <FormField label="GoalsSummary" hasTextareaHeight>
        <Field name="goals_summary" as="textarea" placeholder="GoalsSummary" />
    </FormField>
  

  

  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="FocusArea"
    >
        <Field
            name="focus_area"
            placeholder="FocusArea"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="TimeCommitment"
    >
        <Field
            name="time_commitment"
            placeholder="TimeCommitment"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  

  
    <FormField label="ConstraintsNotes" hasTextareaHeight>
        <Field name="constraints_notes" as="textarea" placeholder="ConstraintsNotes" />
    </FormField>
  

  

  

  

  

  

  

  

  

  

    

  



  

  

  
    <FormField label='AIProfileDraft' hasTextareaHeight>
        <Field
            name='ai_profile_draft'
            id='ai_profile_draft'
            component={RichTextField}
        ></Field>
    </FormField>
  

  

  

  

  

  

  

  

  

    

  



  

  

  
    <FormField label='VisionStatement' hasTextareaHeight>
        <Field
            name='vision_statement'
            id='vision_statement'
            component={RichTextField}
        ></Field>
    </FormField>
  

  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  
      <FormField
          label="OnboardingCompletedAt"
      >
          <DatePicker
              dateFormat="yyyy-MM-dd hh:mm"
              showTimeSelect
              selected={initialValues.onboarding_completed_at ?
                  new Date(
                      dayjs(initialValues.onboarding_completed_at).format('YYYY-MM-DD hh:mm'),
                  ) : null
              }
              onChange={(date) => setInitialValues({...initialValues, 'onboarding_completed_at': date})}
          />
      </FormField>
  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='LinkedAccountsIntent' labelFor='linked_accounts_intent'>
        <Field
            name='linked_accounts_intent'
            id='linked_accounts_intent'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  

  

  
      <FormField label='ResumeDocuments' labelFor='resume_documents'>
          <Field
              name='resume_documents'
              id='resume_documents'
              component={SelectFieldMany}
              options={initialValues.resume_documents}
              itemRef={'resume_documents'}
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
              showField={'document_name'}
            
            
            
            
            
            
          ></Field>
      </FormField>
  

    

  



  

  

  

  

  

  

  

  

  

  

  
      <FormField label='CoachingSessions' labelFor='coaching_sessions'>
          <Field
              name='coaching_sessions'
              id='coaching_sessions'
              component={SelectFieldMany}
              options={initialValues.coaching_sessions}
              itemRef={'coaching_sessions'}
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
              showField={'topic'}
            
            
            
            
            
            
            
            
            
            
          ></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('/private_profiles/private_profiles-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default EditPrivate_profilesPage
