
/* /mass_mailing/static/src/js/mass_mailing_snippets.js */
odoo.define('@mass_mailing/js/mass_mailing_snippets',['@web_editor/js/editor/snippets.options','@web_editor/js/editor/image_processing','@web_editor/js/common/utils','@mass_mailing/js/mass_mailing_design_constants','@web/core/utils/colors'],function(require){'use strict';let __exports={};const options=require("@web_editor/js/editor/snippets.options")[Symbol.for("default")];const{loadImage}=require("@web_editor/js/editor/image_processing");const SelectUserValueWidget=options.userValueWidgetsRegistry['we-select'];const weUtils=require("@web_editor/js/common/utils")[Symbol.for("default")];const{CSS_PREFIX,BTN_SIZE_STYLES,DEFAULT_BUTTON_SIZE,PRIORITY_STYLES,FONT_FAMILIES,getFontName,normalizeFontFamily,initializeDesignTabCss,transformFontFamilySelector,}=require("@mass_mailing/js/mass_mailing_design_constants");const{isCSSColor,normalizeCSSColor}=require("@web/core/utils/colors");options.registry.MassMailingBackgroundImage=options.registry.BackgroundImage.extend({start:function(){this._super();const $table_target=this.$target.find('table:first');if($table_target.length){this.$target=$table_target;}}});options.registry.MassMailingImageTools=options.registry.ImageTools.extend({_getCSSColorValue(color){if(!color||isCSSColor(color)){return color;}
const doc=this.options.document;const tempEl=doc.body.appendChild(doc.createElement('div'));tempEl.className=`bg-${color}`;const colorValue=window.getComputedStyle(tempEl).getPropertyValue("background-color").trim();tempEl.parentNode.removeChild(tempEl);return normalizeCSSColor(colorValue).replace(/"/g,"'");},async computeShape(svgText,img){const dataURL=await this._super(...arguments);const image=await loadImage(dataURL);const canvas=document.createElement("canvas");const imgFilename=(img.dataset.originalSrc.split("/").pop()).split(".")[0];img.dataset.fileName=`${imgFilename}.png`;img.dataset.mimetype="image/png";canvas.width=image.width;canvas.height=image.height;canvas.getContext("2d").drawImage(image,0,0,image.width,image.height);return canvas.toDataURL(`image/png`,1.0);}});options.userValueWidgetsRegistry['we-fontfamilypicker']=SelectUserValueWidget.extend({start:async function(){const res=await this._super(...arguments);for(const fontFamily of FONT_FAMILIES){const button=document.createElement('we-button');button.style.setProperty('font-family',fontFamily);button.dataset.customizeCssProperty=fontFamily;button.dataset.cssProperty='font-family';button.dataset.selectorText=this.el.dataset.selectorText;button.textContent=getFontName(fontFamily);this.menuEl.appendChild(button);};return res;},});options.registry.DesignTab=options.Class.extend({init(){this._super(...arguments);this.setTarget(this.options.wysiwyg.getEditable());},async start(){const res=await this._super(...arguments);const $editable=this.options.wysiwyg.getEditable();this.document=$editable[0].ownerDocument;this.$layout=$editable.find('.o_layout');initializeDesignTabCss($editable);this.styleElement=this.document.querySelector('#design-element');let sheetOwner=this.document.querySelector('#sheet-owner');if(!sheetOwner){sheetOwner=document.createElement('style');sheetOwner.setAttribute('id','sheet-owner');this.document.head.appendChild(sheetOwner);}
sheetOwner.disabled=true;sheetOwner.textContent=this.styleElement.textContent;this.styleSheet=sheetOwner.sheet;return res;},customizeCssProperty(previewMode,widgetValue,params){if(!params.selectorText||!params.cssProperty){return;}
let value=widgetValue||params.activeValue;if(params.cssProperty.includes('color')){value=weUtils.normalizeColor(value);}
let selectors=this._getSelectors(params.selectorText);const firstSelector=selectors[0].replace(CSS_PREFIX,'').trim();if(params.cssProperty==='font-family'){const newSelectors=[];for(const selector of selectors){newSelectors.push(...transformFontFamilySelector(selector));}
selectors=[...new Set(newSelectors)];}
for(const selector of selectors){const priority=PRIORITY_STYLES[firstSelector].includes(params.cssProperty)?' !important':'';const rule=this._getRule(selector);if(rule){if(params.toggle==='true'&&rule.style.getPropertyValue(params.cssProperty)===value){rule.style.removeProperty(params.cssProperty);}else{const cssTexts=[];for(const style of rule.style){const ownPriority=rule.style.getPropertyPriority(style)?' !important':'';if(style!==params.cssProperty){cssTexts.push(`${style}: ${rule.style[style]}${ownPriority};`);}}
cssTexts.push(`${params.cssProperty}: ${value}${priority};`);rule.style.cssText=cssTexts.join('\n');}}else{this.styleSheet.insertRule(`${selector} {
                    ${params.cssProperty}: ${value}${priority};
                }`);}}
this._commitCss();},applyButtonSize(previewMode,widgetValue,params){for(const[styleName,styleValue]of Object.entries(BTN_SIZE_STYLES[widgetValue||params.activeValue||DEFAULT_BUTTON_SIZE])){if(styleValue){this.customizeCssProperty(previewMode,styleValue,Object.assign({},params,{cssProperty:styleName}));}else{for(const selector of this._getSelectors(params.selectorText)){const rule=this._getRule(selector);if(rule){rule.style.removeProperty(styleName);}}}}
this._commitCss();},_commitCss(){const cssTexts=[];for(const rule of this.styleSheet.cssRules||this.styleSheet.rules){cssTexts.push(rule.cssText);}
this.styleElement.textContent=cssTexts.join('\n');this.options.wysiwyg._rulesCache=undefined;},async _computeWidgetState(methodName,params){const res=await this._super(...arguments);if(res===undefined){switch(methodName){case'applyButtonSize':case'customizeCssProperty':{if(!params.selectorText){return;}
const firstSelector=params.selectorText.split(',')[0].replace(CSS_PREFIX,'').trim();const classes=firstSelector.replace(/:not\([^\)]*\)/g,'').match(/\.([\w\d-_]+)/g)||[];const fakeElement=document.createElement(firstSelector.split(/[\.:, ]/)[0]);for(const className of classes){fakeElement.classList.toggle(className.replace('.',''),true);}
this.$layout.find(CSS_PREFIX).prepend(fakeElement);let res;if(methodName==='applyButtonSize'){const padding=getComputedStyle(fakeElement).padding;const classIndex=Object.values(BTN_SIZE_STYLES).findIndex(style=>style.padding===padding);res=classIndex>=0?Object.keys(BTN_SIZE_STYLES)[classIndex]:DEFAULT_BUTTON_SIZE;}else{fakeElement.style.display='none';res=getComputedStyle(fakeElement)[params.cssProperty||'font-family'];if(params.possibleValues&&params.possibleValues[1]===FONT_FAMILIES[0]){res=normalizeFontFamily(res);}
if(params.cssProperty==='font-weight'){res=parseInt(res)>=600?'bolder':'';}else if(res==='auto'){res='100%';}}
fakeElement.remove();return res;}
case'applyButtonSize':const rule=this._getRule(this._getSelectors(params.selectorText)[0]);if(rule){const classIndex=Object.values(BTN_SIZE_STYLES).findIndex(style=>style.padding===rule.style.padding);return classIndex>=0?Object.keys(BTN_SIZE_STYLES)[classIndex]:DEFAULT_BUTTON_SIZE;}else{return DEFAULT_BUTTON_SIZE;}}}else{return res;}},_getSelectors(selectorText){return selectorText.split(',').map(t=>`${t.startsWith(CSS_PREFIX) ? '' : CSS_PREFIX + ' '}${t.trim()}`.trim());;},_getRule(selectorText){return[...(this.styleSheet.cssRules||this.styleSheet.rules)].find(rule=>rule.selectorText===selectorText);},});return __exports;});;

