import { defineComponent, ref, watchEffect, openBlock, createBlock, withCtx, createVNode, unref, mergeProps, createElementBlock, createElementVNode, toDisplayString } from "vue";
import dayjs from "dayjs";
import { DatePicker } from "vant";
import { g as getVantDateValue } from "./index4.js";
import { _ as _sfc_main$2 } from "./index7.js";
import "./index5.js";
import "@wltech/svg";
dayjs().format();
dayjs.locale("zh-cn");
const formatMoment = (val, format) => {
  if (!val)
    return "";
  val = Object.prototype.toString.call(val) === "[object String]" ? val * 1 : val;
  const current_year = dayjs().year();
  const format_year = dayjs(val).year();
  if (["MM-DD", "MM-DD HH:mm:ss"].includes(format) && current_year !== format_year) {
    return dayjs(val).format(`YYYY-${format}`);
  } else {
    return dayjs(val).format(format);
  }
};
const __default__$1 = {
  name: "WlDatePicker"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  ...__default__$1,
  props: {
    modelValue: { type: Boolean, default: false },
    dateValue: { default: () => [] },
    format: { default: "YYYY-MM-DD" },
    title: { default: "" }
  },
  emits: ["onConfrim", "update:modelValue", "update:dateValue"],
  setup(__props, { emit }) {
    const props = __props;
    const popUpVisible = ref(false);
    const data = ref([]);
    const onClose = () => {
      emit("update:modelValue", false);
      popUpVisible.value = false;
    };
    const onConfrim = (val) => {
      emit("update:modelValue", false);
      let timestamp = val.selectedOptions.map((ele) => ele.value).join("/");
      timestamp = new Date(timestamp).getTime();
      const time = formatMoment(timestamp, props.format);
      emit("onConfrim", time);
    };
    watchEffect(() => {
      popUpVisible.value = props.modelValue;
    });
    watchEffect(() => {
      if (props.dateValue instanceof Date) {
        data.value = getVantDateValue(props.dateValue);
      } else {
        data.value = props.dateValue;
      }
    });
    watchEffect(() => {
      emit("update:dateValue", data.value);
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(_sfc_main$2, {
        modelValue: popUpVisible.value,
        "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => popUpVisible.value = $event),
        style: { "height": "300px" },
        headerVisible: false,
        onClose,
        round: ""
      }, {
        default: withCtx(() => [
          createVNode(unref(DatePicker), mergeProps(_ctx.$attrs, {
            modelValue: data.value,
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => data.value = $event),
            title: __props.title,
            type: "date",
            onCancel: onClose,
            onConfirm: onConfrim
          }), null, 16, ["modelValue", "title"])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
});
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1 = {
  class: "rf-date-select-wrap",
  "data-weiling-mobile-ui-rf-date-select-wrap": ""
};
const __default__ = {
  name: "RfDateSelect"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    modelValue: { default: "" },
    format: { default: "YYYY-MM-DD" }
  },
  emits: ["onSelect", "update:modelValue"],
  setup(__props, { emit }) {
    const props = __props;
    const popUpVisible = ref(false);
    const valueText = ref("");
    const defaultSelectTime = ref(new Date());
    const minDate = new Date(1901, 1, 1);
    const maxDate = new Date(new Date().getFullYear() + 10, 12, 31);
    const onClose = () => {
      popUpVisible.value = false;
    };
    const onShow = () => popUpVisible.value = true;
    const onSelect = (date) => {
      emit("onSelect", new Date(date).getTime());
      emit("update:modelValue", new Date(date).getTime());
      onClose();
    };
    watchEffect(() => {
      defaultSelectTime.value = props.modelValue ? new Date(parseInt(props.modelValue + "")) : new Date();
      valueText.value = props.modelValue ? formatMoment(props.modelValue, props.format) : "";
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", {
          class: "rf-date-select",
          onClick: onShow
        }, toDisplayString(valueText.value), 1),
        createVNode(_sfc_main$1, {
          modelValue: popUpVisible.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => popUpVisible.value = $event),
          color: "var(--wl-primary-color)",
          type: "date",
          "min-date": unref(minDate),
          "max-date": unref(maxDate),
          onOnConfrim: onSelect
        }, null, 8, ["modelValue", "min-date", "max-date"])
      ]);
    };
  }
});
export { _sfc_main as default };
