text: (function(){var t="/crm/ml/#entity_type#/#id#/detail";var i=[];BX.CrmScoringButton=function(t){if(!t){t={}}this.entityType=t.entityType.toString().toLowerCase();this.entityId=t.entityId;this.isEntityFinal=t.isFinal;this.mlInstalled=t.mlInstalled;this.scoringEnabled=t.scoringEnabled;var e=BX.prop.getObject(t,"scoringParameters",{});this.spotlightEnabled=e["SHOW_SPOTLIGHT"]===true;this.currentPrediction=e["CURRENT_PREDICTION"];this.isModelReady=e["MODEL_READY"];this.spotlightId=e["SPOTLIGHT_ID"];this.spotlightTimeout=null;this.spotlight=null;this.elements={scoring:null,title:null};this.init();i.push(this)};BX.CrmScoringButton.getInstances=function(){return i};BX.CrmScoringButton.prototype={init:function(){BX.addCustomEvent(window,"BX.Crm.EntityEditorSection:onLayout",this.onEntityEditorLayout.bind(this));BX.addCustomEvent("onPullEvent-crm",this.onPullEvent.bind(this));if(!this.isEntityFinal&&this.mlInstalled&&this.scoringEnabled&&this.isModelReady&&!this.currentPrediction){setTimeout(this.getFirstPrediction.bind(this),200)}},onPullEvent:function(t,i){switch(t){case"predictionUpdate":this.onPredictionUpdate(i);break;default:break}},getFirstPrediction:function(){BX.ajax.runAction("crm.api.ml.scoring.tryCreateFirstPrediction",{data:{entityType:this.entityType,entityId:this.entityId}}).catch(function(t){t.errors.forEach(console.error)})},getTitle:function(){var t=BX.message("CRM_ML_SCORING_BUTTON_TITLE");if(this.currentPrediction){var i=this.currentPrediction["SCORE"];var e=Math.floor(i*100);t+=": "+e+"%"}return t},onEntityEditorLayout:function(t,i){var e=i.serialNumber;if(e===0&&this.mlInstalled){if(!this.elements.scoring){this.elements.scoring=BX.create("div",{props:{className:"crm-entity-widget-scoring"},events:{click:this.onScoringButtonClick.bind(this)},children:[BX.create("div",{props:{className:"crm-entity-widget-scoring-icon"}}),this.elements.title=BX.create("div",{props:{className:"crm-entity-widget-scoring-text"},text:this.getTitle()})]})}i.customNodes.push(this.elements.scoring);if(this.spotlightEnabled){this.showSpotlight()}}},onPredictionUpdate:function(t){var i=t.entityType.toString().toLowerCase();var e=t.entityId;if(i!==this.entityType||e!=this.entityId){return}this.currentPrediction=t.predictionRecord;if(this.elements.title){BX.adjust(this.elements.title,{text:this.getTitle()})}},showSpotlight:function(){clearTimeout(this.spotlightTimeout);this.spotlightTimeout=setTimeout(function(){this.spotlight=new BX.SpotLight({id:this.spotlightId,targetElement:this.elements.scoring,targetVertex:"middle-center",content:this.entityType==="lead"?BX.message("CRM_ML_SCORING_SPOTLIGHT_TEXT_LEAD"):BX.message("CRM_ML_SCORING_SPOTLIGHT_TEXT_DEAL"),autoSave:true});this.spotlight.show()}.bind(this),200)},onScoringButtonClick:function(i){var e=t.replace("#id#",this.entityId).replace("#entity_type#",this.entityType);BX.SidePanel.Instance.open(e,{cacheable:false,width:840})}}})();
  //# sourceMappingURL=crm.scoring.button.map.js