"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Toolbar
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDefaultToolbarItems = void 0;
const React = require("react");
/** Hook that returns items from [[ToolbarItemsManager]].
 * @public
 */
const useDefaultToolbarItems = (manager) => {
    const [items, setItems] = React.useState(() => manager.items);
    const isInitialMount = React.useRef(true);
    React.useEffect(() => {
        if (isInitialMount.current)
            isInitialMount.current = false;
        else {
            setItems(manager.items);
        }
    }, [manager, manager.items]);
    React.useEffect(() => {
        const handleChanged = (args) => {
            setItems(args.items);
        };
        manager.onItemsChanged.addListener(handleChanged);
        return () => {
            manager.onItemsChanged.removeListener(handleChanged);
        };
    }, [manager]);
    return items;
};
exports.useDefaultToolbarItems = useDefaultToolbarItems;
//# sourceMappingURL=useDefaultToolbarItems.js.map