"use strict";
const common_vendor = require("../../../common/vendor.js");
const sheep_index = require("../../index.js");
const sheep_api_promotion_coupon = require("../../api/promotion/coupon.js");
const sheep_util_const = require("../../util/const.js");
const sheep_util_index = require("../../util/index.js");
require("../../api/index.js");
require("../../api/distri/score.js");
require("../../request/index.js");
require("../../config/index.js");
require("../../store/index.js");
require("../../store/app.js");
require("../../api/promotion/diy.js");
require("../../platform/index.js");
require("../../platform/provider/wechat/index.js");
require("../../platform/provider/wechat/miniProgram.js");
require("../../api/member/auth.js");
require("../../api/member/social.js");
require("../../api/member/user.js");
require("../../platform/provider/apple/index.js");
require("../../platform/share.js");
require("../../router/index.js");
require("../../hooks/useModal.js");
require("../../helper/index.js");
require("../../helper/test.js");
require("../../helper/digit.js");
require("../../api/member/signin.js");
require("../../helper/throttle.js");
require("../../url/index.js");
require("../../platform/pay.js");
require("../../api/pay/order.js");
require("../../store/user.js");
require("../../store/cart.js");
require("../../api/trade/cart.js");
require("../../api/pay/wallet.js");
require("../../api/trade/order.js");
require("../../store/sys.js");
require("../../store/modal.js");
require("../../api/distri/share.js");
require("../../api/distri/team.js");
require("../../api/infra/file.js");
require("../../api/member/address.js");
require("../../api/member/point.js");
require("../../api/migration/app.js");
require("../../api/migration/chat.js");
require("../../api/migration/index.js");
require("../../api/migration/third.js");
require("../../api/pay/channel.js");
require("../../api/product/category.js");
require("../../api/product/comment.js");
require("../../api/product/favorite.js");
require("../../api/product/history.js");
require("../../api/product/spu.js");
require("../../api/promotion/activity.js");
require("../../api/promotion/article.js");
require("../../api/promotion/bargain.js");
require("../../api/promotion/combination.js");
require("../../api/promotion/rewardActivity.js");
require("../../api/promotion/seckill.js");
require("../../api/system/area.js");
require("../../api/system/voice.js");
require("../../api/trade/afterSale.js");
require("../../api/trade/brokerage.js");
require("../../api/trade/config.js");
require("../../api/trade/delivery.js");
require("../../config/zIndex.js");
if (!Array) {
  const _easycom_su_coupon2 = common_vendor.resolveComponent("su-coupon");
  _easycom_su_coupon2();
}
const _easycom_su_coupon = () => "../../ui/su-coupon/su-coupon.js";
if (!Math) {
  _easycom_su_coupon();
}
const _sfc_main = {
  __name: "s-coupon-block",
  props: {
    data: {
      type: Object,
      default: () => ({})
    },
    styles: {
      type: Object,
      default: () => ({})
    }
  },
  setup(__props) {
    const props = __props;
    const { columns, button } = props.data;
    const SIZE_LIST = ["lg", "md", "xs"];
    const couponBg = {
      background: `url(${sheep_index.sheep.$url.cdn(props.data.bgImg)}) no-repeat top center / 100% 100%`
    };
    const btnStyles = {
      background: button.bgColor,
      color: button.color
    };
    const formatCouponDiscountType = (coupon) => {
      if (coupon.discountType === sheep_util_const.PromotionDiscountTypeEnum.PRICE.type) {
        return "reduce";
      }
      if (coupon.discountType === sheep_util_const.PromotionDiscountTypeEnum.PERCENT.type) {
        return "percent";
      }
      return `未知【${coupon.discountType}】`;
    };
    const formatCouponDiscountValue = (coupon) => {
      if (coupon.discountType === sheep_util_const.PromotionDiscountTypeEnum.PRICE.type) {
        return sheep_util_index.floatToFixed2(coupon.discountPrice);
      }
      if (coupon.discountType === sheep_util_const.PromotionDiscountTypeEnum.PERCENT.type) {
        return coupon.discountPercent;
      }
      return `未知【${coupon.discountType}】`;
    };
    const formatValidityType = (row) => {
      if (row.validityType === sheep_util_const.CouponTemplateValidityTypeEnum.DATE.type) {
        return `${sheep_util_index.formatDate(row.validStartTime)} 至 ${sheep_util_index.formatDate(row.validEndTime)}`;
      }
      if (row.validityType === sheep_util_const.CouponTemplateValidityTypeEnum.TERM.type) {
        return `领取后第 ${row.fixedStartTerm} - ${row.fixedEndTerm} 天内可用`;
      }
      return "未知【" + row.validityType + "】";
    };
    const couponList = common_vendor.ref([]);
    async function onGetCoupon(id) {
      const { error, msg } = await sheep_api_promotion_coupon.CouponApi.takeCoupon(id);
      if (error === 0) {
        common_vendor.index.showToast({
          title: msg,
          icon: "none"
        });
        return;
      }
      await getCouponTemplateList();
    }
    const getCouponTemplateList = async () => {
      const { data } = await sheep_api_promotion_coupon.CouponApi.getCouponTemplateListByIds(props.data.couponIds.join(","));
      couponList.value = data;
    };
    common_vendor.onMounted(() => {
      getCouponTemplateList();
    });
    return (_ctx, _cache) => {
      return {
        a: common_vendor.f(couponList.value, (item, index, i0) => {
          return common_vendor.e(common_vendor.unref(columns) === 2 ? {
            a: common_vendor.o(($event) => onGetCoupon(item.id), index),
            b: common_vendor.s(btnStyles)
          } : {
            c: common_vendor.s(btnStyles),
            d: common_vendor.o(($event) => onGetCoupon(item.id), index)
          }, {
            e: "6b61b8da-0-" + i0,
            f: common_vendor.p({
              size: SIZE_LIST[common_vendor.unref(columns) - 1],
              textColor: __props.data.textColor,
              background: "",
              couponId: item.id,
              title: item.name,
              type: formatCouponDiscountType(item),
              value: formatCouponDiscountValue(item),
              sellBy: formatValidityType(item)
            }),
            g: index
          });
        }),
        b: common_vendor.unref(columns) === 2,
        c: common_vendor.s(couponBg),
        d: common_vendor.s({
          marginLeft: `${__props.data.space}px`
        })
      };
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-6b61b8da"], ["__file", "D:/zx/mall-front-app/sheep/components/s-coupon-block/s-coupon-block.vue"]]);
wx.createComponent(Component);
