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 { withStyles } from '@signatu/styles';
import { ConsentActionType } from '@signatu/consent';
import PropTypes from 'prop-types';
import React from 'react';
import { CONSENT_BASE_PROPTYPES } from '../lib/consentBase';
import { ConsentStatus } from '../lib/consentStatus';
import { ConsentTitle } from '../lib/consentTitle';
import { ConsentAction } from './consentAction';
var styles = function (theme) { return ({
    root: {
        fontFamily: theme.typography.fontFamily,
        fontWeight: theme.typography.fontWeight,
        fontSize: theme.typography.fontSize,
        padding: theme.spacing.unit * 2,
        backgroundColor: theme.palette.backgroundColor,
        borderColor: theme.palette.borderColor,
        borderRadius: theme.spacing.unit / 2
    }
}); };
var ConsentRequest = /** @class */ (function (_super) {
    __extends(ConsentRequest, _super);
    function ConsentRequest(props) {
        var _this = _super.call(this, props) || this;
        _this.checkboxId = "checkbox-" + Math.random().toString(16).slice(2);
        _this.componentIsMounted = false;
        _this.onAction = function (consent) {
            var onAction = _this.props.onAction;
            if (_this.componentIsMounted) {
                _this.setState({ consent: consent });
                if (onAction) {
                    onAction(consent);
                }
            }
        };
        _this.onLoaded = function (consent) {
            if (_this.componentIsMounted) {
                var onLoaded = _this.props.onLoaded;
                _this.setState({ consent: consent });
                if (onLoaded) {
                    onLoaded(consent);
                }
            }
        };
        _this.state = {};
        return _this;
    }
    ConsentRequest.prototype.componentDidMount = function () {
        this.componentIsMounted = true;
    };
    ConsentRequest.prototype.componentWillUnmount = function () {
        this.componentIsMounted = false;
    };
    ConsentRequest.prototype.render = function () {
        var type = this.props.type || ConsentActionType.CHECKBOX;
        var _a = this.props, classes = _a.classes, title = _a.title, subtitle = _a.subtitle, config = _a.config, subject = _a.subject, issuer = _a.issuer, target = _a.target, delegate = _a.delegate, scope = _a.scope, language = _a.language, acceptText = _a.acceptText, refuseText = _a.refuseText;
        if (!config) {
            return null;
        }
        return (React.createElement("div", { className: classes.root, "data-type": "ConsentRequest" },
            React.createElement(ConsentTitle, { title: title, subtitle: subtitle }),
            React.createElement(ConsentAction, { id: this.checkboxId, config: config, subject: subject, issuer: issuer, target: target, scope: scope, delegate: delegate, language: language, acceptText: acceptText, refuseText: refuseText, type: type, onAction: this.onAction, onLoaded: this.onLoaded },
                this.props.text,
                this.props.children),
            React.createElement(ConsentStatus, { consent: this.state.consent, language: this.props.language || 'en', type: type })));
    };
    /** PropTypes for non-Typescript environments */
    ConsentRequest.propTypes = __assign({}, CONSENT_BASE_PROPTYPES, { type: PropTypes.string, acceptText: PropTypes.string, refuseText: PropTypes.string, classes: PropTypes.any });
    return ConsentRequest;
}(React.Component));
var styled = withStyles(styles)(ConsentRequest);
export { styled as ConsentRequest };
//# sourceMappingURL=consentRequest.js.map