import { useCallback, useState } from 'react'

export function useEditDialogState<T>() {
  const [dialogOpen, setDialogOpen] = useState(false)
  const [editing, setEditing] = useState<T | null>(null)

  const openCreateDialog = useCallback(() => {
    setEditing(null)
    setDialogOpen(true)
  }, [])

  const openEditDialog = useCallback((item: T) => {
    setEditing(item)
    setDialogOpen(true)
  }, [])

  const closeDialog = useCallback(() => {
    setDialogOpen(false)
  }, [])

  return {
    dialogOpen,
    editing,
    openCreateDialog,
    openEditDialog,
    closeDialog,
  }
}
