/*---------------------------------------------------------------------------------------------
* 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
 */
import classnames from "classnames";
import * as React from "react";
import { Centered } from "@itwin/core-react";
import { MessageLayout, MessageProgress, Status } from "@itwin/appui-layout-react";
import { MessageManager } from "../messages/MessageManager";
import { UiFramework } from "../UiFramework";
/** Activity Center Field React component.
 * @public
 */
export 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.setupActivityMessageValues(this.state.message, this.state.percentage, true);
        };
        this.state = {
            message: "",
            percentage: 0,
            isActivityMessageVisible: true,
        };
    }
    componentDidMount() {
        MessageManager.onActivityMessageUpdatedEvent.addListener(this._handleActivityMessageEvent);
        MessageManager.onActivityMessageCancelledEvent.addListener(this._handleActivityMessageCancelledEvent);
    }
    componentWillUnmount() {
        MessageManager.onActivityMessageUpdatedEvent.removeListener(this._handleActivityMessageEvent);
        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.translate("activityCenter.moreDetails");
            const tooltip = `${this.state.message}-${moreDetails}`;
            footerMessages = (React.createElement(Centered, { className: classnames("open-activity-message", this.props.className), style: this.props.style, onClick: this._openActivityMessage, title: tooltip },
                React.createElement(MessageLayout, { progress: React.createElement(MessageProgress, { status: Status.Information, progress: this.state.percentage }) })));
        }
        else {
            footerMessages = React.createElement("div", null);
        }
        return footerMessages;
    }
}
//# sourceMappingURL=ActivityCenter.js.map