import { defineComponent, openBlock, createBlock, unref, createElementBlock, normalizeClass, createElementVNode, renderSlot, withDirectives, createVNode, vShow, createTextVNode, toDisplayString, ref, computed, watchEffect, mergeProps, withCtx, createCommentVNode, withModifiers, pushScopeId, popScopeId } from "vue";
import WlSvg from "@wltech/svg";
import dayjs from "dayjs";
import { Popup, DatePicker } from "vant";
const __default__$4 = {
  name: "WlSvgIcon"
};
const _sfc_main$4 = /* @__PURE__ */ defineComponent({
  ...__default__$4,
  props: {
    type: { default: "" },
    color: { default: "var(--wl-text-color-title-1)" },
    width: { default: "16" },
    height: { default: "16" }
  },
  setup(__props) {
    const sub = location.origin;
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(WlSvg), {
        type: __props.type,
        width: __props.width,
        height: __props.height,
        color: __props.color,
        sub: unref(sub)
      }, null, 8, ["type", "width", "height", "color", "sub"]);
    };
  }
});
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 getVantDateValue = (time) => {
  time = time instanceof Date ? time : new Date(parseInt(time));
  return [
    time.getFullYear(),
    `${time.getMonth() + 1 > 9 ? "" : "0"}${time.getMonth() + 1}`,
    `${time.getDate() + 1 > 9 ? "" : "0"}${time.getDate() + 1}`
  ];
};
const _hoisted_1$2 = { class: "z-2 flex uno-min-w-44 uno-max-w-88" };
const _hoisted_2$2 = { class: "uno-elli-1 z-1 box-border flex-middle-center absolute text-center uno-l-44 uno-r-44" };
const _hoisted_3 = { class: "relative z-2 flex-middle-center uno-min-w-44" };
const __default__$3 = {
  name: "WlHeader"
};
const _sfc_main$3 = /* @__PURE__ */ defineComponent({
  ...__default__$3,
  props: {
    title: { default: "" },
    showBack: { type: Boolean, default: false },
    showClose: { type: Boolean, default: false },
    needAutoBack: { type: Boolean, default: true },
    needBottomBorder: { type: Boolean, default: false }
  },
  emits: ["onBack", "onClose"],
  setup(__props, { emit }) {
    const props = __props;
    const onBackPage = () => {
      if (props.needAutoBack) {
        history.back();
      } else {
        emit("onBack");
      }
    };
    const onClose = () => {
      emit("onClose");
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        class: normalizeClass(`uno-fs-16 uno-h-44 relative font-medium box-border text-base-color bg-white flex-between ${__props.needBottomBorder ? "border-bottom" : " "}`)
      }, [
        createElementVNode("div", _hoisted_1$2, [
          renderSlot(_ctx.$slots, "header_part_left", {}, () => [
            withDirectives(createElementVNode("div", {
              class: "box-content flex-middle-center cursor-pointer uno-h-44 uno-w-44",
              onClick: onBackPage
            }, [
              createVNode(_sfc_main$4, {
                type: "arrowTipLeft",
                width: "22",
                height: "22",
                color: "#000"
              })
            ], 512), [
              [vShow, __props.showBack]
            ])
          ])
        ]),
        createElementVNode("div", _hoisted_2$2, [
          renderSlot(_ctx.$slots, "default", {}, () => [
            createTextVNode(toDisplayString(__props.title), 1)
          ])
        ]),
        createElementVNode("div", _hoisted_3, [
          renderSlot(_ctx.$slots, "header_part_right", {}, () => [
            withDirectives(createElementVNode("div", {
              class: "box-content flex-middle-center cursor-pointer uno-h-44 uno-w-44",
              onClick: onClose
            }, [
              createVNode(_sfc_main$4, {
                type: "close",
                width: "22",
                height: "22",
                color: "#000"
              })
            ], 512), [
              [vShow, __props.showClose]
            ])
          ])
        ])
      ], 2);
    };
  }
});
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1$1 = {
  class: "popup-wrap",
  "data-weiling-mobile-ui-wl-popup": ""
};
const _hoisted_2$1 = { class: "popup-content" };
const __default__$2 = {
  name: "WlPopup"
};
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
  ...__default__$2,
  props: {
    modelValue: { type: Boolean, default: false },
    teleport: { default: "body" },
    position: { default: "bottom" },
    headerVisible: { type: Boolean, default: false },
    title: { default: "" },
    showRightClose: { type: Boolean, default: true },
    showBack: { type: Boolean, default: false },
    needAutoBack: { type: Boolean, default: true }
  },
  emits: ["update:modelValue", "onClose", "onBack"],
  setup(__props, { emit }) {
    const props = __props;
    const popUpVisible = ref(false);
    const popupStyle = computed(() => {
      return {
        height: "70%"
      };
    });
    const onClose = () => {
      emit("update:modelValue", false);
      emit("onClose");
    };
    const onOpen = () => {
      emit("update:modelValue", true);
    };
    const onBack = () => {
      emit("onBack");
    };
    watchEffect(() => {
      popUpVisible.value = props.modelValue;
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(Popup), mergeProps({
        show: popUpVisible.value,
        "onUpdate:show": _cache[0] || (_cache[0] = ($event) => popUpVisible.value = $event),
        teleport: __props.teleport,
        position: __props.position,
        "close-on-popstate": true,
        style: unref(popupStyle)
      }, _ctx.$attrs, {
        onClose,
        onOpen
      }), {
        default: withCtx(() => [
          createElementVNode("div", _hoisted_1$1, [
            __props.headerVisible ? (openBlock(), createBlock(_sfc_main$3, {
              key: 0,
              title: __props.title,
              showClose: __props.showRightClose,
              onOnClose: onClose,
              onOnBack: onBack,
              showBack: __props.showBack,
              needAutoBack: __props.needAutoBack
            }, {
              header_part_left: withCtx(() => [
                renderSlot(_ctx.$slots, "header_part_left")
              ]),
              _: 3
            }, 8, ["title", "showClose", "showBack", "needAutoBack"])) : createCommentVNode("", true),
            createElementVNode("div", _hoisted_2$1, [
              renderSlot(_ctx.$slots, "default")
            ])
          ])
        ]),
        _: 3
      }, 16, ["show", "teleport", "position", "style"]);
    };
  }
});
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_scoped_true_lang = "";
var _export_sfc = (sfc, props) => {
  const target = sfc.__vccOpts || sfc;
  for (const [key, val] of props) {
    target[key] = val;
  }
  return target;
};
const _withScopeId = (n) => (pushScopeId("data-v-414e6113"), n = n(), popScopeId(), n);
const _hoisted_1 = {
  class: "wl-date-range",
  "weiling-mobile-ui-wl-date-range": ""
};
const _hoisted_2 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("p", { class: "space" }, "-", -1));
const __default__ = {
  name: "WlDateRange"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    min_date: { default: "" },
    max_date: { default: "" },
    start_date: { default: "" },
    end_date: { default: "" },
    clearable: { type: Boolean, default: true }
  },
  emits: ["update:start_date", "update:end_date", "onSelect"],
  setup(__props, { emit }) {
    const props = __props;
    const currentTime = new Date().getTime();
    const minDate = computed(() => {
      const t = props.min_date || currentTime - 1e3 * 60 * 60 * 24 * 365 * 10;
      return new Date(parseInt(t));
    });
    const maxDate = computed(() => {
      const t = props.max_date || currentTime + 1e3 * 60 * 60 * 24 * 365 * 10;
      return new Date(parseInt(t));
    });
    const selectd_start_date = ref(""), selectd_end_date = ref("");
    const dateVisbile = ref(false);
    const dateDefaultVal = ref([]);
    const date_text = computed(() => {
      return function(date, type) {
        if (type === "start") {
          return formatMoment(parseInt(date || props.min_date), "YYYY-MM-DD");
        } else {
          return formatMoment(parseInt(date || props.max_date), "YYYY-MM-DD");
        }
      };
    });
    const getResTime = () => {
      return {
        start_date: selectd_start_date.value || minDate.value.getTime(),
        end_date: selectd_end_date.value || maxDate.value.getTime()
      };
    };
    const onClear = (type) => {
      let { start_date, end_date } = getResTime();
      if (type === "start") {
        emit("update:start_date", "");
        start_date = minDate.value.getTime();
      } else {
        emit("update:end_date", "");
        end_date = maxDate.value.getTime();
      }
      emit("onSelect", { start_date, end_date });
    };
    let select_time_type = "";
    const onOpenSelect = (type) => {
      select_time_type = type;
      let time = type === "start" ? getResTime().start_date : getResTime().end_date;
      if (time) {
        time = new Date(parseInt(time));
        dateDefaultVal.value = [
          time.getFullYear() + "",
          `${time.getMonth() + 1 > 9 ? "" : "0"}${time.getMonth() + 1}`,
          time.getDate() + ""
        ];
      } else {
        dateDefaultVal.value = [];
      }
      dateVisbile.value = true;
    };
    const getStartTime = (timestamp) => {
      const time = new Date(Number(timestamp));
      if (time.getHours() === 0 && time.getMinutes() === 0) {
        return timestamp;
      } else {
        return new Date(
          `${time.getFullYear()}/${time.getMonth() + 1}/${time.getDate()} 00:00:00`
        ).getTime();
      }
    };
    const getEndTime = (timestamp) => {
      const time = new Date(Number(timestamp));
      if (time.getHours() === 23 && time.getMinutes() === 59) {
        return timestamp;
      } else {
        return new Date(
          `${time.getFullYear()}/${time.getMonth() + 1}/${time.getDate()} 23:59:59`
        ).getTime();
      }
    };
    const onSelectDate = (date) => {
      dateDefaultVal.value = [];
      const timestamp = new Date(date).getTime();
      let selectedStart = getStartTime(timestamp);
      let selectedEnd = getEndTime(timestamp);
      let { start_date, end_date } = getResTime();
      const origin_start_date = start_date, origin_end_date = end_date;
      if (select_time_type === "start") {
        if (timestamp > end_date) {
          start_date = getStartTime(end_date);
          end_date = selectedEnd;
        } else {
          start_date = selectedStart;
        }
      } else {
        if (timestamp < start_date) {
          end_date = getEndTime(start_date);
          start_date = selectedStart;
        } else {
          end_date = selectedEnd;
        }
      }
      if (start_date !== origin_start_date) {
        emit("update:start_date", start_date);
      }
      if (end_date !== origin_end_date) {
        emit("update:end_date", end_date);
      }
      emit("onSelect", {
        start_date,
        end_date
      });
    };
    watchEffect(() => {
      selectd_end_date.value = props.end_date;
      selectd_start_date.value = props.start_date;
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", {
          class: "date-select",
          onClick: _cache[1] || (_cache[1] = ($event) => onOpenSelect("start"))
        }, [
          createElementVNode("p", {
            class: normalizeClass(["text", __props.start_date ? "" : "text-default"])
          }, toDisplayString(unref(date_text)(__props.start_date, "start")), 3),
          __props.start_date && __props.clearable ? (openBlock(), createElementBlock("p", {
            key: 0,
            class: "icon-wrap",
            onClick: _cache[0] || (_cache[0] = withModifiers(($event) => onClear("start"), ["stop"]))
          }, [
            createVNode(_sfc_main$4, {
              type: "closeCircularLine",
              width: "12",
              color: "var(--wl-text-color-placeholder)"
            })
          ])) : createCommentVNode("", true)
        ]),
        _hoisted_2,
        createElementVNode("div", {
          class: "date-select",
          onClick: _cache[3] || (_cache[3] = ($event) => onOpenSelect("end"))
        }, [
          createElementVNode("p", {
            class: normalizeClass(["text", __props.end_date ? "" : "text-default"])
          }, toDisplayString(unref(date_text)(__props.end_date, "end")), 3),
          __props.end_date && __props.clearable ? (openBlock(), createElementBlock("p", {
            key: 0,
            class: "icon-wrap",
            onClick: _cache[2] || (_cache[2] = withModifiers(($event) => onClear("end"), ["stop"]))
          }, [
            createVNode(_sfc_main$4, {
              type: "closeCircularLine",
              width: "12",
              color: "var(--wl-text-color-placeholder)"
            })
          ])) : createCommentVNode("", true)
        ]),
        createVNode(_sfc_main$1, {
          modelValue: dateVisbile.value,
          "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => dateVisbile.value = $event),
          color: "var(--wl-primary-color)",
          "date-value": dateDefaultVal.value,
          "min-date": unref(minDate),
          "max-date": unref(maxDate),
          onOnConfrim: onSelectDate
        }, null, 8, ["modelValue", "date-value", "min-date", "max-date"])
      ]);
    };
  }
});
var Comp = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-414e6113"]]);
var __uno = "";
Comp.install = (app) => {
  app.component(Comp.name, Comp);
};
export { Comp as default };
