"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 Widget
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePinToggle = exports.PinToggle = void 0;
const React = require("react");
const core_bentley_1 = require("@itwin/core-bentley");
const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
const NineZone_1 = require("../base/NineZone");
const Panel_1 = require("../widget-panels/Panel");
const LayoutStore_1 = require("../base/LayoutStore");
const Button_1 = require("../../preview/widget-action-dropdown/Button");
const usePanelWidgetId_1 = require("./usePanelWidgetId");
const useMaximizedWidget_1 = require("../../preview/enable-maximized-widget/useMaximizedWidget");
/** @internal */
function PinToggle() {
    const side = React.useContext(Panel_1.PanelSideContext);
    (0, core_bentley_1.assert)(!!side);
    const dispatch = React.useContext(NineZone_1.NineZoneDispatchContext);
    const pinLabel = (0, NineZone_1.useLabel)("pinPanelTitle");
    const unpinLabel = (0, NineZone_1.useLabel)("unpinPanelTitle");
    const pinned = (0, LayoutStore_1.useLayout)((state) => state.panels[side].pinned);
    return (React.createElement(Button_1.ActionButton, { icon: pinned ? React.createElement(itwinui_icons_react_1.SvgPin, null) : React.createElement(itwinui_icons_react_1.SvgPinHollow, null), label: pinned ? unpinLabel : pinLabel, onClick: () => {
            dispatch({
                side,
                type: "PANEL_TOGGLE_PINNED",
            });
        } }));
}
exports.PinToggle = PinToggle;
/** @internal */
function usePinToggle() {
    const isMainPanelWidget = !!(0, usePanelWidgetId_1.useMainPanelWidgetId)();
    const isMaximizedWidget = (0, useMaximizedWidget_1.useIsMaximizedWidget)();
    return isMainPanelWidget && !isMaximizedWidget;
}
exports.usePinToggle = usePinToggle;
//# sourceMappingURL=PinToggle.js.map