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

function EditSocialMediaModal() {
  const {objectToEdit} = usePageState()
  const {status , mutate } = useUpdateSocialMedia();

  const handleSubmit = (value:InitialValues)=>{

    const dataToSend = getDataToSend({...value , is_active :value.is_active ? 1:0 })
    
    mutate(dataToSend)
    
}
  return (
    <LayoutModal 
     isAddModal={false}
     getInitialValues={getInitialValues(objectToEdit)} 
     handleSubmit={handleSubmit}
     status={status as QueryStatusEnum}
     headerText='Edit Modal' 
     getValidationSchema={getValidationSchema(objectToEdit)}>
      <FormSocialMedia />
    </LayoutModal>
  )
}

export default EditSocialMediaModal
