"use strict";
const common_vendor = require("../../../../common/vendor.js");
const uni_modules_uviewPro_libs_index = require("../../libs/index.js");
require("../../libs/util/logger.js");
require("../../libs/config/theme-tokens.js");
const uni_modules_uviewPro_components_uTabbar_types = require("./types.js");
if (!Array) {
  const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  const _easycom_u_badge2 = common_vendor.resolveComponent("u-badge");
  (_easycom_u_icon2 + _easycom_u_badge2)();
}
const _easycom_u_icon = () => "../u-icon/u-icon.js";
const _easycom_u_badge = () => "../u-badge/u-badge.js";
if (!Math) {
  (_easycom_u_icon + _easycom_u_badge)();
}
const __default__ = {
  name: "u-tabbar",
  options: {
    addGlobalClass: true,
    virtualHost: true,
    styleIsolation: "shared"
  }
};
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  ...__default__,
  props: uni_modules_uviewPro_components_uTabbar_types.TabbarProps,
  emits: ["change", "update:modelValue"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const uZIndex = common_vendor.computed(() => (props == null ? void 0 : props.zIndex) ?? uni_modules_uviewPro_libs_index.$u.zIndex.tabbar);
    const midButtonLeft = common_vendor.ref("50%");
    const pageUrl = common_vendor.ref("");
    common_vendor.onMounted(() => {
      const pages = getCurrentPages();
      pageUrl.value = pages[pages.length - 1].route;
      if (props.midButton)
        getMidButtonLeft();
    });
    const elIconPath = common_vendor.computed(() => {
      return (index) => {
        var _a;
        const pagePath = (_a = props.list[index]) == null ? void 0 : _a.pagePath;
        if (pagePath) {
          if (pagePath === pageUrl.value || pagePath === "/" + pageUrl.value) {
            return props.list[index].selectedIconPath;
          } else {
            return props.list[index].iconPath;
          }
        } else {
          return index == props.modelValue ? props.list[index].selectedIconPath : props.list[index].iconPath;
        }
      };
    });
    const elColor = common_vendor.computed(() => {
      return (index) => {
        var _a;
        const pagePath = (_a = props.list[index]) == null ? void 0 : _a.pagePath;
        if (pagePath) {
          if (pagePath === pageUrl.value || pagePath === "/" + pageUrl.value)
            return props.activeColor;
          else
            return props.inactiveColor;
        } else {
          return index == props.modelValue ? props.activeColor : props.inactiveColor;
        }
      };
    });
    function getCustomPrefix(index) {
      var _a;
      const customIcon = (_a = props.list[index]) == null ? void 0 : _a.customIcon;
      if (customIcon === void 0 || customIcon === null || customIcon === "") {
        return "uicon";
      }
      if (typeof customIcon === "string") {
        return customIcon;
      }
      if (typeof customIcon === "boolean") {
        return customIcon ? "custom-icon" : "uicon";
      }
      return "uicon";
    }
    async function clickHandler(index) {
      if (props.beforeSwitch && typeof props.beforeSwitch === "function") {
        let beforeSwitchResult = props.beforeSwitch(index);
        if (typeof beforeSwitchResult === "object" && beforeSwitchResult !== null && typeof beforeSwitchResult.then === "function") {
          await beforeSwitchResult.then(() => {
            switchTab(index);
          }).catch(() => {
          });
        } else if (beforeSwitchResult === true) {
          switchTab(index);
        }
      } else {
        switchTab(index);
      }
    }
    function switchTab(index) {
      var _a;
      emit("change", index);
      if ((_a = props.list[index]) == null ? void 0 : _a.pagePath) {
        common_vendor.index.switchTab({ url: props.list[index].pagePath });
      } else {
        emit("update:modelValue", index);
      }
    }
    function getOffsetRight(count, isDot) {
      if (isDot) {
        return -20;
      } else if (count > 9) {
        return -40;
      } else {
        return -30;
      }
    }
    function getBadgeOffsetTop(count, isDot) {
      return -2;
    }
    function getIconSize(index) {
      const item = props.list[index] || {};
      if (props.midButton && item.midButton) {
        return props.midButtonSize;
      }
      if (item.iconSize !== void 0 && item.iconSize !== null && item.iconSize !== "") {
        return item.iconSize;
      }
      return props.iconSize;
    }
    function getTextSize(index) {
      const item = props.list[index] || {};
      if (item.textSize !== void 0 && item.textSize !== null && item.textSize !== "") {
        return item.textSize;
      }
      return props.textSize;
    }
    function getMidButtonLeft() {
      const windowWidth = uni_modules_uviewPro_libs_index.$u.sys().windowWidth;
      midButtonLeft.value = windowWidth / 2 + "px";
    }
    function containerStyle(index) {
      const style = {};
      const item = props.list[index] || {};
      if (item.gap !== void 0 && item.gap !== null && item.gap !== "") {
        style.gap = uni_modules_uviewPro_libs_index.$u.addUnit(item.gap);
      } else {
        style.gap = uni_modules_uviewPro_libs_index.$u.addUnit(props.gap);
      }
      if (props.midButton && item.midButton) {
        const iconSizeRaw = getIconSize(index);
        const numericSize = parseFloat(String(iconSizeRaw)) || parseFloat(String(props.midButtonSize)) || 100;
        style.paddingTop = uni_modules_uviewPro_libs_index.$u.addUnit(numericSize / 2 + 8);
        style.boxSizing = "border-box";
      }
      return uni_modules_uviewPro_libs_index.$u.toStyle(style);
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: props.show
      }, props.show ? common_vendor.e({
        b: common_vendor.f(props.list, (item, index, i0) => {
          return common_vendor.e({
            a: item.iconPath || item.selectedIconPath
          }, item.iconPath || item.selectedIconPath ? common_vendor.e({
            b: "62b8a246-0-" + i0,
            c: common_vendor.p({
              size: getIconSize(index),
              name: elIconPath.value(index),
              ["img-mode"]: "scaleToFill",
              color: elColor.value(index),
              ["custom-prefix"]: getCustomPrefix(index)
            }),
            d: item.count || item.isDot
          }, item.count || item.isDot ? {
            e: "62b8a246-1-" + i0,
            f: common_vendor.p({
              count: item.count,
              ["is-dot"]: item.isDot,
              offset: [getBadgeOffsetTop(item.count || 0, item.isDot || false), getOffsetRight(item.count || 0, item.isDot || false)]
            })
          } : {}, {
            g: common_vendor.n(props.midButton && item.midButton ? "u-tabbar__content__circle__icon" : "u-tabbar__content__item__icon")
          }) : {}, {
            h: item.text
          }, item.text ? {
            i: common_vendor.t(item.text),
            j: elColor.value(index),
            k: common_vendor.unref(uni_modules_uviewPro_libs_index.$u).addUnit(getTextSize(index)),
            l: item.text && !(item.iconPath || item.selectedIconPath) ? 1 : ""
          } : {}, {
            m: props.midButton && item.midButton ? 1 : "",
            n: common_vendor.s(containerStyle(index)),
            o: index,
            p: props.midButton && item.midButton ? 1 : "",
            q: common_vendor.o(($event) => clickHandler(index), index)
          });
        }),
        c: props.bgColor,
        d: props.midButton
      }, props.midButton ? {
        e: props.borderTop ? 1 : "",
        f: props.bgColor,
        g: midButtonLeft.value
      } : {}, {
        h: common_vendor.unref(uni_modules_uviewPro_libs_index.$u).addUnit(props.height),
        i: props.bgColor,
        j: uZIndex.value,
        k: props.borderTop ? 1 : "",
        l: `calc(${common_vendor.unref(uni_modules_uviewPro_libs_index.$u).addUnit(props.height)} + ${props.midButton ? "60rpx" : "1px"})`,
        m: common_vendor.n(_ctx.customClass),
        n: common_vendor.s(common_vendor.unref(uni_modules_uviewPro_libs_index.$u).toStyle(_ctx.customStyle)),
        o: common_vendor.o(() => {
        }, "2e")
      }) : {});
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-62b8a246"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uview-pro/components/u-tabbar/u-tabbar.js.map
