|
1
|
|
-var ct=h=>{throw TypeError(h)};var et=(h,e,i)=>e.has(h)||ct("Cannot "+i);var t=(h,e,i)=>(et(h,e,"read from private field"),i?i.call(h):e.get(h)),f=(h,e,i)=>e.has(h)?ct("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(h):e.set(h,i),d=(h,e,i,a)=>(et(h,e,"write to private field"),a?a.call(h,i):e.set(h,i),i),c=(h,e,i)=>(et(h,e,"access private method"),i);var Y=(h,e,i,a)=>({set _(o){d(h,e,o,i)},get _(){return t(h,e,a)}});const Z=new Map,V=new Map;let L=null;var n,y,A,j,G,D,K,p,k,I,B,T,tt,W,P,$,x,M,O,q,X,J,R,E,H,r,ht,z,N,ft,U,it,mt,st,wt,vt,yt,pt,gt,bt,C;class ut{constructor(e){f(this,r);f(this,n);f(this,y);f(this,A,0);f(this,j);f(this,G);f(this,D,!0);f(this,K,!0);f(this,p,1);f(this,k,2);f(this,I,!1);f(this,B,null);f(this,T,null);f(this,tt,new AbortController);f(this,W,new AbortController);f(this,P,!1);f(this,$,0);f(this,x,null);f(this,M,null);f(this,O,null);f(this,q,null);f(this,X,2);f(this,J,!1);f(this,R,!0);f(this,E,null);f(this,H,!1);d(this,n,e),d(this,y,e.getAttribute("data-post-id")),d(this,A,parseInt(e.getAttribute("data-item-id"),10)||0),d(this,j,e.getAttribute("data-rest-url")),d(this,G,e.getAttribute("data-rest-nonce")),d(this,D,e.getAttribute("data-star-enabled")!=="0"),d(this,K,e.getAttribute("data-star-required")!=="0"),d(this,k,parseInt(e.getAttribute("data-total-steps"))||2),d(this,I,e.getAttribute("data-edit-mode")==="1"),d(this,B,e.getAttribute("data-review-id")),d(this,E,e.getAttribute("data-form-id")),d(this,J,e.getAttribute("data-layout")==="inline"),d(this,R,e.getAttribute("data-container")!=="none"),d(this,X,t(this,J)||!t(this,D)?1:2)}init(){c(this,r,wt).call(this),c(this,r,ht).call(this),c(this,r,ft).call(this),c(this,r,yt).call(this),c(this,r,st).call(this),t(this,I)&&c(this,r,vt).call(this)}open(){c(this,r,z).call(this)}destroy(){clearTimeout(t(this,q)),d(this,q,null),clearTimeout(t(this,x)),d(this,x,null),Y(this,$)._++,d(this,P,!1),t(this,W).abort(),L===this&&(L=null,document.body.style.overflow=""),Z.get(t(this,E))===this&&Z.delete(t(this,E)),V.get(t(this,y))===this&&V.delete(t(this,y));const e=t(this,n).querySelector("[data-review-drawer]");e&&(e.classList.remove("fct-drawer-open"),e.style.display="none"),d(this,T,null)}}n=new WeakMap,y=new WeakMap,A=new WeakMap,j=new WeakMap,G=new WeakMap,D=new WeakMap,K=new WeakMap,p=new WeakMap,k=new WeakMap,I=new WeakMap,B=new WeakMap,T=new WeakMap,tt=new WeakMap,W=new WeakMap,P=new WeakMap,$=new WeakMap,x=new WeakMap,M=new WeakMap,O=new WeakMap,q=new WeakMap,X=new WeakMap,J=new WeakMap,R=new WeakMap,E=new WeakMap,H=new WeakMap,r=new WeakSet,ht=function(){const e=t(this,n).querySelector("[data-review-drawer]");if(!e)return;t(this,E)&&Z.set(t(this,E),this),t(this,y)&&!V.has(t(this,y))&&V.set(t(this,y),this);const i=e.querySelector("[data-close-review-drawer]"),a=e;document.addEventListener("click",o=>{const s=o.target.closest("[data-open-review-drawer]");if(!s)return;const l=s.getAttribute("data-post-id");if(l&&l!==t(this,y))return;const u=s.getAttribute("data-review-form-target");if(u){if(u===t(this,E)){c(this,r,z).call(this);return}!Z.has(u)&&V.get(t(this,y))===this&&c(this,r,z).call(this);return}V.get(t(this,y))===this&&c(this,r,z).call(this)},{signal:t(this,W).signal}),i&&i.addEventListener("click",()=>c(this,r,N).call(this)),a.addEventListener("click",o=>{o.target===a&&c(this,r,N).call(this)}),document.addEventListener("keydown",o=>{if(e.style.display!=="none"&&L===this){if(o.key==="Escape")c(this,r,N).call(this);else if(o.key==="Tab"){const s=e.querySelector("[data-review-drawer-panel]");if(!s)return;const l=s.querySelectorAll('button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])');if(!l.length)return;const u=l[0],m=l[l.length-1];o.shiftKey&&document.activeElement===u?(o.preventDefault(),m.focus()):!o.shiftKey&&document.activeElement===m&&(o.preventDefault(),u.focus())}}},{signal:t(this,W).signal})},z=function(){var i;if(t(this,H))return;const e=t(this,n).querySelector("[data-review-drawer]");e&&(L&&L!==this&&c(i=L,r,N).call(i,{replaced:!0}),L=this,t(this,q)&&(clearTimeout(t(this,q)),d(this,q,null)),t(this,I)||c(this,r,U).call(this,1),d(this,T,document.activeElement),e.style.display="flex",document.body.style.overflow="hidden",requestAnimationFrame(()=>{e.classList.add("fct-drawer-open");const a=e.querySelector("[data-review-drawer-panel]");a&&a.focus()}))},N=function({replaced:e=!1}={}){const i=t(this,n).querySelector("[data-review-drawer]");if(!i)return;if(L===this&&(L=null),Y(this,$)._++,t(this,x)&&(clearTimeout(t(this,x)),d(this,x,null)),t(this,M)){const o=t(this,M);d(this,M,null),o()}if(t(this,O)){const o=t(this,O);d(this,O,null),o()}const a=t(this,n).querySelector("[data-review-form-message]");a&&(a.style.display="none"),i.classList.remove("fct-drawer-open"),t(this,q)&&clearTimeout(t(this,q)),d(this,q,setTimeout(()=>{if(d(this,q,null),i.style.display="none",e){d(this,T,null);return}document.body.style.overflow="",t(this,T)&&(t(this,T).focus(),d(this,T,null)),document.dispatchEvent(new CustomEvent("fct-review-overlay-closed",{detail:{postId:t(this,y),itemId:t(this,A)}}))},300))},ft=function(){const e=t(this,n).querySelector("[data-review-next]"),i=t(this,n).querySelector("[data-review-back]"),a=t(this,n).querySelector("[data-review-submit]");e&&e.addEventListener("click",()=>c(this,r,U).call(this,t(this,p)+1)),i&&i.addEventListener("click",()=>c(this,r,U).call(this,t(this,p)-1)),a&&a.addEventListener("click",()=>c(this,r,pt).call(this))},U=function(e){if(e>t(this,p)&&!c(this,r,it).call(this,t(this,p))||e<1||e>t(this,k))return;const i=t(this,n).querySelector(`[data-review-step="${t(this,p)}"]`),a=t(this,n).querySelector(`[data-review-step="${e}"]`);i&&(i.style.display="none"),a&&(a.style.display=""),d(this,p,e),c(this,r,mt).call(this),c(this,r,st).call(this);const o=t(this,n).querySelector("[data-review-form-message]");o&&(o.style.display="none")},it=function(e){var o;const i=((o=window.fluentcart_review_vars)==null?void 0:o.trans)||{},a=t(this,n).querySelector("[data-review-form-message]");if(t(this,D)&&e===1){const s=t(this,n).querySelector("[data-review-rating]");if(t(this,K)&&(!s||!s.value))return c(this,r,C).call(this,a,i.rating_required||"Please select a rating","error"),!1}if(e===t(this,X)){const s=t(this,n).querySelector("[data-review-form]"),l=s==null?void 0:s.querySelector('textarea[name="content"]');if(!l||!l.value.trim())return c(this,r,C).call(this,a,i.content_required||"Please write a review","error"),!1;const u=s==null?void 0:s.querySelector('input[name="reviewer_name"]:not([type="hidden"])');if(u&&!u.value.trim())return c(this,r,C).call(this,a,i.name_required||"Please enter your name","error"),!1;const m=s==null?void 0:s.querySelector('input[name="reviewer_email"]:not([type="hidden"])');if(m&&!m.value.trim())return c(this,r,C).call(this,a,i.email_required||"Please enter your email","error"),!1}return!0},mt=function(){t(this,n).querySelectorAll("[data-step-indicator]").forEach(i=>{const a=parseInt(i.getAttribute("data-step-indicator"));i.classList.toggle("active",a===t(this,p)),i.classList.toggle("completed",a<t(this,p))})},st=function(){var u;const e=t(this,n).querySelector("[data-review-next]"),i=t(this,n).querySelector("[data-review-back]"),a=t(this,n).querySelector("[data-review-submit]"),o=t(this,n).querySelector("[data-review-step-info]"),s=t(this,p)===t(this,k),l=t(this,p)===1;if(i&&(i.style.display=l?"none":""),e&&(e.style.display=s?"none":""),a&&(a.style.display=s?"":"none"),o)if(t(this,k)<=1)o.style.display="none";else{o.style.display="";const m=((u=window.fluentcart_review_vars)==null?void 0:u.trans)||{},v={};let g=1;t(this,D)&&(v[g++]=m.rating_step_hint||"Rate this product"),v[g++]=m.details_step_hint||"Tell us more",t(this,k)>=g&&(v[g]=m.photos_step_hint||"Photos are optional");const b=v[t(this,p)]||"",_=(m.step_x_of_y||"Step %1$s of %2$s").replace("%1$s",t(this,p)).replace("%2$s",t(this,k));o.textContent=_+(b?` — ${b}`:"")}},wt=function(){const e=t(this,n).querySelector("[data-star-selector]");if(!e)return;const i=e.querySelectorAll("[data-star-value]"),a=t(this,n).querySelector("[data-review-rating]"),o=s=>{a.value=s>0?s:"",i.forEach(l=>{const u=parseInt(l.dataset.starValue);l.classList.toggle("selected",s>0&&u<=s),l.setAttribute("aria-checked",u===s?"true":"false")})};i.forEach(s=>{s.addEventListener("click",()=>{const l=parseInt(s.dataset.starValue),u=l===parseInt(a.value);o(u?0:l),u&&i.forEach(m=>m.classList.remove("hover"))}),s.addEventListener("keydown",l=>{const u=parseInt(s.dataset.starValue);let m=null;if(l.key==="ArrowRight"||l.key==="ArrowUp"?m=Math.min(u+1,5):(l.key==="ArrowLeft"||l.key==="ArrowDown")&&(m=Math.max(u-1,1)),m!==null){l.preventDefault();const v=e.querySelector(`[data-star-value="${m}"]`);v&&(v.focus(),o(m))}}),s.addEventListener("mouseenter",()=>{const l=parseInt(s.dataset.starValue);i.forEach(u=>{u.classList.toggle("hover",parseInt(u.dataset.starValue)<=l)})}),s.addEventListener("mouseleave",()=>{i.forEach(l=>l.classList.remove("hover"))})})},vt=function(){var u,m;const e=parseInt(t(this,n).getAttribute("data-existing-rating"))||0,i=t(this,n).getAttribute("data-existing-title")||"",a=t(this,n).getAttribute("data-existing-content")||"";if(e>0){const v=t(this,n).querySelector("[data-review-rating]"),g=t(this,n).querySelectorAll("[data-star-value]");v&&(v.value=e),g.forEach(b=>{const _=parseInt(b.dataset.starValue);b.classList.toggle("selected",_<=e),b.setAttribute("aria-checked",_===e?"true":"false")})}const o=t(this,n).querySelector('input[name="title"]');o&&(o.value=i);const s=t(this,n).querySelector('textarea[name="content"]');s&&(s.value=a),t(this,n).querySelectorAll("[data-char-count]").forEach(v=>{const g=v.getAttribute("data-char-count"),b=t(this,n).querySelector("#"+g);if(!b)return;const _=parseInt(b.getAttribute("maxlength"))||0;v.textContent=`${b.value.length} / ${_}`});const l=t(this,n).querySelector("[data-review-drawer-title]");l&&(l.textContent=((m=(u=window.fluentcart_review_vars)==null?void 0:u.trans)==null?void 0:m.edit_review)||"Edit your review")},yt=function(){t(this,n).querySelectorAll("[data-char-count]").forEach(i=>{const a=i.getAttribute("data-char-count"),o=t(this,n).querySelector("#"+a);if(!o)return;const s=parseInt(o.getAttribute("maxlength"))||0,l=()=>{i.textContent=`${o.value.length} / ${s}`};o.addEventListener("input",l)})},pt=function(){var b,_,rt,at,nt,ot;if(t(this,P)||t(this,H)||!c(this,r,it).call(this,t(this,p)))return;const e=t(this,n).querySelector("[data-review-form]"),i=t(this,n).querySelector("[data-review-submit]"),a=t(this,n).querySelector("[data-review-form-message]");if(!e)return;const o=new FormData(e),s={};if(o.forEach((w,S)=>{if(S.endsWith("[]")){const F=S.slice(0,-2);Array.isArray(s[F])||(s[F]=[]),s[F].push(w)}else s[S]=w}),s.item_id=t(this,A),t(this,D)&&t(this,K)&&!s.rating){c(this,r,U).call(this,1),c(this,r,C).call(this,a,((_=(b=window.fluentcart_review_vars)==null?void 0:b.trans)==null?void 0:_.rating_required)||"Please select a rating","error");return}if(!s.content||!s.content.trim()){c(this,r,U).call(this,t(this,X)),c(this,r,C).call(this,a,((at=(rt=window.fluentcart_review_vars)==null?void 0:rt.trans)==null?void 0:at.content_required)||"Please write a review","error");return}d(this,P,!0);const l=++Y(this,$)._;i.disabled=!0;const u=i.textContent;i.textContent=((ot=(nt=window.fluentcart_review_vars)==null?void 0:nt.trans)==null?void 0:ot.submitting)||"Submitting...";const m=t(this,I)?`${t(this,j)}/public/reviews/${t(this,y)}/${t(this,B)}`:`${t(this,j)}/public/reviews/${t(this,y)}`,v=new FormData;Object.entries(s).forEach(([w,S])=>{Array.isArray(S)?S.forEach(F=>v.append(`${w}[]`,F)):v.append(w,S)}),e.dispatchEvent(new CustomEvent("fct-review-form-before-submit",{detail:{formData:v,data:s}}));const g={"X-WP-Nonce":t(this,G)};t(this,I)&&(g["X-HTTP-Method-Override"]="PUT"),fetch(m,{method:"POST",headers:g,body:v,signal:t(this,tt).signal}).then(w=>w.ok?w.json():w.json().then(S=>{throw S})).then(w=>{const S=()=>{d(this,P,!1),i.disabled=!1,i.textContent=u};if(!t(this,R)||l!==t(this,$)?S():d(this,O,S),w.can_edit===!1&&(d(this,H,!0),document.querySelectorAll(`[data-open-review-drawer][data-post-id="${t(this,y)}"]`).forEach(Q=>{const dt=Q.getAttribute("data-review-form-target");dt&&dt!==t(this,E)||(parseInt(Q.getAttribute("data-item-id"),10)||0)===t(this,A)&&(Q.hidden=!0,Q.style.display="none")})),l!==t(this,$)){document.dispatchEvent(new CustomEvent("fct-review-submitted",{detail:{postId:t(this,y),itemId:t(this,A),response:w}}));return}c(this,r,C).call(this,a,w.message||"Review submitted successfully!","success",!t(this,R));const F=t(this,I);!F&&w.can_edit===!0&&w.review&&w.review.id&&c(this,r,gt).call(this,w.review,s),e.dispatchEvent(new CustomEvent("fct-review-form-saved",{detail:{review:w.review||null,media:w.media||[]}}));const lt=()=>{document.dispatchEvent(new CustomEvent("fct-review-submitted",{detail:{postId:t(this,y),itemId:t(this,A),response:w}}))};if(!t(this,R)){F||c(this,r,bt).call(this),lt();return}d(this,M,lt),d(this,x,setTimeout(()=>{d(this,x,null),c(this,r,N).call(this)},1e3))}).catch(w=>{d(this,P,!1),w.name!=="AbortError"&&(i.disabled=!1,i.textContent=u,l===t(this,$)&&c(this,r,C).call(this,a,w.message||"Something went wrong","error"))})},gt=function(e,i){var o,s;d(this,I,!0),d(this,B,String(e.id)),t(this,n).setAttribute("data-edit-mode","1"),t(this,n).setAttribute("data-review-id",t(this,B)),t(this,n).setAttribute("data-existing-rating",String(i.rating||"")),t(this,n).setAttribute("data-existing-title",String(i.title||"")),t(this,n).setAttribute("data-existing-content",String(i.content||""));const a=t(this,n).querySelector("[data-review-drawer-title]");a&&(a.textContent=((s=(o=window.fluentcart_review_vars)==null?void 0:o.trans)==null?void 0:s.edit_review)||"Edit your review"),document.querySelectorAll(`[data-open-review-drawer][data-post-id="${t(this,y)}"]`).forEach(l=>{const u=l.getAttribute("data-review-form-target");if(u&&u!==t(this,E)||(parseInt(l.getAttribute("data-item-id"),10)||0)!==t(this,A))return;const v=l.querySelector("[data-cta-add]"),g=l.querySelector("[data-cta-edit]");v&&(v.hidden=!0),g&&(g.hidden=!1)})},bt=function(){t(this,n).classList.add("fct-review-form-submitted");const e=t(this,n).querySelector("[data-review-form]"),i=t(this,n).querySelector(".fct-review-standalone-footer"),a=t(this,n).querySelector("[data-review-stepper]");e&&(e.style.display="none"),i&&(i.style.display="none"),a&&(a.style.display="none")},C=function(e,i,a,o=!1){e&&(e.textContent=i,e.className=`fct-review-form-message fct-review-form-message-${a}`,e.style.display="block",a==="success"&&!o&&setTimeout(()=>{e.style.display="none"},5e3))};document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("[data-fluent-cart-review-form]").forEach(e=>{new ut(e).init()})});document.addEventListener("fct-review-form-mount",h=>{const e=h.detail&&h.detail.container;if(!e||!e.hasAttribute("data-fluent-cart-review-form"))return;const i=new ut(e);i.init(),h.detail.controller=i,document.dispatchEvent(new CustomEvent("fct-review-form-mounted",{detail:{container:e}})),h.detail.open&&i.open()}); |
|
1
|
+var ft=f=>{throw TypeError(f)};var at=(f,e,s)=>e.has(f)||ft("Cannot "+s);var t=(f,e,s)=>(at(f,e,"read from private field"),s?s.call(f):e.get(f)),h=(f,e,s)=>e.has(f)?ft("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(f):e.set(f,s),l=(f,e,s,n)=>(at(f,e,"write to private field"),n?n.call(f,s):e.set(f,s),s),r=(f,e,s)=>(at(f,e,"access private method"),s);var it=(f,e,s,n)=>({set _(o){l(f,e,o,s)},get _(){return t(f,e,n)}});const st=new Map,K=new Map;let C=null;var g,v,x,H,Z,B,z,b,T,_,V,$,rt,G,M,F,L,U,j,A,N,J,tt,O,I,Q,i,wt,P,u,Y,W,vt,X,nt,pt,ot,yt,gt,bt,St,Et,qt,k;class mt{constructor(e){h(this,i);h(this,g);h(this,v);h(this,x,0);h(this,H);h(this,Z);h(this,B,!0);h(this,z,!0);h(this,b,1);h(this,T,2);h(this,_,!1);h(this,V,null);h(this,$,null);h(this,rt,new AbortController);h(this,G,new AbortController);h(this,M,!1);h(this,F,0);h(this,L,null);h(this,U,null);h(this,j,null);h(this,A,null);h(this,N,null);h(this,J,2);h(this,tt,!1);h(this,O,!0);h(this,I,null);h(this,Q,!1);l(this,g,e),l(this,v,e.getAttribute("data-post-id")),l(this,x,parseInt(e.getAttribute("data-item-id"),10)||0),l(this,H,e.getAttribute("data-rest-url")),l(this,Z,e.getAttribute("data-rest-nonce")),l(this,B,e.getAttribute("data-star-enabled")!=="0"),l(this,z,e.getAttribute("data-star-required")!=="0"),l(this,T,parseInt(e.getAttribute("data-total-steps"))||2),l(this,_,e.getAttribute("data-edit-mode")==="1"),l(this,V,e.getAttribute("data-review-id")),l(this,I,e.getAttribute("data-form-id")),l(this,tt,e.getAttribute("data-layout")==="inline"),l(this,O,e.getAttribute("data-container")!=="none"),l(this,J,t(this,tt)||!t(this,B)?1:2)}init(){r(this,i,yt).call(this),r(this,i,wt).call(this),r(this,i,vt).call(this),r(this,i,bt).call(this),r(this,i,ot).call(this),t(this,_)&&r(this,i,gt).call(this)}open(){r(this,i,Y).call(this)}destroy(){clearTimeout(t(this,A)),l(this,A,null),clearTimeout(t(this,L)),l(this,L,null),it(this,F)._++,l(this,M,!1),t(this,G).abort(),C===this&&(C=null,document.body.style.overflow=""),st.get(t(this,I))===this&&st.delete(t(this,I)),K.get(t(this,v))===this&&K.delete(t(this,v));const e=r(this,i,P).call(this);e&&(e.classList.remove("fct-drawer-open"),e.style.display="none",e.parentNode&&e.parentNode.removeChild(e)),l(this,N,null),l(this,$,null)}}g=new WeakMap,v=new WeakMap,x=new WeakMap,H=new WeakMap,Z=new WeakMap,B=new WeakMap,z=new WeakMap,b=new WeakMap,T=new WeakMap,_=new WeakMap,V=new WeakMap,$=new WeakMap,rt=new WeakMap,G=new WeakMap,M=new WeakMap,F=new WeakMap,L=new WeakMap,U=new WeakMap,j=new WeakMap,A=new WeakMap,N=new WeakMap,J=new WeakMap,tt=new WeakMap,O=new WeakMap,I=new WeakMap,Q=new WeakMap,i=new WeakSet,wt=function(){const e=r(this,i,P).call(this);if(!e)return;t(this,I)&&st.set(t(this,I),this),t(this,v)&&!K.has(t(this,v))&&K.set(t(this,v),this);const s=e.querySelector("[data-close-review-drawer]"),n=e;document.addEventListener("click",o=>{const a=o.target.closest("[data-open-review-drawer]");if(!a)return;const d=a.getAttribute("data-post-id");if(d&&d!==t(this,v))return;const c=a.getAttribute("data-review-form-target");if(c){if(c===t(this,I)){r(this,i,Y).call(this);return}!st.has(c)&&K.get(t(this,v))===this&&r(this,i,Y).call(this);return}K.get(t(this,v))===this&&r(this,i,Y).call(this)},{signal:t(this,G).signal}),s&&s.addEventListener("click",()=>r(this,i,W).call(this)),n.addEventListener("click",o=>{o.target===n&&r(this,i,W).call(this)}),document.addEventListener("keydown",o=>{if(e.style.display!=="none"&&C===this){if(o.key==="Escape")r(this,i,W).call(this);else if(o.key==="Tab"){const a=e.querySelector("[data-review-drawer-panel]");if(!a)return;const d=a.querySelectorAll('button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])');if(!d.length)return;const c=d[0],m=d[d.length-1];o.shiftKey&&document.activeElement===c?(o.preventDefault(),m.focus()):!o.shiftKey&&document.activeElement===m&&(o.preventDefault(),c.focus())}}},{signal:t(this,G).signal})},P=function(){if(t(this,N)&&t(this,N).isConnected)return t(this,N);const e=t(this,g).querySelector("[data-review-drawer]");return e?(document.body.appendChild(e),l(this,N,e),e):null},u=function(){return t(this,O)?r(this,i,P).call(this)||t(this,g):t(this,g)},Y=function(){var s;if(t(this,Q))return;const e=r(this,i,P).call(this);e&&(C&&C!==this&&r(s=C,i,W).call(s,{replaced:!0}),C=this,t(this,A)&&(clearTimeout(t(this,A)),l(this,A,null)),t(this,_)||r(this,i,X).call(this,1),l(this,$,document.activeElement),e.style.display="flex",document.body.style.overflow="hidden",requestAnimationFrame(()=>{e.classList.add("fct-drawer-open");const n=e.querySelector("[data-review-drawer-panel]");n&&n.focus()}))},W=function({replaced:e=!1}={}){const s=r(this,i,P).call(this);if(!s)return;if(C===this&&(C=null),it(this,F)._++,t(this,L)&&(clearTimeout(t(this,L)),l(this,L,null)),t(this,U)){const o=t(this,U);l(this,U,null),o()}if(t(this,j)){const o=t(this,j);l(this,j,null),o()}const n=r(this,i,u).call(this).querySelector("[data-review-form-message]");n&&(n.style.display="none"),s.classList.remove("fct-drawer-open"),t(this,A)&&clearTimeout(t(this,A)),l(this,A,setTimeout(()=>{if(l(this,A,null),s.style.display="none",e){l(this,$,null);return}document.body.style.overflow="",t(this,$)&&(t(this,$).focus(),l(this,$,null)),document.dispatchEvent(new CustomEvent("fct-review-overlay-closed",{detail:{postId:t(this,v),itemId:t(this,x)}}))},300))},vt=function(){const e=r(this,i,u).call(this).querySelector("[data-review-next]"),s=r(this,i,u).call(this).querySelector("[data-review-back]"),n=r(this,i,u).call(this).querySelector("[data-review-submit]");e&&e.addEventListener("click",()=>r(this,i,X).call(this,t(this,b)+1)),s&&s.addEventListener("click",()=>r(this,i,X).call(this,t(this,b)-1)),n&&n.addEventListener("click",()=>r(this,i,St).call(this))},X=function(e){if(e>t(this,b)&&!r(this,i,nt).call(this,t(this,b))||e<1||e>t(this,T))return;const s=r(this,i,u).call(this).querySelector(`[data-review-step="${t(this,b)}"]`),n=r(this,i,u).call(this).querySelector(`[data-review-step="${e}"]`);s&&(s.style.display="none"),n&&(n.style.display=""),l(this,b,e),r(this,i,pt).call(this),r(this,i,ot).call(this);const o=r(this,i,u).call(this).querySelector("[data-review-form-message]");o&&(o.style.display="none")},nt=function(e){var o;const s=((o=window.fluentcart_review_vars)==null?void 0:o.trans)||{},n=r(this,i,u).call(this).querySelector("[data-review-form-message]");if(t(this,B)&&e===1){const a=r(this,i,u).call(this).querySelector("[data-review-rating]");if(t(this,z)&&(!a||!a.value))return r(this,i,k).call(this,n,s.rating_required||"Please select a rating","error"),!1}if(e===t(this,J)){const a=r(this,i,u).call(this).querySelector("[data-review-form]"),d=a==null?void 0:a.querySelector('textarea[name="content"]');if(!d||!d.value.trim())return r(this,i,k).call(this,n,s.content_required||"Please write a review","error"),!1;const c=a==null?void 0:a.querySelector('input[name="reviewer_name"]:not([type="hidden"])');if(c&&!c.value.trim())return r(this,i,k).call(this,n,s.name_required||"Please enter your name","error"),!1;const m=a==null?void 0:a.querySelector('input[name="reviewer_email"]:not([type="hidden"])');if(m&&!m.value.trim())return r(this,i,k).call(this,n,s.email_required||"Please enter your email","error"),!1}return!0},pt=function(){r(this,i,u).call(this).querySelectorAll("[data-step-indicator]").forEach(s=>{const n=parseInt(s.getAttribute("data-step-indicator"));s.classList.toggle("active",n===t(this,b)),s.classList.toggle("completed",n<t(this,b))})},ot=function(){var c;const e=r(this,i,u).call(this).querySelector("[data-review-next]"),s=r(this,i,u).call(this).querySelector("[data-review-back]"),n=r(this,i,u).call(this).querySelector("[data-review-submit]"),o=r(this,i,u).call(this).querySelector("[data-review-step-info]"),a=t(this,b)===t(this,T),d=t(this,b)===1;if(s&&(s.style.display=d?"none":""),e&&(e.style.display=a?"none":""),n&&(n.style.display=a?"":"none"),o)if(t(this,T)<=1)o.style.display="none";else{o.style.display="";const m=((c=window.fluentcart_review_vars)==null?void 0:c.trans)||{},p={};let y=1;t(this,B)&&(p[y++]=m.rating_step_hint||"Rate this product"),p[y++]=m.details_step_hint||"Tell us more",t(this,T)>=y&&(p[y]=m.photos_step_hint||"Photos are optional");const S=p[t(this,b)]||"",E=(m.step_x_of_y||"Step %1$s of %2$s").replace("%1$s",t(this,b)).replace("%2$s",t(this,T));o.textContent=E+(S?` — ${S}`:"")}},yt=function(){const e=r(this,i,u).call(this).querySelector("[data-star-selector]");if(!e)return;const s=e.querySelectorAll("[data-star-value]"),n=r(this,i,u).call(this).querySelector("[data-review-rating]"),o=a=>{n.value=a>0?a:"",s.forEach(d=>{const c=parseInt(d.dataset.starValue);d.classList.toggle("selected",a>0&&c<=a),d.setAttribute("aria-checked",c===a?"true":"false")})};s.forEach(a=>{a.addEventListener("click",()=>{const d=parseInt(a.dataset.starValue),c=d===parseInt(n.value);o(c?0:d),c&&s.forEach(m=>m.classList.remove("hover"))}),a.addEventListener("keydown",d=>{const c=parseInt(a.dataset.starValue);let m=null;if(d.key==="ArrowRight"||d.key==="ArrowUp"?m=Math.min(c+1,5):(d.key==="ArrowLeft"||d.key==="ArrowDown")&&(m=Math.max(c-1,1)),m!==null){d.preventDefault();const p=e.querySelector(`[data-star-value="${m}"]`);p&&(p.focus(),o(m))}}),a.addEventListener("mouseenter",()=>{const d=parseInt(a.dataset.starValue);s.forEach(c=>{c.classList.toggle("hover",parseInt(c.dataset.starValue)<=d)})}),a.addEventListener("mouseleave",()=>{s.forEach(d=>d.classList.remove("hover"))})})},gt=function(){var c,m,p;const e=parseInt(t(this,g).getAttribute("data-existing-rating"))||0,s=t(this,g).getAttribute("data-existing-title")||"",n=t(this,g).getAttribute("data-existing-content")||"";if(e>0){const y=r(this,i,u).call(this).querySelector("[data-review-rating]"),S=r(this,i,u).call(this).querySelectorAll("[data-star-value]");y&&(y.value=e),S.forEach(E=>{const R=parseInt(E.dataset.starValue);E.classList.toggle("selected",R<=e),E.setAttribute("aria-checked",R===e?"true":"false")})}const o=r(this,i,u).call(this).querySelector('input[name="title"]');o&&(o.value=s);const a=r(this,i,u).call(this).querySelector('textarea[name="content"]');a&&(a.value=n),r(this,i,u).call(this).querySelectorAll("[data-char-count]").forEach(y=>{const S=y.getAttribute("data-char-count"),E=r(this,i,u).call(this).querySelector("#"+S);if(!E)return;const R=parseInt(E.getAttribute("maxlength"))||0;y.textContent=`${E.value.length} / ${R}`});const d=(c=r(this,i,P).call(this))==null?void 0:c.querySelector("[data-review-drawer-title]");d&&(d.textContent=((p=(m=window.fluentcart_review_vars)==null?void 0:m.trans)==null?void 0:p.edit_review)||"Edit your review")},bt=function(){r(this,i,u).call(this).querySelectorAll("[data-char-count]").forEach(s=>{const n=s.getAttribute("data-char-count"),o=r(this,i,u).call(this).querySelector("#"+n);if(!o)return;const a=parseInt(o.getAttribute("maxlength"))||0,d=()=>{s.textContent=`${o.value.length} / ${a}`};o.addEventListener("input",d)})},St=function(){var S,E,R,lt,dt,ct;if(t(this,M)||t(this,Q)||!r(this,i,nt).call(this,t(this,b)))return;const e=r(this,i,u).call(this).querySelector("[data-review-form]"),s=r(this,i,u).call(this).querySelector("[data-review-submit]"),n=r(this,i,u).call(this).querySelector("[data-review-form-message]");if(!e)return;const o=new FormData(e),a={};if(o.forEach((w,q)=>{if(q.endsWith("[]")){const D=q.slice(0,-2);Array.isArray(a[D])||(a[D]=[]),a[D].push(w)}else a[q]=w}),a.item_id=t(this,x),t(this,B)&&t(this,z)&&!a.rating){r(this,i,X).call(this,1),r(this,i,k).call(this,n,((E=(S=window.fluentcart_review_vars)==null?void 0:S.trans)==null?void 0:E.rating_required)||"Please select a rating","error");return}if(!a.content||!a.content.trim()){r(this,i,X).call(this,t(this,J)),r(this,i,k).call(this,n,((lt=(R=window.fluentcart_review_vars)==null?void 0:R.trans)==null?void 0:lt.content_required)||"Please write a review","error");return}l(this,M,!0);const d=++it(this,F)._;s.disabled=!0;const c=s.textContent;s.textContent=((ct=(dt=window.fluentcart_review_vars)==null?void 0:dt.trans)==null?void 0:ct.submitting)||"Submitting...";const m=t(this,_)?`${t(this,H)}/public/reviews/${t(this,v)}/${t(this,V)}`:`${t(this,H)}/public/reviews/${t(this,v)}`,p=new FormData;Object.entries(a).forEach(([w,q])=>{Array.isArray(q)?q.forEach(D=>p.append(`${w}[]`,D)):p.append(w,q)}),e.dispatchEvent(new CustomEvent("fct-review-form-before-submit",{detail:{formData:p,data:a}}));const y={"X-WP-Nonce":t(this,Z)};t(this,_)&&(y["X-HTTP-Method-Override"]="PUT"),fetch(m,{method:"POST",headers:y,body:p,signal:t(this,rt).signal}).then(w=>w.ok?w.json():w.json().then(q=>{throw q})).then(w=>{const q=()=>{l(this,M,!1),s.disabled=!1,s.textContent=c};if(!t(this,O)||d!==t(this,F)?q():l(this,j,q),w.can_edit===!1&&(l(this,Q,!0),document.querySelectorAll(`[data-open-review-drawer][data-post-id="${t(this,v)}"]`).forEach(et=>{const ht=et.getAttribute("data-review-form-target");ht&&ht!==t(this,I)||(parseInt(et.getAttribute("data-item-id"),10)||0)===t(this,x)&&(et.hidden=!0,et.style.display="none")})),d!==t(this,F)){document.dispatchEvent(new CustomEvent("fct-review-submitted",{detail:{postId:t(this,v),itemId:t(this,x),response:w}}));return}r(this,i,k).call(this,n,w.message||"Review submitted successfully!","success",!t(this,O));const D=t(this,_);!D&&w.can_edit===!0&&w.review&&w.review.id&&r(this,i,Et).call(this,w.review,a),e.dispatchEvent(new CustomEvent("fct-review-form-saved",{detail:{review:w.review||null,media:w.media||[]}}));const ut=()=>{document.dispatchEvent(new CustomEvent("fct-review-submitted",{detail:{postId:t(this,v),itemId:t(this,x),response:w}}))};if(!t(this,O)){D||r(this,i,qt).call(this),ut();return}l(this,U,ut),l(this,L,setTimeout(()=>{l(this,L,null),r(this,i,W).call(this)},1e3))}).catch(w=>{l(this,M,!1),w.name!=="AbortError"&&(s.disabled=!1,s.textContent=c,d===t(this,F)&&r(this,i,k).call(this,n,w.message||"Something went wrong","error"))})},Et=function(e,s){var o,a,d;l(this,_,!0),l(this,V,String(e.id)),t(this,g).setAttribute("data-edit-mode","1"),t(this,g).setAttribute("data-review-id",t(this,V)),t(this,g).setAttribute("data-existing-rating",String(s.rating||"")),t(this,g).setAttribute("data-existing-title",String(s.title||"")),t(this,g).setAttribute("data-existing-content",String(s.content||""));const n=(o=r(this,i,P).call(this))==null?void 0:o.querySelector("[data-review-drawer-title]");n&&(n.textContent=((d=(a=window.fluentcart_review_vars)==null?void 0:a.trans)==null?void 0:d.edit_review)||"Edit your review"),document.querySelectorAll(`[data-open-review-drawer][data-post-id="${t(this,v)}"]`).forEach(c=>{const m=c.getAttribute("data-review-form-target");if(m&&m!==t(this,I)||(parseInt(c.getAttribute("data-item-id"),10)||0)!==t(this,x))return;const y=c.querySelector("[data-cta-add]"),S=c.querySelector("[data-cta-edit]");y&&(y.hidden=!0),S&&(S.hidden=!1)})},qt=function(){t(this,g).classList.add("fct-review-form-submitted");const e=r(this,i,u).call(this).querySelector("[data-review-form]"),s=r(this,i,u).call(this).querySelector(".fct-review-standalone-footer"),n=r(this,i,u).call(this).querySelector("[data-review-stepper]");e&&(e.style.display="none"),s&&(s.style.display="none"),n&&(n.style.display="none")},k=function(e,s,n,o=!1){e&&(e.textContent=s,e.className=`fct-review-form-message fct-review-form-message-${n}`,e.style.display="block",n==="success"&&!o&&setTimeout(()=>{e.style.display="none"},5e3))};document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("[data-fluent-cart-review-form]").forEach(e=>{new mt(e).init()})});document.addEventListener("fct-review-form-mount",f=>{const e=f.detail&&f.detail.container;if(!e||!e.hasAttribute("data-fluent-cart-review-form"))return;const s=new mt(e);s.init(),f.detail.controller=s,document.dispatchEvent(new CustomEvent("fct-review-form-mounted",{detail:{container:e}})),f.detail.open&&s.open()}); |