function e(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,o){if(e){if("string"==typeof e)return t(e,o);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,o):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=Array(t);o<t;o++)r[o]=e[o];return r}function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}document.addEventListener("DOMContentLoaded",function(){PostViewsCounterPro={promise:null,args:{},crawlerDetect:null,init:function(e){if(this.args=e,"undefined"!=typeof PostViewsCounterCrawlerDetect&&(e.blockAI||e.blockBots)){if(this.crawlerDetect=new PostViewsCounterCrawlerDetect,e.blockBots&&this.crawlerDetect.isCrawler())return void console.log("PVC Pro: Crawler detected, skipping view count.");if(e.blockAI&&(this.crawlerDetect.isAIBot()||this.crawlerDetect.isLikelyBot()))return void console.log("PVC Pro: AI Bot detected, skipping view count.")}if(this.loadViews(),!0===e.contentActive&&Object.prototype.hasOwnProperty.call(e.content,"type")&&!1!==e.content.type){var t={subtype:e.content.subtype,referrer:document.referrer},o="pvc_visits".concat("post"===e.content.type?"":"_".concat(e.content.type)).concat(!1!==e.multisite?"_".concat(parseInt(e.multisite)):"");"cookieless"===e.dataStorage&&this.isLocalStorageAvailable()?(t.storage_type="cookieless",t.storage_data=this.readStorageData(o),t.storage_data_all=JSON.stringify(this.readAllStorageData("cookieless"))):(t.storage_type="cookies",t.storage_data=this.readCookieData(o),t.storage_data_all=JSON.stringify(this.readAllStorageData("cookies"))),"rest_api"===e.mode?this.promise=this.request(e.requestURL,t,"POST",{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8","Cache-Control":"no-store","X-WP-Nonce":e.nonce},o):(t.action="pvcp-check-post",t.pvcp_nonce=e.nonce,t.content=e.content.data,t.type=e.content.type,this.promise=this.request(e.requestURL,t,"POST",{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8","Cache-Control":"no-store"},o))}},request:function(e,t,r,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"",i={method:r,headers:n,mode:"same-origin",cache:"no-cache",credentials:"same-origin",keepalive:!0};switch(r){case"HEAD":case"GET":break;default:i.body=this.prepareRequestData(t)}var c=this;return fetch(e,i).then(function(e){if(!e.ok)throw Error(e.statusText);return e.json()}).then(function(e){try{if("object"===o(e)&&null!==e)if("success"in e&&!1===e.success)console.log("PVC Pro: Request error."),console.log(e.data);else{var t="string"==typeof e.effective_type&&""!==e.effective_type?e.effective_type:e.type;"cookieless"===c.args.dataStorage?c.saveStorageData(a,e.storage,t):c.saveCookieData(a,e.storage),c.triggerEvent("pvcCheckPost",e)}else console.log("PVC Pro: Invalid object."),console.log(e)}catch(r){console.log("PVC Pro: Invalid JSON data."),console.log(r)}}).catch(function(e){console.log("PVC Pro: Invalid response."),console.log(e)})},prepareRequestData:function(e){return Object.keys(e).map(function(t){return encodeURIComponent(t)+"="+encodeURIComponent(e[t])}).join("&").replace(/%20/g,"+")},triggerEvent:function(e,t){var o=new CustomEvent(e,{bubbles:!0,detail:t});document.dispatchEvent(o)},getCookiePath:function(){var e="string"==typeof this.args.path?this.args.path.trim():"";if(!e||"/"===e)return"/";var t=e.replace(/\/{2,}/g,"/").replace(/^\/+|\/+$/g,"");return t?"/".concat(t,"/"):"/"},saveStorageData:function(e,t,r){if(t&&"object"===o(t))if(Object.prototype.hasOwnProperty.call(t,"version")){var n=JSON.stringify(t);this.getStorageNames().forEach(function(e){window.localStorage.setItem(e,n)})}else Object.prototype.hasOwnProperty.call(t,r)&&window.localStorage.setItem(e,JSON.stringify(t[r]))},getStorageNames:function(){var e=!1!==this.args.multisite?"_".concat(parseInt(this.args.multisite,10)):"";return(Array.isArray(this.args.storageBuckets)&&this.args.storageBuckets.length>0?this.args.storageBuckets:["post","term","user","other"]).map(function(t){return"pvc_visits".concat("post"===t?"":"_".concat(t)).concat(e)})},readAllStorageData:function(e){var t=this,o=this.getStorageNames(),r=Array.isArray(this.args.storageBuckets)&&this.args.storageBuckets.length>0?this.args.storageBuckets:["post","term","user","other"],n={};return r.forEach(function(r,a){var i=o[a];n[r]="cookies"===e?t.readCookieData(i):t.readStorageData(i)}),n},readStorageData:function(e){var t=null;return null===(t=window.localStorage.getItem(e))&&(t=""),t},saveCookieData:function(t,o){var r=this;if(Object.prototype.hasOwnProperty.call(o,"name")){var n=e(new Set(o.name.map(function(e){return e.replace(/\[\d+\]$/,"")}))),a="";"https:"===document.location.protocol&&(a=";secure"),n.forEach(function(e){document.cookie.split(";").forEach(function(t){var o=t.split("=")[0];if(void 0!==o){var n=o.trim();new RegExp("^".concat(e,"\\[(\\d+)\\]$")).test(n)&&(document.cookie=n+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path="+r.getCookiePath()+";domain="+r.args.domain+a+";SameSite=Lax")}})});for(var i=0;i<o.name.length;i++){var c=new Date,s=parseInt(o.expiry[i]),l=o.value[i];"string"!=typeof l&&(l=String(null!=l?l:"")),s?s*=1e3:s=c.getTime()+864e5,c.setTime(s),document.cookie=o.name[i]+"="+encodeURIComponent(l)+";expires="+c.toUTCString()+";path="+this.getCookiePath()+";domain="+this.args.domain+a+";SameSite=Lax"}}},readCookieData:function(e){var t=[];document.cookie.split(";").forEach(function(o){if(o&&o.trim()){var r=o.split("="),n=r[0],a=r.slice(1).join("=");if(n){var i=n.trim(),c=new RegExp("^".concat(e,"\\[(\\d+)\\]$")),s=i.match(c);if(s){var l=a||"";try{l=decodeURIComponent(l)}catch(u){l=a||""}t.push({index:parseInt(s[1],10),value:l})}}}}),t.sort(function(e,t){return e.index-t.index});var r=t.map(function(e){return e.value||""}),n=r.join("");if(n)try{var a=JSON.parse(n);if(a&&"object"===o(a)&&1===a.version)return n}catch(i){}return r.join("a")},isLocalStorageAvailable:function(){var e;try{return(e=window.localStorage).setItem("__pvcStorageTest",0),e.removeItem("__pvcStorageTest"),!0}catch(t){return t instanceof DOMException&&(22===t.code||1014===t.code||"QuotaExceededError"===t.name||"NS_ERROR_DOM_QUOTA_REACHED"===t.name)&&e&&0!==e.length}},loadViews:function(){var e=this,t=document.getElementsByClassName("post-views"),o={};if(0!==t.length)for(var r=function(){var r=t[n],a=r.className;if(!a.includes("load-dynamic"))return 1;var i=a.match(/[a-zA-Z]+-[0-9]+.*?/),c="",s=0;if(null!=i){var l=i[0].split("-");c=l[0],s=l[1],o["".concat(c,"-").concat(s)]=r;var u={action:"pvcp-views-count",pvcp_nonce:e.args.nonceCount,type:c,ID:s},p={method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8","Cache-Control":"no-store"},body:e.prepareRequestData(u),mode:"same-origin",cache:"no-cache",credentials:"same-origin",keepalive:!1};r.classList.add("loading"),e.promise=fetch(e.args.adminAjax,p).then(function(e){if(!e.ok)throw Error(e.statusText);return e.text()}).then(function(e){try{if("string"==typeof e&&null!==e){var t="".concat(u.type,"-").concat(u.ID);if(t in o){var r=o[t].querySelector(".post-views-count");r&&(r.innerText=e)}else console.log("Invalid DOM element")}else console.log("Invalid string")}catch(n){console.log("Invalid JSON data")}}).catch(function(e){console.log("Invalid response"),console.log(e)}).finally(function(){var e="".concat(u.type,"-").concat(u.ID);e in o&&(o[e].classList.add("loaded"),o[e].classList.remove("loading"))})}},n=0;n<t.length;n++)r()}},PostViewsCounterPro.init(pvcpArgsFrontend)});