1import{r as n,j as t}from"./jsx-runtime-kF-aRxYe.js";import{C as gt}from"./ChoiceList-BCFkQvtH.js";import{u as yt,S as he,a as wt,b as vt,c as xt,F as Rt}from"./StarFilledIcon.svg-CYMDgxkq.js";import{F,T as St}from"./Toast-BSkyrb3p.js";import{M as C,I as fe}from"./Modal-DoQWO5ot.js";import{B as Y,g as H,T as me,b as k,I as ge,a as O,h as jt,f as ye,c as we}from"./Page-RCHDyLd1.js";import{I as g}from"./IndexTable-DtKTPRPk.js";import{T as bt,S as Ct,a as kt}from"./ViewIcon.svg-DsIn45e6.js";import{L as At}from"./Link-DFJP1-I8.js";import{E as It}from"./EmptySearchResult-DuQNzfHm.js";import{L as ve}from"./Layout-BAcNQvwh.js";import{C as Tt}from"./Card-S6K8GLCp.js";import{u as Mt}from"./context-ClUtXUi6.js";import"./RadioButton-C4KQHPdA.js";import"./Checkbox-BPrTdIr3.js";import"./PlusIcon.svg-CqnoD7CY.js";import"./set-root-property-BPOnANDm.js";import"./XIcon.svg-BFgNHS0e.js";import"./context-DqE-dl7J.js";import"./components-Bg6F3iAF.js";import"./AfterInitialMount-vjkVt0KT.js";import"./Sticky-DatVYi8Y.js";import"./banner-context-BgvF_mjc.js";const rs=({data:xe,store:h,translations:v,currentLanguage:A,filters:Nt,onSearch:Et})=>{const a=(e,s)=>{if(!v||!A)return s;const i=e.split(".");if(v[A]){let o=v[A];for(const l of i)if(o&&o[l])o=o[l];else break;if(o&&typeof o=="string")return o}if(A!=="fr"&&v.fr){let o=v.fr;for(const l of i)if(o&&o[l])o=o[l];else break;if(o&&typeof o=="string")return o}if(A!=="en"&&v.en){let o=v.en;for(const l of i)if(o&&o[l])o=o[l];else break;if(o&&typeof o=="string")return o}return s},[Re,K]=n.useState(!1),[f,m]=n.useState(xe),[Se,u]=n.useState(""),[je,c]=n.useState(!1),[be,p]=n.useState(""),[Ce,I]=n.useState(!1),[y,r]=n.useState(!1),[w,_]=n.useState(null),ke={singular:"review",plural:"reviews"},X={position:"absolute",top:"0",bottom:"0",display:"flex",left:"0",right:"0",width:"100%",height:"100%",opacity:"0",cursor:"pointer",zIndex:"99"},[N,ee]=n.useState([]),[te,Ae]=n.useState([]),[se,Ie]=n.useState(""),[Te,ae]=n.useState(""),[x,$]=n.useState(null),Me=n.useCallback(async e=>{ee(e),r(!0);const s={action:"Rating",type:e};try{const i=await fetch("/api/get-filter?type=moderate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!i.ok)throw new Error("Network response was not ok");const o=await i.json();m(o.data),r(!1)}catch(i){console.error("API call failed:",i)}},[]),Ne=n.useCallback(async e=>{ae(e),r(!0);try{const i=await(await fetch(`/api/getfilter?type=${e}&all=all`)).json();i.success?(m(i.data),r(!1)):(m([]),r(!1))}catch(s){r(!1),console.error("Error fetching data:",s)}},[]),U=n.useCallback(()=>{ee([]),setFilteredReviews(f)},[]),B=n.useCallback(()=>{Ae([]),m(f)},[]),L=n.useCallback(()=>{Ie(""),m(f)},[]),V=n.useCallback(()=>{ae(""),m(f)},[]),Ee=n.useCallback(()=>{U(),B(),L(),V()},[U,V,B,L]),Pe=[{key:"rating",label:a("filters.rating","Rating"),filter:t.jsx(gt,{title:a("filters.rating","Rating"),titleHidden:!0,choices:[{label:a("filters.fiveStars","5 Stars"),value:"5"},{label:a("filters.fourStars","4 Stars"),value:"4"},{label:a("filters.threeStars","3 Stars"),value:"3"},{label:a("filters.twoStars","2 Stars"),value:"2"},{label:a("filters.oneStar","1 Star"),value:"1"}],selected:Array.isArray(N)?N:[],onChange:Me,allowMultiple:!0}),shortcut:!0}],E=[];if(!z(N)){const e="rating";E.push({key:e,label:W(e,N),onRemove:U})}if(!z(te)){const e="source";E.push({key:e,label:W(e,te),onRemove:B})}if(!z(se)){const e="status";E.push({key:e,label:W(e,se),onRemove:L})}const{selectedResources:j,allResourcesSelected:De,handleSelectionChange:Fe,clearSelection:ie,removeSelectedResources:J}=yt(f||[]),Oe=e=>{const s=new Date(e),i=s.getFullYear(),o=String(s.getMonth()+1).padStart(2,"0"),l=String(s.getDate()).padStart(2,"0");return`${i}-${o}-${l}`},_e=n.useCallback(()=>c(e=>!e),[]);function $e(e,s){const i=e.split(" ");return i.length>s?i.slice(0,s).join(" ")+"...":e}const Ue=je?t.jsx(F,{children:t.jsx(St,{content:Se,onDismiss:_e,error:be})}):null,b=async(e,s,i)=>{const o=j;r(!0);const d=await fetch("/api/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:e,store_name:i,ids:o,type:"Moderations"})});if(!d.ok)throw new Error("Network response was not ok");const Z=await d.json();Z.success?(c(!0),p(!1),R(!1),r(!1),m(Z.data),ie(),u("Successfully")):(r(!1),c(!0),R(!1),p(!0),u("There is some error while update"))},Be=[{content:"Publish",loading:Re,onAction:()=>Le(w,h)}],Le=async(e,s)=>{const i=j;r(!0);try{const l=await fetch("/api/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"publish",ids:i,store_name:s,type:"Moderations"})});if(!l.ok)throw new Error("Network response was not ok");const d=await l.json();d.success?(c(!0),p(!1),R(!1),r(!1),u("Reviews Published Successfully"),m(d.data),ie()):(r(!1),c(!0),R(!1),p(!0),u("There is some error while update"))}catch(o){console.error("Error fetching data:",o)}finally{r(!1)}},[Pt,R]=n.useState(null),[oe,ne]=n.useState(""),Ve=n.useCallback((e,s,i)=>{ne(e.storeReply),I(!0),_(i),$(s)},[]),Je=async()=>{r(!0),I(!0);try{const s=await fetch("/api/updateReview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"SaveReply",type:"Moderations",product_id:w,store_name:h,id:x,reply_content:oe})});if(!s.ok)throw new Error("Network response was not ok");const i=await s.json();i.data?(c(!0),I(!1),R(!1),p(!1),m(i.data),J([x]),r(!1),u("Reply Saved")):(K(!1),c(!0),R(!1),p(!0),u("There is some error while update"))}catch(e){console.error("Error fetching data:",e)}finally{}},T=(e,s)=>{ce(i=>({...i,[s]:e}))},[Dt,Qe]=n.useState([]),[We,M]=n.useState(!1),[re,le]=n.useState([]),[ze,P]=n.useState([]),Ze=n.useCallback((e,s,i)=>{Qe(e.image),_(i),le(e.image),$(s),P([]),M(!0)},[]),qe=(e,s,i)=>{const o=Array.from(s.target.files),l=o.map(d=>URL.createObjectURL(d));[...o],P(d=>[...d,...o]),le(d=>[...d,...l])},Ge=async()=>{r(!0);const e=new FormData;re.filter(s=>
1!s.includes("blob")).forEach((s,i)=>{e.append("exist",s)}),ze.forEach((s,i)=>{e.append("files",s)}),e.append("product_id",w),e.append("store_name",h),e.append("id",x);try{const i=await(await fetch("/api/uploads",{method:"POST",body:e})).json();i.success?(P([]),r(!1),p(!1),c(!0),m(i.data),J([x]),M(!1),u("Saved successfully")):(K(!1),c(!0),r(!1),P([]),R(!1),p(!0),u("There is some error while update"))}catch{r(!1),M(!1)}},Ye=t.jsx("div",{className:"modals",children:t.jsx(F,{children:t.jsx(C,{open:We,onClose:()=>M(!1),title:a("editReview.update","Update"),primaryAction:{content:a("editReview.save","Save"),onAction:Ge,loading:y},secondaryActions:[{content:a("editReview.close","Close"),onAction:()=>M(!1)}],children:t.jsx(C.Section,{children:t.jsxs(Y,{gap:"300",children:[t.jsxs(fe,{columns:4,gap:"400",children:[re.map((e,s)=>t.jsxs("div",{className:"modal-image-box",style:{width:"100%",borderRadius:"10px",aspectRatio:"1/1",border:"1px solid #ddd",overflow:"hidden",position:"relative"},children:[t.jsx("img",{src:e,style:{width:"100%",objectFit:"cover",height:"100%"}},e.index),t.jsx("span",{style:X,className:"delete-icon",onClick:()=>handleDeleteImage(e),children:t.jsx(H,{source:he,tone:"inherit"})})]})),t.jsxs("div",{className:"",style:{width:"100%",borderRadius:"10px",display:"flex",cursor:"pointer",aspectRatio:"1/1",border:"1px solid #ddd",overflow:"hidden",position:"relative"},children:[t.jsx("input",{type:"file",hidden:!0,className:"hidden",accept:"image/jpg,image/jpeg,image/png,image/gif,image/webp",style:X,onChange:e=>qe(x,e)}),t.jsx(H,{source:wt})]})]}),t.jsx(me,{tone:"subdued",children:a("editReview.error","Error")})]})})})})}),He=[{content:"Mark unfeatured",loading:y,onAction:()=>b("unfeatured",w,h)},{loading:y,content:"Mark featured",onAction:()=>b("featured",w,h)},{loading:y,content:"Verified",onAction:()=>b("Verified",w,h)},{loading:y,content:"Not Verified",onAction:()=>b("Not Verified",w,h)},{loading:y,content:"Unpublished",onAction:()=>b("Unpublished",w,h)},{loading:y,icon:he,destructive:!0,content:"Delete ",onAction:()=>b("Delete",w,h)}],Ke=t.jsx("div",{className:"modals",children:t.jsx(F,{children:t.jsx(C,{open:Ce,onClose:()=>I(!1),title:a("editReview.reply","Reply"),primaryAction:{content:a("editReview.replybtn","Reply"),loading:y,onAction:()=>Je()},secondaryActions:[{content:a("editReview.close","Close"),onAction:()=>I(!1)}],children:t.jsx(C.Section,{children:t.jsx(k,{onChange:e=>{ne(e)},value:oe,multiline:5,autoComplete:"off"})})})})}),[S,ce]=n.useState({rating:"",name:"",date:"",email:"",content:""}),[Ft,Ot]=n.useState(!0),[Xe,Q]=n.useState(!1),et=n.useCallback((e,s,i)=>{ce({rating:e.rating,name:e.name,date:e.createdAt,email:e.email,content:e.reviewDesc}),_(i),$(s),Q(!0)},[]);let de=()=>{Q(!1)};const tt=async()=>{r(!0);try{const e=String(S.rating||"").trim(),s=Number.parseInt(e,10);if(!Number.isInteger(s)||s<1||s>5){c(!0),p(!0),u(a("productreview.InvalidRating","Rating must be between 1 and 5.")),r(!1);return}const i={product_id:w,store_name:h,id:x,editReview:{...S,rating:String(s)}},o=await fetch("/api/updateReview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!o.ok)throw new Error("Network response was not ok");const l=await o.json();l.data?(c(!0),p(!1),Q(!1),m(l.data),J([x]),u(a("editReview.updated","Review updated"))):(c(!0),p(!0),u(a("editReview.updateError","There was an error updating the review")))}catch(e){console.error("Error updating review:",e),c(!0),p(!0),u(a("editReview.updateError","There was an error updating the review"))}finally{r(!1)}},st=t.jsx("div",{className:"modals",children:t.jsx(F,{children:t.jsx(C,{open:Xe,onClose:de,title:a("editReview.heading","Edit Review"),primaryAction:{content:a("editReview.save","Save"),onAction:tt,loading:y},secondaryActions:[{content:a("editReview.close","Close"),onAction:de}],children:t.jsx(C.Section,{children:t.jsxs(Y,{gap:300,children:[t.jsx(k,{value:S.rating,label:a("editReview.rating","Rating"),onChange:e=>{const s=String(e||"").replace(/[^\d]/g,"");T(s.slice(0,1),"rating")},type:"number",min:1,max:5}),t.jsx(k,{onChange:e=>{T(e,"name")},value:S.name,label:a("editReview.name","Name"),autoComplete:"off"}),t.jsxs(fe,{columns:{sm:"100%",md:"2"},gap:200,children:[t.jsx(k,{onChange:e=>{T(e,"date")},value:Oe(S.date),label:a("editReview.Date","Date"),type:"date"}),t.jsx(k,{value:S.email,type:"email",onChange:e=>{T(e,"email")},readOnly:!0,label:a("editReview.email","Email")})]}),t.jsx(k,{value:S.content,label:a("editReview.content","Content"),onChange:e=>{T(e,"content")},multiline:4,autoComplete:"off"})]})})})})}),at=f.length>0?f.map(({id:e,name:s,featured:i,reviewDesc:o,storeReply:l,product_title:d,email:Z,source:ot,rating:nt,createdAt:rt,status:lt,product_handle:ct,product_id:q,image:ue,verified:dt},D)=>{const G=new Date(rt),ut=G.getUTCDate(),pt=G.getUTCMonth()+1,ht=G.getUTCFullYear(),ft=`${pt}/${ut}/${ht}`,mt=`https://${h}/products/${ct}`;return t.jsxs(g.Row,{id:e,selected:j&&j.includes?j.includes(e):!1,position:D,children:[t.jsx(g.Cell,{children:t.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[dt===!0&&t.jsxs("svg",{viewBox:"0 0 20 20",className:"Polaris-Icon__Svg",focu
1sable:"false","aria-hidden":"true",style:{width:"20px",height:"20px",verticalAlign:"middle",marginRight:"8px"},children:[t.jsx("path",{fill:"#29845a",d:"M13.28 9.03a.75.75 0 0 0-1.06-1.06l-2.97 2.97-1.22-1.22a.75.75 0 0 0-1.06 1.06l1.75 1.75a.75.75 0 0 0 1.06 0l3.5-3.5Z"}),t.jsx("path",{fillRule:"evenodd",fill:"#29845a",d:"M17 10a7 7 0 1 1-14 0 7 7 0 0 1 14 0Zm-1.5 0a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0Z"})]}),t.jsx("span",{children:s})]})}),t.jsx(g.Cell,{children:t.jsx(ge,{gap:0,blockAlign:"center",children:Array.from({length:nt}).map((_t,pe)=>t.jsx("span",{className:"star-icon",style:{color:"#ffb800"},children:t.jsx(H,{gap:0,source:vt,tone:"inherit"},pe)},pe))})}),t.jsx(g.Cell,{children:t.jsxs(Y,{gap:200,inlineAlign:"start",children:[t.jsx(me,{children:$e(o,7)}),t.jsxs(ge,{gap:200,children:[i&&t.jsx(O,{tone:"info",children:a("editReview.Featured","Featured")}),l&&t.jsx(O,{tone:"info",children:a("editReview.Replied","Replied")})]})]})}),t.jsx(g.Cell,{children:ot}),t.jsx(g.Cell,{children:t.jsx("span",{onClick:()=>Ze(f[D],e,q),style:{display:"inline-block"},children:t.jsx(bt,{source:ue.length>0?ue[0]:Ct,size:"small",alt:""})})}),t.jsx(g.Cell,{children:t.jsx(At,{dataPrimaryLink:!0,target:"_blank",url:mt,children:d})}),t.jsx(g.Cell,{children:String(lt||"").toLowerCase()==="published"?t.jsx(O,{tone:"success",children:a("editReview.Published","Published")}):t.jsx(O,{tone:"attention",children:a("editReview.moderations","Moderation")})}),t.jsx(g.Cell,{children:ft}),t.jsx(g.Cell,{children:t.jsxs(jt,{children:[t.jsx(ye,{content:a("editReview.details","Details"),children:t.jsx(we,{icon:kt,accessibilityLabel:a("editReview.details","Details"),onClick:()=>et(f[D],e,q),variant:"tertiary"})}),t.jsx(ye,{content:a("editReview.write","Write"),children:t.jsx(we,{icon:xt,accessibilityLabel:a("editReview.write","Write"),onClick:()=>Ve(f[D],e,q),variant:"tertiary"})})]})})]},e)}):t.jsx("div",{children:a("editReview.noexits","No reviews exist")}),it=t.jsx(It,{title:a("editReview.empty","No reviews"),description:a("editReview.emptyDesc","No reviews found"),withIllustration:!0});return t.jsxs(t.Fragment,{children:[t.jsx(ve,{children:t.jsx(ve.Section,{children:t.jsxs(Tt,{padding:0,roundedAbove:"sm",style:{overflow:"hidden"},children:[t.jsx(Rt,{queryValue:Te,queryPlaceholder:a("filters.searchItems","Search items"),filters:Pe,appliedFilters:E,onQueryChange:Ne,onQueryClear:V,onClearAll:Ee,loading:y}),t.jsx(g,{condensed:Mt().smDown,resourceName:ke,emptyState:it,itemCount:f.length,selectedItemsCount:De?"All":j.length,onSelectionChange:Fe,headings:[{title:a("editReview.name","Name")},{title:a("editReview.rating","Rating")},{title:a("editReview.review","Review")},{title:a("editReview.source","Source")},{title:a("editReview.photos","Photos")},{title:"Product"},{title:a("editReview.status","Status")},{title:a("editReview.date","Date")},{title:a("editReview.actions","Actions")}],bulkActions:He,promotedBulkActions:Be,children:at})]})})}),Ye,Ke,st,Ue]});function W(e,s){switch(e){case"rating":return`Rating is ${s}`;case"source":return`Source is is ${s}`;case"status":return`Status is ${s}`;default:return s.toString()}}function z(e){return Array.isArray(e)?e.length===0:e===""||e==null}};export{rs as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.