bwdefine("Randomness",["config","bw/widget","jquery","bw/tr","lodash","groupwheel","bw/fontScaler","bw/ProgressLogger"],function(e,t,n,o,s,a,l,i){"use strict";return n(function(){function s(e,t){n.each(e,function(n,o){setTimeout(function(){e[n].shuffle(t)},100*n)})}function r(){var e=n(".slotMachine"),t=parseInt(e.attr("wheelcount")),o=n(".wheel"),a=(parseInt(o.css("border-left")),parseInt(o.css("margin-left")));e.hide();var l=n("#bottom-container").width(),i=parseInt(n("#bottom-container").css("padding"));isNaN(i)&&(i=parseInt(n("#bottom-container").css("padding-left")));var r=parseInt((l-2*i-(t-1*a))/t),h=n("#bottom-container").height(),c=parseInt(n("#bottom-container").css("padding"));isNaN(c)&&(c=parseInt(n("#bottom-container").css("padding-top")));var u=h-2*c-150,d=Math.min(r,u);console.log(l,i,c,t,a,d),n(".wheel, .wheel:after").css({height:d,width:d});var p=n(".slot, .image-slot");p.css({height:d}),e.show(),m.adjustFontSizes(n(".text-slot-wrapper"),n(".slot").height()),s(m._wheels,0)}function h(e,t,o){var s=[];return n.each(e.text_slots,function(n){s.push(m.addTextSlotToWheel(t,e.text_slots[n]))}),m.adjustFontSizes(s,100),setTimeout(function(){var n=m.finalizeWheel(t,e.text_slots.length);m.pushFinalizedWheel(n)},2),1}function c(e,t,o){n.each(e.image_slots,function(n){m.addImageSlotToWheel(t,e.image_slots[n])});var s=m.finalizeWheel(t,e.image_slots.length);return m.pushFinalizedWheel(s),1}t.makeWidget({layout:"title_layout",title:e.title,"no-user-select":!0});var u=i(),d=0,p=u.registerQuantity("count",o("Spins"),0,!0),m={_wheels:[],_slotMachine:null,_lastWheelElem:null,init:function(e){this._slotMachine=e},getFirstWheel:function(){return this._lastWheelElem},createWheelElement:function(){var e=n(document.createElement("div"));return this._slotMachine.append(e),e.addClass("wheel"),this._lastWheelElem=e,e},addTextSlotToWheel:function(e,t){var o=n(document.createElement("div"));o.addClass("slot");var s=n(document.createElement("div"));s.addClass("text-slot-wrapper"),o.append(s);var a=n(document.createElement("div"));return a.addClass("text-slot"),a.html(t),s.append(a),e.append(o),s},addImageSlotToWheel:function(e,t){var o=n(document.createElement("div"));o.addClass("slot");var s=n(document.createElement("div"));s.addClass("image-slot"),s.css("background-image","url("+t+")"),o.append(s),e.append(o)},adjustFontSizes:function(e,t){console.log("adjustfontsizes ",t),setTimeout(function(){l.scaleToBox(e,"wheel",10,parseInt(.7*t),.8*n(".wheel").width(),.8*n(".wheel").height())},1)},finalizeWheel:function(t,n){return t.slotMachine({active:Math.floor(Math.random()*n),delay:e.milisecondsForOneTurn})},pushFinalizedWheel:function(e){this._wheels.push(e)},reportConfigurationError:function(e){alert(e)}};n(document).ready(function(){var t=n(".slotMachine"),l=0;m.init(t),n.each(e.wheels,function(t){var n=m.createWheelElement(),o=e.wheels[t];"Text"===o.wheel_type?l+=h(o,n,m._wheels):"Images"===o.wheel_type?l+=c(o,n,m._wheels):"Group"===o.wheel_type?l+=a.processGroupWheelConfig(o,m).numWheels:console.log("Internal error: unsupported wheel_type: "+o.wheel_type)}),t.addClass("total-wheel-count-"+l),t.attr("wheelcount",l),n(window).resize(r),r(),n("#spinButton").makeButton().tapOrClick(function(t){s(m._wheels,parseInt(e.numTurns)),p.update(++d)}),s(m._wheels,0),n("#spinButton").html(o("Spin"))})}),null}),bwdefine.finalize();