"use strict";
const common_vendor = require("../../common/vendor.js");
if (!Math) {
  Icon();
}
const Icon = () => "../icon/index.js";
const _sfc_main = {
  __name: "index",
  props: {
    // 按钮文本
    text: {
      type: String,
      default: "增加"
    },
    // 是否禁用
    disabled: {
      type: Boolean,
      default: false
    },
    // 按钮高度
    height: {
      type: [String, Number],
      default: "36px"
    },
    // 前置图标名称
    preIcon: {
      type: String,
      default: ""
    },
    // 后置图标名称
    suffixIcon: {
      type: String,
      default: ""
    },
    // 图标大小
    iconSize: {
      type: [String, Number],
      default: "32"
    },
    // 图标颜色
    iconColor: {
      type: String,
      default: "#585d6e"
    },
    // 自定义按钮样式
    customStyle: {
      type: Object,
      default: () => ({})
    },
    // 跳转链接（兼容原JSP用法）
    href: {
      type: String,
      default: ""
    },
    // 选项列表 - 新增
    options: {
      type: Array,
      default: () => []
    }
  },
  emits: ["click", "optionClick"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const showOptionsMenu = common_vendor.ref(false);
    const hasOptions = common_vendor.computed(() => {
      return props.options && Array.isArray(props.options) && props.options.length > 0;
    });
    const hasMultipleOptions = common_vendor.computed(() => {
      return props.options && props.options.length > 1;
    });
    const isSingleOption = common_vendor.computed(() => {
      return props.options && props.options.length === 1;
    });
    const buttonStyle = common_vendor.computed(() => ({
      height: typeof props.height === "number" ? `${props.height}px` : props.height,
      ...props.customStyle
    }));
    const handleClick = () => {
      if (!hasOptions.value) {
        emit("click");
      } else if (isSingleOption.value) {
        handleOptionClick(props.options[0], 0);
      } else if (hasMultipleOptions.value) {
        const wasOpen = showOptionsMenu.value;
        common_vendor.index.$emit("closeAllButtonMenus");
        showOptionsMenu.value = !wasOpen;
      }
    };
    const handleOptionClick = (option, index) => {
      showOptionsMenu.value = false;
      if (option.onclick && typeof option.onclick === "function") {
        option.onclick();
      }
      emit("optionClick", { option, index });
      emit("click", { option, index });
    };
    const closeMenu = () => {
      showOptionsMenu.value = false;
    };
    common_vendor.onMounted(() => {
      common_vendor.index.$on("closeAllButtonMenus", closeMenu);
    });
    common_vendor.onUnmounted(() => {
      common_vendor.index.$off("closeAllButtonMenus", closeMenu);
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: __props.preIcon || _ctx.$slots.preIcon
      }, __props.preIcon || _ctx.$slots.preIcon ? common_vendor.e({
        b: __props.preIcon
      }, __props.preIcon ? {
        c: common_vendor.p({
          name: __props.preIcon,
          size: __props.iconSize,
          color: __props.iconColor
        })
      } : {}) : {}, {
        d: common_vendor.t(__props.text),
        e: __props.suffixIcon || _ctx.$slots.suffixIcon
      }, __props.suffixIcon || _ctx.$slots.suffixIcon ? common_vendor.e({
        f: __props.suffixIcon
      }, __props.suffixIcon ? {
        g: common_vendor.p({
          name: __props.suffixIcon,
          size: __props.iconSize,
          color: __props.iconColor
        })
      } : {}) : {}, {
        h: common_vendor.s(buttonStyle.value),
        i: common_vendor.o(handleClick),
        j: __props.disabled,
        k: showOptionsMenu.value && hasMultipleOptions.value
      }, showOptionsMenu.value && hasMultipleOptions.value ? {
        l: common_vendor.f(__props.options, (option, index, i0) => {
          return common_vendor.e({
            a: option.icon
          }, option.icon ? {
            b: common_vendor.n(option.icon)
          } : {}, {
            c: common_vendor.t(option.text),
            d: index,
            e: common_vendor.o(($event) => handleOptionClick(option, index), index)
          });
        }),
        m: common_vendor.o(() => {
        })
      } : {}, {
        n: showOptionsMenu.value ? 1 : "",
        o: common_vendor.gei(_ctx, "")
      });
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-817d40fa"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/components/SsSearchButton/index.js.map
