text: define(["exports","../hax-body-behaviors/lib/HAXWiring.js"],function(_exports,_HAXWiring){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.RandomItem=void 0;class RandomItem extends HTMLElement{get html(){return`\n<style>:host {\n  display: block;\n}\n\n:host([hidden]) {\n  display: none;\n}\n</style>\n${this.dataPoint}`}static get haxProperties(){return{canScale:!0,canPosition:!0,canEditSource:!1,gizmo:{title:"Random item",description:"Show a random item from a list of items",icon:"communication:rss-feed",color:"red",groups:["Item"],handles:[],meta:{author:"btopro",owner:"The Pennsylvania State University"}},settings:{quick:[],configure:[{property:"field",title:"Field",description:"Field in the file to show",inputMethod:"textfield",required:!1},{property:"source",title:"Source",description:"URL pointing to a CSV file",inputMethod:"haxupload",required:!0}],advanced:[]}}}static get properties(){let props={source:{name:"source",type:String},field:{name:"field",type:String}};return super.properties&&(props=Object.assign(props,super.properties)),props}static get tag(){return"random-item"}constructor(delayRender=!1){super(),this.tag=RandomItem.tag,this.template=document.createElement("template"),this.attachShadow({mode:"open"}),delayRender||this.render()}connectedCallback(){window.ShadyCSS&&window.ShadyCSS.styleElement(this),this.HAXWiring=new _HAXWiring.HAXWiring,this.HAXWiring.setup(RandomItem.haxProperties,RandomItem.tag,this)}render(){this.shadowRoot.innerHTML=null,this.template.innerHTML=this.html,window.ShadyCSS&&window.ShadyCSS.prepareTemplate(this.template,this.tag),this.shadowRoot.appendChild(this.template.content.cloneNode(!0))}static get observedAttributes(){return["source","field"]}attributeChangedCallback(attr,oldValue,newValue){"source"===attr&&newValue?(this.source=newValue,this.sourceChanged(newValue)):"field"===attr&&newValue&&(this.field=newValue,this.source&&this.setDataWithRandom())}async sourceChanged(value){let data=await fetch(value).then(function(response){return response.text()});this.items=this.CSVtoArray(data);var heading=this.items.shift();this.qKey=heading,this.entryPoint=0,this.setDataWithRandom()}setDataWithRandom(){for(let key in this.qKey)this.qKey[key]===this.field&&(this.entryPoint=Number(key));var qKey=Math.floor(Math.random()*this.items.length);this.dataPoint=this.items[qKey][this.entryPoint],this.render()}CSVtoArray(text){let l,p="",row=[""],ret=[row],i=0,r=0,s=!0;for(l in text)'"'===(l=text[l])?(s&&l===p&&(row[i]+=l),s=!s):","===l&&s?l=row[++i]="":"\n"===l&&s?("\r"===p&&(row[i]=row[i].slice(0,-1)),row=ret[++r]=[l=""],i=0):row[i]+=l,p=l;return ret}}_exports.RandomItem=RandomItem,window.customElements.define(RandomItem.tag,RandomItem)});