function t(t){return function(t){if(Array.isArray(t))return e(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,o){if(t){if("string"==typeof t)return e(t,o);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(t,o):void 0}}(t)||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 e(t,e){(null==e||e>t.length)&&(e=t.length);for(var o=0,r=Array(e);o<e;o++)r[o]=t[o];return r}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}document.addEventListener("DOMContentLoaded",function(){PostViewsCounterPro={promise:null,args:{},crawlerDetect:null,init:function(t){if(this.args=t,"undefined"!=typeof PostViewsCounterCrawlerDetect&&(t.blockAI||t.blockBots)){if(this.crawlerDetect=new PostViewsCounterCrawlerDetect,t.blockBots&&this.crawlerDetect.isCrawler())return void console.log("PVC Pro: Crawler detected, skipping view count.");if(t.blockAI&&(this.crawlerDetect.isAIBot()||this.crawlerDetect.isLikelyBot()))return void console.log("PVC Pro: AI Bot detected, skipping view count.")}if(this.loadViews(),!0===t.contentActive&&Object.prototype.hasOwnProperty.call(t.content,"type")&&!1!==t.content.type){var e={subtype:t.content.subtype,referrer:document.referrer},o="pvc_visits".concat("post"===t.content.type?"":"_".concat(t.content.type)).concat(!1!==t.multisite?"_".concat(parseInt(t.multisite)):"");"cookieless"===t.dataStorage&&this.isLocalStorageAvailable()?(e.storage_type="cookieless",e.storage_data=this.readStorageData(o),e.storage_data_all=JSON.stringify(this.readAllStorageData("cookieless"))):(e.storage_type="cookies",e.storage_data=this.readCookieData(o),e.storage_data_all=JSON.stringify(this.readAllStorageData("cookies"))),"rest_api"===t.mode?this.promise=this.request(t.requestURL,e,"POST",{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8","Cache-Control":"no-store","X-WP-Nonce":t.nonce},o):(e.action="pvcp-check-post",e.pvcp_nonce=t.nonce,e.content=t.content.data,e.type=t.content.type,this.promise=this.request(t.requestURL,e,"POST",{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8","Cache-Control":"no-store"},o))}},request:function(t,e,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(e)}var c=this;return fetch(t,i).then(function(t){if(!t.ok)throw Error(t.statusText);return t.json()}).then(function(t){try{"object"===o(t)&&null!==t?"success"in t&&!1===t.success?(console.log("PVC Pro: Request error."),console.log(t.data)):("cookieless"===c.args.dataStorage?c.saveStorageData(a,t.storage,t.type):c.saveCookieData(a,t.storage),c.triggerEvent("pvcCheckPost",t)):(console.log("PVC Pro: Invalid object."),console.log(t))}catch(e){console.log("PVC Pro: Invalid JSON data."),console.log(e)}}).catch(function(t){console.log("PVC Pro: Invalid response."),console.log(t)})},prepareRequestData:function(t){return Object.keys(t).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t[e])}).join("&").replace(/%20/g,"+")},triggerEvent:function(t,e){var o=new CustomEvent(t,{bubbles:!0,detail:e});document.dispatchEvent(o)},getCookiePath:function(){var t="string"==typeof this.args.path?this.args.path.trim():"";if(!t||"/"===t)return"/";var e=t.replace(/\/{2,}/g,"/").replace(/^\/+|\/+$/g,"");return e?"/".concat(e,"/"):"/"},saveStorageData:function(t,e,r){if(e&&"object"===o(e))if(Object.prototype.hasOwnProperty.call(e,"version")){var n=JSON.stringify(e);this.getStorageNames().forEach(function(t){window.localStorage.setItem(t,n)})}else Object.prototype.hasOwnProperty.call(e,r)&&window.localStorage.setItem(t,JSON.stringify(e[r]))},getStorageNames:function(){var t=!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(e){return"pvc_visits".concat("post"===e?"":"_".concat(e)).concat(t)})},readAllStorageData:function(t){var e=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"===t?e.readCookieData(i):e.readStorageData(i)}),n},readStorageData:function(t){var e=null;return null===(e=window.localStorage.getItem(t))&&(e=""),e},saveCookieData:function(e,o){var r=this;if(Object.prototype.hasOwnProperty.call(o,"name")){var n=t(new Set(o.name.map(function(t){return t.replace(/\[\d+\]$/,"")}))),a="";"https:"===document.location.protocol&&(a=";secure"),n.forEach(function(t){document.cookie.split(";").forEach(function(e){var o=e.split("=")[0];if(void 0!==o){var n=o.trim();new RegExp("^".concat(t,"\\[(\\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(t){var e=[];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(t,"\\[(\\d+)\\]$")),s=i.match(c);if(s){var l=a||"";try{l=decodeURIComponent(l)}catch(u){l=a||""}e.push({index:parseInt(s[1],10),value:l})}}}}),e.sort(function(t,e){return t.index-e.index});var r=e.map(function(t){return t.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 t;try{return(t=window.localStorage).setItem("__pvcStorageTest",0),t.removeItem("__pvcStorageTest"),!0}catch(e){return e instanceof DOMException&&(22===e.code||1014===e.code||"QuotaExceededError"===e.name||"NS_ERROR_DOM_QUOTA_REACHED"===e.name)&&t&&0!==t.length}},loadViews:function(){var t=this,e=document.getElementsByClassName("post-views"),o={};if(0!==e.length)for(var r=function(){var r=e[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:t.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:t.prepareRequestData(u),mode:"same-origin",cache:"no-cache",credentials:"same-origin",keepalive:!1};r.classList.add("loading"),t.promise=fetch(t.args.adminAjax,p).then(function(t){if(!t.ok)throw Error(t.statusText);return t.text()}).then(function(t){try{if("string"==typeof t&&null!==t){var e="".concat(u.type,"-").concat(u.ID);if(e in o){var r=o[e].querySelector(".post-views-count");r&&(r.innerText=t)}else console.log("Invalid DOM element")}else console.log("Invalid string")}catch(n){console.log("Invalid JSON data")}}).catch(function(t){console.log("Invalid response"),console.log(t)}).finally(function(){var t="".concat(u.type,"-").concat(u.ID);t in o&&(o[t].classList.add("loaded"),o[t].classList.remove("loading"))})}},n=0;n<e.length;n++)r()}},PostViewsCounterPro.init(pvcpArgsFrontend)});