(()=>{function e(){const n=document.querySelectorAll(".response"),o=document.querySelectorAll(".response-comment"),d=document.querySelectorAll(".saveMsg"),s=document.getElementById("ask-a-question"),c=document.querySelectorAll(".updateMsg"),a=document.querySelectorAll(".delete-comment"),l=document.querySelectorAll(".updateMsgBdd"),i=document.querySelectorAll(".cancel"),m=document.getElementById("ask-new"),r=document.getElementById("cancel-ask");function u(){I("show"),isLogged().then((e=>{if(e){I("hide"),L();let e=this.dataset.subject,t=document.getElementById("answerForm-"+e),n=document.getElementById("CONTENT-"+e);t.classList.remove("hidden"),t.scrollIntoView({behavior:"smooth",block:"center"}),n.focus()}else getZmodal(this,"loginform")}))}function h(){I("show"),isLogged().then((e=>{if(e){I("hide"),L();let e=this.dataset.id,t=document.getElementById("editForm-"+e);t.classList.remove("hidden"),t.scrollIntoView({behavior:"smooth",block:"center"}),t.classList.add("focus"),document.getElementById("EDIT-CONTENT-"+e).focus()}else getZmodal(this,"loginform")}))}function E(){I("show"),function(n){let o=document.getElementById("EDIT-CONTENT-"+n.dataset.id);(async function(e){let t=await fetch("/comments/update-msg/",{method:"post",body:JSON.stringify(e)});return await t.json()})({ID:n.dataset.id,ID_LANGUE:n.dataset.lang,CONTENT:o.value,TITLE:o.value}).then((o=>{t(n.dataset.originalsubject).then((t=>{document.getElementById("content-comms").innerHTML=t.html,I("hide"),e(),zmAlert({type:o.type,data:o.msg,timeout:2500})}))}))}(this)}function g(){let e=document.querySelectorAll(".form-comments:not(.hidden)");e.length>0&&e[0].classList.add("hidden")}function f(){I("show"),function(n){let o=n.dataset.id,d=document.getElementById("CONTENT-"+o);(async function(e){let t=await fetch("/comments/add-msg/",{method:"post",body:JSON.stringify(e)});return await t.json()})({SUBJECT_ID:n.dataset.id,SUBJECT_TABLE:n.dataset.table,ID_MEMBER:n.dataset.user,CONTENT:d.value}).then((o=>{t(n.dataset.subject).then((t=>{document.getElementById("content-comms").innerHTML=t.html,I("hide"),e(),zmAlert({type:o.type,data:o.msg,timeout:2500})}))}))}(this)}function y(){var n;I("show"),async function(e){let t=await fetch("/comments/update-status-msg/",{method:"post",body:JSON.stringify(e)});return await t.json()}({SUBJECT_ID:(n=this).dataset.subject,SUBJECT_TABLE:n.dataset.table,ID_COMMS:n.dataset.id,ID_LANGUE:n.dataset.lang,STATUS:2}).then((o=>{t(n.dataset.originalsubject).then((t=>{document.getElementById("content-comms").innerHTML=t.html,I("hide"),e(),zmAlert({type:o.type,data:o.msg,timeout:2500})}))}))}function L(){let e=document.querySelectorAll(".form-comments:not(.hidden)");e.length>0&&e[0].classList.add("hidden")}function I(e){if("show"===e){const e=document.getElementById("div-loader"),t=document.getElementById("loader"),n=document.getElementById("content-comms");e.classList.remove("hidden"),t.classList.add("loading"),n.classList.add("blur")}if("hide"===e){const e=document.getElementById("div-loader"),t=document.getElementById("loader"),n=document.getElementById("content-comms");e.classList.add("hidden"),t.classList.remove("loading"),n.classList.remove("blur")}}r&&r.addEventListener("click",(function(){document.getElementById("ask").classList.add("hidden"),s.removeAttribute("disabled")})),m&&m.addEventListener("click",(function(){I("show"),isLogged().then((e=>{if(e){let e=this.dataset.subject;I("hide"),L();let t=document.getElementById("ask-new-form"),n=document.getElementById("CONTENT-"+e);t.classList.remove("hidden"),t.scrollIntoView({behavior:"smooth",block:"center"}),t.classList.add("focus"),n.focus()}else getZmodal(this,"loginform")}))})),s&&s.addEventListener("click",(function(){I("show"),isLogged().then((e=>{if(e){I("hide"),L(),document.querySelector(".labelElement").textContent="Votre réponse";let e=document.getElementById("ask");e.classList.remove("hidden"),e.scrollIntoView({behavior:"smooth",block:"center"}),e.classList.add("focus"),s.setAttribute("disabled",!0)}else getZmodal(this,"loginform")}))})),c&&c.forEach((e=>{e.addEventListener("click",h)})),i&&i.forEach((e=>{e.addEventListener("click",g)})),a&&a.forEach((e=>{e.addEventListener("click",y)})),n&&n.forEach((e=>{e.addEventListener("click",u)})),o&&o.forEach((e=>{e.addEventListener("click",u)})),d&&d.forEach((e=>{e.addEventListener("click",f)})),l&&l.forEach((e=>{e.addEventListener("click",E)}))}async function t(e){let t=await fetch("/comments/get-comments/id/"+e+"/reload/true/table/blog_comments/",{dataType:"json"});return await t.json()}document.addEventListener("DOMContentLoaded",(()=>{t(current_id).then((t=>{document.getElementById("content-comms").innerHTML=t.html,e()}))}))})();