import { defineComponent, openBlock, createBlock, unref, createElementBlock, normalizeClass, createElementVNode, renderSlot, withDirectives, createVNode, vShow, createTextVNode, toDisplayString, ref, computed, watchEffect, mergeProps, withCtx, createCommentVNode, watch, normalizeStyle } from "vue";
import { Popup, Picker } from "vant";
import WlSvg from "@wltech/svg";
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"]);
    };
  }
});
const _hoisted_1$2 = { class: "z-2 flex uno-min-w-44 uno-max-w-88" };
const _hoisted_2$1 = { 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$1, [
          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 = { 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, [
              renderSlot(_ctx.$slots, "default")
            ])
          ])
        ]),
        _: 3
      }, 16, ["show", "teleport", "position", "style"]);
    };
  }
});
const __default__$1 = {
  name: "WlPicker"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  ...__default__$1,
  props: {
    columns: { default: () => [] },
    modelValue: { type: Boolean, default: false },
    pickerDefaultValue: { default: () => [] },
    teleport: { default: "body" },
    contentHeight: { default: "fit-content" }
  },
  emits: ["onConfirm", "onChange", "update:modelValue", "onClose"],
  setup(__props, { emit }) {
    const props = __props;
    const visible = ref(false);
    const pickerRef = ref();
    const defaultValue = ref([]);
    const onConfirm = (item) => {
      emit("onConfirm", item.selectedValues, item.selectedIndexes, item);
      onClose();
    };
    const onClose = () => {
      emit("update:modelValue", false);
      emit("onClose");
    };
    const onChange = (item) => {
      emit("onChange", item.selectedValues, item.selectedIndexes, item);
    };
    watchEffect(() => {
      visible.value = props.modelValue;
    });
    watch(
      () => [props.modelValue, props.pickerDefaultValue],
      () => {
        if (props.modelValue) {
          defaultValue.value = props.pickerDefaultValue;
        }
      },
      {
        immediate: true
      }
    );
    return (_ctx, _cache) => {
      return openBlock(), createBlock(_sfc_main$2, {
        modelValue: visible.value,
        "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => visible.value = $event),
        style: normalizeStyle(`height: ${__props.contentHeight}`),
        round: "",
        teleport: __props.teleport,
        position: "bottom",
        onClose
      }, {
        default: withCtx(() => [
          createVNode(unref(Picker), {
            ref_key: "pickerRef",
            ref: pickerRef,
            "show-toolbar": "",
            columns: __props.columns,
            modelValue: defaultValue.value,
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => defaultValue.value = $event),
            onCancel: onClose,
            onConfirm,
            onChange
          }, null, 8, ["columns", "modelValue"])
        ]),
        _: 1
      }, 8, ["modelValue", "style", "teleport"]);
    };
  }
});
const dateKey = {
  year: "year",
  month: "month",
  day: "day"
};
const timeKey = {
  hour: "hour",
  minute: "minute",
  second: "second"
};
const dataKeyArr = Reflect.ownKeys(dateKey);
const timeKeyArr = Reflect.ownKeys(timeKey);
const keyToMethods = {
  year: "getFullYear",
  month: "getMonth",
  day: "getDate",
  hour: "getHours",
  minute: "getMinutes",
  second: "getSeconds"
};
const isLeapYear = (year) => {
  if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
    return true;
  }
  return false;
};
const onGetDayNumber = (month, year) => {
  const month31 = [1, 3, 5, 7, 8, 10, 12];
  if (month === 2) {
    if (year && isLeapYear(year)) {
      return 29;
    } else {
      return 28;
    }
  } else {
    if (month31.includes(month)) {
      return 31;
    } else {
      return 30;
    }
  }
};
const onGetTime = (data) => {
  let time = data.reduce((pre, cur, currentIndex) => {
    let prefix = "", suffix = "";
    if ([dateKey.day, dateKey.month].includes(cur.type) && pre) {
      prefix = "/";
    }
    if ([timeKey.minute, timeKey.second].includes(cur.type) && pre) {
      prefix = ":";
    }
    if (cur.type === timeKey.hour && pre) {
      prefix = " ";
    }
    if (cur.type === timeKey.hour && currentIndex === data.length - 1) {
      suffix = ":0:0";
    }
    pre = pre + prefix + cur.value + suffix;
    return pre;
  }, "");
  if (time.indexOf("/") === time.lastIndexOf("/") && time.indexOf("/") !== -1) {
    time += "/1";
  }
  if (time.indexOf("/") === -1) {
    const currentTime = new Date();
    time += `/${currentTime.getMonth() + 1}/${currentTime.getDate()}`;
  }
  return new Date(time);
};
const _hoisted_1 = {
  class: "wl-date-time-picker",
  "data-weiling-mobile-ui-wl-date-time-picker": ""
};
const __default__ = {
  name: "WlDateTimePicker"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    minDate: { default: () => new Date("2000/1/1") },
    maxDate: { default: () => new Date("2050/12/31") },
    type: { default: "date-time" },
    show: { type: Boolean, default: false },
    title: { default: "" },
    descShow: { type: Boolean, default: true },
    defalutTime: { default: () => new Date() }
  },
  emits: ["onConfirm", "onChange", "update:show", "onClose"],
  setup(__props, { emit }) {
    const props = __props;
    const pickerColumns = ref([]);
    const visible = ref(true);
    const pickerDefaultValue = ref([]);
    const getNeedColumns = (type = "date") => {
      let needColumns = [];
      if (type === "date") {
        if (props.type.includes("date")) {
          return dataKeyArr;
        } else {
          dataKeyArr.forEach((ele) => {
            if (props.type.includes(ele)) {
              needColumns.push(ele);
            }
          });
        }
      }
      if (type === "time") {
        if (props.type.includes("time")) {
          return timeKeyArr;
        } else {
          timeKeyArr.forEach((ele) => {
            if (props.type.includes(ele)) {
              needColumns.push(ele);
            }
          });
        }
      }
      return needColumns;
    };
    const getNeedValue = (funcName, type, desc = "", addStep = 0, min = 0, max = 0) => {
      const minData = funcName ? props.minDate[funcName]() + addStep : min;
      const maxData = funcName ? props.maxDate[funcName]() + addStep : max;
      let data = [];
      for (let i = minData; i <= maxData; i++) {
        data.push({
          text: `${i < 10 ? "0" + i : i}${!props.descShow ? "" : desc}`,
          value: i,
          type
        });
      }
      return data;
    };
    const onGetDayCols = (currentYear, currentMonth) => {
      const minYear = props.minDate["getFullYear"]();
      const maxYear = props.maxDate["getFullYear"]();
      const minMon = props.minDate["getMonth"]() + 1;
      const maxMon = props.maxDate["getMonth"]() + 1;
      const minDay = props.minDate["getDate"]();
      const maxDay = props.maxDate["getDate"]();
      let minD = 1, maxD = 31;
      if (currentYear === minYear && currentMonth === minMon && currentMonth) {
        minD = minDay;
      } else if (currentYear === maxYear && currentMonth === maxMon && currentMonth) {
        maxD = maxDay;
      } else if (currentMonth) {
        if (currentMonth === 2) {
          maxD = currentYear ? onGetDayNumber(currentYear, currentMonth) : 29;
        } else {
          maxD = onGetDayNumber(
            currentMonth,
            currentYear || new Date().getFullYear()
          );
        }
      }
      return getNeedValue("", dateKey.day, "\u65E5", 0, minD, maxD);
    };
    const onGetMonthCol = (currentYear) => {
      const minYear = props.minDate["getFullYear"]();
      const maxYear = props.maxDate["getFullYear"]();
      const minMon = props.minDate["getMonth"]() + 1;
      const maxMon = props.maxDate["getMonth"]() + 1;
      const minMonth = currentYear === minYear ? minMon : 1;
      const maxMonth = currentYear === maxYear ? maxMon : 12;
      const data = getNeedValue("", dateKey.month, "\u6708", 1, minMonth, maxMonth);
      return data;
    };
    const getDateColumns = () => {
      var _a, _b, _c;
      const needColumns = getNeedColumns("date");
      let columns = [];
      if (needColumns.includes(dateKey.year)) {
        const data = getNeedValue("getFullYear", dateKey.year, "\u5E74");
        columns.push(data);
      }
      if (needColumns.includes(dateKey.month)) {
        const currentYear = ((_a = props.defalutTime) == null ? void 0 : _a.getFullYear()) || new Date().getFullYear();
        columns.push(onGetMonthCol(currentYear));
      }
      if (needColumns.includes(dateKey.day)) {
        columns.push(
          onGetDayCols(
            ((_b = props.defalutTime) == null ? void 0 : _b.getFullYear()) || new Date().getFullYear(),
            ((_c = props.defalutTime) == null ? void 0 : _c.getMonth()) + 1 || new Date().getMonth() + 1
          )
        );
      }
      return columns;
    };
    const getTimeColumns = () => {
      const needColumns = getNeedColumns("time");
      let columns = [];
      if (needColumns.includes(timeKey.hour)) {
        const data = getNeedValue("", timeKey.hour, "\u65F6", 0, 0, 23);
        columns.push(data);
      }
      if (needColumns.includes(timeKey.minute)) {
        const data = getNeedValue("", timeKey.minute, "\u5206", 0, 0, 59);
        columns.push(data);
      }
      if (needColumns.includes(timeKey.second)) {
        const data = getNeedValue("", timeKey.second, "\u79D2", 0, 0, 59);
        columns.push(data);
      }
      return columns;
    };
    const onConfirm = (val, indexs, { selectedOptions: data }) => {
      console.log(1111111, val, indexs, data);
      emit("onConfirm", {
        data,
        time: onGetTime(data)
      });
    };
    let preChangeData = [];
    const onChange = (val, index, { selectedOptions: data }) => {
      const dayIndex = data.findIndex((ele) => ele.type === dateKey.day);
      const monthIndex = data.findIndex((ele) => ele.type === dateKey.month);
      if (dayIndex !== -1) {
        const columns = pickerColumns.value;
        let preYear = { value: 0 }, preMonth = { value: 0 };
        let curYear = { value: 0 }, curMonth = { value: 0 };
        if (dayIndex !== 1) {
          preYear = preChangeData[0] || { value: 0 };
          preMonth = preChangeData[1] || { value: 0 };
          curYear = data[0];
          curMonth = data[1];
        } else {
          preMonth = preChangeData[0] || { value: 0 };
          curMonth = data[0];
        }
        if (curYear.value !== preYear.value) {
          columns[dayIndex] = onGetDayCols(curYear.value, curMonth.value);
          columns[monthIndex] = onGetMonthCol(curYear.value);
        } else if (preMonth.value !== curMonth.value) {
          columns[dayIndex] = onGetDayCols(curYear.value, curMonth.value);
          preChangeData = data;
          pickerColumns.value = columns;
        }
      }
      emit("onChange", {
        data,
        time: onGetTime(data)
      });
    };
    const onClose = () => {
      emit("update:show", false);
      emit("onClose");
    };
    watch(
      () => [props.type, props.maxDate, props.minDate, props.defalutTime],
      () => {
        pickerColumns.value = [...getDateColumns(), ...getTimeColumns()];
      },
      { immediate: true }
    );
    watchEffect(() => {
      visible.value = props.show;
    });
    watch(
      () => [props.defalutTime, pickerColumns.value],
      () => {
        if (props.defalutTime && pickerColumns.value.length !== 0) {
          const needColumns = [
            ...getNeedColumns("date"),
            ...getNeedColumns("time")
          ];
          const indexs = [];
          needColumns.forEach((key, i) => {
            let data = props.defalutTime[keyToMethods[key]]();
            if (key === dateKey.month) {
              data += 1;
            }
            indexs.push(data);
          });
          pickerDefaultValue.value = indexs;
        }
      },
      {
        immediate: true
      }
    );
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createVNode(_sfc_main$1, {
          modelValue: visible.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => visible.value = $event),
          title: __props.title,
          columns: pickerColumns.value,
          teleport: "",
          contentHeight: "300px",
          pickerDefaultValue: pickerDefaultValue.value,
          onOnConfirm: onConfirm,
          onOnChange: onChange,
          onOnClose: onClose
        }, null, 8, ["modelValue", "title", "columns", "pickerDefaultValue"])
      ]);
    };
  }
});
var __uno = "";
_sfc_main.install = (app) => {
  app.component(_sfc_main.name, _sfc_main);
};
export { _sfc_main as default };
