import { defineComponent, ref, watchEffect, watch, openBlock, createBlock, normalizeStyle, withCtx, createVNode, unref, createElementBlock, createElementVNode, toDisplayString } from "vue";
import { Picker } from "vant";
import { _ as _sfc_main$2 } from "./index7.js";
import "./index5.js";
import "@wltech/svg";
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"]);
    };
  }
});
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1 = { class: "rf-select-wrap" };
const __default__ = {
  name: "RfSelect"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    modelValue: { default: "" },
    options: { default: null }
  },
  emits: ["update:modelValue", "onSelect", "onClose"],
  setup(__props, { emit }) {
    const props = __props;
    const popUpVisible = ref(false);
    const fieldValue = ref("");
    const fieldIndex = ref(0);
    const onClose = () => {
      popUpVisible.value = false;
      emit("onClose");
    };
    const onShow = () => popUpVisible.value = true;
    const onConfirm = (val, indexs, { selectedOptions: item }) => {
      fieldValue.value = item.text;
      emit("update:modelValue", item.text);
      emit("onSelect", item);
    };
    watchEffect(() => {
      fieldValue.value = props.modelValue;
      fieldIndex.value = props.options.findIndex((ele) => ele === props.modelValue);
      fieldIndex.value = fieldIndex.value === -1 ? 0 : fieldIndex.value;
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", {
          class: "chosed-value",
          onClick: onShow
        }, toDisplayString(fieldValue.value), 1),
        createVNode(_sfc_main$1, {
          modelValue: popUpVisible.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => popUpVisible.value = $event),
          columns: __props.options,
          pickerDefaultValue: fieldIndex.value,
          onOnClose: onClose,
          onOnConfirm: onConfirm
        }, null, 8, ["modelValue", "columns", "pickerDefaultValue"])
      ]);
    };
  }
});
export { _sfc_main as default };
