"use strict";
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfirmationButton = void 0;
var React = require("react");
var PropTypes = require("prop-types");
var classnames = require("classnames");
var Button_1 = require("../Button/Button");
var ModalButton_1 = require("../ModalButton/ModalButton");
var utils_1 = require("../utils");
require("./ConfirmationButton.less");
var propPrefix = "confirmButton";
var propTypes = __assign(__assign(__assign({}, utils_1.prefixKeys(Button_1.Button.propTypes, propPrefix)), ModalButton_1.ModalButton.propTypes), { className: PropTypes.string, onConfirm: PropTypes.func });
var defaultProps = __assign(__assign(__assign({}, utils_1.prefixKeys(Button_1.Button.defaultProps, propPrefix)), ModalButton_1.ModalButton.defaultProps), { confirmButtonType: "primary", confirmButtonValue: "Confirm" });
var ConfirmationButton = /** @class */ (function (_super) {
    __extends(ConfirmationButton, _super);
    function ConfirmationButton(props) {
        var _this = _super.call(this, props) || this;
        _this.modalButton = React.createRef();
        _this.handleConfirm = _this.handleConfirm.bind(_this);
        _this.handleCancel = _this.handleCancel.bind(_this);
        return _this;
    }
    ConfirmationButton.prototype.handleConfirm = function () {
        this.modalButton.current.hideModal();
        if (this.props.onConfirm)
            this.props.onConfirm();
    };
    ConfirmationButton.prototype.handleCancel = function () {
        this.modalButton.current.hideModal();
        if (this.props.onClose)
            this.props.onClose();
    };
    ConfirmationButton.prototype.render = function () {
        var modalButtonProps = utils_1.propsFor(ModalButton_1.ModalButton, this.props);
        var confirmButtonProps = utils_1.propsFor(Button_1.Button, utils_1.unprefixKeys(this.props, propPrefix));
        var wrapperClass = "ConfirmationButton--dialog-buttons";
        return (React.createElement(ModalButton_1.ModalButton, __assign({}, modalButtonProps, { ref: this.modalButton }),
            this.props.children,
            React.createElement("div", { className: classnames(wrapperClass, this.props.className) },
                React.createElement(Button_1.Button, { type: "link", value: "Cancel", onClick: this.handleCancel }),
                React.createElement(Button_1.Button, __assign({}, confirmButtonProps, { onClick: this.handleConfirm })))));
    };
    ConfirmationButton.propTypes = propTypes;
    ConfirmationButton.defaultProps = defaultProps;
    return ConfirmationButton;
}(React.Component));
exports.ConfirmationButton = ConfirmationButton;