/* /mass_mailing/static/src/snippets/s_masonry_block/options.js */
odoo.define('@mass_mailing/snippets/s_masonry_block/options',['@web_editor/js/editor/snippets.options'],function(require){'use strict';let __exports={};const options=require("@web_editor/js/editor/snippets.options")[Symbol.for("default")];options.registry.MasonryLayout=options.registry.SelectTemplate.extend({init(){this._super(...arguments);this.containerSelector='> .container, > .container-fluid, > .o_container_small';this.selectTemplateWidgetName='masonry_template_opt';},});return __exports;});;

/* /mass_mailing/static/src/snippets/s_media_list/options.js */
odoo.define('@mass_mailing/snippets/s_media_list/options',['@web_editor/js/editor/snippets.options'],function(require){'use strict';let __exports={};const options=require("@web_editor/js/editor/snippets.options")[Symbol.for("default")];options.registry.MediaItemLayout=options.Class.extend({layout:function(previewMode,widgetValue,params){const $image=this.$target.find('.s_media_list_img_wrapper');const $content=this.$target.find('.s_media_list_body');for(const possibleValue of params.possibleValues){$image.removeClass(`col-lg-${possibleValue}`);$content.removeClass(`col-lg-${12 - possibleValue}`);}
$image.addClass(`col-lg-${widgetValue}`);$content.addClass(`col-lg-${12 - widgetValue}`);},_computeWidgetState(methodName,params){switch(methodName){case'layout':{const $image=this.$target.find('.s_media_list_img_wrapper');for(const possibleValue of params.possibleValues){if($image.hasClass(`col-lg-${possibleValue}`)){return possibleValue;}}}}
return this._super(...arguments);},});return __exports;});;

