'use strict';

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

var vue = require('vue');
var elementPlus = require('element-plus');
var dayjs = require('dayjs');
var index = require('../../segmented/index.js');

"use strict";
const _hoisted_1 = {
  class: "me-select-date",
  style: {}
};
const _hoisted_2 = { class: "flex flex-col items-center gap-2 p-2" };
const __default__ = vue.defineComponent({
  name: "me-select-date"
});
var script = /* @__PURE__ */ vue.defineComponent({
  ...__default__,
  props: /* @__PURE__ */ vue.mergeModels({
    format: { type: String, required: false, default: "YYYY-MM-DD" },
    options: { type: Array, required: false, default: () => [
      {
        label: "\u4ECA\u65E5",
        value: "\u4ECA\u65E5"
      },
      {
        label: "\u6628\u65E5",
        value: "\u6628\u65E5"
      },
      {
        label: "\u6700\u8FD17\u5929",
        value: "\u6700\u8FD17\u5929"
      },
      {
        label: "\u81EA\u5B9A\u4E49",
        value: "\u81EA\u5B9A\u4E49"
      }
    ] },
    getDate: { type: Function, required: false }
  }, {
    "modelValue": { type: [String, Array] },
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props) {
    const props = __props;
    const model = vue.useModel(__props, "modelValue");
    const options = vue.ref(props.options);
    const segmentValue = vue.ref(options.value[0].value);
    const getDate = (val) => {
      if (val == "\u4ECA\u65E5") {
        model.value = dayjs().format(props.format);
      }
      if (val == "\u6628\u65E5") {
        model.value = dayjs().subtract(1, "day").format(props.format);
      }
      if (val == "\u6700\u8FD17\u5929") {
        model.value = [dayjs().subtract(6, "day").format(props.format), dayjs().format(props.format)];
      }
      if (val == "\u81EA\u5B9A\u4E49") {
        model.value = [];
      }
    };
    vue.watch(
      segmentValue,
      (val) => {
        if (props.getDate) {
          model.value = props.getDate(val);
        } else {
          getDate(val);
        }
      },
      {
        immediate: true
      }
    );
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
        vue.createVNode(vue.unref(index.MeSegmented), {
          modelValue: segmentValue.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => segmentValue.value = $event),
          options: options.value,
          size: "large",
          style: { "margin-right": "10px" }
        }, {
          default: vue.withCtx((scope) => [
            vue.createElementVNode("div", _hoisted_2, [
              vue.createElementVNode(
                "div",
                null,
                vue.toDisplayString(scope.item.label),
                1
                /* TEXT */
              )
            ])
          ]),
          _: 1
          /* STABLE */
        }, 8, ["modelValue", "options"]),
        vue.renderSlot(_ctx.$slots, "date", {}, () => [
          segmentValue.value == "\u4ECA\u65E5" ? (vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElDatePicker), {
            key: 0,
            size: "large",
            type: "date",
            "value-format": props.format,
            modelValue: model.value,
            "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => model.value = $event)
          }, null, 8, ["value-format", "modelValue"])) : vue.createCommentVNode("v-if", true),
          segmentValue.value == "\u6628\u65E5" ? (vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElDatePicker), {
            key: 1,
            size: "large",
            type: "date",
            "value-format": props.format,
            modelValue: model.value,
            "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => model.value = $event)
          }, null, 8, ["value-format", "modelValue"])) : vue.createCommentVNode("v-if", true),
          segmentValue.value == "\u6700\u8FD17\u5929" ? (vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElDatePicker), {
            key: 2,
            size: "large",
            type: "daterange",
            "value-format": props.format,
            modelValue: model.value,
            "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => model.value = $event)
          }, null, 8, ["value-format", "modelValue"])) : vue.createCommentVNode("v-if", true)
        ]),
        segmentValue.value == "\u81EA\u5B9A\u4E49" ? (vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElDatePicker), {
          key: 0,
          style: { "height": "35px", "max-width": "280px", "margin-left": "10px" },
          modelValue: model.value,
          "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => model.value = $event),
          type: "daterange",
          "range-separator": "\u81F3",
          "start-placeholder": "\u5F00\u59CB\u65E5\u671F",
          "end-placeholder": "\u7ED3\u675F\u65E5\u671F",
          "value-format": props.format
        }, null, 8, ["modelValue", "value-format"])) : vue.createCommentVNode("v-if", true)
      ]);
    };
  }
});

exports.default = script;
//# sourceMappingURL=select-date.vue2.js.map
