"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = tslib_1.__importStar(require("react"));
var Dialog_1 = require("@fluentui/react/lib/Dialog");
var Button_1 = require("@fluentui/react/lib/Button");
var Callout_1 = require("@fluentui/react/lib/Callout");
var ContextualMenu_1 = require("@fluentui/react/lib/ContextualMenu");
var Utilities_1 = require("@fluentui/react/lib/Utilities");
var sp_core_library_1 = require("@microsoft/sp-core-library");
var DebugPrompt_resx_1 = tslib_1.__importDefault(require("./DebugPrompt.resx"));
var debugComponents_module_scss_1 = tslib_1.__importDefault(require("./../debugComponents.module.scss"));
var DebugPrompt_module_scss_1 = tslib_1.__importDefault(require("./DebugPrompt.module.scss"));
var KillSwitches_1 = require("../../../utilities/KillSwitches");
var DebugPrompt = /** @class */ (function (_super) {
    tslib_1.__extends(DebugPrompt, _super);
    function DebugPrompt(props) {
        var _this = _super.call(this, props) || this;
        _this._handleCancelClick = function () {
            _this._handleButtonClick(false);
        };
        _this._handleConfirmClick = function () {
            _this._handleButtonClick(true);
        };
        _this._handleButtonClick = function (allow) {
            // Hide the dialog after 200ms to let the callout disappear
            _this._timeouts.push(setTimeout(function () { return _this.setState({ dismissed: true }); }, 200));
            _this.setState({
                showCallout: false,
                showDialog: false
            });
            _this.props.callback(allow);
        };
        _this.state = {
            showDialog: true,
            showCallout: false,
            dismissed: false
        };
        _this._calloutRef = React.createRef();
        _this._timeouts = [];
        return _this;
    }
    DebugPrompt.prototype.componentDidMount = function () {
        var _this = this;
        this._timeouts.push(setTimeout(function () {
            return _this.setState({
                showCallout: _this.state.showDialog // Only show the callout if the dialog is still open
            });
        }, 5000 // Show the callout after 5 seconds.
        ));
    };
    DebugPrompt.prototype.componentWillUnmount = function () {
        for (var _i = 0, _a = this._timeouts; _i < _a.length; _i++) {
            var id = _a[_i];
            clearTimeout(id);
        }
        this._timeouts = [];
    };
    DebugPrompt.prototype.render = function () {
        var _a;
        return !this.state.dismissed ? (React.createElement("div", { role: 'dialog', "data-automation-id": 'debugManifestPromptDialog', "aria-labelledby": 'manifestWarningLabel' },
            React.createElement(Dialog_1.Dialog, { dialogContentProps: {
                    type: Dialog_1.DialogType.largeHeader,
                    title: this.props.title
                }, hidden: !this.state.showDialog, modalProps: {
                    isBlocking: true,
                    containerClassName: debugComponents_module_scss_1.default.dialogContainer,
                    layerProps: !(0, KillSwitches_1.isFixDebugDialogUIKSActivated)()
                        ? {
                            eventBubblingEnabled: true
                        }
                        : undefined
                } },
                React.createElement("p", { className: DebugPrompt_module_scss_1.default.warningText }, DebugPrompt_resx_1.default.debugManifestLoadingWarning),
                React.createElement("p", { className: DebugPrompt_module_scss_1.default.warningText }, sp_core_library_1.Text.format(DebugPrompt_resx_1.default.debugManifestLoadingWarning2, DebugPrompt_resx_1.default.debugManifestLoadingCancel)),
                React.createElement(Dialog_1.DialogFooter, null,
                    React.createElement(Button_1.DefaultButton, { "data-automation-id": 'debugManifestConfirmButton', onClick: this._handleConfirmClick }, DebugPrompt_resx_1.default.debugManifestLoadingConfirm),
                    React.createElement(Button_1.PrimaryButton, { "data-automation-id": 'debugManifestCancelButton', onClick: this._handleCancelClick },
                        React.createElement("div", { ref: this._calloutRef }, DebugPrompt_resx_1.default.debugManifestLoadingCancel)))),
            ((0, KillSwitches_1.isFixDebugDialogUIKSActivated)() || !!this.state.showCallout) && (React.createElement(Callout_1.Callout, { className: (0, Utilities_1.css)(DebugPrompt_module_scss_1.default.callout, (_a = {}, _a[DebugPrompt_module_scss_1.default.calloutFadeIn] = !!this.state.showCallout, _a)), target: this._calloutRef, directionalHint: ContextualMenu_1.DirectionalHint.bottomCenter, gapSpace: 10 },
                React.createElement("div", { className: DebugPrompt_module_scss_1.default.calloutText }, DebugPrompt_resx_1.default.debugManifestLoadingCalloutText))))) : null; // tslint:disable-line:no-null-keyword
    };
    return DebugPrompt;
}(React.Component));
exports.default = DebugPrompt;
//# sourceMappingURL=DebugPrompt.js.map