import { defineComponent, ref, watchEffect, resolveComponent, openBlock, createElementBlock, createElementVNode, toDisplayString, createVNode, withCtx, createTextVNode, createCommentVNode, Fragment, renderList, withModifiers, unref } from "vue";
import { d as _sfc_main$1, x as _sfc_main$2, m as _sfc_main$3 } from "./index2.js";
import "vant";
import "@wltech/svg";
import "dayjs";
import "qs";
import "vuedraggable";
import "vue-router";
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1 = { class: "mul-rf-select-wrap" };
const _hoisted_2 = {
  class: "mult-select",
  "data-weiling-mobile-ui-rf-mul-select-popup": ""
};
const _hoisted_3 = {
  key: 0,
  class: "header"
};
const _hoisted_4 = { class: "content" };
const _hoisted_5 = ["onClick"];
const _hoisted_6 = { class: "text" };
const _hoisted_7 = { class: "footer" };
const _hoisted_8 = /* @__PURE__ */ createTextVNode("\u786E\u8BA4\u9009\u62E9");
const __default__ = {
  name: "RfMulSelect"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    modelValue: { default: () => [] },
    options: { default: () => [] },
    title: null
  },
  emits: ["onSelect", "update:modelValue", "onSubmit"],
  setup(__props, { emit }) {
    const props = __props;
    const popUpVisible = ref(false);
    const choosedKey = ref([]);
    const valueText = ref("");
    const onClose = () => {
      popUpVisible.value = false;
    };
    const onShow = () => popUpVisible.value = true;
    const onSubmit = () => {
      emit("update:modelValue", unref(choosedKey));
      onClose();
    };
    const onSelect = (item) => {
      const index = choosedKey.value.indexOf(item.key);
      if (index === -1) {
        choosedKey.value.push(item.key);
      } else {
        choosedKey.value.splice(index, 1);
      }
      emit("onSelect", item);
    };
    watchEffect(() => {
      choosedKey.value = props.modelValue.map((ele) => ele);
      valueText.value = props.options.reduce((pre, cur) => {
        if (props.modelValue.includes(cur.key)) {
          return pre + (pre ? "," + cur.value : cur.value);
        } else {
          return pre;
        }
      }, "");
    });
    return (_ctx, _cache) => {
      const _component_WlHeader = resolveComponent("WlHeader");
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", {
          class: "mul-rf-select",
          onClick: onShow
        }, toDisplayString(valueText.value), 1),
        createVNode(_sfc_main$1, {
          position: "bottom",
          round: "",
          style: { "height": "50%" },
          onClose,
          modelValue: popUpVisible.value,
          "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => popUpVisible.value = $event)
        }, {
          default: withCtx(() => [
            createElementVNode("div", _hoisted_2, [
              __props.title ? (openBlock(), createElementBlock("div", _hoisted_3, [
                createVNode(_component_WlHeader, {
                  showClose: "",
                  onOnClose: _cache[0] || (_cache[0] = ($event) => popUpVisible.value = false)
                }, {
                  default: withCtx(() => [
                    createTextVNode(toDisplayString(__props.title), 1)
                  ]),
                  _: 1
                })
              ])) : createCommentVNode("", true),
              createElementVNode("div", _hoisted_4, [
                (openBlock(true), createElementBlock(Fragment, null, renderList(__props.options, (item) => {
                  return openBlock(), createElementBlock("div", {
                    key: item.key
                  }, [
                    createElementVNode("div", {
                      class: "item",
                      onClick: withModifiers(($event) => onSelect(item), ["stop"])
                    }, [
                      createElementVNode("p", _hoisted_6, toDisplayString(item.value), 1),
                      createVNode(_sfc_main$2, {
                        isChoosed: choosedKey.value.includes(item.key),
                        isHookType: true,
                        onOnClick: ($event) => onSelect(item)
                      }, null, 8, ["isChoosed", "onOnClick"])
                    ], 8, _hoisted_5)
                  ]);
                }), 128))
              ]),
              createElementVNode("div", _hoisted_7, [
                createVNode(_sfc_main$3, {
                  type: "primary",
                  block: "",
                  onOnClick: onSubmit
                }, {
                  default: withCtx(() => [
                    _hoisted_8
                  ]),
                  _: 1
                })
              ])
            ])
          ]),
          _: 1
        }, 8, ["modelValue"])
      ]);
    };
  }
});
export { _sfc_main as default };
