"use strict";
const common_vendor = require("../../../../common/vendor.js");
const _sfc_main = {
  name: "wht-select",
  props: {
    options: {
      type: Array,
      default: () => []
    },
    value: {
      type: [String, Number],
      default: ""
    },
    placeholder: {
      type: String,
      default: "请选择"
    },
    disabled: {
      type: Boolean,
      default: false
    },
    clearable: {
      type: Boolean,
      default: false
    },
    // 样式相关的props
    height: {
      type: Number,
      default: 40
    },
    fontSize: {
      type: Number,
      default: 14
    },
    borderColor: {
      type: String,
      default: "#dcdfe6"
    },
    borderRadius: {
      type: Number,
      default: 4
    },
    backgroundColor: {
      type: String,
      default: "#ffffff"
    },
    textColor: {
      type: String,
      default: "#606266"
    },
    placeholderColor: {
      type: String,
      default: "#c0c4cc"
    },
    activeColor: {
      type: String,
      default: "#409eff"
    },
    filterable: {
      type: Boolean,
      default: false
    },
    searchPlaceholder: {
      type: String,
      default: "请输入搜索内容"
    }
  },
  data() {
    return {
      currentValue: "",
      isOpen: false,
      searchQuery: ""
    };
  },
  computed: {
    currentLabel() {
      const option = this.options.find((item) => item.value === this.currentValue);
      return option ? option.label : "";
    },
    filteredOptions() {
      if (!this.filterable || !this.searchQuery) {
        return this.options;
      }
      return this.options.filter(
        (item) => item.label.toLowerCase().includes(this.searchQuery.toLowerCase())
      );
    }
  },
  watch: {
    value: {
      handler(newVal) {
        this.currentValue = newVal;
      },
      immediate: true
    }
  },
  methods: {
    togglePicker() {
      if (this.disabled)
        return;
      this.isOpen = !this.isOpen;
      if (!this.isOpen) {
        this.searchQuery = "";
      }
    },
    selectOption(item, index) {
      if (item.disabled)
        return;
      this.currentValue = item.value;
      this.searchQuery = "";
      this.$emit("input", item.value);
      this.$emit("change", item);
      this.isOpen = false;
    },
    clearValue(e) {
      this.currentValue = "";
      this.searchQuery = "";
      this.$emit("input", "");
      this.$emit("change", null);
      this.$emit("clear");
    },
    onSearch() {
      this.$emit("search", this.searchQuery);
    },
    handleFocus() {
      if (!this.disabled) {
        this.isOpen = true;
      }
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: $props.filterable
  }, $props.filterable ? {
    b: $data.currentValue ? $options.currentLabel : $props.placeholder,
    c: $props.fontSize + "px",
    d: $data.currentValue ? $props.textColor : $props.placeholderColor,
    e: common_vendor.o$1(() => {
    }),
    f: common_vendor.o$1([($event) => $data.searchQuery = $event.detail.value, (...args) => $options.onSearch && $options.onSearch(...args)]),
    g: common_vendor.o$1((...args) => $options.handleFocus && $options.handleFocus(...args)),
    h: $data.searchQuery
  } : {
    i: common_vendor.t($options.currentLabel || $props.placeholder),
    j: $props.fontSize + "px",
    k: $data.currentValue ? $props.textColor : $props.placeholderColor
  }, {
    l: $props.clearable && $data.currentValue && !$props.disabled
  }, $props.clearable && $data.currentValue && !$props.disabled ? {
    m: common_vendor.o$1((...args) => $options.clearValue && $options.clearValue(...args))
  } : {
    n: $props.placeholderColor
  }, {
    o: $data.isOpen ? 1 : "",
    p: !$data.currentValue ? 1 : "",
    q: $props.height + "px",
    r: $props.backgroundColor,
    s: $props.borderColor,
    t: $props.borderRadius + "px",
    v: common_vendor.o$1((...args) => $options.togglePicker && $options.togglePicker(...args)),
    w: $data.isOpen
  }, $data.isOpen ? common_vendor.e({
    x: common_vendor.o$1((...args) => $options.togglePicker && $options.togglePicker(...args)),
    y: $options.filteredOptions.length > 0
  }, $options.filteredOptions.length > 0 ? {
    z: common_vendor.f($options.filteredOptions, (item, index, i0) => {
      return {
        a: common_vendor.t(item.label),
        b: item.value,
        c: item.disabled ? 1 : "",
        d: $data.currentValue === item.value ? 1 : "",
        e: item.disabled ? $props.placeholderColor : $props.textColor,
        f: $data.currentValue === item.value ? $props.activeColor + "20" : $props.backgroundColor,
        g: common_vendor.o$1(($event) => $options.selectOption(item, index), item.value)
      };
    }),
    A: $props.fontSize + "px"
  } : {
    B: $props.fontSize + "px",
    C: $props.placeholderColor
  }, {
    D: $props.backgroundColor,
    E: $props.borderRadius + "px"
  }) : {}, {
    F: $props.disabled ? 1 : ""
  });
}
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-57f09195"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/wht-select/components/wht-select/wht-select.js.map
