"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 WidgetPanels
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.WidgetPanelExpanders = exports.WidgetPanelExpander = void 0;
require("./Expander.scss");
const classnames_1 = require("classnames");
const React = require("react");
const Panel_1 = require("./Panel");
const NineZone_1 = require("../base/NineZone");
const core_react_1 = require("@itwin/core-react");
const LayoutStore_1 = require("../base/LayoutStore");
/** Component that is used to auto-expand unpinned widget panel.
 * @internal
 */
function WidgetPanelExpander({ side }) {
    // eslint-disable-next-line deprecation/deprecation
    const timer = React.useRef(new core_react_1.Timer(200));
    const lastPosition = React.useRef(new core_react_1.Point());
    const dispatch = React.useContext(NineZone_1.NineZoneDispatchContext);
    React.useEffect(() => {
        timer.current.setOnExecute(() => {
            dispatch({
                side,
                collapsed: false,
                type: "PANEL_SET_COLLAPSED",
            });
        });
    }, [side, dispatch]);
    const className = (0, classnames_1.default)("nz-widgetPanels-expander", `nz-${side}`);
    return (React.createElement("div", { className: className, onMouseOverCapture: (e) => {
            lastPosition.current = new core_react_1.Point(e.clientX, e.clientY);
            timer.current.start();
        }, onMouseOutCapture: () => {
            timer.current.stop();
        }, onMouseMoveCapture: (e) => {
            const newPosition = new core_react_1.Point(e.clientX, e.clientY);
            if (lastPosition.current.getDistanceTo(newPosition) > 5) {
                timer.current.start();
                lastPosition.current = newPosition;
            }
        } }));
}
exports.WidgetPanelExpander = WidgetPanelExpander;
/** @internal */
function WidgetPanelExpanders() {
    const expanders = (0, LayoutStore_1.useLayout)((state) => {
        const panels = state.panels;
        return Panel_1.panelSides.filter((side) => {
            const panel = panels[side];
            return !panel.pinned && panel.collapsed;
        });
    }, true);
    return (React.createElement(React.Fragment, null, expanders.map((side) => {
        return React.createElement(WidgetPanelExpander, { key: side, side: side });
    })));
}
exports.WidgetPanelExpanders = WidgetPanelExpanders;
//# sourceMappingURL=Expander.js.map