define(["jquery","knockout","text!/literacy-score/literacy-data.json","https://www.gstatic.com/charts/loader.js"],function(e,t,a){!function(){function t(){new Date-a<r?setTimeout(t,r):(o=!1,e(window).trigger("resizeEnd"))}var a=new Date(1,1,2e3,12,0,0),o=!1,r=200;e(window).resize(function(){a=new Date,!1===o&&(o=!0,setTimeout(t,r))})}(),google.charts.load("current",{packages:["corechart"]});var o=JSON.parse(a.replace(/\n/g,"\\\\n").replace(/\r/g,"\\\\r").replace(/\t/g,"\\\\t")),r={start:{head:"We'll be asking a series of questions in order to help you improve your financial literacy and generate your WalletLiteracy Score.",txt:"We believe it is more important for people to be able to reach the correct answer, rather than know it off the top of their head. So feel free to use a calculator or any online resources in order to successfully complete this test. <b>Good luck!</b> Your wallet will thank you!",back:!1,next:"1"},forbidden:{head:"Please answer the questions in the order presented. You should use the back and continue buttons to navigate between questions.",next:!1,replace:!0},results:{head:'Thank you for completing the survey. Your answers have been logged. Here is your four-digit code to use on Mechanical Turk to complete the task:                <div style="text-align:center;margin-top:20px"><input type="text" class="single fixed-medium" readonly="readonly" value="{{digits}}" /></div>',txt:"We cannot tell you how many questions you answered correctly at this point because we do not want people to game the system. You will be able to figure out how many you answered correctly at the time of payment. Note that the demographic questions are not included in this total.",next:!1,back:!1,ender:!0},unavailable:{head:"We're sorry, once you have completed the survey you cannot go back and change your answers.",txt:'However, if you would like to retake the survey, please <a data-action="reset">click here</a>.',next:!1,back:!1,replace:!0},restricted:{head:"We're sorry, there was an error with the system",txt:'Please <a data-action="refresh">refresh the page</a>. If the problem still persists, please <a data-action="fullReset">start over</a>.',next:!1,back:!1,replace:!0,ender:!0},completed:{template:"literacy-score/user-results.html",next:!1,back:!1,ender:!0,knockout:{percentage:t.observable(0),percEl:function(t,a){var o,r={backgroundColor:"none",legend:"none",pieSliceText:"none",pieSliceBorderColor:"none",title:null,pieStartAngle:100,pieHole:.85,chartArea:{width:"85.71%",height:"85.71%"},tooltip:{textStyle:{fontSize:12,fontName:"Inter-Regular",bold:!1},text:"value"},width:100,height:100,colors:["#C8C8C8","#63CA84"]};google.charts.setOnLoadCallback(function(){o=google.visualization.arrayToDataTable([["A","B"],["Below",(100-a)/100],["Above",a/100]]),pattern="#%",formatter=new google.visualization.NumberFormat({pattern:pattern}),formatter.format(o,1),setTimeout(function(){new google.visualization.PieChart(t).draw(o,r),e(t).prev().css({left:"50%",top:"50%","margin-left":-1*parseFloat(e(t).prev().css("width"))/2,"margin-top":-1*parseFloat(e(t).prev().css("height"))/2})})})},tableChart:function(t,a,o){var r=this;setTimeout(function(){var n={backgroundColor:"none",legend:"none",title:null,tooltip:{textStyle:{fontSize:12,fontName:"Inter-Regular",bold:!1},text:"value"},bar:{groupWidth:"40%"},vAxis:{minValue:0,textStyle:{fontSize:13,fontName:"Inter-Regular",bold:!1},textPosition:"in",viewWindowMode:"pretty",gridlines:{color:"#373737"}},hAxis:{minValue:0,textStyle:{fontSize:13,fontName:"Inter-Regular",bold:!1},gridlines:{color:"#373737"},format:"percent",viewWindowMode:"pretty",ticks:[0,.05,.1,.15,.2,.25]},width:e(t).parent().width(),height:300,chartArea:{top:0,left:20,width:e(t).parent().width()-36,height:280}},i=[["A",0,"color: #279FD8;height:8px"],["A-",0,"color: #279FD8;height:8px"],["B+",0,"color: #279FD8;height:8px"],["B",0,"color: #279FD8;height:8px"],["B-",0,"color: #279FD8;height:8px"],["C+",0,"color: #279FD8;height:8px"],["C",0,"color: #279FD8;height:8px"],["C-",0,"color: #279FD8;height:8px"],["D",0,"color: #279FD8;height:8px"]];for(var s in a){var l=a[s],h=!1;for(var d in i)if(i[d][0]==l){i[d][1]+=1,h=!0;break}h||(0==l.indexOf("A")?i[0][1]+=1:0!=l.indexOf("D")&&"F"!=l||(i[8][1]+=1))}for(var d in i)i[d][1]=Math.round(100*i[d][1]/a.length)/100,i[d][0]==o&&(i[d][2]="color: 63CA84;height:8px");"D-"!=o&&"D+"!=o&&"F"!=o||(i[8][2]="color: 63CA84;height:8px"),"A+"==o&&(i[0][2]="color: 63CA84;height:8px"),i.unshift(["Grade","Percentage",{role:"style"}]),google.charts.setOnLoadCallback(function(){var s=google.visualization.arrayToDataTable(i);new google.visualization.NumberFormat({pattern:"#%"}).format(s,1);var l=new google.visualization.BarChart(t);google.visualization.events.addListener(l,"ready",function(){e('text[text-anchor="start"]').attr("x",0),e(t).data("window-resize",function(){r.tableChart.call(r,t,a,o),e(window).unbind("resizeEnd",e(t).data("window-resize"))}),e(window).bind("resizeEnd",e(t).data("window-resize"))}),l.draw(s,n)})},10)},tableVal:t.observable([]),ctrlDetails:function(t){e(t).parents(".q").hasClass("show-d")?e(t).parents(".q").removeClass("show-d"):e(t).parents(".q").addClass("show-d").siblings().removeClass("show-d")}}}},n=function(t){var a=this;e(t).each(function(){var t=e(this),o=t.prev(".ui-slider-popup"),r=o.find("i"),n=(e(this).find(".ui-slider-handle"),function(n,i){e(this).find(".ui-slider-handle");setTimeout(function(){var a=(t.outerWidth()-o.outerWidth())/t.outerWidth()*100,n=(t.outerWidth()-r.outerWidth())/t.outerWidth()*100,s=r.outerWidth()/t.outerWidth()*100,l=parseFloat(e(i.handle)[0].style.left),h=o.outerWidth()/2/t.outerWidth()*100;r.css("left",Math.min(n,Math.max(s,l))+"%"),o.css("margin-left",Math.min(a,Math.max(0,l-h))+"%"),l<Math.round(100*s)/100?r.addClass("left-edge"):r.removeClass("left-edge"),l>Math.round(100*n)/100?r.addClass("right-edge"):r.removeClass("right-edge")}),a.slide&&a.slide(n,i)});e(t).slider({min:1,max:7,slide:n,change:n,step:1,range:"min"}),a.def&&e(t).slider("value",a.def),e(window).resize(function(){e(t).slider("value",e(t).slider("value"))})})},i=function(a){var o={selected:t.observableArray([]),length:a.length};for(var r in a)a[r].checked=t.observable(!1),a[r].checked.subscribe(function(t){var a=o.selected(),r=this.value;t?a.push(r):a.splice(e.inArray(r,a),1),o.selected(a)},a[r]);return o.items=a,o.reset=function(){for(var e in o.items)o.items[e].checked(!1)},o},s=function(a){return{box:null,items:a,initial:[],top_rank:t.observable("Most Important"),bottom_rank:t.observable("Least Important"),initials:function(){if(!(this.initial.length>0)){var t=this;e(this.box).find(".ui-state-default").each(function(){t.initial.push(this)})}},set:function(t){var a=this,o=setInterval(function(){if(e(a.box).find("[data-ans]").length>1){var r=t;for(var n in r)e(a.box).append(e(a.box).find('*[data-ans="'+r[n]+'"]'));clearInterval(o)}},100)},labels:function(t){this.box=t,e(this.box).data("sortable")||(e(this.box).sortable({containment:"parent"}),e(this.box).disableSelection(),e(this.box).data("sortable",!0),e(this.box).sortable("refreshPositions"),e(this.box).on("sortstop",function(){e(this.box).sortable("refreshPositions"),e(this.box).sortable("refresh")}))},order:function(){var t=[];return e(this.box).find("*[data-ans]").each(function(){t.push(e(this).attr("data-ans"))}),t},reset:function(){for(var t in this.initial)e(this.box).append(this.initial[t])}}},l=function(a){var o=this,r=!0;o.items=t.observableArray(a),o.opened=t.observable(!1),o.answer={label:t.observable(),value:t.observable()},o.change=function(e){o.answer.label(e.label),o.answer.value(e.value),o.opened(!1)},o.select=function(){o.opened()?o.opened(!1):o.opened(!0),r=!0,setTimeout(function(){r=!1})},e(document).click(function(){r||o.opened(!1)});var n={label:o.items()[0].label,value:o.items()[0].value};o.reset=function(){n.text&&(o.answer.label(n.label),o.answer.value(n.value))},o.change(o.items()[0])},h=function(a){return e.extend({buttons:!1,checkers:!1,ranks:!1,slider:!1,dropdown:!1,last:t.observable(!1),landed:!1,getAnswers:function(e){return this.buttons?this.buttons.answer():this.checkers?this.checkers.selected():this.ranks?this.ranks.order():this.slider?this.slider.value():this.dropdown?{text:this.dropdown.answer.text(),value:this.dropdown.answer.value()}:void 0},status:t.observable("")},a)},d=[];for(var c in o)if(o[c]&&!(o[c].length<2)&&o[c][0]){var u,b,f=[];switch(o[c][0].toLowerCase()){case"button":b="buttons";break;case"checkboxes":b="checkers";break;case"rank":b="ranks";break;case"slider":b="slider";break;default:b=null}for(var p=2;p<9;p++)o[c][p].length>1&&f.push({label:o[c][p],value:String.fromCharCode(95+p).toUpperCase()});u=h({text:o[c][1]}),"buttons"==b?(u.buttons={items:f,name:"q"+c,answer:t.observable(!1),reset:function(){this.answer(!1)}},u.disable=t.computed(function(){return!this.buttons.answer()},u),u.reset=function(){this.buttons.reset()}):"checkers"==b?(u.checkers=i(f),u.disable=t.computed(function(){return this.checkers.selected().length<1},u),u.reset=function(){this.checkers.reset()}):"ranks"==b?(u.ranks=s(f),u.disable=t.observable(!1),u.reset=function(){this.ranks.reset()},o[c][12].length>1&&u.ranks.top_rank(o[c][12]),o[c][13].length>1&&u.ranks.bottom_rank(o[c][13])):"slider"==b?(u.slider={value:t.observable(1),el:null,init:function(e){this.el||(n.call(this,e),this.el=e)},slide:function(e,t){var a=t.value;this.value(a)},def:4},u.disable=t.observable(!1),u.reset=function(){e(this.slider.el).slider("value",4)}):"dropdown"==b?(u.dropdown=new l(f),u.disable=t.computed(function(){return this.dropdown.answer.value()<0},u),u.reset=function(){this.dropdown.reset()}):u.disable=t.observable(!0),o[c][10].length>1&&(u.expl=o[c][10]),o[c][11].length>1&&(u.bullet=o[c][11]),d.push(u)}return d[d.length-1].last(!0),{messages:r,questions:d}});