"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 Notification
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActivityCenterField = void 0;
const classnames_1 = require("classnames");
const React = require("react");
const core_react_1 = require("@itwin/core-react");
const MessageManager_1 = require("../messages/MessageManager");
const UiFramework_1 = require("../UiFramework");
const itwinui_react_1 = require("@itwin/itwinui-react");
/** Activity Center Field React component.
 * @public
 */
function ActivityCenterField(props) {
    const [message, setMessage] = React.useState("");
    const [percentage, setPercentage] = React.useState(0);
    const [isVisible, setIsVisible] = React.useState(true);
    const [label] = React.useState(UiFramework_1.UiFramework.translate("activityCenter.percentComplete"));
    React.useEffect(() => {
        return MessageManager_1.MessageManager.onActivityMessageUpdatedEvent.addListener((args) => {
            setMessage(args.message);
            setPercentage(args.percentage);
            setIsVisible(true);
        });
    }, []);
    React.useEffect(() => {
        return MessageManager_1.MessageManager.onActivityMessageCancelledEvent.addListener(() => {
            setIsVisible(false);
        });
    }, []);
    const openActivityMessage = () => {
        MessageManager_1.MessageManager.setupActivityMessageValues(message, percentage, true);
    };
    const isPercentageValid = percentage > 0 && percentage < 100;
    if (!isVisible || !isPercentageValid)
        return null;
    const moreDetails = UiFramework_1.UiFramework.translate("activityCenter.moreDetails");
    const tooltip = `${message}-${moreDetails}`;
    return (React.createElement(core_react_1.Centered, { className: (0, classnames_1.default)("open-activity-message", props.className), style: {
            height: "100%",
            minWidth: 120,
            padding: "0 8px",
            alignItems: "end",
            ...props.style,
        }, onClick: openActivityMessage, title: tooltip },
        React.createElement(itwinui_react_1.ProgressLinear, { style: {
                flex: "1",
            }, value: percentage, labels: [
                React.createElement(itwinui_react_1.Text, { variant: "small", key: 0 },
                    percentage,
                    " ",
                    label),
            ] })));
}
exports.ActivityCenterField = ActivityCenterField;
//# sourceMappingURL=ActivityCenter.js.map