"use strict";
const common_vendor = require("../../../common/vendor.js");
const utils_file = require("../../../utils/file.js");
if (!Math) {
  BasicModal();
}
const BasicModal = () => "../../../components/Modal/BasicModal.js";
const _sfc_main = {
  __name: "CouponModal",
  props: {
    open: {
      type: Boolean,
      default: false
    },
    couponList: {
      type: Array,
      default: () => []
    }
  },
  emits: ["update:open", "receive", "close"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const getOpen = common_vendor.computed({
      get: () => props.open,
      set: (val) => emit("update:open", val)
    });
    const formatExpireDate = (date) => {
      if (!date)
        return "";
      if (typeof date === "string") {
        const d = new Date(date);
        if (!isNaN(d.getTime())) {
          const year = d.getFullYear();
          const month = String(d.getMonth() + 1).padStart(2, "0");
          const day = String(d.getDate()).padStart(2, "0");
          return `${year}/${month}/${day}`;
        }
        if (date.includes("/")) {
          return date;
        }
      }
      return date;
    };
    const handleClose = () => {
      getOpen.value = false;
      emit("close");
    };
    const handleReceive = (coupon, index) => {
      emit("receive", { coupon, index });
    };
    const copyUrl = () => {
      common_vendor.index.setClipboardData({
        data: "http:https://modao.cc/proto/KQv3fh5Kt7fy7tfvLMTCx/sharing?view_mode=read_only",
        success: () => {
          common_vendor.index.showToast({
            title: "复制成功",
            icon: "none"
          });
        }
      });
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.unref(utils_file.getFileUrl)("img/icon/close.png"),
        b: common_vendor.o(handleClose),
        c: __props.couponList.length > 0
      }, __props.couponList.length > 0 ? {
        d: common_vendor.f(__props.couponList, (coupon, index, i0) => {
          return common_vendor.e({
            a: common_vendor.t(coupon.amount),
            b: common_vendor.t(coupon.minAmount),
            c: common_vendor.t(coupon.name),
            d: common_vendor.t(formatExpireDate(coupon.expireDate)),
            e: !coupon.isReceived
          }, !coupon.isReceived ? {
            f: common_vendor.o(($event) => handleReceive(coupon, index), coupon.id || index)
          } : {
            g: common_vendor.unref(utils_file.getFileUrl)("img/icon/ylq.png")
          }, {
            h: coupon.id || index,
            i: common_vendor.n({
              "coupon-card--received": coupon.isReceived
            })
          });
        })
      } : {}, {
        e: __props.couponList.length === 0
      }, __props.couponList.length === 0 ? {
        f: common_vendor.unref(utils_file.getFileUrl)("img/icon/noCoupon.png"),
        g: common_vendor.o(copyUrl)
      } : {}, {
        h: common_vendor.o(($event) => getOpen.value = $event),
        i: common_vendor.p({
          type: "bottom",
          isMack: true,
          open: getOpen.value
        })
      });
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-c66d46bb"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/orderFood/components/CouponModal.js.map
