var e = require("@babel/runtime/helpers/slicedToArray.js");

module.exports = {
    formatTime: function(e, t) {
        var n = t.getHours() < 10 ? "0" + t.getHours() : t.getHours(), r = t.getMinutes() < 10 ? "0" + t.getMinutes() : t.getMinutes();
        return "full" == e ? t.getFullYear() + "年" + (t.getMonth() + 1) + "月" + t.getDate() + "日" + n + ":" + r : t.getMonth() + 1 + "月" + t.getDate() + "日" + n + ":" + r;
    },
    base64src: function(t) {
        var n = "tmp_base64src_" + new Date().getTime();
        return new Promise(function(r, o) {
            var a = /data:image\/(\w+);base64,(.*)/.exec(t) || [], c = e(a, 3), i = c[1], s = c[2];
            i || o(new Error("ERROR_BASE64SRC_PARSE"));
            var l = "".concat(wx.env.USER_DATA_PATH, "/").concat(n, ".").concat(i), u = wx.base64ToArrayBuffer(s);
            wx.getFileSystemManager().writeFile({
                filePath: l,
                data: u,
                encoding: "binary",
                success: function() {
                    r(l);
                },
                fail: function() {
                    o(new Error("ERROR_BASE64SRC_WRITE"));
                }
            });
        });
    },
    calculateScores: function(e, t, n, r) {
        if (1 == e.length) return {
            averageScore: e[0],
            totalScore: e[0]
        };
        e.sort(function(e, t) {
            return e - t;
        }), e.length > r && e.splice(e.length - r, r), e.length > n && e.splice(0, n);
        for (var o = 0, a = 0, c = 0; c < e.length; c++) o += e[c];
        return e.length > 0 && (a = o / e.length), {
            averageScore: a,
            totalScore: o
        };
    },
    competitionNoExistShowModal: function(e) {
        -1 == e && (wx.hideLoading(), wx.stopPullDownRefresh(), wx.hideShareMenu(), wx.showModal({
            showCancel: !1,
            content: "主办方已删除比赛",
            confirmColor: "#FF5A5F",
            confirmText: "我知道了",
            success: function(e) {
                wx.reLaunch({
                    url: "/pages/index/index"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        }));
    }
};