var t = require("../../../../common/vendor.js"),
  i = require("./i18n/index.js"),
  e = t.initVueI18n(i.messages).t,
  n = {
    name: "UniCountdown",
    emits: ["timeup"],
    props: {
      showDay: { type: Boolean, default: !0 },
      showColon: { type: Boolean, default: !0 },
      start: { type: Boolean, default: !0 },
      backgroundColor: { type: String, default: "" },
      color: { type: String, default: "#333" },
      fontSize: { type: Number, default: 14 },
      splitorColor: { type: String, default: "#333" },
      day: { type: Number, default: 0 },
      hour: { type: Number, default: 0 },
      minute: { type: Number, default: 0 },
      second: { type: Number, default: 0 },
      milliSecond: { type: Number, default: 0 },
      timestamp: { type: Number, default: 0 },
    },
    data: function () {
      return {
        timer: null,
        syncFlag: !1,
        d: "00",
        h: "00",
        i: "00",
        s: "00",
        ms: "00",
        milliSeconds: 0,
      };
    },
    computed: {
      dayText: function () {
        return e("uni-countdown.day");
      },
      hourText: function (t) {
        return e("uni-countdown.h");
      },
      minuteText: function (t) {
        return e("uni-countdown.m");
      },
      secondText: function (t) {
        return e("uni-countdown.s");
      },
      timeStyle: function () {
        var t = this.color,
          i = this.backgroundColor,
          e = this.fontSize;
        return {
          color: t,
          backgroundColor: i,
          fontSize: "".concat(e, "rpx"),
          width: (22 * e) / 14 + "rpx",
          lineHeight: (20 * e) / 14 + "rpx",
          borderRadius: (3 * e) / 14 + "rpx",
        };
      },
      splitorStyle: function () {
        var t = this.splitorColor,
          i = this.fontSize;
        this.backgroundColor;
        return { color: t, fontSize: "".concat(i, "rpx") };
      },
    },
    watch: {
      day: function (t) {
        this.changeFlag();
      },
      hour: function (t) {
        this.changeFlag();
      },
      minute: function (t) {
        this.changeFlag();
      },
      second: function (t) {
        this.changeFlag();
      },
      milliSecond: function (t) {
        this.changeFlag();
      },
      start: {
        immediate: !0,
        handler: function (t, i) {
          if (t) this.startData();
          else {
            if (!i) return;
            clearInterval(this.timer);
          }
        },
      },
    },
    created: function (t) {
      (this.milliSeconds = this.toMilliSeconds(
        this.day,
        this.hour,
        this.minute,
        this.second,
        this.milliSecond
      )),
        this.countDown();
    },
    unmounted: function () {
      clearInterval(this.timer);
    },
    methods: {
      toMilliSeconds: function (t, i, e, n, o) {
        return (
          24 * t * 60 * 60 * 1e3 +
          60 * i * 60 * 1e3 +
          60 * e * 1e3 +
          1e3 * n +
          o
        );
      },
      timeUp: function () {
        clearInterval(this.timer), this.$emit("timeup");
      },
      countDown: function () {
        var t = this.milliSeconds,
          i = 0,
          e = 0,
          n = 0,
          o = 0,
          s = 0;
        t > 0
          ? ((i = Math.floor(t / 864e5)),
            (e = Math.floor(t / 36e5) - 24 * i),
            (n = Math.floor(t / 6e4) - 24 * i * 60 - 60 * e),
            (o = Math.floor(t / 1e3) - 24 * i * 60 * 60 - 60 * e * 60 - 60 * n),
            (s = Math.floor(t) - 24 * i * 60 * 60 - 60 * e * 60 - 60 * n - o))
          : this.timeUp(),
          i < 10 && (i = "0" + i),
          e < 10 && (e = "0" + e),
          n < 10 && (n = "0" + n),
          o < 10 && (o = "0" + o),
          (s = s < 10 ? "0" + s : ((s % 1e3) / 10).toFixed(0)),
          (this.d = i),
          (this.h = e),
          (this.i = n),
          (this.s = o),
          (this.ms = s);
      },
      startData: function () {
        var t = this;
        if (
          ((this.milliSeconds = this.toMilliSeconds(
            this.day,
            this.hour,
            this.minute,
            this.second,
            this.milliSecond
          )),
          this.milliSeconds <= 0)
        )
          return (
            (this.milliSeconds = this.toMilliSeconds(0, 0, 0, 0, 0)),
            void this.countDown()
          );
        clearInterval(this.timer),
          this.countDown(),
          (this.timer = setInterval(function () {
            (t.milliSeconds = t.milliSeconds - 10),
              t.milliSeconds < 0 ? t.timeUp() : t.countDown();
          }, 10));
      },
      update: function () {
        this.startData();
      },
      changeFlag: function () {
        this.syncFlag ||
          ((this.milliSeconds = this.toSeconds(
            this.day,
            this.hour,
            this.minute,
            this.second,
            this.milliSecond
          )),
          this.startData(),
          (this.syncFlag = !0));
      },
    },
  },
  o = t._export_sfc(n, [
    [
      "render",
      function (i, e, n, o, s, r) {
        return {
          a: t.t(s.i),
          b: t.s(r.timeStyle),
          c: t.s(r.splitorStyle),
          d: t.t(s.s),
          e: t.s(r.timeStyle),
          f: t.s(r.splitorStyle),
          g: t.t(s.ms),
          h: t.s(r.timeStyle),
        };
      },
    ],
    ["__scopeId", "data-v-edf646b4"],
  ]);
wx.createComponent(o);
