"use strict";
const common_vendor = require("../../../../common/vendor.js");
const sheep_index = require("../../../../sheep/index.js");
const sheep_helper_throttle = require("../../../../sheep/helper/throttle.js");
const sheep_hooks_useModal = require("../../../../sheep/hooks/useModal.js");
const sheep_api_product_favorite = require("../../../../sheep/api/product/favorite.js");
require("../../../../sheep/api/index.js");
require("../../../../sheep/api/distri/score.js");
require("../../../../sheep/request/index.js");
require("../../../../sheep/config/index.js");
require("../../../../sheep/store/index.js");
require("../../../../sheep/store/app.js");
require("../../../../sheep/api/promotion/diy.js");
require("../../../../sheep/platform/index.js");
require("../../../../sheep/platform/provider/wechat/index.js");
require("../../../../sheep/platform/provider/wechat/miniProgram.js");
require("../../../../sheep/api/member/auth.js");
require("../../../../sheep/api/member/social.js");
require("../../../../sheep/api/member/user.js");
require("../../../../sheep/platform/provider/apple/index.js");
require("../../../../sheep/platform/share.js");
require("../../../../sheep/router/index.js");
require("../../../../sheep/url/index.js");
require("../../../../sheep/platform/pay.js");
require("../../../../sheep/helper/index.js");
require("../../../../sheep/helper/test.js");
require("../../../../sheep/helper/digit.js");
require("../../../../sheep/api/pay/order.js");
require("../../../../sheep/store/user.js");
require("../../../../sheep/store/cart.js");
require("../../../../sheep/api/trade/cart.js");
require("../../../../sheep/api/pay/wallet.js");
require("../../../../sheep/api/trade/order.js");
require("../../../../sheep/api/promotion/coupon.js");
require("../../../../sheep/store/sys.js");
require("../../../../sheep/store/modal.js");
require("../../../../sheep/api/distri/share.js");
require("../../../../sheep/api/distri/team.js");
require("../../../../sheep/api/infra/file.js");
require("../../../../sheep/api/member/address.js");
require("../../../../sheep/api/member/point.js");
require("../../../../sheep/api/member/signin.js");
require("../../../../sheep/api/migration/app.js");
require("../../../../sheep/api/migration/chat.js");
require("../../../../sheep/api/migration/index.js");
require("../../../../sheep/api/migration/third.js");
require("../../../../sheep/api/pay/channel.js");
require("../../../../sheep/api/product/category.js");
require("../../../../sheep/api/product/comment.js");
require("../../../../sheep/api/product/history.js");
require("../../../../sheep/api/product/spu.js");
require("../../../../sheep/api/promotion/activity.js");
require("../../../../sheep/api/promotion/article.js");
require("../../../../sheep/api/promotion/bargain.js");
require("../../../../sheep/api/promotion/combination.js");
require("../../../../sheep/api/promotion/rewardActivity.js");
require("../../../../sheep/api/promotion/seckill.js");
require("../../../../sheep/api/system/area.js");
require("../../../../sheep/api/system/voice.js");
require("../../../../sheep/api/trade/afterSale.js");
require("../../../../sheep/api/trade/brokerage.js");
require("../../../../sheep/api/trade/config.js");
require("../../../../sheep/api/trade/delivery.js");
require("../../../../sheep/config/zIndex.js");
if (!Array) {
  const _easycom_su_status_bar2 = common_vendor.resolveComponent("su-status-bar");
  const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
  (_easycom_su_status_bar2 + _easycom_su_fixed2)();
}
const _easycom_su_status_bar = () => "../../../../sheep/ui/su-status-bar/su-status-bar.js";
const _easycom_su_fixed = () => "../../../../sheep/ui/su-fixed/su-fixed.js";
if (!Math) {
  (_easycom_su_status_bar + _easycom_su_fixed)();
}
const _sfc_main = {
  __name: "detail-navbar",
  props: {
    modelValue: {
      type: Object,
      default() {
      }
    },
    collectIcon: {
      type: Boolean,
      default: true
    },
    shareIcon: {
      type: Boolean,
      default: true
    }
  },
  emits: ["clickLeft"],
  setup(__props, { emit: __emit }) {
    const isLogin = common_vendor.computed(() => sheep_index.sheep.$store("user").isLogin);
    const sys_statusBar = sheep_index.sheep.$platform.device.statusBarHeight;
    const sys_navBar = sheep_index.sheep.$platform.navbar;
    const capsuleStyle = {
      width: sheep_index.sheep.$platform.capsule.width + "px",
      height: sheep_index.sheep.$platform.capsule.height + "px"
    };
    const state = common_vendor.reactive({
      tabOpacityVal: 0,
      curTab: "goods",
      tabList: [
        {
          label: "商品",
          value: "goods",
          to: "detail-swiper-selector"
        },
        {
          label: "评价",
          value: "comment",
          to: "detail-comment-selector"
        },
        {
          label: "详情",
          value: "detail",
          to: "detail-content-selector"
        }
      ]
    });
    const props = __props;
    const emits = __emit;
    const hasHistory = sheep_index.sheep.$router.hasHistory();
    function onClickLeft() {
      if (hasHistory) {
        sheep_index.sheep.$router.back();
      } else {
        sheep_index.sheep.$router.go("/pages/index/index");
      }
      emits("clickLeft");
    }
    function onClickRight() {
      sheep_hooks_useModal.showMenuTools();
    }
    let commentCard = {
      top: 0,
      bottom: 0
    };
    function getCommentCardNode() {
      return new Promise((res, rej) => {
        common_vendor.index.createSelectorQuery().select(".detail-comment-selector").boundingClientRect((data) => {
          if (data) {
            commentCard.top = data.top;
            commentCard.bottom = data.top + data.height;
            res(data);
          } else {
            res(null);
          }
        }).exec();
      });
    }
    function onTab(tab) {
      let scrollTop = 0;
      if (tab.value === "comment") {
        scrollTop = commentCard.top - sys_navBar + 1;
      } else if (tab.value === "detail") {
        scrollTop = commentCard.bottom - sys_navBar + 1;
      }
      common_vendor.index.pageScrollTo({
        scrollTop,
        duration: 200
      });
    }
    async function onFavorite() {
      if (!isLogin.value) {
        sheep_hooks_useModal.showAuthModal();
        return;
      }
      if (props.modelValue.favorite) {
        const {
          code
        } = await sheep_api_product_favorite.FavoriteApi.deleteFavorite(props.modelValue.id);
        if (code !== 0) {
          return;
        }
        sheep_index.sheep.$helper.toast("取消收藏");
        props.modelValue.favorite = false;
      } else {
        const {
          code
        } = await sheep_api_product_favorite.FavoriteApi.createFavorite(props.modelValue.id);
        await sheep_api_product_favorite.FavoriteApi.createCollectBefore(props.modelValue.id);
        if (code !== 0) {
          return;
        }
        sheep_index.sheep.$helper.toast("收藏成功");
        props.modelValue.favorite = true;
      }
    }
    common_vendor.onPageScroll((e) => {
      state.tabOpacityVal = e.scrollTop > sheep_index.sheep.$platform.navbar ? 1 : e.scrollTop * 0.01;
      if (commentCard.top === 0) {
        sheep_helper_throttle.throttle(() => {
          getCommentCardNode();
        }, 50);
      }
      if (e.scrollTop < commentCard.top - sys_navBar) {
        state.curTab = "goods";
      } else if (e.scrollTop >= commentCard.top - sys_navBar && e.scrollTop <= commentCard.bottom - sys_navBar) {
        state.curTab = "comment";
      } else {
        state.curTab = "detail";
      }
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.unref(hasHistory)
      }, common_vendor.unref(hasHistory) ? {} : {}, {
        b: common_vendor.o(onClickLeft),
        c: common_vendor.o(onClickRight),
        d: common_vendor.f(state.tabList, (item, k0, i0) => {
          return {
            a: common_vendor.t(item.label),
            b: common_vendor.n(state.curTab === item.value ? "cur-tab-title" : ""),
            c: state.curTab === item.value,
            d: item.value,
            e: common_vendor.o(($event) => onTab(item), item.value)
          };
        }),
        e: common_vendor.s({
          opacity: state.tabOpacityVal
        }),
        f: __props.collectIcon
      }, __props.collectIcon ? common_vendor.e({
        g: __props.modelValue.favorite
      }, __props.modelValue.favorite ? {
        h: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/collect_1.gif")
      } : {
        i: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/collect_0.png")
      }, {
        j: common_vendor.o(onFavorite)
      }) : {}, {
        k: __props.shareIcon
      }, __props.shareIcon ? {
        l: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/share.png"),
        m: common_vendor.o(($event) => common_vendor.unref(sheep_hooks_useModal.showShareModal)(__props.modelValue.id))
      } : {}, {
        n: common_vendor.s({
          opacity: state.tabOpacityVal
        }),
        o: common_vendor.s(capsuleStyle),
        p: common_vendor.s({
          height: common_vendor.unref(sys_navBar) - common_vendor.unref(sys_statusBar) + "px"
        }),
        q: common_vendor.p({
          alway: true,
          bgStyles: {
            background: "#fff"
          },
          val: 0,
          noNav: true,
          opacity: true,
          placeholder: false
        })
      });
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-3e9ea950"], ["__file", "D:/zx/mall-front-app/pages/goods/components/detail/detail-navbar.vue"]]);
wx.createComponent(Component);
