! function(a, b) {
    "use strict";
    "function" == typeof define && define.amd ? define("ajax", b) : "object" == typeof exports ? exports = module.exports = b() : a.ajax = b()
}(this, function() {
    "use strict";

    function a(a) {
        var d = ["get", "post", "put", "delete"];
        return a = a || {}, a.baseUrl = a.baseUrl || "", a.method && a.url ? c(a.method, a.baseUrl + a.url, b(a.data), a) : d.reduce(function(d, e) {
            return d[e] = function(d, f) {
                return c(e, a.baseUrl + d, b(f), a)
            }, d
        }, {})
    }

    function b(a) {
        return a || null
    }

    function c(a, b, c, e) {
        var g = ["then", "catch", "always"],
            i = g.reduce(function(a, b) {
                return a[b] = function(c) {
                    return a[b] = c, a
                }, a
            }, {}),
            j = new XMLHttpRequest;
        return j.open(a, b, !0), d(j, e.headers), j.addEventListener("readystatechange", f(i, j), !1), j.send(h(c)), i.abort = function() {
            return j.abort()
        }, i
    }

    function d(a, b) {
        b = b || {}, e(b) || (b["Content-Type"] = "application/x-www-form-urlencoded"), Object.keys(b).forEach(function(c) {
            b[c] && a.setRequestHeader(c, b[c])
        })
    }

    function e(a) {
        return Object.keys(a).some(function(a) {
            return "content-type" === a.toLowerCase()
        })
    }

    function f(a, b) {
        return function c() {
            b.readyState === b.DONE && (b.removeEventListener("readystatechange", c, !1), a.always.apply(a, g(b)), b.status >= 200 && b.status < 300 ? a.then.apply(a, g(b)) : a.catch.apply(a, g(b)))
        }
    }

    function g(a) {
        var b;
        try {
            b = JSON.parse(a.responseText)
        } catch (c) {
            b = a.responseText
        }
        return [b, a]
    }

    function h(a) {
        return i(a) ? j(a) : a
    }

    function i(a) {
        return "[object Object]" === Object.prototype.toString.call(a)
    }

    function j(a) {
        return Object.keys(a).reduce(function(b, c) {
            var d = b ? b + "&" : "";
            return d + k(c) + "=" + k(a[c])
        }, "")
    }

    function k(a) {
        return encodeURIComponent(a)
    }
    return a
});
var iqwerty = iqwerty || {};
iqwerty.toast = function() {
    function a(c, d, f) {
        if (null !== b()) a.prototype.toastQueue.push({
            text: c,
            options: d,
            transitions: f
        });
        else {
            a.prototype.Transitions = f || e;
            var g = d || {};
            g = a.prototype.mergeOptions(a.prototype.DEFAULT_SETTINGS, g), a.prototype.show(c, g), g = null
        }
    }

    function b() {
        return f
    }

    function c(a) {
        f = a
    }
    var d = 400,
        e = {
            SHOW: {
                "-webkit-transition": "opacity " + d + "ms, -webkit-transform " + d + "ms",
                transition: "opacity " + d + "ms, transform " + d + "ms",
                opacity: "1",
                "-webkit-transform": "translateY(-100%) translateZ(0)",
                transform: "translateY(-100%) translateZ(0)"
            },
            HIDE: {
                opacity: "0",
                "-webkit-transform": "translateY(150%) translateZ(0)",
                transform: "translateY(150%) translateZ(0)"
            }
        },
        f = null;
    return a.prototype.DEFAULT_SETTINGS = {
        style: {
            main: {
                background: "rgba(0, 0, 0, .85)",
                "box-shadow": "0 0 10px rgba(0, 0, 0, .8)",
                "border-radius": "3px",
                "z-index": "99999",
                color: "rgba(255, 255, 255, .9)",
                padding: "10px 15px",
                "max-width": "60%",
                width: "100%",
                "word-break": "keep-all",
                margin: "0 auto",
                "text-align": "center",
                position: "fixed",
                left: "0",
                right: "0",
                bottom: "0",
                "-webkit-transform": "translateY(150%) translateZ(0)",
                transform: "translateY(150%) translateZ(0)",
                "-webkit-filter": "blur(0)",
                opacity: "0"
            }
        },
        settings: {
            duration: 4e3
        }
    }, a.prototype.Transitions = {}, a.prototype.toastQueue = [], a.prototype.timeout = null, a.prototype.mergeOptions = function(b, c) {
        var d = c;
        for (var e in b) d.hasOwnProperty(e) ? null !== b[e] && b[e].constructor === Object && (d[e] = a.prototype.mergeOptions(b[e], d[e])) : d[e] = b[e];
        return d
    }, a.prototype.generate = function(d, e) {
        var f = document.createElement("div");
        "string" == typeof d && (d = document.createTextNode(d)), f.appendChild(d), c(f), f = null, a.prototype.stylize(b(), e)
    }, a.prototype.stylize = function(a, b) {
        Object.keys(b).forEach(function(c) {
            a.style[c] = b[c]
        })
    }, a.prototype.show = function(c, d) {
        this.generate(c, d.style.main);
        var e = b();
        document.body.insertBefore(e, document.body.firstChild), e.offsetHeight, a.prototype.stylize(e, a.prototype.Transitions.SHOW), e = null, clearTimeout(a.prototype.timeout), a.prototype.timeout = setTimeout(a.prototype.hide, d.settings.duration)
    }, a.prototype.hide = function() {
        var c = b();
        a.prototype.stylize(c, a.prototype.Transitions.HIDE), clearTimeout(a.prototype.timeout), c.addEventListener("transitionend", a.prototype.animationListener), c = null
    }, a.prototype.animationListener = function() {
        b().removeEventListener("transitionend", a.prototype.animationListener), a.prototype.destroy.call(this)
    }, a.prototype.destroy = function() {
        var d = b();
        if (document.body.removeChild(d), d = null, c(null), a.prototype.toastQueue.length > 0) {
            var e = a.prototype.toastQueue.shift();
            a(e.text, e.options, e.transitions), e = null
        }
    }, {
        Toast: a
    }
}(), "undefined" != typeof module && (module.exports = iqwerty.toast);
var Login = function() {
    function a(a) {
        this.email = a.email, this.password = a.password, this.btn = a.btn, this.url = a.url, this.successUrl = a.successUrl, this.mode = a.mode, this.init()
    }
    return a.prototype.urlDef = "/login", a.prototype.urlAfterLogin = "/home", a.prototype.modeDef = "toast", a.prototype.init = function() {
        this.checkProperty(this.email) && this.checkProperty(this.password) && this.checkProperty(this.btn) ? this.doLogin(this) : console.log("Login Ajax miss one prams ...")
    }, a.prototype.doLogin = function(a) {
        a.addEventListener(a.btn, "click", function() {
            a.empty(a.getVal(a.email)) === !0 && a.empty(a.getVal(a.password)) === !0 ? a.ajax(a) : a.showErrors("Please fill all fields")
        })
    }, a.prototype.ajax = function(a) {
        ajax().post(this.getUrl(), this.info()).then(function(b, xhr) {
            console.log(xhr);
            if(xhr.status == 419){
                a.showErrors("Ваш токен устарел. Обновите страницу и попробуйте еще раз");
                return false;
            }
            b === !0 ? a.doneLogin() : a.errorLogin(b)
        }, function(b, xhr) {
            console.log(xhr);
            a.showErrors("There is server Error refresh the page ..")
        })
    }, a.prototype.doneLogin = function() {
        var a = this.checkProperty(this.successUrl) === !1 ? this.urlAfterLogin : this.successUrl;
        return window.location = a
    }, a.prototype.errorLogin = function(a) {
        var b = this.checkProperty(a.password) ? a.password : "",
            c = this.checkProperty(a.email) ? a.email : " ";
        this.showErrors(c + b)
    }, a.prototype.addEventListener = function(a, b, c) {
        this.getById(a).addEventListener(b, function(a) {
            a.preventDefault(), c()
        })
    }, a.prototype.info = function() {
        return {
            email: this.getVal(this.email),
            password: this.getVal(this.password),
            _token: this.getToken(),
            remember: this.getByName("remember")[0].value
        }
    }, a.prototype.getById = function(a) {
        return document.getElementById(a)
    }, a.prototype.getVal = function(a) {
        return this.getById(a).value
    }, a.prototype.setVal = function(a, b) {
        return this.getById(a).value = b
    }, a.prototype.checkProperty = function(a) {
        return void 0 !== a && null != a
    }, a.prototype.empty = function(a) {
        return "" != a
    }, a.prototype.getUrl = function() {
        return this.checkProperty(this.url) ? this.url : this.urlDef
    }, a.prototype.getMode = function() {
        return this.checkProperty(this.mode) ? this.mode : this.modeDef
    }, a.prototype.getToken = function() {
        return this.getByName("_token")[0].value
    }, a.prototype.getByName = function(a) {
        return document.getElementsByName(a)
    }, a.prototype.showToast = function(a) {
        new iqwerty.toast.Toast(a)
    }, a.prototype.showErrors = function(a) {
        "toast" == this.getMode() ? this.showToast(a) : alert(a)
    }, a
}();