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

function EditWorksModal() {
  const {objectToEdit} = usePageState()
  const {status, mutate} = useUpdateWorks();

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

export default EditWorksModal
