'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../../utils/index.js');
var core = require('@vueuse/core');
var antDesignVue = require('ant-design-vue');
var CronParser = require('cron-parser');
require('../config/index.js');
var dayUi = require('./tabs/day-ui.vue.js');
var hourUi = require('./tabs/hour-ui.vue.js');
var minuteUi = require('./tabs/minute-ui.vue.js');
var monthUi = require('./tabs/month-ui.vue.js');
var secondUi = require('./tabs/second-ui.vue.js');
var weekUi = require('./tabs/week-ui.vue.js');
var yearUi = require('./tabs/year-ui.vue.js');
var createNamespace = require('../../../../utils/create-namespace.js');
var dateUtils = require('../config/date-utils.js');
var cronExpressionBuilder = require('../config/cron-expression-builder.js');

"use strict";
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{ name: "CronInner" },
  __name: "cron-inner",
  props: cronExpressionBuilder.cronExpressionBuilderProps,
  emits: cronExpressionBuilder.cronExpressionBuilderEmits,
  setup(__props, { emit: __emit }) {
    const bem = createNamespace.createNamespace("cron-inner");
    const props = __props;
    const emits = __emit;
    const activeKey = vue.ref(props.hideSecond ? "minute" : "second");
    const second = vue.ref("*");
    const minute = vue.ref("*");
    const hour = vue.ref("*");
    const day = vue.ref("*");
    const month = vue.ref("*");
    const week = vue.ref("?");
    const year = vue.ref("*");
    const inputValues = vue.reactive({
      second: "",
      minute: "",
      hour: "",
      day: "",
      month: "",
      week: "",
      year: "",
      cron: ""
    });
    const preTimeList = vue.ref("\u6267\u884C\u9884\u89C8\uFF0C\u4F1A\u5FFD\u7565\u5E74\u4EFD\u53C2\u6570\u3002");
    const cronValueInner = vue.computed(() => {
      const result = [];
      if (!props.hideSecond) {
        result.push(second.value ? second.value : "*");
      }
      result.push(minute.value ? minute.value : "*");
      result.push(hour.value ? hour.value : "*");
      result.push(day.value ? day.value : "*");
      result.push(month.value ? month.value : "*");
      result.push(week.value ? week.value : "?");
      if (!props.hideYear && !props.hideSecond)
        result.push(year.value ? year.value : "*");
      return result.join(" ");
    });
    const cronValueNoYear = vue.computed(() => {
      const v = cronValueInner.value;
      if (props.hideYear || props.hideSecond) return v;
      const vs = v.split(" ");
      if (vs.length >= 6) {
        vs[5] = convertWeekToQuartz(vs[5]);
      }
      return vs.slice(0, vs.length - 1).join(" ");
    });
    const calTriggerList = core.useDebounceFn(calTriggerListInner, 500);
    vue.watch(
      () => props.value,
      (newVal) => {
        if (newVal === cronValueInner.value) {
          return;
        }
        formatValue();
      },
      { immediate: true }
    );
    vue.watch(cronValueInner, (newValue) => {
      calTriggerList();
      emitValue(newValue);
      assignInput();
    });
    assignInput();
    formatValue();
    calTriggerListInner();
    function assignInput() {
      inputValues.second = second.value;
      inputValues.minute = minute.value;
      inputValues.hour = hour.value;
      inputValues.day = day.value;
      inputValues.month = month.value;
      inputValues.week = week.value;
      inputValues.year = year.value;
      inputValues.cron = cronValueInner.value;
      if (!props.value) emitValue(inputValues.cron);
    }
    function formatValue() {
      if (!props.value) return;
      const values = props.value.split(" ").filter((item) => !!item);
      if (!values || values.length <= 0) return;
      let i = 0;
      if (!props.hideSecond) second.value = values[i++];
      if (values.length > i) minute.value = values[i++];
      if (values.length > i) hour.value = values[i++];
      if (values.length > i) day.value = values[i++];
      if (values.length > i) month.value = values[i++];
      if (values.length > i) week.value = values[i++];
      if (values.length > i) year.value = values[i];
      assignInput();
    }
    function convertWeekToQuartz(week2) {
      const convert = (v) => {
        if (v === "0") {
          return "1";
        }
        if (v === "1") {
          return "0";
        }
        return (Number.parseInt(v) - 1).toString();
      };
      const patten1 = /^([0-7])([-/])([0-7])$/;
      const patten2 = /^([0-7])(,[0-7])+$/;
      if (/^[0-7]$/.test(week2)) {
        return convert(week2);
      } else if (patten1.test(week2)) {
        return week2.replace(patten1, (_$0, before, separator, after) => {
          if (separator === "/") {
            return convert(before) + separator + after;
          } else {
            return convert(before) + separator + convert(after);
          }
        });
      } else if (patten2.test(week2)) {
        return week2.split(",").map((v) => convert(v)).join(",");
      }
      return week2;
    }
    function calTriggerListInner() {
      if (props.remote) {
        props.remote(cronValueInner.value, +/* @__PURE__ */ new Date(), (v) => {
          preTimeList.value = v;
        });
        return;
      }
      const options = {
        currentDate: dateUtils.formatToDateTime(/* @__PURE__ */ new Date())
      };
      const iter = CronParser.parseExpression(cronValueNoYear.value, options);
      const result = [];
      for (let i = 1; i <= 10; i++) {
        result.push(dateUtils.formatToDateTime(new Date(iter.next())));
      }
      preTimeList.value = result.length > 0 ? result.join("\n") : "\u65E0\u6267\u884C\u65F6\u95F4";
    }
    function onInputBlur() {
      second.value = inputValues.second;
      minute.value = inputValues.minute;
      hour.value = inputValues.hour;
      day.value = inputValues.day;
      month.value = inputValues.month;
      week.value = inputValues.week;
      year.value = inputValues.year;
    }
    function onInputCronBlur(event) {
      emitValue(event.target.value);
    }
    function emitValue(value) {
      emits("change", value);
      emits("update:value", value);
    }
    return (_ctx, _cache) => {
      const _component_ll_input = vue.resolveComponent("ll-input");
      const _component_ll_tooltip = vue.resolveComponent("ll-tooltip");
      const _component_ll_textarea = vue.resolveComponent("ll-textarea");
      return vue.openBlock(), vue.createElementBlock(
        "div",
        {
          class: vue.normalizeClass(vue.unref(bem).b())
        },
        [
          vue.createElementVNode(
            "div",
            {
              class: vue.normalizeClass(vue.unref(bem).e("content"))
            },
            [
              vue.createVNode(vue.unref(antDesignVue.Tabs), {
                "active-key": activeKey.value,
                "onUpdate:activeKey": _cache[7] || (_cache[7] = ($event) => activeKey.value = $event),
                class: vue.normalizeClass(vue.unref(bem).m("cron-list")),
                size: "small",
                type: "card",
                "tab-bar-gutter": 0
              }, {
                default: vue.withCtx(() => [
                  !_ctx.hideSecond ? (vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.TabPane), {
                    key: "second",
                    tab: "\u79D2"
                  }, {
                    default: vue.withCtx(() => [
                      vue.createVNode(secondUi.default, {
                        value: second.value,
                        "onUpdate:value": _cache[0] || (_cache[0] = ($event) => second.value = $event),
                        disabled: _ctx.disabled
                      }, null, 8, ["value", "disabled"])
                    ]),
                    _: 1
                    /* STABLE */
                  })) : vue.createCommentVNode("v-if", true),
                  vue.createVNode(vue.unref(antDesignVue.TabPane), {
                    key: "minute",
                    tab: "\u5206"
                  }, {
                    default: vue.withCtx(() => [
                      vue.createVNode(minuteUi.default, {
                        value: minute.value,
                        "onUpdate:value": _cache[1] || (_cache[1] = ($event) => minute.value = $event),
                        disabled: _ctx.disabled
                      }, null, 8, ["value", "disabled"])
                    ]),
                    _: 1
                    /* STABLE */
                  }),
                  vue.createVNode(vue.unref(antDesignVue.TabPane), {
                    key: "hour",
                    tab: "\u65F6"
                  }, {
                    default: vue.withCtx(() => [
                      vue.createVNode(hourUi.default, {
                        value: hour.value,
                        "onUpdate:value": _cache[2] || (_cache[2] = ($event) => hour.value = $event),
                        disabled: _ctx.disabled
                      }, null, 8, ["value", "disabled"])
                    ]),
                    _: 1
                    /* STABLE */
                  }),
                  vue.createVNode(vue.unref(antDesignVue.TabPane), {
                    key: "day",
                    tab: "\u65E5"
                  }, {
                    default: vue.withCtx(() => [
                      vue.createVNode(dayUi.default, {
                        value: day.value,
                        "onUpdate:value": _cache[3] || (_cache[3] = ($event) => day.value = $event),
                        week: week.value,
                        disabled: _ctx.disabled
                      }, null, 8, ["value", "week", "disabled"])
                    ]),
                    _: 1
                    /* STABLE */
                  }),
                  vue.createVNode(vue.unref(antDesignVue.TabPane), {
                    key: "month",
                    tab: "\u6708"
                  }, {
                    default: vue.withCtx(() => [
                      vue.createVNode(monthUi.default, {
                        value: month.value,
                        "onUpdate:value": _cache[4] || (_cache[4] = ($event) => month.value = $event),
                        disabled: _ctx.disabled
                      }, null, 8, ["value", "disabled"])
                    ]),
                    _: 1
                    /* STABLE */
                  }),
                  vue.createVNode(vue.unref(antDesignVue.TabPane), {
                    key: "week",
                    tab: "\u5468"
                  }, {
                    default: vue.withCtx(() => [
                      vue.createVNode(weekUi.default, {
                        value: week.value,
                        "onUpdate:value": _cache[5] || (_cache[5] = ($event) => week.value = $event),
                        day: day.value,
                        disabled: _ctx.disabled
                      }, null, 8, ["value", "day", "disabled"])
                    ]),
                    _: 1
                    /* STABLE */
                  }),
                  !_ctx.hideYear && !_ctx.hideSecond ? (vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.TabPane), {
                    key: "year",
                    tab: "\u5E74"
                  }, {
                    default: vue.withCtx(() => [
                      vue.createVNode(yearUi.default, {
                        value: year.value,
                        "onUpdate:value": _cache[6] || (_cache[6] = ($event) => year.value = $event),
                        disabled: _ctx.disabled
                      }, null, 8, ["value", "disabled"])
                    ]),
                    _: 1
                    /* STABLE */
                  })) : vue.createCommentVNode("v-if", true)
                ]),
                _: 1
                /* STABLE */
              }, 8, ["active-key", "class"]),
              _cache[24] || (_cache[24] = vue.createElementVNode(
                "div",
                { style: { "margin-bottom": "14px" } },
                "\u7ED3\u679C",
                -1
                /* CACHED */
              )),
              vue.createCommentVNode(" \u6267\u884C\u65F6\u95F4\u9884\u89C8 "),
              vue.createElementVNode(
                "div",
                {
                  class: vue.normalizeClass(vue.unref(bem).m("cron-result"))
                },
                [
                  vue.createVNode(vue.unref(antDesignVue.Row), { gutter: 8 }, {
                    default: vue.withCtx(() => [
                      vue.createVNode(vue.unref(antDesignVue.Col), { span: 24 }, {
                        default: vue.withCtx(() => [
                          vue.createVNode(vue.unref(antDesignVue.Row), { gutter: 8 }, {
                            default: vue.withCtx(() => [
                              vue.createVNode(vue.unref(antDesignVue.Col), {
                                span: 24,
                                class: vue.normalizeClass(vue.unref(bem).m("time-list"))
                              }, {
                                default: vue.withCtx(() => [
                                  !_ctx.hideSecond ? (vue.openBlock(), vue.createBlock(_component_ll_input, {
                                    key: 0,
                                    value: inputValues.second,
                                    "onUpdate:value": _cache[9] || (_cache[9] = ($event) => inputValues.second = $event),
                                    "allow-clear": false,
                                    onBlur: onInputBlur
                                  }, {
                                    addonBefore: vue.withCtx(() => [
                                      vue.createElementVNode(
                                        "span",
                                        {
                                          class: vue.normalizeClass(vue.unref(bem).m("allow-click")),
                                          onClick: _cache[8] || (_cache[8] = ($event) => activeKey.value = "second")
                                        },
                                        " \u79D2 ",
                                        2
                                        /* CLASS */
                                      )
                                    ]),
                                    _: 1
                                    /* STABLE */
                                  }, 8, ["value"])) : vue.createCommentVNode("v-if", true),
                                  vue.createVNode(_component_ll_input, {
                                    value: inputValues.minute,
                                    "onUpdate:value": _cache[11] || (_cache[11] = ($event) => inputValues.minute = $event),
                                    "allow-clear": false,
                                    onBlur: onInputBlur
                                  }, {
                                    addonBefore: vue.withCtx(() => [
                                      vue.createElementVNode(
                                        "span",
                                        {
                                          class: vue.normalizeClass(vue.unref(bem).m("allow-click")),
                                          onClick: _cache[10] || (_cache[10] = ($event) => activeKey.value = "minute")
                                        },
                                        " \u5206 ",
                                        2
                                        /* CLASS */
                                      )
                                    ]),
                                    _: 1
                                    /* STABLE */
                                  }, 8, ["value"]),
                                  vue.createVNode(_component_ll_input, {
                                    value: inputValues.hour,
                                    "onUpdate:value": _cache[13] || (_cache[13] = ($event) => inputValues.hour = $event),
                                    "allow-clear": false,
                                    onBlur: onInputBlur
                                  }, {
                                    addonBefore: vue.withCtx(() => [
                                      vue.createElementVNode(
                                        "span",
                                        {
                                          class: vue.normalizeClass(vue.unref(bem).m("allow-click")),
                                          onClick: _cache[12] || (_cache[12] = ($event) => activeKey.value = "hour")
                                        },
                                        " \u65F6 ",
                                        2
                                        /* CLASS */
                                      )
                                    ]),
                                    _: 1
                                    /* STABLE */
                                  }, 8, ["value"]),
                                  vue.createVNode(_component_ll_input, {
                                    value: inputValues.day,
                                    "onUpdate:value": _cache[15] || (_cache[15] = ($event) => inputValues.day = $event),
                                    "allow-clear": false,
                                    onBlur: onInputBlur
                                  }, {
                                    addonBefore: vue.withCtx(() => [
                                      vue.createElementVNode(
                                        "span",
                                        {
                                          class: vue.normalizeClass(vue.unref(bem).m("allow-click")),
                                          onClick: _cache[14] || (_cache[14] = ($event) => activeKey.value = "day")
                                        },
                                        " \u65E5 ",
                                        2
                                        /* CLASS */
                                      )
                                    ]),
                                    _: 1
                                    /* STABLE */
                                  }, 8, ["value"]),
                                  vue.createVNode(_component_ll_input, {
                                    value: inputValues.month,
                                    "onUpdate:value": _cache[17] || (_cache[17] = ($event) => inputValues.month = $event),
                                    "allow-clear": false,
                                    onBlur: onInputBlur
                                  }, {
                                    addonBefore: vue.withCtx(() => [
                                      vue.createElementVNode(
                                        "span",
                                        {
                                          class: vue.normalizeClass(vue.unref(bem).m("allow-click")),
                                          onClick: _cache[16] || (_cache[16] = ($event) => activeKey.value = "month")
                                        },
                                        " \u6708 ",
                                        2
                                        /* CLASS */
                                      )
                                    ]),
                                    _: 1
                                    /* STABLE */
                                  }, 8, ["value"]),
                                  vue.createVNode(_component_ll_input, {
                                    value: inputValues.week,
                                    "onUpdate:value": _cache[19] || (_cache[19] = ($event) => inputValues.week = $event),
                                    "allow-clear": false,
                                    onBlur: onInputBlur
                                  }, {
                                    addonBefore: vue.withCtx(() => [
                                      vue.createElementVNode(
                                        "span",
                                        {
                                          class: vue.normalizeClass(vue.unref(bem).m("allow-click")),
                                          onClick: _cache[18] || (_cache[18] = ($event) => activeKey.value = "week")
                                        },
                                        " \u5468 ",
                                        2
                                        /* CLASS */
                                      )
                                    ]),
                                    _: 1
                                    /* STABLE */
                                  }, 8, ["value"]),
                                  !_ctx.hideYear && !_ctx.hideSecond ? (vue.openBlock(), vue.createBlock(_component_ll_input, {
                                    key: 1,
                                    value: inputValues.year,
                                    "onUpdate:value": _cache[21] || (_cache[21] = ($event) => inputValues.year = $event),
                                    "allow-clear": false,
                                    onBlur: onInputBlur
                                  }, {
                                    addonBefore: vue.withCtx(() => [
                                      vue.createElementVNode(
                                        "span",
                                        {
                                          class: vue.normalizeClass(vue.unref(bem).m("allow-click")),
                                          onClick: _cache[20] || (_cache[20] = ($event) => activeKey.value = "year")
                                        },
                                        " \u5E74 ",
                                        2
                                        /* CLASS */
                                      )
                                    ]),
                                    _: 1
                                    /* STABLE */
                                  }, 8, ["value"])) : vue.createCommentVNode("v-if", true)
                                ]),
                                _: 1
                                /* STABLE */
                              }, 8, ["class"]),
                              vue.createVNode(vue.unref(antDesignVue.Col), {
                                span: 24,
                                class: vue.normalizeClass(vue.unref(bem).e("time-result-list"))
                              }, {
                                default: vue.withCtx(() => [
                                  vue.createVNode(_component_ll_input, {
                                    value: inputValues.cron,
                                    "onUpdate:value": _cache[22] || (_cache[22] = ($event) => inputValues.cron = $event),
                                    "allow-clear": false,
                                    onBlur: onInputCronBlur
                                  }, {
                                    addonBefore: vue.withCtx(() => [
                                      vue.createVNode(_component_ll_tooltip, { tip: "Cron\u8868\u8FBE\u5F0F" }, {
                                        default: vue.withCtx(() => [
                                          vue.createElementVNode(
                                            "span",
                                            {
                                              class: vue.normalizeClass(vue.unref(bem).m("addon-before"))
                                            },
                                            " Cron\u8868\u8FBE\u5F0F ",
                                            2
                                            /* CLASS */
                                          )
                                        ]),
                                        _: 1
                                        /* STABLE */
                                      })
                                    ]),
                                    _: 1
                                    /* STABLE */
                                  }, 8, ["value"])
                                ]),
                                _: 1
                                /* STABLE */
                              }, 8, ["class"])
                            ]),
                            _: 1
                            /* STABLE */
                          })
                        ]),
                        _: 1
                        /* STABLE */
                      })
                    ]),
                    _: 1
                    /* STABLE */
                  }),
                  vue.createVNode(vue.unref(antDesignVue.Row), { style: { "margin-top": "20px", "width": "830px" } }, {
                    default: vue.withCtx(() => [
                      vue.createVNode(vue.unref(antDesignVue.Col), { span: 24 }, {
                        default: vue.withCtx(() => [
                          _cache[23] || (_cache[23] = vue.createElementVNode(
                            "div",
                            { style: { "margin-bottom": "8px" } },
                            "\u8FD1\u5341\u6B21\u6267\u884C\u65F6\u95F4\uFF08\u4E0D\u542B\u5E74\uFF09",
                            -1
                            /* CACHED */
                          )),
                          vue.createVNode(_component_ll_textarea, {
                            value: preTimeList.value,
                            rows: 3
                          }, null, 8, ["value"])
                        ]),
                        _: 1
                        /* STABLE */
                      })
                    ]),
                    _: 1
                    /* STABLE */
                  })
                ],
                2
                /* CLASS */
              )
            ],
            2
            /* CLASS */
          )
        ],
        2
        /* CLASS */
      );
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=cron-inner.vue2.js.map