/* /mass_mailing/static/src/snippets/s_showcase/options.js */
odoo.define('@mass_mailing/snippets/s_showcase/options',['@web_editor/js/editor/snippets.options'],function(require){'use strict';let __exports={};const options=require("@web_editor/js/editor/snippets.options")[Symbol.for("default")];options.registry.Showcase=options.Class.extend({onMove:function(){const $showcaseCol=this.$target.parent().closest('.row > div');const isLeftCol=$showcaseCol.index()<=0;const $title=this.$target.children('.s_showcase_title');$title.toggleClass('flex-lg-row-reverse',isLeftCol);$showcaseCol.find('.s_showcase_icon.ms-3').removeClass('ms-3').addClass('ms-lg-3');$title.find('.s_showcase_icon').toggleClass('me-lg-0 ms-lg-3',isLeftCol);},});return __exports;});;

/* /mass_mailing/static/src/snippets/s_rating/options.js */
odoo.define('@mass_mailing/snippets/s_rating/options',['@web_editor/components/media_dialog/media_dialog','@web_editor/js/editor/snippets.options'],function(require){'use strict';let __exports={};const{MediaDialog}=require("@web_editor/components/media_dialog/media_dialog");const options=require("@web_editor/js/editor/snippets.options")[Symbol.for("default")];options.registry.Rating=options.Class.extend({start:function(){this.iconType=this.$target[0].dataset.icon;this.faClassActiveCustomIcons=this.$target[0].dataset.activeCustomIcon||'';this.faClassInactiveCustomIcons=this.$target[0].dataset.inactiveCustomIcon||'';return this._super.apply(this,arguments);},setIcons:function(previewMode,widgetValue,params){this.iconType=widgetValue;this._renderIcons();this.$target[0].dataset.icon=widgetValue;delete this.$target[0].dataset.activeCustomIcon;delete this.$target[0].dataset.inactiveCustomIcon;},customIcon:async function(previewMode,widgetValue,params){const media=document.createElement('i');media.className=params.customActiveIcon==='true'?this.faClassActiveCustomIcons:this.faClassInactiveCustomIcons;this.call("dialog","add",MediaDialog,{noImages:true,noDocuments:true,noVideos:true,media,save:icon=>{const customClass=icon.className;const $activeIcons=this.$target.find('.s_rating_active_icons > i');const $inactiveIcons=this.$target.find('.s_rating_inactive_icons > i');const $icons=params.customActiveIcon==='true'?$activeIcons:$inactiveIcons;$icons.removeClass().addClass(customClass);this.faClassActiveCustomIcons=$activeIcons.length>0?$activeIcons.attr('class'):customClass;this.faClassInactiveCustomIcons=$inactiveIcons.length>0?$inactiveIcons.attr('class'):customClass;this.$target[0].dataset.activeCustomIcon=this.faClassActiveCustomIcons;this.$target[0].dataset.inactiveCustomIcon=this.faClassInactiveCustomIcons;this.$target[0].dataset.icon='custom';this.iconType='custom';}});},activeIconsNumber:function(previewMode,widgetValue,params){this.nbActiveIcons=parseInt(widgetValue);this._createIcons();},totalIconsNumber:function(previewMode,widgetValue,params){this.nbTotalIcons=Math.max(parseInt(widgetValue),1);this._createIcons();},_computeWidgetState:function(methodName,params){switch(methodName){case'setIcons':{return this.$target[0].dataset.icon;}
case'activeIconsNumber':{this.nbActiveIcons=this.$target.find('.s_rating_active_icons > i').length;return this.nbActiveIcons;}
case'totalIconsNumber':{this.nbTotalIcons=this.$target.find('.s_rating_icons i').length;return this.nbTotalIcons;}}
return this._super(...arguments);},_createIcons:function(){const $activeIcons=this.$target.find('.s_rating_active_icons');const $inactiveIcons=this.$target.find('.s_rating_inactive_icons');this.$target.find('.s_rating_icons i').remove();for(let i=0;i<this.nbTotalIcons;i++){if(i<this.nbActiveIcons){$activeIcons.append('<i></i> ');}else{$inactiveIcons.append('<i></i> ');}}
this._renderIcons();},_renderIcons:function(){const icons={'fa-star':'fa-star-o','fa-thumbs-up':'fa-thumbs-o-up','fa-circle':'fa-circle-o','fa-square':'fa-square-o','fa-heart':'fa-heart-o'};const faClassActiveIcons=(this.iconType==="custom")?this.faClassActiveCustomIcons:'fa '+this.iconType;const faClassInactiveIcons=(this.iconType==="custom")?this.faClassInactiveCustomIcons:'fa '+icons[this.iconType];const $activeIcons=this.$target.find('.s_rating_active_icons > i');const $inactiveIcons=this.$target.find('.s_rating_inactive_icons > i');$activeIcons.removeClass().addClass(faClassActiveIcons);$inactiveIcons.removeClass().addClass(faClassInactiveIcons);},});return __exports;});