"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 appui_layout_react_1 = require("@itwin/appui-layout-react");
const MessageManager_1 = require("../messages/MessageManager");
const UiFramework_1 = require("../UiFramework");
/** Activity Center Field React component.
 * @public
 */
class ActivityCenterField extends React.Component {
    constructor(p) {
        super(p);
        this._handleActivityMessageEvent = (args) => {
            this.setState({
                message: args.message,
                percentage: args.percentage,
                isActivityMessageVisible: true,
            });
        };
        this._handleActivityMessageCancelledEvent = () => {
            this.setState({
                isActivityMessageVisible: false,
            });
        };
        this._openActivityMessage = () => {
            MessageManager_1.MessageManager.setupActivityMessageValues(this.state.message, this.state.percentage, true);
        };
        this.state = {
            message: "",
            percentage: 0,
            isActivityMessageVisible: true,
        };
    }
    componentDidMount() {
        MessageManager_1.MessageManager.onActivityMessageUpdatedEvent.addListener(this._handleActivityMessageEvent);
        MessageManager_1.MessageManager.onActivityMessageCancelledEvent.addListener(this._handleActivityMessageCancelledEvent);
    }
    componentWillUnmount() {
        MessageManager_1.MessageManager.onActivityMessageUpdatedEvent.removeListener(this._handleActivityMessageEvent);
        MessageManager_1.MessageManager.onActivityMessageCancelledEvent.removeListener(this._handleActivityMessageCancelledEvent);
    }
    render() {
        let footerMessages;
        const isPercentageValid = (this.state.percentage > 0 && this.state.percentage < 100);
        if (this.state.isActivityMessageVisible && isPercentageValid) {
            const moreDetails = UiFramework_1.UiFramework.translate("activityCenter.moreDetails");
            const tooltip = `${this.state.message}-${moreDetails}`;
            footerMessages = (React.createElement(core_react_1.Centered, { className: (0, classnames_1.default)("open-activity-message", this.props.className), style: this.props.style, onClick: this._openActivityMessage, title: tooltip },
                React.createElement(appui_layout_react_1.MessageLayout, { progress: React.createElement(appui_layout_react_1.MessageProgress, { status: appui_layout_react_1.Status.Information, progress: this.state.percentage }) })));
        }
        else {
            footerMessages = React.createElement("div", null);
        }
        return footerMessages;
    }
}
exports.ActivityCenterField = ActivityCenterField;
//# sourceMappingURL=ActivityCenter.js.map