import { e as extractQuote } from './extractQuote-aa1e3309.js';
import './sortQuotesByDeliverySpeedEstimate-f8c8a1b8.js';
import 'date-fns';
import 'duration-fns';

function isDifferentTargetCountry(quotes) {
  return quotes.some(q => q.targetCountry !== quotes[0].targetCountry);
}
function transformQuotesResponse(quotesResults, targetCurrency) {
  const quotes = quotesResults.providers.map(p => {
    const quote = extractQuote(p.quotes, targetCurrency);
    const transformedQuote = {
      id: p.id,
      alias: p.alias,
      name: p.name,
      providerType: p.type,
      logos: p.logos,
      partner: typeof p.partner === 'undefined' ? false : p.partner,
      // TODO: Can be removed once field is live
      dateCollected: quote.dateCollected,
      fees: quote.fee,
      rate: quote.rate,
      receivedAmount: quote.receivedAmount,
      deliveryEstimation: quote.deliveryEstimation
    };
    if (p.quotes.length > 1 && isDifferentTargetCountry(p.quotes)) {
      transformedQuote.targetCountry = quote.targetCountry;
    }
    return transformedQuote;
  });

  // TODO: Can we just return quotes instead, rather than wrapping it in an object?
  return {
    quotes
  };
}

export { transformQuotesResponse as default };
//# sourceMappingURL=transformQuotesResponse.js.map
