"use client"

import { createContext, useContext } from "react"

// Closes the nearest dialog/sheet wrapper. `null` means the form is not
// inside a dialog that should auto-close (or a parent has explicitly
// shadowed the context, e.g. CrudDialog).
export const DialogCloseContext = createContext<(() => void) | null>(null)

export function useDialogClose(): (() => void) | null {
    return useContext(DialogCloseContext)
}
