Liferay.Loader.define("@liferay/search-experiences-web@3.0.30/sxp_blueprint_admin/js/utils/sxp_element/replace_template_variable",["module","exports","require","liferay!search-experiences-web$moment","../constants","../functions/is_empty","../functions/replace_str","../functions/to_number","../types/inputTypes","./clean_ui_configuration","./is_custom_json_sxp_element","./parse_custom_sxp_element"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function replaceTemplateVariable({sxpElement:e,uiConfigurationValues:t}){var n,c;const _=(0,r.default)(null===(n=e.elementDefinition)||void 0===n?void 0:n.uiConfiguration).fieldSets;if(_.length&&!(0,f.default)(t)){var d;let n=JSON.stringify((null===(d=e.elementDefinition)||void 0===d?void 0:d.configuration)||{});return _.map((({fields:e})=>{e.map((e=>{var r;let f="";const p=t[e.name];if((null===(r=e.typeOptions)||void 0===r?void 0:r.nullable)&&(0,a.default)(p,e.type)){const t='\\"[\\w\\._]+\\"\\:\\"\\$\\{'.concat(o.CONFIG_PREFIX,"\\.").concat(e.name,'}\\"');n=(0,l.default)(n,new RegExp(t+","),""),n=(0,l.default)(n,new RegExp(","+t),""),n=(0,l.default)(n,new RegExp(t),"")}else if(e.type===s.INPUT_TYPES.DATE){var c;f=p?JSON.parse(i.default.unix(p).format((null===(c=e.typeOptions)||void 0===c?void 0:c.format)||"YYYYMMDDHHMMSS")):""}else if(e.type===s.INPUT_TYPES.ITEM_SELECTOR)f=JSON.stringify(p.map((e=>e.value)));else if(e.type===s.INPUT_TYPES.FIELD_MAPPING){const{boost:e,field:t,languageIdPosition:n,locale:i=""}=p,o=i?"_".concat(i):i;let a;a=n>-1?t.substring(0,n)+o+t.substring(n):t+o,a=(0,l.default)(a,/[\\"]+/,""),f=e&&e>0?"".concat(a,"^").concat(e):a}else if(e.type===s.INPUT_TYPES.FIELD_MAPPING_LIST){const e=p.filter((({field:e})=>!!e)).map((({boost:e,field:t,languageIdPosition:n,locale:i=""})=>{const o=i?"_".concat(i):i;let a;return a=n>-1?t.substring(0,n)+o+t.substring(n):t+o,a=(0,l.default)(a,/[\\"]+/,""),e&&e>0?"".concat(a,"^").concat(e):a}));f=JSON.stringify(e)}else if(e.type===s.INPUT_TYPES.JSON)try{JSON.parse(p),f=p}catch(e){f="{}"}else if(e.type===s.INPUT_TYPES.KEYWORDS)f=(0,l.default)(p,/[\\"]+/,"")||"${keywords}";else if(e.type===s.INPUT_TYPES.MULTISELECT)f=JSON.stringify(p.map((e=>e.value)));else if(e.type===s.INPUT_TYPES.NUMBER){var _,d,y;const t=p.value?(0,u.default)(p.value):p;f="string"==typeof(null===(_=e.typeOptions)||void 0===_?void 0:_.unitSuffix)?"string"==typeof t?t.concat(null===(d=e.typeOptions)||void 0===d?void 0:d.unitSuffix):JSON.stringify(t).concat(null===(y=e.typeOptions)||void 0===y?void 0:y.unitSuffix):t}else f=e.type===s.INPUT_TYPES.SLIDER?p:(0,l.default)(p,/[\\"]+/,"");const T="number"==typeof f||e.type===s.INPUT_TYPES.ITEM_SELECTOR||e.type===s.INPUT_TYPES.FIELD_MAPPING_LIST||e.type===s.INPUT_TYPES.JSON||e.type===s.INPUT_TYPES.MULTISELECT?'"${'.concat(o.CONFIG_PREFIX,".").concat(e.name,'}"'):"${".concat(o.CONFIG_PREFIX,".").concat(e.name,"}");n=(0,l.default)(n,T,f)}))})),JSON.parse(n)}return(null===(c=(0,p.default)(e,t).elementDefinition)||void 0===c?void 0:c.configuration)||{}};var i=_interopRequireDefault(n("liferay!search-experiences-web$moment")),o=n("../constants"),a=_interopRequireDefault(n("../functions/is_empty")),l=_interopRequireDefault(n("../functions/replace_str")),u=_interopRequireDefault(n("../functions/to_number")),s=n("../types/inputTypes"),r=_interopRequireDefault(n("./clean_ui_configuration")),f=_interopRequireDefault(n("./is_custom_json_sxp_element")),p=_interopRequireDefault(n("./parse_custom_sxp_element"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}}}));
//# sourceMappingURL=replace_template_variable.js.map