"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: "SelectCouponModal",
  props: {
    open: {
      type: Boolean,
      default: false
    },
    couponList: {
      type: Array,
      default: () => []
    },
    selectedCouponId: {
      type: [Number, String],
      default: null
    }
  },
  emits: ["update:open", "select", "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 isSelected = (coupon) => {
      return props.selectedCouponId !== null && coupon.id === props.selectedCouponId;
    };
    const handleSelect = (coupon, index) => {
      const newSelectedId = isSelected(coupon) ? null : coupon.id;
      emit("select", { coupon, index, selectedId: newSelectedId });
    };
    const handleClose = () => {
      getOpen.value = false;
      emit("close");
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.unref(utils_file.getFileUrl)("img/icon/close.png"),
        b: common_vendor.o(handleClose),
        c: common_vendor.f(__props.couponList, (coupon, index, i0) => {
          return {
            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: isSelected(coupon),
            f: !isSelected(coupon),
            g: coupon.id || index,
            h: common_vendor.o(($event) => handleSelect(coupon, index), coupon.id || index)
          };
        }),
        d: common_vendor.unref(utils_file.getFileUrl)("img/icon/sele1.png"),
        e: common_vendor.unref(utils_file.getFileUrl)("img/icon/sele2.png"),
        f: common_vendor.o(($event) => getOpen.value = $event),
        g: common_vendor.p({
          type: "bottom",
          isMack: true,
          open: getOpen.value
        })
      };
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-5880f75a"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/orderFood/components/SelectCouponModal.js.map
