
import React from 'react'
import LayoutModal from '../../Layout/Dashboard/LayoutModal'
import FormTeamMember from './FormTeamMember'
import { InitialValues, getDataToSend, getInitialValues, getValidationSchema } from './formUtil'
import { usePageState } from '../../lib/state mangment/LayoutPagestate'
import { QueryStatusEnum } from '../../config/QueryStatus'
import { useUpdateTeamMember } from '../../api/teamMember'

function EditTeamMemberModal() {
  const {objectToEdit} = usePageState()
  const {mutate,status} = useUpdateTeamMember();

  const handleSubmit = (value:InitialValues)=>{
    const dataToSend = getDataToSend({...value})
    
    mutate(dataToSend)
}
  
  return (
    <LayoutModal 
     isAddModal={false}
     getInitialValues={getInitialValues(objectToEdit)} 
     handleSubmit={handleSubmit}
     status={status as QueryStatusEnum}
     headerText='Edit Modal' 
     getValidationSchema={getValidationSchema(objectToEdit)}>
      <FormTeamMember />
    </LayoutModal>
  )
}

export default EditTeamMemberModal
