function ge(r){r=document.getElementById(r);return r}const oParamInfos={"radio-bdr-none":["border","type","radio","",""],"radio-bdr-party":["border","type","radio","",""],"radio-committees-chairs":["filters","chairs","chkbox","",""],"radio-committees-members":["filters","members","chkbox","",""],"radio-committees-vicechairs":["filters","viceChairs","chkbox","",""],"radio-param-imgChoice-clean":["params","imgChoice","radio","",""],"radio-param-imgChoice-g":["params","imgChoice","radio","",""],"radio-param-imgChoice-n":["params","imgChoice","radio","",""],"radio-param-imgChoice-dn":["params","imgChoice","radio","",""],"radio-param-imgChoice-dnp":["params","imgChoice","radio","",""],"radio-param-imgChoice-dgnp":["params","imgChoice","radio","",""],"radio-party-democrat":["filters","party","radio","",""],"radio-party-either":["filters","party","radio","",""],"radio-party-republican":["filters","party","radio","",""],"radio-score-any":["filters","score","radio","",""],"radio-score-highest":["filters","score","radio","",""],"radio-score-lowest":["filters","score","radio","",""],"radio-sex-both":["filters","sex","radio","",""],"radio-sex-female":["filters","sex","radio","",""],"radio-sex-male":["filters","sex","radio","",""],"radio-substitutes-show":["filters","substitutes","radio","",""],"radio-substitutes-hide":["filters","substitutes","radio","",""],"radio-sort1-committee":["sort","firstOn","radio","",""],"radio-sort1-district":["sort","firstOn","radio","",""],"radio-sort1-firstname":["sort","firstOn","radio","",""],"radio-sort1-lastname":["sort","firstOn","radio","",""],"radio-sort1-party":["sort","firstOn","radio","",""],"radio-sort1-random":["sort","firstOn","radio","",""],"radio-sort1-score":["sort","firstOn","radio","",""],"radio-sort1-unsorted":["sort","firstOn","radio","",""],"radio-sort2-committee":["sort","secondOn","radio","",""],"radio-sort2-district":["sort","secondOn","radio","",""],"radio-sort2-firstname":["sort","secondOn","radio","",""],"radio-sort2-lastname":["sort","secondOn","radio","",""],"radio-sort2-party":["sort","secondOn","radio","",""],"radio-sort2-random":["sort","secondOn","radio","",""],"radio-sort2-score":["sort","secondOn","radio","",""],"radio-sort2-unsorted":["sort","secondOn","radio","",""],"radio-sort3-committee":["sort","thirdOn","radio","",""],"radio-sort3-district":["sort","thirdOn","radio","",""],"radio-sort3-firstname":["sort","thirdOn","radio","",""],"radio-sort3-lastname":["sort","thirdOn","radio","",""],"radio-sort3-party":["sort","thirdOn","radio","",""],"radio-sort3-random":["sort","thirdOn","radio","",""],"radio-sort3-score":["sort","thirdOn","radio","",""],"radio-sort3-unsorted":["sort","thirdOn","radio","",""],"show-committees":["show","committees","chkbox","",""],"show-district":["show","district","chkbox","",""],"show-image":["show","image","chkbox","",""],"show-offices":["show","offices","chkbox","",""],"show-party":["show","party","chkbox","",""],"show-profession":["show","profession","chkbox","",""],"show-ratings":["show","ratings","chkbox","",""],"show-sex":["show","sex","chkbox","",""],"show-substitutes":["show","substitutes","chkbox","",""],"show-terms":["show","terms","chkbox","",""],"text-bdr-radius":["border","radius","integer",0,10],"text-bdr-thickness":["border","thickness","integer",0,10],txtImgAspectX:["image","aspectX","integer",0,10],txtImgAspectY:["image","aspectY","integer",0,10],txtImgHeight:["image","height","integer",0,500],txtImgWidth:["image","width","integer",0,500],txtTblCols:["table","cols","integer",0,20],txtTblRows:["table","rows","integer",0,20]};function getFilteredMembers(i,r){if("Any"!=i.sex&&(r=r.filter(r=>r.sex==i.sex)),"Any"!=i.party&&(r=r.filter(r=>r.party==i.party)),"Hide"==i.substitutes&&(r=r.filter(r=>!r.substituteFor)),"Any"!=i.score){let e=0,o=100;r.forEach(r=>{r=r.rating2022;r>e&&(e=r),r{let t=r.rating2022;return"Highest"==i.score?t==e:"Lowest"==i.score&&(t=o)})}return i.members&&(r=r.filter(r=>r.memberOf&&0r.vicechairOf&&0r.chairOf&&0{r.rnd=Math.random()});const sortFunctionTemplate=`(a, b) => { if (a.%sortField% < b.%sortField%) { return -1; } else if (a.%sortField% > b.%sortField%) { return 1; } else { return %isLeaf% ? 0 : %nextLevelSortFunction%(a, b); } }`,thirdOnSortFnString=sortFunctionTemplate.replace(/%sortField%/g,oSort.thirdOn).replace(/%isLeaf%/g,"true").replace(/%nextLevelSortFunction%/g,"noSortFn"),thirdOnSortFn=eval(thirdOnSortFnString),secondOnSortFnString=sortFunctionTemplate.replace(/%sortField%/g,oSort.secondOn).replace(/%isLeaf%/g,"false").replace(/%nextLevelSortFunction%/g,"thirdOnSortFn"),secondOnSortFn=eval(secondOnSortFnString),firstOnSortFnString=sortFunctionTemplate.replace(/%sortField%/g,oSort.firstOn).replace(/%isLeaf%/g,"false").replace(/%nextLevelSortFunction%/g,"secondOnSortFn"),firstOnSortFn=eval(firstOnSortFnString);return aMembers.sort(firstOnSortFn),aMembers}function renderTableLayout(a,r,n){const d="  ",c="
\n";let m="";return r.forEach(function(i,r){var t=getFullName(i),s="Senate"==i.house?"Senator":"Representative",e=a.show.party&&i.party&&i.party.length?`(${i.party[0]})`:"",o="F"==i.sex?"Madam":"";if(0==a.table.cols?m+=r?"
":"
":r%Number(a.table.cols)==0?m+=r?"
":"
":m+="",m=(m+=`${o} ${s} ${t} `+e)+c,a.show.offices&&(i.majorityLeader&&(m=(m=(m+=d)+`Majority Leader of the ${i.house}.`)+c),i.minorityLeader&&(m=(m=(m+=d)+`Minority Leader of the ${i.house}.`)+c),i.assistantMajorityLeader&&(m=(m=(m+=d)+`Assistant Majority Leader of the ${i.house}.`)+c),i.assistantMinorityLeader&&(m=(m=(m+=d)+`Assistant Minority Leader of the ${i.house}.`)+c),i.majorityCaususChair&&(m=(m=(m+=d)+`Majority Caucus Chair of the ${i.house}.`)+c),i.minorityCaususChair&&(m=(m=(m+=d)+`Minority Caucus Chair of the ${i.house}.`)+c)),a.show.substitutes&&(i.substituteFor&&(m=(m=(m+=d)+"Substituting for "+getFullName(n[i.substituteFor]))+c),i.substitute&&(m=(m=(m+=d)+"Substitute is "+getFullName(n[i.substitute]))+c)),a.show.district&&(m=(m+=d)+"District: "+i.district,i.seat&&(m+=" Seat: "+i.seat),m+=c),a.show.committees&&(i.chairOf&&i.chairOf.length&&(m=m+d+"Chiarman of: ",i.chairOf.forEach((r,t)=>{t&&(m+=", "),m+=""+r}),m+=c),i.vicechairOf&&i.vicechairOf.length&&(m=m+d+"Vice Chiarman of: ",i.vicechairOf.forEach((r,t)=>{t&&(m+=", "),m+=""+r}),m+=c),i.memberOf&&i.memberOf.length&&(m=m+d+"Member of:",i.memberOf.forEach((r,t)=>{m=m+(c+d+d)+r}),m+=c)),a.show.terms&&(m+=d,r=Number((new Date).getFullYear())-Number(i.yearFirstElected)+1,o=Math.floor(r/2)+1,m=(m+="Term: "+o)+c),a.show.image){let r=Number(a.image.width),t=Number(a.image.height);0==r?r=Math.floor(t*a.image.aspectX/a.image.aspectY):t=0;s=a.params.imgChoice;m=(m+=d)+d;let e="",o=(t&&(e='height="'+t+'"'),"");r&&(o='width="'+r+'"'),m=(m+=``)+c}a.show.ratings&&(m=(m=(m+=d)+`2022 Rating: ${i.rating2022}`)+c),a.show.profession&&(m=(m=(m+=d)+i.profession)+c)}),m+="
"}function renderOutput(r){let t;var r=getParams(t="string"==typeof r?r:r.srcElement.id),e=JSON.parse(JSON.stringify(Object.values(oMembers))),e=getFilteredMembers(r.filters,e);e=sortMembers(r.sort,e);let o='
\n';o=renderTableLayout(r,e,oMembers),o+="
",ge("output").innerHTML=o,ge("html-output").innerText=o,ge("params-output").value=JSON.stringify(r,null,2)}let oParams={};function getParams(r){if(r)getParam(r);else{var t=Object.keys(oParamInfos);for(let r=0;r=s&&n<=a;break;default:throw new Exception("internal error")}return t?(null==n&&"radio"==i||(oParams[e][o]=n),ge(r).style.color="black"):ge(r).style.color="red",oParams}function getFullName(r){let t="";return t=r.MiddleName?`${r.FirstName} ${r.MiddleName} `+r.LastName:r.FirstName+" "+r.LastName}renderOutput(""),myAddEventListener(Object.keys(oParamInfos),["change","keydown"],renderOutput);