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/user_physical_baselines/user_physical_baselinesSlice'
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 EditUser_physical_baselinesPage = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()
  const initVals = {
      
    

    

    

    

    

    

    

    

    

    

    

    
    user: null,
    

    
    
    
    'height_cm': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'height_ft': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'height_in': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'weight_kg': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'weight_lb': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'wrist_circumference_cm': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    dominant_hand: '',
    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    fitzpatrick_skin_type: '',
    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    blood_type: '',
    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    rh_factor: '',
    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    body_frame_size: '',
    

    

    

    

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

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

  const { id } = router.query

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

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

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

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

  return (
    <>
      <Head>
        <title>{getPageTitle('Edit user_physical_baselines')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={'Edit user_physical_baselines'} 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="Height(cm)"
    >
        <Field
            type="number"
            name="height_cm"
            placeholder="Height(cm)"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="Height(ft)"
    >
        <Field
            type="number"
            name="height_ft"
            placeholder="Height(ft)"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="Height(in)"
    >
        <Field
            type="number"
            name="height_in"
            placeholder="Height(in)"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="Weight(kg)"
    >
        <Field
            type="number"
            name="weight_kg"
            placeholder="Weight(kg)"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="Weight(lb)"
    >
        <Field
            type="number"
            name="weight_lb"
            placeholder="Weight(lb)"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="WristCircumference(cm)"
    >
        <Field
            type="number"
            name="wrist_circumference_cm"
            placeholder="WristCircumference(cm)"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="DominantHand" labelFor="dominant_hand">
        <Field name="dominant_hand" id="dominant_hand" component="select">
          
            <option value="left">left</option>
          
            <option value="right">right</option>
          
            <option value="ambidextrous">ambidextrous</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="FitzpatrickSkinType" labelFor="fitzpatrick_skin_type">
        <Field name="fitzpatrick_skin_type" id="fitzpatrick_skin_type" component="select">
          
            <option value="1">1</option>
          
            <option value="2">2</option>
          
            <option value="3">3</option>
          
            <option value="4">4</option>
          
            <option value="5">5</option>
          
            <option value="6">6</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="BloodType" labelFor="blood_type">
        <Field name="blood_type" id="blood_type" component="select">
          
            <option value="a_plus">a_plus</option>
          
            <option value="a_minus">a_minus</option>
          
            <option value="b_plus">b_plus</option>
          
            <option value="b_minus">b_minus</option>
          
            <option value="ab_plus">ab_plus</option>
          
            <option value="ab_minus">ab_minus</option>
          
            <option value="o_plus">o_plus</option>
          
            <option value="o_minus">o_minus</option>
          
            <option value="unknown">unknown</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="RhFactor" labelFor="rh_factor">
        <Field name="rh_factor" id="rh_factor" component="select">
          
            <option value="positive">positive</option>
          
            <option value="negative">negative</option>
          
            <option value="unknown">unknown</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="BodyFrameSize" labelFor="body_frame_size">
        <Field name="body_frame_size" id="body_frame_size" component="select">
          
            <option value="small">small</option>
          
            <option value="medium">medium</option>
          
            <option value="large">large</option>
          
            <option value="unknown">unknown</option>
          
        </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('/user_physical_baselines/user_physical_baselines-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default EditUser_physical_baselinesPage
