"use strict";let star1,star2,star3,star4,star5,publicObject=fsrs_object,hoverTextEl=document.getElementById("rating-hov-text"),liveRatingEl=document.getElementById("fsrs-live-rating"),liveRatingCount=document.getElementById("fsrs-live-rating-count");if(document.getElementById("fsrs-rating-before-content")&&null===document.getElementById("fsrs-rating-after-content-three-emoji-ico")){new FsrsStarConstructor(document.getElementById("fsrs-rating-before-content"),!0,!1)}if(document.getElementById("fsrs-rating-after-content")){new FsrsStarConstructor(document.getElementById("fsrs-rating-after-content"),!1,!1);setupAfterContentStarsEvents("fsrs-rating-icon")}if(void 0!==document.getElementById("fsrs-rating-after-content-emoji-ico")&&null!=document.getElementById("fsrs-rating-after-content-emoji-ico")){new FsrsStarConstructor(document.getElementById("fsrs-rating-after-content-emoji-ico"),!1,!0);setupAfterContentStarsEvents("fsrs-rating-emoji-icon")}if(void 0!==document.getElementById("fsrs-rating-after-content-three-emoji-ico")&&null!=document.getElementById("fsrs-rating-after-content-three-emoji-ico")){new FsrsStarConstructor(document.getElementById("fsrs-rating-after-content-three-emoji-ico"),!1,!1,!0);setupAfterContentThreeEmojiEvents("fsrs-rating-three-emoji-icon")}function setupAfterContentThreeEmojiEvents(e){getRatingSettings();for(let t=1;t<=5;t+=2){let s=document.getElementById(`${e}${t}`);document.getElementById(`fsrs-min-width-star-hover-txt${t}`).innerHTML=t,s.onmouseover=initOnStarHoverEvent(s,t),s.onmouseleave=function(){s.classList.remove("selected"),domFadeOut(document.getElementById(`fsrs-star-hover-txt--${t}`))},s.onclick=initOnStarClickEvent(s)}}function setupAfterContentStarsEvents(e){getRatingSettings();for(let t=1;t<=5;t++){let s=document.getElementById(`${e}${t}`);document.getElementById(`fsrs-min-width-star-hover-txt${t}`).innerHTML=t,s.onmouseover=initOnStarHoverEvent(s,t),s.onmouseleave=function(){s.classList.remove("selected"),domFadeOut(document.getElementById(`fsrs-star-hover-txt--${t}`))},s.onclick=initOnStarClickEvent(s)}}function initOnStarHoverEvent(e,t){return function(){let s;switch(e.classList.add("selected"),t){case 1:s=star1;break;case 2:s=star2;break;case 3:s=star3;break;case 4:s=star4;break;case 5:s=star5}document.getElementById(`fsrs-star-hover-txt--${t}`).style.display="block",domFadeIn(document.getElementById(`fsrs-star-hover-txt--${t}`)),document.getElementById(`fsrs-star-hover-txt--${t}`).innerHTML=s}}function initOnStarClickEvent(e){return function(){if(e.onmouseover=null,e.onmouseleave=null,document.getElementById("fsrs-rating-after-content-emoji-ico")){setEmojiRating(e.getAttribute("fsrs-star-value"),"default","checked","fsrs-rating-icon--clicked");for(let e=1;e<=5;e++){const t=document.getElementById(`fsrs-rating-emoji-icon${e}`);t.onclick=null,t.classList.remove("fsrs-rating-emoji-icon"),t.classList.add("fsrs-rating-icon--disabled"),domFadeOut(document.getElementById(`fsrs-star-hover-txt--${e}`))}}else if(document.getElementById("fsrs-rating-after-content")){setRating(e.getAttribute("fsrs-star-value"),"default","checked","fsrs-rating-icon--clicked");for(let e=1;e<=5;e++){const t=document.getElementById(`fsrs-rating-icon${e}`);t.onclick=null,t.classList.remove("fsrs-rating-icon"),t.classList.add("fsrs-rating-icon--disabled"),domFadeOut(document.getElementById(`fsrs-star-hover-txt--${e}`))}}else if(document.getElementById("fsrs-rating-after-content-three-emoji-ico")){setThreeEmojiIcoRating(e.getAttribute("fsrs-star-value"),"default","checked","fsrs-rating-icon--clicked");for(let e=1;e<=5;e+=2){const t=document.getElementById(`fsrs-rating-three-emoji-icon${e}`);t.onclick=null,t.classList.remove("fsrs-rating-three-emoji-icon"),t.classList.add("fsrs-rating-icon--disabled"),domFadeOut(document.getElementById(`fsrs-star-hover-txt--${e}`))}}postData(publicObject.ajax_url,"action=savePostData&nonce="+publicObject._wpnonce+"&fsrsPostId="+document.getElementById("post-id").value+"&pRating="+e.getAttribute("fsrs-star-value")).then(null)}}async function postData(e="",t=""){let s=document.getElementById("fsrs-loading");s&&(s.style.display="block",domFadeIn(s));let n=new XMLHttpRequest;n.open("POST",e,!0),n.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),n.onload=function(){if(!(this.status>=200&&this.status<400))throw s&&(s.style.display="none",domFadeOut(s)),new Error("request failed!");if(s&&(s.style.display="none",domFadeOut(s)),"success"===this.response.result){initPopups();const e=this.response.ratingValue;document.getElementById("fsrs-rating-before-content")&&null===document.getElementById("fsrs-rating-after-content-three-emoji-ico")&&setReadonlyRating(e),document.getElementById("fsrs-rating-after-content-emoji-ico")&&setEmojiRating(e,"default","checked","fsrs-rating-icon--clicked"),document.getElementById("fsrs-rating-after-content-three-emoji-ico")?setThreeEmojiRating(e,"default","checked","fsrs-rating-icon--clicked"):setRating(e,"default","checked","fsrs-rating-icon--clicked"),hoverTextEl&&(hoverTextEl.innerHTML=publicObject.thanks_text),liveRatingEl&&(liveRatingEl.innerHTML=this.response.liveRating),liveRatingCount&&(liveRatingCount.innerHTML=this.response.liveRatingCount)}else hoverTextEl.innerText=this.response.result},n.onerror=function(){s&&(s.style.display="none",domFadeOut(s))},n.responseType="json",n.send(t)}function getRatingSettings(){star1=publicObject.star1,star2=publicObject.star2,star3=publicObject.star3,star4=publicObject.star4,star5=publicObject.star5}function initPopups(){getPopupInfoRequest().then(null)}async function getPopupInfoRequest(){let e=new XMLHttpRequest;e.open("POST",publicObject.ajax_url,!0),e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.onload=function(){let e=this.response;if(!(this.status>=200&&this.status<400))throw new Error("request failed!");{const t=e.popup_options,s=JSON.parse(t);"1"===s.fsrs_user_info_dialog_show&&getInfoPopup(s.fsrs_get_user_info_title,e.post_url,s.fsrs_email_field_helper_text,s.fsrs_user_info_submit_text,s.fsrs_user_info_deny_text,s.fsrs_share_dialog_show,s.fsrs_share_facebook_show,s.fsrs_share_linkedin_show,s.fsrs_share_twitter_show,s.fsrs_share_telegram_show,s.fsrs_share_email_show,s.fsrs_user_privacy_text,s.fsrs_share_dialog_title,s.fsrs_user_info_thanks_text),"1"!==s.fsrs_user_info_dialog_show&&"1"===s.fsrs_share_dialog_show&&sharePopup(e.post_url,s.fsrs_share_dialog_title,s.fsrs_share_facebook_show,s.fsrs_share_linkedin_show,s.fsrs_share_twitter_show,s.fsrs_share_telegram_show,s.fsrs_share_email_show)}},e.onerror=function(){console.log("request failed!")},e.responseType="json",e.send("action=fsrs_get_dialog_info_setting&nonce="+publicObject._wpnonce+"&p_id="+document.getElementById("post-id").value)}function getInfoPopup(e,t,s,n,r,o,i,a,l,c,u,d,f,m){Swal.fire({title:e,input:"text",validationMessage:publicObject.email_error_message,customClass:{validationMessage:"my-validation-message"},inputAttributes:{autocapitalize:"off",placeholder:s,style:"text-align: center!important;font-family: sans-serif!important;border-radius: 4px;"},html:`<p style="font-size:12px!important;font-family:inherit;color:#a5a3a1">${d}</p>`,showCancelButton:!0,confirmButtonText:n,cancelButtonText:r,preConfirm:e=>{null!==e&&""!==e&&void 0!==e||Swal.showValidationMessage(publicObject.email_error_message)}}).then(e=>{if(e.isConfirmed&&(""===!e.value||e.value)){Swal.fire({title:"لطفا صبر کنید...",allowOutsideClick:!1,showCancelButton:!1,showCloseButton:!1,showDenyButton:!1,showConfirmButton:!1,onBeforeOpen:()=>{Swal.showLoading()}});let s=new XMLHttpRequest;s.open("POST",publicObject.ajax_url,!0),s.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),s.onload=function(){this.status>=200&&this.status<400?"success"===this.response.result?(Swal.close(),"1"===o?sharePopup(t,f,i,a,l,c,u):Swal.fire({title:m,icon:"success",confirmButtonText:"بستن پنجره"})):(Swal.close(),Swal.fire({title:"متاسفانه مشکلی در اجرای درخواست شما پیش آمده است. لطفا بعدا دوباره تلاش کنید.",icon:"error",confirmButtonText:"بستن پنجره"})):Swal.showValidationMessage("متاسفانه خطایی رخ داده")},s.onerror=function(){console.log("request failed!"),Swal.showValidationMessage(`متاسفانه خطایی رخ داده: ${error}`)},s.responseType="json",s.send("action=fsrs_add_user_email&nonce="+publicObject._wpnonce+"&email="+`${e.value}`+"&post_id="+document.getElementById("post-id").value)}})}function sharePopup(e,t,s,n,r,o,i){let a,l,c=`https://www.linkedin.com/sharing/share-offsite/?url=${e}`,u=`https://twitter.com/share?url=${e}`,d=`https://www.facebook.com/sharer.php?u=${e}`,f=`https://telegram.me/share/url?url=${e}`,m=`mailto:?subject=${publicObject.post_title}&amp;body="${e}`,g="",h="",p="",_="",y="";a="<hr><div><ul class='fsrs-share-ul'>","1"===s&&(g=`<li class='fsrs-share-li' style='background: #3b5998'>\n                 <a href='${d}' target='_blank'>${publicObject.share_facebook}</a></li>`),"1"===n&&(h=`<li class='fsrs-share-li' style='background: #0e76a8!important'>\n                 <a href='${c}' target='_blank'>${publicObject.share_linkedin}</a></li>`),"1"===r&&(p=`<li class='fsrs-share-li' \n                style='background: #00acee'><a href='${u}'\n                 target='_blank'>${publicObject.share_twitter}</a></li>`),"1"===o&&(_=`<li class='fsrs-share-li' style='background: #2ca5e0'>\n                 <a href='${f}' target='_blank'>${publicObject.share_telegram}</a></li>`),"1"===i&&(y=`<li class='fsrs-share-li' style='background: #0166ff'>\n                 <a href='${m}' target='_blank'>${publicObject.share_email}</a></li>`),l="</ul></div>";let b="<hr><div><ul class='fsrs-share-ul'>"+h+p+g+_+y+"</ul></div>";swal.fire({title:t,icon:"success",html:b,showDenyButton:!1,showConfirmButton:!1,dangerMode:!0,showCloseButton:!0})}function domFadeOut(e){let t=1,s=setInterval(function(){t<=.1&&(clearInterval(s),e.style.display="none"),e.style.opacity=t,e.style.filter="alpha(opacity="+100*t+")",t-=100*t},5)}function domFadeIn(e){let t=.1;e.style.display="block";let s=setInterval(function(){t>=1&&clearInterval(s),e.style.opacity=t,e.style.filter="alpha(opacity="+100*t+")",t+=.1*t},10)};