(function(){"use strict";var SVG_NS="http://www.w3.org/2000/svg";var SUBMIT_FIELD="imunify_security_bot_action";function ready(fn){if("loading"!==document.readyState){fn()}else{document.addEventListener("DOMContentLoaded",fn)}}function readData(){var node=document.getElementById("imunify-bot-traffic-data");if(!node){return null}try{return JSON.parse(node.textContent||"{}")}catch(e){return null}}function svgEl(tag,attrs){var node=document.createElementNS(SVG_NS,tag);var key;for(key in attrs){if(Object.prototype.hasOwnProperty.call(attrs,key)){node.setAttribute(key,attrs[key])}}return node}var tipNode=null;function tipEl(){if(!tipNode){tipNode=document.createElement("div");tipNode.className="imunify-security__bot-traffic-tooltip";tipNode.setAttribute("role","tooltip");document.body.appendChild(tipNode)}return tipNode}function tipRow(el,label,value,isTotal){var row=document.createElement("div");row.className="imunify-security__bot-traffic-tooltip-row"+(isTotal?" is-total":"");var k=document.createElement("span");k.textContent=label;var v=document.createElement("b");v.textContent=value;row.appendChild(k);row.appendChild(v);el.appendChild(row)}function moveTip(e){var el=tipEl();var pad=14;var rect=el.getBoundingClientRect();var x=e.clientX+pad;var y=e.clientY+pad;if(x+rect.width>window.innerWidth-8){x=e.clientX-rect.width-pad}if(y+rect.height>window.innerHeight-8){y=e.clientY-rect.height-pad}el.style.left=x+"px";el.style.top=y+"px"}function bindTip(hit,point){hit.addEventListener("mouseenter",function(e){var el=tipEl();el.textContent="";var head=document.createElement("div");head.className="imunify-security__bot-traffic-tooltip-h";head.textContent=point.rangeLabel||point.label;el.appendChild(head);tipRow(el,"Allowed",(point.allow||0).toLocaleString());tipRow(el,"Rate-limited",(point.rate_limit||0).toLocaleString());tipRow(el,"Blocked",(point.block||0).toLocaleString());tipRow(el,"Total",point.countLabel,true);el.style.opacity="1";moveTip(e)});hit.addEventListener("mousemove",moveTip);hit.addEventListener("mouseleave",function(){if(tipNode){tipNode.style.opacity="0"}})}function labelChart(svg,mount){var label=mount.getAttribute("data-label");if(label){svg.setAttribute("aria-label",label)}}function maxCount(items){var max=0;var i;for(i=0;imax){max=items[i].count}}return 0=v){return 1}var p=Math.pow(10,Math.floor(Math.log(v)/Math.LN10));return Math.ceil(v/p)*p}function renderTimelineLegend(){var mount=document.querySelector(".js-bot-traffic-timeline-legend");if(!mount){return}var items=[{seg:"allow",label:"Allowed"},{seg:"rate_limit",label:"Rate-limited (429)"},{seg:"block",label:"Blocked (403)"}];var html="";var i;for(i=0;i'+''+items[i].label+""}mount.innerHTML=html}function renderTimelineChart(points){var mount=document.querySelector(".js-bot-traffic-timeline-chart");if(!mount||!points||!points.length){return}var W=720;var H=220;var padL=44;var padR=10;var padT=10;var padB=26;var plotW=W-padL-padR;var plotH=H-padT-padB;var base=padT+plotH;var count=points.length;var gap=3;var barW=(plotW-(count-1)*gap)/count;var max=niceMax(maxCount(points));var segments=["allow","rate_limit","block"];var svg=svgEl("svg",{viewBox:"0 0 "+W+" "+H,role:"img",preserveAspectRatio:"xMinYMin meet"});labelChart(svg,mount);var ticks=[0,Math.round(max/2),max];var t;for(t=0;t=value){continue}var segH=Math.max(1,Math.round(value/max*plotH));yCursor-=segH;svg.appendChild(svgEl("rect",{x:x,y:yCursor,width:barW,height:segH,rx:1,class:"imunify-security__bot-traffic-timeline-bar is-"+seg}))}var hit=svgEl("rect",{x:x,y:padT,width:barW,height:plotH,fill:"transparent",class:"imunify-security__bot-traffic-timeline-hit"});bindTip(hit,point);svg.appendChild(hit);if(0===i%6){var xl=svgEl("text",{x:x+barW/2,y:H-8,"text-anchor":"middle",class:"imunify-security__bot-traffic-axis-text"});xl.textContent=point.label;svg.appendChild(xl)}}mount.appendChild(svg)}function setRowHidden(el,hide){if(hide){el.setAttribute("hidden","hidden")}else{el.removeAttribute("hidden")}}function toggleDrill(toggle){var expanded="true"===toggle.getAttribute("aria-expanded");toggle.setAttribute("aria-expanded",expanded?"false":"true");var panelId=toggle.getAttribute("aria-controls");var panel=panelId?document.getElementById(panelId):null;if(panel){setRowHidden(panel,expanded)}var group=toggle.getAttribute("data-target");if(group){var rows=document.querySelectorAll('[data-group="'+group+'"]');var r;for(r=0;rxhr.status&&ok){window.location.reload()}else{button.disabled=false;showError(form,imunifyBotTraffic.errorMessage)}};xhr.send(body)}function bindOptOut(){var form=document.querySelector(".js-bot-traffic-optout-form");if(!form){return}form.addEventListener("submit",function(e){e.preventDefault();var button=form.querySelector(".js-bot-traffic-optout-toggle");if(button){postToggle(button.value,button,form)}})}ready(function(){var data=readData();if(data){renderTimelineLegend();renderTimelineChart(data.timeline)}bindOptOut();bindDrillDown()})})();