!function(){"use strict";window.addEventListener("load",(function(){!function(){const e="#commentform",t="sp-upload-review-image";jQuery((function(a){a(e).attr("enctype","multipart/form-data"),a("a.sp-upvote-button").each(((e,t)=>{const o=a(t).data("review-id"),n=a(t).data("key");"voted"===localStorage.getItem("nv_apr_upvote_"+n+o)&&(a(t).attr("data-already-liked",1),a(t).find(".sp-upvote-icon").addClass("active"))}));let o=!1;a(".sp-apr-upvote-section").on("click","a.sp-upvote-button",(e=>{if(e.preventDefault(),!0===o)return;const t=a(e.currentTarget),n="1"===t.attr("data-already-liked"),l=t.data("review-id"),r=t.data("product-id"),s=t.data("key");let i=localStorage.getItem("nv_apr_upvote_"+s+l);n&&"voted"!==i&&(localStorage.setItem("nv_apr_upvote_"+s+l,"voted"),i="voted"),a.ajax({type:"post",url:sparksApr.adminAjaxUrl+r+"/vote",beforeSend(e){o=!0,e.setRequestHeader("X-WP-Nonce",sparksApr.adminAjaxNonce)},data:{reviewId:l,hasVoted:i},success(e){if(o=!1,e.success){const a=e.latestCount;t.find(".sp-upvote-count").html(a>0?a:""),t.attr("data-already-liked",n?0:1),n?localStorage.removeItem("nv_apr_upvote_"+s+l):localStorage.setItem("nv_apr_upvote_"+s+l,"voted"),t.find(".sp-upvote-icon").toggleClass("active")}}})})),a(".sp-review-gallery").on("click","a.sp-review-image",(e=>{e.preventDefault();const t=e.currentTarget.getAttribute("data-image"),a=document.querySelector("#review-image-modal"),o=document.querySelector("#review-image-modal .sp-modal-container"),n=document.querySelector("#review-image-modal .sp-modal-container .sp-modal-inner-content"),l=document.createElement("img");l.style.display="block",l.style.width="100%",l.src=t,a.classList.add("open"),o.style.height="auto",o.classList.remove("is-loading"),n.innerHTML=l.outerHTML}));const n=[],l=e=>{document.getElementById("sp-upload-max").style.display="none";const t=document.getElementById("sp-upload-review-list"),a=function(e,t){const a=new FileReader;a.readAsDataURL(e[t]),a.onload=function(e){document.getElementById("img_preview_"+t).style.backgroundImage='url("'+e.target.result+'")'}};for(;t.hasChildNodes();)t.removeChild(t.firstChild);for(let o=0;o<e.files.length;o++){const n=document.createElement("li");n.classList.add("sp-upload-img-preview"),n.setAttribute("id","img_preview_"+o),n.innerHTML='<button value="'+o+'" class="sp-apr-remove-product">×</button>',a(e.files,o),t.appendChild(n)}};a("#sp-do-upload").click((function(){a(`#${t}`).click()})),a(`#${t}`).on("change",(e=>{if(!e.target.files)return;const a=e.target.files,o=Array.from(a);if(n.length+o.length>5){document.getElementById("sp-upload-max").style.display="block";const e=new DataTransfer;for(let t=0;t<n.length;t++){const a=n[t];e.items.add(a)}return void(document.getElementById(t).files=e.files)}const r=new DataTransfer;for(let e=0;e<n.length;e++){const t=n[e];r.items.add(t)}for(let e=0;e<o.length;e++){const t=a[e];r.items.add(t),n.push(t)}const s=document.getElementById(t);s.files=r.files,l(s)})),a("#sp-upload-review-list").on("click","li .sp-apr-remove-product",(e=>{e.preventDefault();const a=parseInt(e.target.value),o=document.getElementById(t),r=new DataTransfer,{files:s}=o;for(let e=0;e<s.length;e++){const t=s[e];a===e&&n.splice(e,1),a!==e&&r.items.add(t)}o.files=r.files,l(o)})),a(e).submit((function(){if(document.getElementById(t).files.length>5)return!1}))}))}()}))}();