import { defineComponent, ref, watch, openBlock, createBlock, unref, mergeProps, withCtx, createVNode } from "vue";
import dayjs from "dayjs";
import { n as _export_sfc, A as _sfc_main$1 } from "./index2.js";
import { Field } from "vant";
import "@wltech/svg";
import "qs";
import "vuedraggable";
import "vue-router";
var index_vue_vue_type_style_index_0_scoped_true_lang = "";
var index_vue_vue_type_style_index_1_lang = "";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    value: { default: "" },
    item: { default: () => {
    } }
  },
  emits: ["update:value"],
  setup(__props, { emit }) {
    const props = __props;
    const formatDate = (stamp, type) => {
      if (!stamp)
        return "";
      return dayjs(+stamp).format(type);
    };
    const DATE_TIME_TYPE = {
      YYYY: "year",
      "YYYY/MM": "year month",
      "YYYY/MM/DD": "year month day",
      "YYYY/MM/DD HH": "year month day hour",
      "YYYY/MM/DD HH:mm": "year month day hour minute",
      "YYYY/MM/DD HH:mm:ss": "year month day hour minute"
    };
    const fieldValue = ref("");
    const currentDate = ref(new Date());
    const showCalendar = ref(false);
    const onConfirmSelect = (item) => {
      currentDate.value = item.time;
      fieldValue.value = formatDate(
        new Date(item.time).getTime(),
        props.item.property_format || "YYYY-MM-DD"
      );
      emit("update:value", new Date(item.time).getTime() + "");
      showCalendar.value = false;
    };
    watch(
      () => props.value,
      (val) => {
        if (val) {
          currentDate.value = new Date(val);
          fieldValue.value = formatDate(
            val,
            props.item.property_format || "YYYY/MM/DD"
          );
        }
      },
      {
        immediate: true
      }
    );
    const onReset = () => {
      currentDate.value = "";
      fieldValue.value = "";
      emit("update:value", "");
    };
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(Field), mergeProps({
        modelValue: fieldValue.value,
        "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => fieldValue.value = $event),
        label: __props.item.label
      }, __props.item, {
        readonly: "",
        "right-icon": fieldValue.value && __props.item.clearable ? "clear" : "",
        onClickInput: _cache[2] || (_cache[2] = ($event) => showCalendar.value = true),
        onClickRightIcon: onReset
      }), {
        extra: withCtx(() => [
          createVNode(_sfc_main$1, mergeProps(__props.item.dateConfig, {
            defalutTime: currentDate.value,
            show: showCalendar.value,
            "onUpdate:show": _cache[0] || (_cache[0] = ($event) => showCalendar.value = $event),
            onOnConfirm: onConfirmSelect,
            type: DATE_TIME_TYPE[__props.item.property_format] || "date"
          }), null, 16, ["defalutTime", "show", "type"])
        ]),
        _: 1
      }, 16, ["modelValue", "label", "right-icon"]);
    };
  }
});
var index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-40ac8b98"]]);
export { index as default };
