import{SF_ErrorCodes as e,ERROR_ACTION_FOCUS_FIELD as r,ERROR_ACTION_BLUR_SCENARIO as t,ErrorCodePrefixes as n}from"./constants.js";import{ENCRYPTED_PWD_FIELD as o,ENCRYPTED_SECURITY_CODE as s,ENCRYPTED_EXPIRY_YEAR as a,ENCRYPTED_EXPIRY_MONTH as i,ENCRYPTED_EXPIRY_DATE as c,ENCRYPTED_CARD_NUMBER as l}from"../../components/internal/SecuredFields/lib/constants.js";function u(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}const f=(r,t)=>Object.values(e).reduce((e,n)=>(n.includes(t)&&(e[n]=r.get(n)),e),{}),b=(e,r,t)=>{const n=function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(r){u(e,r,t[r])})}return e}({},e),o=y(t);return n.error=f(r,o),n},p=(e,r)=>{let t=e;for(const[n,o]of Object.entries(r))if(o===e){t=n;break}return null==t?void 0:t.toLowerCase().replace(/[_.\s]/g,"-")},y=e=>{let r;switch(e){case l:r=n.CC_NUM;break;case c:r=n.CC_DAT;break;case i:r=n.CC_MTH;break;case a:r=n.CC_YR;break;case s:r=n.CC_CVC;break;case o:r=n.KCP_PWD}return r},g=({errors:e,i18n:r,layout:t,countrySpecificLabels:n,fieldTypeMappingFn:o})=>Object.entries(e).reduce((s,[a,i])=>{if(i){const i=e[a],c="errorI18n"in i&&"rootNode"in i,l="object"==typeof i.errorMessage;let u,f;if(u=c?i.error:l?i.errorMessage.translationKey:i.errorMessage,c&&"errorI18n"in i)f=i.errorI18n+"";else{const e=o?o(a,r,n):"";if(l){const t=i.errorMessage.translationKey,n=i.errorMessage.translationObject.values.format;f=`${r.get(t,{values:{label:e,format:n}})}`}else f=r.get(i.errorMessage,{values:{label:e}})+""}s.push({field:a,errorMessage:f,errorCode:u}),t&&s.sort((e,r)=>t.indexOf(e.field)-t.indexOf(r.field))}return s},[]),d=({i18n:e,fieldTypeMappingFn:n,SRPanelRef:o},{errors:s,isValidating:a,layout:i,countrySpecificLabels:c})=>{const l=g({errors:s,i18n:e,fieldTypeMappingFn:n,countrySpecificLabels:c,layout:i});if(l.length){if(a){const e=l.map(e=>e.errorMessage);o.setMessages(e);const t=l.map(e=>e.field);return{currentErrorsSortedByLayout:l,action:r,fieldToFocus:t[0]}}return null==o||o.setMessages(null),{currentErrorsSortedByLayout:l,action:t}}return null==o||o.setMessages(null),{currentErrorsSortedByLayout:l,action:"none"}},M=(e,r)=>{if(!e)return null;return Object.entries(e).reduce((e,[t,n])=>{if(n){e[`${r}${t}`]=n}return e},{})};export{b as addErrorTranslationsToObject,M as enhanceErrorObjectKeys,p as getErrorMessageFromCode,f as getTranslatedErrors,d as setSRMessagesFromErrors,g as sortErrorsByLayout};
//# sourceMappingURL=utils.js.map
