/**
 * Handles coupon calculation
 * @param amount The amount from the form
 * @param coupon The coupon object
 * @returns The new total
 */
export function applyCoupon(amount, coupon) {
  // not valid
  if (!coupon) {
    return amount;
  }
  // amount off
  if (coupon === null || coupon === void 0 ? void 0 : coupon.amount_off) {
    return amount - coupon.amount_off;
  }
  // percent off
  if (coupon === null || coupon === void 0 ? void 0 : coupon.percent_off) {
    return amount - amount * (coupon.percent_off / 100);
  }
  return amount;
}
