import{SF_ErrorCodes as e,ERROR_ACTION_FOCUS_FIELD as r,ERROR_ACTION_BLUR_SCENARIO as s,ErrorCodePrefixes as t}from"./constants.js";import{ENCRYPTED_PWD_FIELD as o,ENCRYPTED_SECURITY_CODE as n,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";const u=(r,s)=>Object.values(e).reduce((e,t)=>(t.includes(s)&&(e[t]=r.get(t)),e),{}),f=(e,r,s)=>{const t={...e},o=p(s);return t.error=u(r,o),t},d=(e,r)=>{let s=e;for(const[t,o]of Object.entries(r))if(o===e){s=t;break}return s?.toLowerCase().replace(/[_.\s]/g,"-")},p=e=>{let r;switch(e){case l:r=t.CC_NUM;break;case c:r=t.CC_DAT;break;case i:r=t.CC_MTH;break;case a:r=t.CC_YR;break;case n:r=t.CC_CVC;break;case o:r=t.KCP_PWD}return r},g=({errors:e,i18n:r,layout:s,countrySpecificLabels:t,fieldTypeMappingFn:o})=>Object.entries(e).reduce((n,[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,t):"";if(l){const s=i.errorMessage.translationKey,t=i.errorMessage.translationObject.values.format;f=`${r.get(s,{values:{label:e,format:t}})}`}else f=r.get(i.errorMessage,{values:{label:e}})+""}n.push({field:a,errorMessage:f,errorCode:u}),s&&n.sort((e,r)=>s.indexOf(e.field)-s.indexOf(r.field))}return n},[]),b=({i18n:e,fieldTypeMappingFn:t,SRPanelRef:o},{errors:n,isValidating:a,layout:i,countrySpecificLabels:c})=>{const l=g({errors:n,i18n:e,fieldTypeMappingFn:t,countrySpecificLabels:c,layout:i});if(l.length){if(a){const e=l.map(e=>e.errorMessage);o.setMessages(e);const s=l.map(e=>e.field);return{currentErrorsSortedByLayout:l,action:r,fieldToFocus:s[0]}}return o?.setMessages(null),{currentErrorsSortedByLayout:l,action:s}}return o?.setMessages(null),{currentErrorsSortedByLayout:l,action:"none"}},y=(e,r)=>{if(!e)return null;return Object.entries(e).reduce((e,[s,t])=>{if(t){e[`${r}${s}`]=t}return e},{})};export{f as addErrorTranslationsToObject,y as enhanceErrorObjectKeys,d as getErrorMessageFromCode,u as getTranslatedErrors,b as setSRMessagesFromErrors,g as sortErrorsByLayout};
//# sourceMappingURL=utils.js.map
