const convertLineItemsToLineItemData = (lineItems) => {
  return ((lineItems === null || lineItems === void 0 ? void 0 : lineItems.data) || []).map(item => {
    return {
      price_id: item.price.id,
      quantity: item.quantity,
    };
  });
};
/**
 * Get price ids from line items
 * @param order
 * @returns
 */
const getLineItemPriceIds = (line_items) => {
  return ((line_items === null || line_items === void 0 ? void 0 : line_items.data) || []).map(item => item.price.id);
};
/**
 * Is the price in a checkout session
 */
const isPriceInOrder = (price, order) => {
  const priceIds = getLineItemPriceIds(order === null || order === void 0 ? void 0 : order.line_items);
  return !!priceIds.find(id => (price === null || price === void 0 ? void 0 : price.id) === id);
};
/** Check if the order has a subscription */
const hasSubscription = (order) => {
  var _a, _b, _c;
  // no line items.
  if (!((_b = (_a = order === null || order === void 0 ? void 0 : order.line_items) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.length))
    return false;
  // has subscription product.
  return (_c = order === null || order === void 0 ? void 0 : order.line_items.data) === null || _c === void 0 ? void 0 : _c.some(item => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.price) === null || _a === void 0 ? void 0 : _a.recurring_interval_count; });
};

export { convertLineItemsToLineItemData as c, hasSubscription as h, isPriceInOrder as i };
