import { dialog , Dialogic , notification } from "dialogic" ; import type { UseDialogicInstanceProps } from "dialogic-hooks" ; import { useEffect , useState } from "mithril-hooks" ; let useDialogicCounter = 0 ; export const useDialogic = < T > ( { isIgnore , isShow , isHide , instance , deps = [ ] , props = { } as T & Dialogic . Options < T > , } ) => { const [ id ] = useState ( useDialogicCounter ++ ) ; const augProps = { ... props , ... ( props ?. dialogic ? { dialogic : { ... props . dialogic , id : props . dialogic . id || id , } , } : { dialogic : { id , } , } ) , } ; const showInstance = ( ) => { instance . show < T > ( augProps ) ; } ; const hideInstance = ( ) => { instance . hide < T > ( augProps ) ; } ; useEffect ( ( ) => { if ( isIgnore ) { return ; } if ( isShow !== undefined ) { if ( isShow ) { showInstance ( ) ; } else { hideInstance ( ) ; } } } , [ ... deps , isShow ] ) ; useEffect ( ( ) => { if ( isIgnore ) { return ; } if ( isHide !== undefined ) { if ( isHide ) { hideInstance ( ) ; } } } , [ ... deps , isHide ] ) ; useEffect ( ( ) => { if ( isIgnore ) { return undefined ; } return ( ) => { hideInstance ( ) ; } ; } , [ ] ) ; return { show : showInstance , hide : hideInstance , } ; } ; export const useDialog = < T > ( props ) => useDialogic < T > ( { instance : dialog , ... props } ) ; export const useNotification = < T > ( props ) => useDialogic < T > ( { instance : notification , ... props , } ) ;