;(function($, window, document){
!function($){if(void 0!==$){var a=null,e=null;if("undefined"!=typeof pvcColumnModal){var t=function(a){var e=$(".pvc-modal-tab");e.prop("disabled",a),a?e.addClass("pvc-tab-disabled"):e.removeClass("pvc-tab-disabled");var t=$(".pvc-modal-nav a");a?t.each(function(){$(this).addClass("pvc-temp-disabled pvc-disabled").attr("aria-disabled","true")}):$(".pvc-modal-nav a.pvc-temp-disabled").each(function(){$(this).removeClass("pvc-temp-disabled pvc-disabled").removeAttr("aria-disabled")})},o=function(a,e){var o=$(".pvc-modal-chart-container");o.addClass("loading"),o.find(".spinner").addClass("is-active"),t(!0),$.ajax({url:pvcColumnModal.ajaxURL,type:"POST",dataType:"json",data:{action:"pvc_column_chart",nonce:pvcColumnModal.nonce,post_id:a,period:e},success:function(a){a.success?n(a.data):d(a.data.message||pvcColumnModal.i18n.error)},error:function(){d(pvcColumnModal.i18n.error)},complete:function(){t(!1),o.removeClass("loading"),o.find(".spinner").removeClass("is-active")}})},n=function(e){var t=document.getElementById("pvc-modal-chart");if(t){a&&(a.destroy(),a=null),$(".pvc-modal-error").remove(),$(t).show(),$(".pvc-modal-views-label").text(pvcColumnModal.i18n.summary),$(".pvc-modal-count").text(e.total_views.toLocaleString()),$(".pvc-modal-dates").html(e.dates_html);var o={type:"line",data:e.data,options:{maintainAspectRatio:!1,responsive:!0,plugins:{legend:{display:!1},tooltip:{callbacks:{title:function(a){return e.data.dates[a[0].dataIndex]},label:function(a){var e=a.parsed.y,t=1===e?pvcColumnModal.i18n.view:pvcColumnModal.i18n.views;return"".concat(e.toLocaleString()," ").concat(t)}}}},scales:{x:{display:!0,grid:{display:!1}},y:{display:!0,beginAtZero:!0,ticks:{precision:0},grid:{color:"rgba(0, 0, 0, 0.05)"}}}}};e.design&&o.data.datasets.forEach(function(a){Object.assign(a,e.design),a.tension=.4}),a=new Chart(t.getContext("2d"),o),$(".pvc-modal-content-middle").show()}},d=function(e){a&&(a.destroy(),a=null),$(".pvc-modal-summary").text(""),$(".pvc-modal-dates").html(""),$(".pvc-modal-content-middle").hide();var t=$(".pvc-modal-chart-container");t.removeClass("loading"),t.find(".spinner").removeClass("is-active"),$(".pvc-modal-error").remove(),t.before('<p class="pvc-modal-error">'.concat(e,"</p>")),t.find("canvas").hide()};$(function(){0!==$("#pvc-chart-modal").length&&"undefined"!=typeof MicroModal&&(MicroModal.init({disableScroll:!0,awaitCloseAnimation:!0}),1)&&($(document).on("click",".pvc-view-chart",function(n){n.preventDefault();var d=$(n.currentTarget),l=d.data("post-id"),i=d.data("post-title");l&&function(a,o){if(!a)return!1;e=a,$("#pvc-modal-title").text(o);var n=$(".pvc-modal-chart-container");return n.addClass("loading"),n.find(".spinner").addClass("is-active"),t(!0),$(".pvc-modal-views-label").text(""),$(".pvc-modal-count").text(""),$(".pvc-modal-dates").html(""),$(".pvc-modal-content-middle").hide(),!0}(l,i)&&"undefined"!=typeof MicroModal&&MicroModal.show("pvc-chart-modal",{onShow:function(){e&&o(e,"")},onClose:function(){a&&(a.destroy(),a=null),e=null,function(){$("#pvc-modal-title").text(""),$(".pvc-modal-views-label").text(""),$(".pvc-modal-count").text(""),$(".pvc-modal-dates").html(""),$(".pvc-modal-content-middle").hide();var a=$(".pvc-modal-chart-container");a.removeClass("loading"),a.find(".spinner").removeClass("is-active"),$(".pvc-modal-error").remove()}()},disableScroll:!0,awaitCloseAnimation:!0})}),$(document).on("click",".pvc-modal-nav-prev, .pvc-modal-nav-next",function(a){a.preventDefault();var t=$(a.currentTarget);if(!t.hasClass("pvc-disabled")){var n=t.data("period");n&&e&&o(e,n)}}))})}}}(jQuery);

})(jQuery, window, document);
