"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
;/* empty css                                               */
;/* empty css                                                */
;/* empty css                                               */
;/* empty css                                                  */
;/* empty css                                                */
;/* empty css                                                  */
;/* empty css                                                 */
;/* empty css                                                */
;/* empty css                                                     */
;/* empty css                                               */
;/* empty css                                              */
;/* empty css                                                       */
;/* empty css                                                 */
const Vue = require("vue");
const index = require("../field/index.js");
const optionUtil = require("../../../utils/optionUtil.js");
const common = require("../../../utils/common.js");
const index$2 = require("../../../../node_modules/vant/es/picker/index.js");
const index$1 = require("../../../../node_modules/vant/es/popup/index.js");
const index$3 = require("../../../../node_modules/vant/es/icon/index.js");
const _sfc_main = {
  __name: "FieldPicker",
  props: {
    pickerOptions: {
      type: Array,
      default: []
    },
    treeOptionsFieldNames: {
      type: Object,
      default: {
        text: "text",
        value: "value"
      }
    },
    modelValue: {
      type: String,
      default: ""
    },
    disabled: {
      type: Boolean,
      default: false
    },
    readonly: {
      type: Boolean,
      default: false
    },
    "is-link": false,
    optionConfig: {
      type: Object,
      default: () => ({})
    },
    dataSources: {
      type: Array,
      default: () => []
    },
    formData: {
      type: Object,
      default: () => {
      }
    },
    fields: {
      type: Array,
      default: () => []
    }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    const currentInstance = Vue.getCurrentInstance();
    const ctx = currentInstance.proxy;
    const props = __props;
    Vue.useAttrs();
    const finalOptions = Vue.ref([]);
    Vue.watch(
      () => common.cloneDeep(props.optionConfig),
      (val) => {
        optionUtil.getOptions({
          ctx,
          dataSources: props.dataSources,
          formData: props.formData,
          fields: props.fields,
          ...props.optionConfig
        }).then((data) => {
          finalOptions.value = data;
        });
      },
      {
        deep: true,
        immediate: true
      }
    );
    const showPicker = Vue.ref(false);
    const emit = __emit;
    const pickerValue = Vue.computed({
      get: () => {
        const value = props.modelValue;
        return value.split(",");
      },
      set: (val) => {
        emit("update:modelValue", val.join(","));
      }
    });
    const fieldTextValue = Vue.computed(() => {
      const selectedOption = finalOptions.value.find(
        (option) => option.value == pickerValue.value.join(",")
      );
      return selectedOption ? selectedOption.label : "";
    });
    const onConfirm = ({ selectedValues, selectedOptions }) => {
      pickerValue.value = selectedValues;
      showPicker.value = false;
    };
    return (_ctx, _cache) => {
      const _component_van_icon = index$3.Icon;
      const _component_van_picker = index$2.Picker;
      const _component_van_popup = index$1.Popup;
      return Vue.openBlock(), Vue.createBlock(Vue.unref(index.MobileField), Vue.mergeProps(_ctx.$attrs, {
        modelValue: Vue.unref(fieldTextValue),
        "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => Vue.isRef(fieldTextValue) ? fieldTextValue.value = $event : null),
        isLink: __props.readonly || __props.disabled ? false : true,
        readonly: "",
        disabled: __props.disabled,
        onOpenPicker: _cache[4] || (_cache[4] = () => {
          if (!__props.readonly) {
            showPicker.value = true;
          }
        })
      }), Vue.createSlots({
        default: Vue.withCtx(() => [
          Vue.createVNode(_component_van_popup, {
            show: Vue.unref(showPicker),
            "onUpdate:show": _cache[2] || (_cache[2] = ($event) => Vue.isRef(showPicker) ? showPicker.value = $event : null),
            "destroy-on-close": "",
            position: "bottom",
            teleport: "body"
          }, {
            default: Vue.withCtx(() => [
              Vue.createVNode(_component_van_picker, Vue.mergeProps(_ctx.$attrs, {
                title: `${_ctx.$attrs.label}`,
                columns: Vue.unref(finalOptions),
                "columns-field-names": {
                  text: "label",
                  value: "value",
                  children: "children"
                },
                "model-value": Vue.unref(pickerValue),
                readonly: false,
                onConfirm,
                onCancel: _cache[1] || (_cache[1] = ($event) => showPicker.value = false)
              }), null, 16, ["title", "columns", "model-value"])
            ]),
            _: 1
          }, 8, ["show"])
        ]),
        _: 2
      }, [
        !__props.readonly && !__props.disabled && Vue.unref(fieldTextValue) ? {
          name: "right-icon",
          fn: Vue.withCtx(() => [
            Vue.createVNode(_component_van_icon, {
              name: "clear",
              class: "custom-close-icon",
              onClick: _cache[0] || (_cache[0] = Vue.withModifiers(($event) => pickerValue.value = null, ["stop"]))
            })
          ]),
          key: "0"
        } : void 0
      ]), 1040, ["modelValue", "isLink", "disabled"]);
    };
  }
};
exports.default = _sfc_main;
