"undefined"==typeof ExposureHandler&&(ExposureHandler={}); (function(){function q(){MarketExposureObj.eventId=null;MarketExposureObj.marketId=null;MarketExposureObj.numberOfWinner=0;MarketExposureObj.defaultActiveRunners=0;MarketExposureObj.numberOfActiveRunners=0;MarketExposureObj.marketExposure=0;MarketExposureObj.betSelections={};SelectionExposureObj.minExposure=0;SelectionExposureObj.diff=0;SelectionExposureObj.selectionWinPL=0;SelectionExposureObj.selectionLossPL=0;NotActiveSelectionIds=[]}function u(b){var f=b.selectionKey;MarketExposureObj.betSelections[f]= MarketExposureObj.betSelections[f]||l(MarketExposureObj.betSelections[0]);var a=Object.keys(MarketExposureObj.betSelections).length-1;r();var d=a==MarketExposureObj.numberOfActiveRunners,c=0;$j.each(MarketExposureObj.betSelections,function(e,g){var h=g.minExposure;h=f==e?MathUtil.decimal.add(h,b.selectionWinPL):MathUtil.decimal.add(h,b.selectionLossPL);g.minExposure=h;d&&0==e||(c=c>h?h:c)});MarketExposureObj.marketExposure=c}function v(b){$j.each(b,function(d,c){d=c.selectionKey;var e=MarketExposureObj.betSelections[d]|| l(SelectionExposureObj);e.selectionWinPL=MathUtil.decimal.add(e.selectionWinPL,c.selectionWinPL);e.selectionLossPL=MathUtil.decimal.add(e.selectionLossPL,c.selectionLossPL);e.diff=MathUtil.decimal.subtract(e.selectionWinPL,e.selectionLossPL);if(0==MarketExposureObj.numberOfWinner){c=e.selectionWinPL;var g=e.selectionLossPL;c=c>g?g:c;e.minExposure=0=MarketExposureObj.numberOfWinner&&a<=b?0:a-b,a=MarketExposureObj.numberOfWinner);f=w(b,a)}MarketExposureObj.marketExposure=f}function w(b,f){for(var a=0;b<=f;b++){var d=x(b);a=a>d?d:a}return a}function x(b){var f=[];$j.each(MarketExposureObj.betSelections,function(g,h){h.selectionKey=g;f.push(h)}); f.sort(function(g,h){g=g.diff;h=h.diff;return g>h?1:gd?d:0;Trace.debug("winner:["+b+"],exposureOfWinner:"+a);return a}function l(b){return JSON.parse(JSON.stringify(b))}function r(){var b=Object.keys(MarketExposureObj.betSelections),f=0;$j.each(b,function(a,d){-1!=NotActiveSelectionIds.indexOf(d)&& f++});0!=f&&(MarketExposureObj.numberOfActiveRunners=MarketExposureObj.defaultActiveRunners+f)}MarketExposureObj={eventId:null,marketId:null,numberOfWinner:0,defaultActiveRunners:0,numberOfActiveRunners:0,marketExposure:0,betSelections:{},plTable:{}};SelectionExposureObj={minExposure:0,diff:0,selectionWinPL:0,selectionLossPL:0};NotActiveSelectionIds=[];ExposureHandler.getMarketExposure=function(){return l(MarketExposureObj)};ExposureHandler.setMarketExposure=function(b){q();MarketExposureObj=l(b)}; ExposureHandler.initMarketInfo=function(b,f,a,d,c,e){if(!$j.isArray(e))throw"notActiveSelectionIdArr must bet array";q();MarketExposureObj.eventId=b;MarketExposureObj.marketId=f;MarketExposureObj.numberOfWinner=d;MarketExposureObj.defaultActiveRunners=c;MarketExposureObj.numberOfActiveRunners=c;NotActiveSelectionIds=e;1==d&&(MarketExposureObj.betSelections[0]=l(SelectionExposureObj))};ExposureHandler.initPlTable=function(b,f){if("ASIAN_HANDICAP"==b){b=new Set;for(const a of f)b.has(a.selectionId)? !1:b.add(a.selectionId);MarketExposureObj.plTable={};for(const a of b){MarketExposureObj.plTable[a]={};for(const d of AsianHandicapScoreType.values())MarketExposureObj.plTable[a][d.value]=0}MarketExposureObj.plTable[0]={};MarketExposureObj.plTable[0][0]=0}};ExposureHandler.clearPlTable=function(){MarketExposureObj.plTable={}};ExposureHandler.generatorBetTicketObj=function(b,f,a,d,c,e,g,h,t,m,n){d=MathUtil.decimal.multiply(1==e?1:-1,MathUtil.decimal.multiply(MathUtil.decimal.subtract(d,1),c));c=MathUtil.decimal.multiply(1== e?-1:1,c);return{eventId:b,marketId:f,selectionKey:a,selectionId:m,handicap:n,selectionWinPL:!g&&0g?k=MathUtil.decimal.add(k,c):0