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);
};
const getLineItemBumpIds = (line_items) => {
  return ((line_items === null || line_items === void 0 ? void 0 : line_items.data) || []).map(item => { var _a; return ((_a = item === null || item === void 0 ? void 0 : item.bump) === null || _a === void 0 ? void 0 : _a.id) || (item === null || item === void 0 ? void 0 : item.bump); });
};
const getLineItemByPriceId = (line_items, priceId) => {
  return ((line_items === null || line_items === void 0 ? void 0 : line_items.data) || []).find(item => item.price.id === priceId);
};
/**
 * 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);
};
/**
 * Is the price in a checkout session
 */
const isBumpInOrder = (bump, order) => {
  const bumpIds = getLineItemBumpIds(order === null || order === void 0 ? void 0 : order.line_items);
  return !!bumpIds.find(id => (bump === null || bump === void 0 ? void 0 : bump.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 { isBumpInOrder as a, convertLineItemsToLineItemData as c, getLineItemByPriceId as g, hasSubscription as h, isPriceInOrder as i };
