!function(){"use strict";function t(t,{is:e,className:s,attributes:a=[]},i=[]){const l=e?document.createElement(t,{is:e}):document.createElement(t);return a.forEach(([t,e])=>{!1===e||null==e?l.removeAttribute(t):!0===e?l.setAttribute(t,""):l.setAttribute(t,e)}),s&&(l.className=s),l.append(...i),l}function e(t){return Math.round(1e3*Math.random())%t}class s{constructor(){this.data=[],this.backup=null,this.selected=null,this.id=1}buildData(t=1e3){for(var s=["pretty","large","big","small","tall","short","long","handsome","plain","quaint","clean","elegant","easy","angry","crazy","helpful","mushy","odd","unsightly","adorable","important","inexpensive","cheap","expensive","fancy"],a=["red","yellow","blue","green","pink","brown","purple","brown","white","black","orange"],i=["table","chair","house","bbq","desk","car","pony","cookie","sandwich","burger","pizza","mouse","keyboard"],l=[],h=0;h<t;h++)l.push({id:this.id++,label:s[e(s.length)]+" "+a[e(a.length)]+" "+i[e(i.length)]});return l}updateData(t=10){for(let t=0;t<this.data.length;t+=10)this.data[t].label+=" !!!"}delete(t){const e=this.data.findIndex(e=>e.id==t);return this.data=this.data.filter((t,s)=>s!=e),this}run(){this.data=this.buildData(),this.selected=null}add(){this.data=this.data.concat(this.buildData(1e3)),this.selected=null}update(){this.updateData(),this.selected=null}select(t){this.selected=t}hideAll(){this.backup=this.data,this.data=[],this.selected=null}showAll(){this.data=this.backup,this.backup=null,this.selected=null}runLots(){this.data=this.buildData(1e4),this.selected=null}clear(){this.data=[],this.selected=null}swapRows(){if(this.data.length>998){var t=this.data[1];this.data[1]=this.data[998],this.data[998]=t}}}var a=function(t){for(;t;){if("TR"===t.tagName)return t.data_id;t=t.parentNode}};new class{constructor(t){this.store=new s,this.select=this.select.bind(this),this.delete=this.delete.bind(this),this.add=this.add.bind(this),this.run=this.run.bind(this),this.update=this.update.bind(this),this.start=0,this.rows=[],this.data=[],this.selectedRow=void 0,document.getElementById("main").addEventListener("click",t=>{if(t.target.matches("#add"))t.preventDefault(),this.add();else if(t.target.matches("#run"))t.preventDefault(),this.run();else if(t.target.matches("#update"))t.preventDefault(),this.update();else if(t.target.matches("#hideall"))t.preventDefault(),this.hideAll();else if(t.target.matches("#showall"))t.preventDefault(),this.showAll();else if(t.target.matches("#runlots"))t.preventDefault(),this.runLots();else if(t.target.matches("#clear"))t.preventDefault(),this.clear();else if(t.target.matches("#swaprows"))t.preventDefault(),this.swapRows();else if(t.target.matches(".remove")){t.preventDefault();let e=a(t.target),s=this.findIdx(e);this.delete(s)}else if(t.target.matches(".lbl")){t.preventDefault();let e=a(t.target),s=this.findIdx(e);this.select(s)}}),this.tbody=document.getElementById("tbody")}findIdx(t){for(let e=0;e<this.data.length;e++)if(this.data[e].id===t)return e}run(){this.removeAllRows(),this.store.clear(),this.rows=[],this.data=[],this.store.run(),this.appendRows(),this.unselect()}add(){this.store.add(),this.appendRows()}update(){this.store.update();for(let t=0;t<this.data.length;t+=10)this.rows[t].setLabel(this.store.data[t].label)}unselect(){void 0!==this.selectedRow&&(this.selectedRow.className="",this.selectedRow=void 0)}select(t){this.unselect(),this.store.select(this.data[t].id),this.selectedRow=this.rows[t],this.selectedRow.className="danger"}recreateSelection(){let t=this.store.selected,e=this.store.data.findIndex(e=>e.id===t);e>=0&&(this.store.select(this.data[e].id),this.selectedRow=this.rows[e],this.selectedRow.className="danger")}delete(t){this.store.delete(this.data[t].id),this.rows[t].remove(),this.rows.splice(t,1),this.data.splice(t,1),this.unselect(),this.recreateSelection()}removeAllRows(){this.tbody.textContent=""}runLots(){this.removeAllRows(),this.store.clear(),this.rows=[],this.data=[],this.store.runLots(),this.appendRows(),this.unselect()}clear(){this.store.clear(),this.rows=[],this.data=[],this.removeAllRows(),this.unselect()}swapRows(){if(this.data.length>10){this.store.swapRows(),this.data[1]=this.store.data[1],this.data[998]=this.store.data[998],this.tbody.insertBefore(this.rows[998],this.rows[2]),this.tbody.insertBefore(this.rows[1],this.rows[999]);let t=this.rows[998];this.rows[998]=this.rows[1],this.rows[1]=t}}appendRows(){var t=this.rows,e=this.store.data,s=this.data,a=this.tbody;for(let i=t.length;i<e.length;i++){let l=this.createRow(e[i]);t[i]=l,s[i]=e[i],a.appendChild(l)}}createRow(e){let s;const a=t("tr",{},[t("td",{className:"col-md-1"},[e.id]),t("td",{className:"col-md-4"},[s=t("a",{className:"lbl"},[e.label])]),t("td",{className:"col-md-1"},[t("a",{className:"remove"},[t("span",{className:"remove glyphicon glyphicon-remove",attributes:[["aria-hidden","true"]]})])]),t("td",{className:"col-md-6"})]);return a.setLabel=t=>{s.innerText=t},a.data_id=e.id,a}}}();
