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 * as React from "react";
import * as PropTypes from "prop-types";
import * as classnames from "classnames";
import { Button } from "../Button/Button";
import { ModalButton } from "../ModalButton/ModalButton";
import { propsFor, prefixKeys, unprefixKeys } from "../utils";
import "./ConfirmationButton.less";
var propPrefix = "confirmButton";
var propTypes = __assign(__assign(__assign({}, prefixKeys(Button.propTypes, propPrefix)), ModalButton.propTypes), { className: PropTypes.string, onConfirm: PropTypes.func });
var defaultProps = __assign(__assign(__assign({}, prefixKeys(Button.defaultProps, propPrefix)), 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 = propsFor(ModalButton, this.props);
        var confirmButtonProps = propsFor(Button, unprefixKeys(this.props, propPrefix));
        var wrapperClass = "ConfirmationButton--dialog-buttons";
        return (React.createElement(ModalButton, __assign({}, modalButtonProps, { ref: this.modalButton }),
            this.props.children,
            React.createElement("div", { className: classnames(wrapperClass, this.props.className) },
                React.createElement(Button, { type: "link", value: "Cancel", onClick: this.handleCancel }),
                React.createElement(Button, __assign({}, confirmButtonProps, { onClick: this.handleConfirm })))));
    };
    ConfirmationButton.propTypes = propTypes;
    ConfirmationButton.defaultProps = defaultProps;
    return ConfirmationButton;
}(React.Component));
export { ConfirmationButton };
