letnamespace="vp";$(document).ready(function(){const$cmd=$("#custommodeldata");constform=$("#calculatorForm");constformOptions=$("#formItems");constfileName=$("#filename");constitem=$("#item");constitemCount=$("#itemcount");constitems=$("#items");constoutput=$("#content");constcopyButton=$("#copyButton");constdownloadButton=$("#downloadButton");constminus=$("#minus");constplus=$("#plus");constinput=$("input[name='quant']");constnsp=$("#namespace");const$select=$("#item");minus.click(function(){constcurrentVal=parseInt(input.attr("value"));if(!isNaN(currentVal)){if(currentVal>input.attr("min")){input.attr("value",(currentVal-1).toString())}if(currentVal-1===input.attr("min")){$(this).attr("disabled",true)}$("#iteminput"+currentVal).remove()}else{input.attr("value","0")}});plus.click(function(){constcurrentVal=parseInt(input.attr("value"));if(!isNaN(currentVal)){if(currentVal<input.attr("max")){input.attr("value",(currentVal+1).toString())}if(currentVal===input.attr("max")){$(this).attr("disabled",true);return}if(parseInt(input.attr("value"))>1){minus.prop("disabled",false)}else{minus.prop("disabled",true)}items.append('<div id="iteminput'+(currentVal+1)+'" class="mb-3 w-50"><label for="item'+(currentVal+1)+'">Model for damage '+(currentVal+1)+':</label><div class="input-group mb-3"><span class="input-group-text" id="namespace'+(currentVal+1)+'">'+namespace+':item/</span><input type="text" class="form-control" id="item'+(currentVal+1)+'" name="item'+(currentVal+1)+'" placeholder="cars/'+randomModel()+'" required></div></div>')}else{input.attr("value","0")}});$.each(itemDamages,function(key){constitemName=capitalize(key);$select.append($("<option></option>").attr("value",key).text(itemName))});$cmd.change(function(){$select.find("option").each(function(){constkey=$(this).val();constitemName=capitalize(key);consthasSupportText=$(this).text().includes("(supports");if(key===""){return}if($cmd.is(":checked")){if(hasSupportText){$(this).text(itemName)}}else{if(!hasSupportText){constupdatedText=itemName+" (supports "+itemDamages[key]+" models)";$(this).text(updatedText)}}})});nsp.change(function(){namespace=nsp.val();if(!namespace)namespace="minecraft";nsp.val(namespace);$("span[id^='namespace']").text(namespace+":item/")});item.change(function(){if(this.value!==""){formOptions.show();fileName.text(this.value+".json");constmax=itemDamages[this.value];itemCount.prop("max",max);plus.prop("disabled",false)}else{formOptions.hide();output.text("Fill in the form above to get an output.");fileName.text("file")}});form.on("submit",function(e){e.preventDefault();constsupportsCMD=$cmd.is(":checked");constselectedItem=item.val();constcurrentVal=parseInt(input.attr("value"));constmodels=[];for(leti=0;i<currentVal;i++){models[i]=$("#item"+(i+1)).val()}constjson=buildJSON(supportsCMD,selectedItem,namespace,models);output.html(syntaxHighlight(json));constdataStr="data:text/json;charset=utf-8,"+encodeURIComponent(json);downloadButton.attr("href",dataStr);downloadButton.attr("download",selectedItem+".json");returnfalse});copyButton.click(function(e){e.preventDefault();navigator.clipboard.writeText(output.text())});functioncapitalize(str){returnstr.split("_").map(word=>word.charAt(0).toUpperCase()+word.slice(1)).join(" ")}functionrandomModel(){constmonths=["red_car","blue_car","green_car","orange_car","blue_bicycle","red_bicycle","green_bicycle","orange_bicycle"];returnmonths[Math.floor(Math.random()*months.length)]}});