import { defineComponent, ref, watchEffect, watch, openBlock, createBlock, normalizeStyle, withCtx, createVNode, unref } from "vue";
import { Picker } from "vant";
import { _ as _sfc_main$1 } from "./index9.js";
const __default__ = {
  name: "WlPicker"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  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$1, {
        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"]);
    };
  }
});
export { _sfc_main as _ };
