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

function EditContactModal() {
  const {objectToEdit} = usePageState()
  const {status, mutate} = useUpdateContact();

  const handleSubmit = (value:InitialValues)=>{
    console.log(value.direction);
    
    const dataToSend = getDataToSend({...value,direction:value?.direction == true ? 1:0,is_have_button:value?.direction == true ? 1:0})
    
    mutate(dataToSend)
}
  
  return (
    <LayoutModal 
     isAddModal={false}
     getInitialValues={getInitialValues(objectToEdit)} 
     handleSubmit={handleSubmit}
     status={status as QueryStatusEnum}
     headerText='Edit Modal' 
     getValidationSchema={getValidationSchema(objectToEdit)}>
      <FormContact />
    </LayoutModal>
  )
}

export default EditContactModal
