Liferay.Loader.define("data-engine-js-components-web@1.0.79/js/core/reducers/languageReducer.es",["module","exports","require","../../utils/fieldSupport","../../utils/repeatable.es","../../utils/visitors.es","../actions/eventTypes.es"],(function(e,a,t){window;{Object.defineProperty(a,"__esModule",{value:!0}),a.default=function(e,a){switch(a.type){case r.EVENT_TYPES.LANGUAGE.CHANGE:{const{availableLanguageIds:t,defaultLanguageId:l,focusedField:r}=e,{defaultLanguageId:s=l,editingLanguageId:d,pages:g}=a.payload,p=new i.PagesVisitor(null!=g?g:e.pages);let f=r;const b=p.mapFields((e=>{let{localizable:a,localizedValue:l,localizedValueEdited:i,value:r}=e,g=function(e,a){if(null==e)return{};var t,n,l=function(e,a){if(null==e)return{};var t,n,l={},i=Object.keys(e);for(n=0;n<i.length;n++)t=i[n],a.indexOf(t)>=0||(l[t]=e[t]);return l}(e,a);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)t=i[n],a.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(l[t]=e[t])}return l}(e,["localizable","localizedValue","localizedValueEdited","value"]);if(g.settingsContext){const e=u(u(u({},g),c(u(u({},g),{},{availableLanguageIds:t,defaultLanguageId:s,editingLanguageId:d}))),{},{value:r});return e.inputMask&&(0,n.updateInputMaskProperties)(d,e),g.fieldName===f.fieldName&&(f=e),e}return{value:o({defaultLanguageId:s,editingLanguageId:d,localizable:a,localizedValue:l,localizedValueEdited:i,type:g.type,value:r})}}),!0,!0);return{defaultLanguageId:s,editingLanguageId:d,focusedField:f,pages:b}}case r.EVENT_TYPES.LANGUAGE.ADD:{const{languageId:t}=a.payload,{availableLanguageIds:n}=e;return n.includes(t)?e:{availableLanguageIds:[...n,t]}}case r.EVENT_TYPES.LANGUAGE.UPDATE:{const{availableLanguageIds:t,focusedField:n,pages:l}=e,i=a.payload.activeLanguageIds,r=new Set(i),s=t.filter((e=>!r.has(e))),d=new Set(t),o=i.filter((e=>!d.has(e)));return s.length?u({availableLanguageIds:i},g(n,l,...s)):o.length?{availableLanguageIds:[...i]}:e}case r.EVENT_TYPES.LANGUAGE.DELETE:{const{languageIds:t}=a.payload,{availableLanguageIds:n,focusedField:l,pages:i}=e;return u({availableLanguageIds:n.filter((e=>!t.includes(e)))},g(l,i,...t))}default:return e}};var n=t("../../utils/fieldSupport"),l=t("../../utils/repeatable.es"),i=t("../../utils/visitors.es"),r=t("../actions/eventTypes.es");function s(e,a){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);a&&(n=n.filter((function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable}))),t.push.apply(t,n)}return t}function u(e){for(var a=1;a<arguments.length;a++){var t=null!=arguments[a]?arguments[a]:{};a%2?s(Object(t),!0).forEach((function(a){d(e,a,t[a])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):s(Object(t)).forEach((function(a){Object.defineProperty(e,a,Object.getOwnPropertyDescriptor(t,a))}))}return e}function d(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}const e=(a,...t)=>new i.PagesVisitor(a).mapFields((a=>{const{localizedValue:n}=a,l=u({},a);if(n){const e=u({},n);t.forEach((a=>{delete e[a]})),l.localizedValue=e}return a.settingsContext&&(l.settingsContext=u(u({},a.settingsContext),{},{pages:e(a.settingsContext.pages,...t)})),l})),o=({defaultLanguageId:e,editingLanguageId:a,localizable:t,localizedValue:n,localizedValueEdited:l,type:i,value:r})=>{if(!t)return r;let s;const u=n[e];var d;n&&(null!==n[a]&&void 0!==n[a]?s=!Array.isArray(n[a])||(null===(d=n[a])||void 0===d?void 0:d.length)||(null==l?void 0:l[a])?n[a]:u:u&&(s=u));switch(i){case"image":try{return JSON.parse(r)}catch(e){return s}case"numeric":case"select":case"text":return s;default:try{return JSON.parse(s)}catch(e){return s}}},c=({availableLanguageIds:e,dataSourceType:a,defaultLanguageId:t,editingLanguageId:r,instanceId:s,name:d,options:o,settingsContext:c,type:g})=>{var p;const f=new i.PagesVisitor(c.pages),b=f.findField((({fieldName:e})=>"options"===e)),v=null!==(p=null==b?void 0:b.value[r])&&void 0!==p?p:null==b?void 0:b.value[t],I=f.mapFields((e=>{const a=(0,n.localizeField)(e,t,r);return v&&"predefinedValue"===e.fieldName&&(a.options=v),a.locale=r,a})),y=u(u({},c),{},{availableLanguageIds:e,defaultLanguageId:t,pages:I}),L=u(u({},(0,n.getFieldProperties)(y,t,r)),{},{locale:r,name:(0,l.generateName)(d,{instanceId:s||(0,n.generateInstanceId)(),repeatedIndex:(0,l.getRepeatedIndex)(d)}),settingsContext:y});return"select"===g&&a&&a.includes("data-provider")?u(u({},L),{},{options:o}):L},g=(a,t,...n)=>{let l=e(t,...n);const r=new i.PagesVisitor(l);let s={};return r.mapFields((e=>{e.instanceId===a.instanceId&&(s=e)})),l=r.mapPages((e=>{const{contentRenderer:a,localizedDescription:t,localizedTitle:l}=e;return"success"===a?e:(n.forEach((e=>{delete t[e],delete l[e]})),u(u({},e),{},{localizedDescription:t,localizedTitle:l}))})),{focusedField:s,pages:l}}}}));
//# sourceMappingURL=languageReducer.es.js.map