export default (function (window) {
    var n = window.history.__proto__, o = [], r = -1, a = !1;
    Object.assign(window.history, {
        go: function (e) {
            var t = r + e;
            if (t >= 0 && t <= o.length - 1) {
                var i = o[(r = t)], c = i.url, l = i.state, u = document.location.href;
                n.replaceState.call(window.history, l, '', c);
                var d = document.location.href;
                s(d),
                    window.dispatchEvent(new PopStateEvent('popstate', {
                        state: l,
                    })),
                    -1 !== d.indexOf('#') &&
                        ((a = !0),
                            window.dispatchEvent(new HashChangeEvent('hashchange', {
                                oldURL: u,
                                newURL: d,
                            })));
            }
        },
        back: function () {
            window.history.go(-1);
        },
        forward: function () {
            window.history.go(1);
        },
        pushState: function (e, t, o) {
            n.replaceState.call(window.history, e, t, o),
                i(o, e),
                s(document.location.href);
        },
        replaceState: function (e, t, a) {
            n.replaceState.call(window.history, e, t, a),
                (o[r] = {
                    state: e,
                    url: a,
                }),
                s(document.location.href);
        },
    });
    Object.defineProperties(window.history, {
        length: {
            get: function () {
                return o.length;
            },
        },
        state: {
            get: function () {
                return o[r].state;
            },
        },
    });
    window.addEventListener('hashchange', function () {
        a ? (a = !1) : (i(c(document.location), null), s(document.location.href));
    });
    i(c(document.location), null);
    // setTimeout(function () {
    //   s(document.location.href);
    // });
    function s(e) {
        var payload = {
            type: 'urlchange',
            url: e,
            back: r > 0,
            forward: r < o.length - 1,
        };
        // console.log(payload);
        // t.dispatch(payload);
    }
    function i(e, t) {
        o.splice(r + 1),
            o.push({
                url: e,
                state: t,
            }),
            (r = o.length - 1);
    }
    function c(e) {
        return ''.concat(e.pathname).concat(e.hash);
    }
    return window;
})(global);
//# sourceMappingURL=hisroty-polyfill.js.map