"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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var Yup = require("yup");
var formik_1 = require("formik");
var httpService_1 = require("../../../../services/httpService");
var react_toastify_1 = require("react-toastify");
var routes_1 = require("../../../../apiClient/routes");
var localStorageService_1 = require("../../../../services/localStorageService");
var ChangePasswordForm = /** @class */ (function (_super) {
    __extends(ChangePasswordForm, _super);
    function ChangePasswordForm() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.handleSubmit = function (data) {
            httpService_1.default.post(routes_1.AccountController_ChangePassword, data, { validateStatus: function (status) { return status <= 400; } }).then(function (response) {
                if (response.status === 200) {
                    react_toastify_1.toast.success('👍 Heslo úspěšně změněno!', {
                        position: "top-right",
                        autoClose: 3000,
                        hideProgressBar: true,
                        closeOnClick: true,
                        pauseOnHover: false,
                        draggable: true,
                        progress: undefined,
                    });
                }
                else if (response.status === 400) {
                    react_toastify_1.toast.error('Něco se nepovedlo!', {
                        position: "top-right",
                        autoClose: 3000,
                        hideProgressBar: true,
                        closeOnClick: true,
                        pauseOnHover: false,
                        draggable: true,
                        progress: undefined,
                    });
                }
            }).catch(function (e) {
                console.log(e);
            });
        };
        return _this;
    }
    ChangePasswordForm.prototype.componentDidMount = function () {
        document.title = "Změna hesla";
        if (!localStorageService_1.IsCustomerLoggedIn) {
            this.props.history.push("/");
        }
    };
    ChangePasswordForm.prototype.render = function () {
        var _this = this;
        var passwordChangeValidationSchema = Yup.object().shape({
            oldPassword: Yup.string().required("Aktuální heslo je vyžadováno!"),
            password: Yup.string().required("Nové heslo je vyžadováno!").min(8, "Minimální délka hesla je 8 znaků!"),
            confirmPassword: Yup.string().required("Potvrzení hesla je vyžadováno!").oneOf([Yup.ref('password'), null], "Hesla musí být stejná!")
        });
        var passwordChangeInitValues = {
            oldPassword: '',
            password: '',
            confirmPassword: ''
        };
        return (React.createElement(React.Fragment, null,
            React.createElement("div", { className: "row" },
                React.createElement("div", { className: "col-lg-3" }),
                React.createElement("div", { className: "col-lg-6" },
                    React.createElement(formik_1.Formik, { initialValues: passwordChangeInitValues, validationSchema: passwordChangeValidationSchema, onSubmit: function (values, _a) {
                            var resetForm = _a.resetForm;
                            _this.handleSubmit(values);
                            resetForm({ values: passwordChangeInitValues });
                        } }, function (_a) {
                        var errors = _a.errors, handleReset = _a.handleReset, handleSubmit = _a.handleSubmit, touched = _a.touched;
                        return (React.createElement(formik_1.Form, { onReset: handleReset, onSubmit: handleSubmit },
                            React.createElement("div", { className: "checkout__input" },
                                React.createElement("p", null,
                                    "Aktu\u00E1ln\u00ED heslo",
                                    React.createElement("span", null, "*")),
                                React.createElement(formik_1.Field, { name: "oldPassword", type: "password", placeholder: "Aktu\u00E1ln\u00ED heslo", className: (touched.oldPassword && errors.oldPassword)
                                        ? 'input__error'
                                        : (touched.oldPassword && !errors.oldPassword ? 'input__success' : '') }),
                                errors && touched.oldPassword && errors.oldPassword && React.createElement(React.Fragment, null,
                                    React.createElement("label", { className: "error-message" }, errors.oldPassword))),
                            React.createElement("div", { className: "checkout__input" },
                                React.createElement("p", null,
                                    "Heslo",
                                    React.createElement("span", null, "*")),
                                React.createElement(formik_1.Field, { name: "password", type: "password", placeholder: "Heslo", className: (touched.password && errors.password)
                                        ? 'input__error'
                                        : (touched.password && !errors.password ? 'input__success' : '') }),
                                errors && touched.password && errors.password && React.createElement(React.Fragment, null,
                                    React.createElement("label", { className: "error-message" }, errors.password))),
                            React.createElement("div", { className: "checkout__input" },
                                React.createElement("p", null,
                                    "Potvrzen\u00ED hesla",
                                    React.createElement("span", null, "*")),
                                React.createElement(formik_1.Field, { name: "confirmPassword", type: "password", placeholder: "Potvrzen\u00ED hesla", className: (touched.confirmPassword && errors.confirmPassword)
                                        ? 'input__error'
                                        : (touched.confirmPassword && !errors.confirmPassword ? 'input__success' : '') }),
                                errors && touched.confirmPassword && errors.confirmPassword && React.createElement(React.Fragment, null,
                                    React.createElement("label", { className: "error-message" }, errors.confirmPassword))),
                            React.createElement("button", { type: "submit", className: "site-btn" }, "Zm\u011Bnit heslo")));
                    })),
                React.createElement("div", { className: "col-lg-3" }))));
    };
    return ChangePasswordForm;
}(React.Component));
exports.default = ChangePasswordForm;
//# sourceMappingURL=ChangePasswordForm.js.map