"use strict";
const common_vendor = require("../../common/vendor.js");
if (!Math) {
  Icon();
}
const Icon = () => "../icon/index.js";
const _sfc_main = {
  __name: "index",
  props: {
    item: {
      type: Object,
      default: () => ({})
    }
  },
  emits: ["click", "buttonClick"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const showButtonMenu = common_vendor.ref(false);
    const hasButtons = common_vendor.computed(() => {
      var _a;
      return ((_a = props.item) == null ? void 0 : _a.buttons) && Array.isArray(props.item.buttons) && props.item.buttons.length > 0;
    });
    const isMultipleButtons = common_vendor.computed(() => {
      var _a;
      return ((_a = props.item) == null ? void 0 : _a.buttons) && props.item.buttons.length > 1;
    });
    const isSingleButton = common_vendor.computed(() => {
      var _a;
      return ((_a = props.item) == null ? void 0 : _a.buttons) && props.item.buttons.length === 1;
    });
    const handleCardClick = () => {
      if (showButtonMenu.value) {
        showButtonMenu.value = false;
        return;
      }
      emit("click");
    };
    const handleSettingClick = () => {
      if (isSingleButton.value) {
        handleButtonClick(props.item.buttons[0], 0);
      } else if (isMultipleButtons.value) {
        const wasOpen = showButtonMenu.value;
        common_vendor.index.$emit("closeAllCardMenus");
        showButtonMenu.value = !wasOpen;
      }
    };
    const closeMenu = () => {
      showButtonMenu.value = false;
    };
    common_vendor.onMounted(() => {
      common_vendor.index.$on("closeAllCardMenus", closeMenu);
    });
    common_vendor.onUnmounted(() => {
      common_vendor.index.$off("closeAllCardMenus", closeMenu);
    });
    const handleButtonClick = (btn, index) => {
      showButtonMenu.value = false;
      if (btn.onclick && typeof btn.onclick === "function") {
        btn.onclick();
      }
      emit("buttonClick", { button: btn, index, item: props.item });
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: hasButtons.value
      }, hasButtons.value ? common_vendor.e({
        b: common_vendor.p({
          name: "icon-chilun",
          size: "32",
          color: "#999"
        }),
        c: showButtonMenu.value && isMultipleButtons.value
      }, showButtonMenu.value && isMultipleButtons.value ? {
        d: common_vendor.f(__props.item.buttons, (btn, index, i0) => {
          return common_vendor.e({
            a: btn.icon
          }, btn.icon ? {
            b: common_vendor.n(btn.icon)
          } : {}, {
            c: common_vendor.t(btn.title),
            d: index,
            e: common_vendor.o(($event) => handleButtonClick(btn, index), index)
          });
        }),
        e: common_vendor.o(() => {
        })
      } : {}, {
        f: common_vendor.o(handleSettingClick)
      }) : {}, {
        g: common_vendor.o(handleCardClick),
        h: common_vendor.gei(_ctx, "")
      });
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-9c884cfa"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/components/SsCard/index.js.map
