import{V as t,M as r,A as s,D as i}from"./p-78ba7ca9.js";import{m as e,a,s as d}from"./p-262ec334.js";import{I as n}from"./p-abd7aeaa.js";class o extends n{static validateCreditCardDigits(t){const r=e(t).reverse();return!(r.length<12||r.length>19)&&a(r,(t=>t%2==0)).reduce(d,0)%10==0}evaluate(t){if(!this.isAcceptedInputType(t))throw new Error(`Unexpected type of input: ${typeof t}: ${t}`);const r=this.formatCreditCardNumber(t),s=this.isValidVisaCreditCard(t)||this.isValidAmexCreditCard(t)||this.isValidDiscoverCreditCard(t)||this.isValidMasterCardCreditCard(t)||!this.isSupportedCreditCardType(r)&&o.validateCreditCardDigits(r);return{isValid:s,message:s?"":"Credit card number is invalid"}}canEvaluate(t,r){return r?this.isAcceptedInputType(t)&&!r.disabled&&r.visible:this.isAcceptedInputType(t)}shouldShowError(t){return!t.disabled&&t.visible&&(t.touched||t.modified)}isValidVisaCreditCard(r){const s=this.formatCreditCardNumber(r);return t.test(s)&&(13===s.length||16===s.length||19===s.length)&&o.validateCreditCardDigits(s)}isValidMasterCardCreditCard(t){const s=this.formatCreditCardNumber(t);return r.test(s)&&16===s.length&&o.validateCreditCardDigits(s)}isValidAmexCreditCard(t){const r=this.formatCreditCardNumber(t);return s.test(r)&&15===r.length&&o.validateCreditCardDigits(r)}isValidDiscoverCreditCard(t){const r=this.formatCreditCardNumber(t);return i.test(r)&&16===r.length&&o.validateCreditCardDigits(r)}isAcceptedInputType(t){return"string"==typeof t}formatCreditCardNumber(t){return t.replace(/\s/g,"")}isSupportedCreditCardType(e){return t.test(e)||r.test(e)||s.test(e)||i.test(e)}}export{o as V}