"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getCardType = void 0;
var _getCardConfig = require("./getCardConfig");
var _Payment = require("../../../Payment.constants");
const getCardType = (card, cards) => {
  const {
    maxLength = {}
  } = (0, _getCardConfig.getCardConfig)(card);
  if (!card || maxLength.card !== card.length) return;
  const cardTypes = {
    [_Payment.CARD.AMERICAN_EXPRESS]: /^3[47][0-9]{13}$/,
    [_Payment.CARD.DINERS_CLUB]: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
    [_Payment.CARD.DISCOVER]: /^6(?:011|5[0-9]{2})[0-9]{12}$/,
    [_Payment.CARD.JCB]: /^(?:2131|1800|35\d{3})\d{11}$/,
    [_Payment.CARD.MAESTRO]: /^(5018|5020|5038|6304|6759|6761|6763)[0-9]{8,15}$/,
    [_Payment.CARD.MASTERCARD]: /^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/,
    [_Payment.CARD.UNIONPAY]: /^(62[0-9]{14,17})$/,
    [_Payment.CARD.VISA]: /^4[0-9]{12}(?:[0-9]{3})?$/
  };
  for (const cardType in cardTypes) {
    if (card.replaceAll(' ', '').match(cardTypes[cardType]) && (!cards || cards.includes(cardType))) {
      return cardType;
    }
  }
};
exports.getCardType = getCardType;
//# sourceMappingURL=getCardType.js.map