import{getCardImageUrl as e}from"../utils.js";import{ENCRYPTED_CARD_NUMBER as t,ENCRYPTED_SECURITY_CODE as r,ENCRYPTED_EXPIRY_DATE as n,ENCRYPTED_EXPIRY_MONTH as i,ENCRYPTED_EXPIRY_YEAR as s,DATE_POLICY_REQUIRED as o,CVC_POLICY_REQUIRED as a,OPTIONAL as l,HIDDEN as d}from"../lib/constants.js";import{existy as u}from"../../../../utils/commonUtils.js";import c from"../../../../core/Errors/AdyenCheckoutError.js";function p(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function h(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){p(e,t,r[t])})}return e}function f(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}),e}function y(e,t,r,n){return(t!==l&&t!==d||0!==r[e])&&n[e]}var m={handleFocus:function(e){this.numCharsInField[e.fieldType]=e.numChars,this.props.onFocus(e)},handleOnAllValid:function(e){return!this.state.detectedUnsupportedBrands&&(this.setState({isSfpValid:e.allValid},()=>{this.props.onChange(this.state,{event:"handleOnAllValid"}),this.props.onAllValid(e)}),!0)},handleOnAutoComplete:function(e){this.setState({autoCompleteName:e.value},()=>{this.props.onChange(this.state,{event:"handleOnAutoComplete",fieldType:e.fieldType}),this.setState({autoCompleteName:null})}),this.props.onAutoComplete(e)},handleOnFieldValid:function(e){return(!this.state.detectedUnsupportedBrands||e.fieldType!==t)&&(this.setState(t=>{var r;return{data:f(h({},t.data),{[e.encryptedFieldName]:e.blob}),valid:f(h({},t.valid),{[e.encryptedFieldName]:e.valid}),errors:f(h({},t.errors),{[e.fieldType]:null!==(r=t.errors[e.fieldType])&&void 0!==r?r:null})}},()=>{this.props.onChange(this.state,{event:"handleOnFieldValid",fieldType:e.fieldType}),this.props.onFieldValid(e)}),!0)},handleOnLoad:function(e){clearTimeout(this.csfLoadFailTimeout),this.csfLoadFailTimeout=null,this.props.onLoad(e),this.csfConfigFailTimeout=setTimeout(()=>{"ready"!==this.state.status&&(this.setState({status:"csfConfigFailure"}),this.props.onError(new c("ERROR","secured fields have failed to configure")))},this.csfConfigFailTimeoutMS)},handleOnConfigSuccess:function(e){clearTimeout(this.csfConfigFailTimeout),this.csfConfigFailTimeout=null,this.setState({status:"ready"},()=>{this.props.onConfigSuccess(e)})},handleOnBrand:function(t){this.setState(e=>{var l,d;const c=y(r,t.cvcPolicy,this.numCharsInField,e.errors),p=1===this.numDateFields?y(n,t.expiryDatePolicy,this.numCharsInField,e.errors):null,f=2===this.numDateFields?y(i,t.expiryDatePolicy,this.numCharsInField,e.errors):null,m=2===this.numDateFields?y(s,t.expiryDatePolicy,this.numCharsInField,e.errors):null;return{brand:t.brand,cvcPolicy:null!==(l=t.cvcPolicy)&&void 0!==l?l:a,showSocialSecurityNumber:t.showSocialSecurityNumber,errors:h({},e.errors,u(c)&&{[r]:c},u(p)&&{[n]:p},u(f)&&{[i]:f},u(m)&&{[s]:m}),expiryDatePolicy:null!==(d=t.expiryDatePolicy)&&void 0!==d?d:o}},()=>{var r,n;this.props.onChange(this.state,{event:"handleOnBrand"});const i=null!==(r=null===(n=this.props.brandsConfiguration[t.brand])||void 0===n?void 0:n.icon)&&void 0!==r?r:e(t.brand,this.props.resources);this.props.onBrand(f(h({},t),{brandImageUrl:i}))})},handleOnError:function(e,r=null){const n=e.error;return this.setState(i=>h({errors:f(h({},i.errors),{[e.fieldType]:n||null})},r&&{data:f(h({},i.data),{[t]:void 0})},r&&{valid:f(h({},i.valid),{[t]:!1})},r&&{isSfpValid:!1}),()=>{this.props.onChange(this.state,{event:"handleOnError",fieldType:e.fieldType})}),!0},handleOnNoDataRequired:function(){this.setState({status:"ready"},()=>this.props.onChange({isSfpValid:!0}))},handleOnTouchstartIOS:function(e){var t,r;null===(t=(r=this.props).disableIOSArrowKeys)||void 0===t||t.call(r,e)},handleKeyPressed:function(e){if("enterKeyPressed"===e.action){var t,r;const e=new KeyboardEvent("keypress",{bubbles:!0,cancelable:!0,key:"Enter",code:"Enter"});null===(t=(r=this.props).handleKeyPress)||void 0===t||t.call(r,e)}}};export{m as default};
//# sourceMappingURL=SecuredFieldsProviderHandlers.js.map
