/*!
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project.
 */ import { useCallback, useMemo, useState } from 'react';
/**
 * A hook to consolidate view-state for modals
 *
 * @param onHide - callback to be called when the modal is dismissed
 * @returns The modal state
 */ export function useModalState(onShow, onHide) {
    const [isOpen, setIsOpen] = useState(false);
    const open = useCallback(()=>setIsOpen(true), [
        setIsOpen
    ]);
    const close = useCallback(()=>setIsOpen(false), [
        setIsOpen
    ]);
    /**
	 * Shw logic
	 */ const show = useCallback(()=>{
        onShow?.();
        open();
    }, [
        onShow,
        open
    ]);
    /**
	 * Hide logic
	 */ const hide = useCallback(()=>{
        close();
        onHide?.();
    }, [
        close,
        onHide
    ]);
    /**
	 * Toggle logic
	 */ const toggle = useCallback(()=>isOpen ? hide() : show(), [
        isOpen,
        hide,
        show
    ]);
    return useMemo(()=>({
            isOpen,
            show,
            hide,
            toggle
        }), [
        isOpen,
        show,
        hide,
        toggle
    ]);
}
