var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React from 'react';
import { Popup } from '../components/consentPopup';
/** Create a conditional popup when there is no existing consent event */
/**
 * Props: autoClose: boolean - close when the user has given or revoked consent
 */
export var makeConsentCondPopup = function (Component, defaultCloseDelay) {
    if (defaultCloseDelay === void 0) { defaultCloseDelay = 500; }
    return /** @class */ (function (_super) {
        __extends(class_1, _super);
        function class_1() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.state = {
                show: false,
            };
            _this.onLoaded = function (consent) {
                if (!consent) {
                    _this.setState({ show: true });
                }
                _this.props.onLoaded && _this.props.onLoaded(consent);
            };
            _this.onAction = function (consent) {
                _this.props.onAction && _this.props.onAction(consent);
                if (_this.props.autoClose) {
                    _this.close();
                }
            };
            _this.close = function () {
                setTimeout(function () { return _this.setState({ show: false }); }, _this.props.closeDelay || defaultCloseDelay);
            };
            return _this;
        }
        class_1.prototype.render = function () {
            /** We need to pre-load the component, so we cannot have it behind a conditional */
            return React.createElement(Popup, { preload: true, show: this.state.show, contentStyle: { maxWidth: "600px", overflow: "auto" }, onClose: this.close },
                React.createElement(Component, __assign({}, this.props, { onLoaded: this.onLoaded, onAction: this.onAction })));
        };
        return class_1;
    }(React.Component));
};
//# sourceMappingURL=makeCondPopup.js.map