import{r as p,y as C,q as ye,i as qe,C as Be,V as ze,aA as Ue,bt as Ge,ak as je,cq as Qe,N,K as _,a3 as g,u,E as c,O as V,D as S,F as A,P as m,Q as b,R as y,J as ve,S as R,aC as Me,aG as We,aH as Ye,aB as Ke,at as He,L as Je}from"./vendor-BGtMsOoo.js";import{g as ee,v as ne,L as K,cp as P,Q as Ze,cq as Xe,cr as en,b1 as nn,cs as an}from"./index-CRze-aDK.js";import{u as tn}from"./useFiles-DW9DMZJb.js";import"./constants-55usBUX1.js";var U={kind:"Document",definitions:[{kind:"OperationDefinition",operation:"mutation",name:{kind:"Name",value:"CreateReview"},variableDefinitions:[{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"command"}},type:{kind:"NonNullType",type:{kind:"NamedType",name:{kind:"Name",value:"CreateReviewCommandType"}}},directives:[]}],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"createReview"},arguments:[{kind:"Argument",name:{kind:"Name",value:"command"},value:{kind:"Variable",name:{kind:"Name",value:"command"}}}],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"id"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"validationErrors"},arguments:[],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"errorCode"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"errorMessage"},arguments:[],directives:[]}]}}]}}]}}],loc:{start:0,end:173}};U.loc.source={body:`mutation CreateReview($command: CreateReviewCommandType!) {
  createReview(command: $command) {
    id
    validationErrors {
      errorCode
      errorMessage
    }
  }
}
`,name:"GraphQL request",locationOffset:{line:1,column:1}};function O(e,n){if(e.kind==="FragmentSpread")n.add(e.name.value);else if(e.kind==="VariableDefinition"){var a=e.type;a.kind==="NamedType"&&n.add(a.name.value)}e.selectionSet&&e.selectionSet.selections.forEach(function(i){O(i,n)}),e.variableDefinitions&&e.variableDefinitions.forEach(function(i){O(i,n)}),e.definitions&&e.definitions.forEach(function(i){O(i,n)})}var J={};(function(){U.definitions.forEach(function(n){if(n.name){var a=new Set;O(n,a),J[n.name.value]=a}})})();function fe(e,n){for(var a=0;a<e.definitions.length;a++){var i=e.definitions[a];if(i.name&&i.name.value==n)return i}}function sn(e,n){var a={kind:e.kind,definitions:[fe(e,n)]};e.hasOwnProperty("loc")&&(a.loc=e.loc);var i=J[n]||new Set,v=new Set,l=new Set;for(i.forEach(function(s){l.add(s)});l.size>0;){var w=l;l=new Set,w.forEach(function(s){if(!v.has(s)){v.add(s);var o=J[s]||new Set;o.forEach(function(k){l.add(k)})}})}return v.forEach(function(s){var o=fe(e,s);o&&a.definitions.push(o)}),a}sn(U,"CreateReview");async function ln(e){const{storeId:n}=ee,{data:a}=await ne.mutate({mutation:U,variables:{command:{...e,storeId:n}}});return a==null?void 0:a.createReview}var G={kind:"Document",definitions:[{kind:"OperationDefinition",operation:"query",name:{kind:"Name",value:"GetCustomerReviews"},variableDefinitions:[{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"storeId"}},type:{kind:"NonNullType",type:{kind:"NamedType",name:{kind:"Name",value:"String"}}},directives:[]},{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"entityId"}},type:{kind:"NonNullType",type:{kind:"NamedType",name:{kind:"Name",value:"String"}}},directives:[]},{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"entityType"}},type:{kind:"NonNullType",type:{kind:"NamedType",name:{kind:"Name",value:"String"}}},directives:[]},{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"first"}},type:{kind:"NamedType",name:{kind:"Name",value:"Int"}},directives:[]},{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"after"}},type:{kind:"NamedType",name:{kind:"Name",value:"String"}},directives:[]},{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"sort"}},type:{kind:"NamedType",name:{kind:"Name",value:"String"}},directives:[]}],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"customerReviews"},arguments:[{kind:"Argument",name:{kind:"Name",value:"storeId"},value:{kind:"Variable",name:{kind:"Name",value:"storeId"}}},{kind:"Argument",name:{kind:"Name",value:"entityId"},value:{kind:"Variable",name:{kind:"Name",value:"entityId"}}},{kind:"Argument",name:{kind:"Name",value:"entityType"},value:{kind:"Variable",name:{kind:"Name",value:"entityType"}}},{kind:"Argument",name:{kind:"Name",value:"first"},value:{kind:"Variable",name:{kind:"Name",value:"first"}}},{kind:"Argument",name:{kind:"Name",value:"after"},value:{kind:"Variable",name:{kind:"Name",value:"after"}}},{kind:"Argument",name:{kind:"Name",value:"sort"},value:{kind:"Variable",name:{kind:"Name",value:"sort"}}}],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"totalCount"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"items"},arguments:[],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"id"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"createdDate"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"userId"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"userName"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"title"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"review"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"rating"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"images"},arguments:[],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"id"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"url"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"name"},arguments:[],directives:[]}]}}]}}]}}]}}],loc:{start:0,end:483}};G.loc.source={body:`query GetCustomerReviews(
  $storeId: String!
  $entityId: String!
  $entityType: String!
  $first: Int
  $after: String
  $sort: String
) {
  customerReviews(
    storeId: $storeId
    entityId: $entityId
    entityType: $entityType
    first: $first
    after: $after
    sort: $sort
  ) {
    totalCount
    items {
      id
      createdDate
      userId
      userName
      title
      review
      rating
      images {
        id
        url
        name
      }
    }
  }
}
`,name:"GraphQL request",locationOffset:{line:1,column:1}};function q(e,n){if(e.kind==="FragmentSpread")n.add(e.name.value);else if(e.kind==="VariableDefinition"){var a=e.type;a.kind==="NamedType"&&n.add(a.name.value)}e.selectionSet&&e.selectionSet.selections.forEach(function(i){q(i,n)}),e.variableDefinitions&&e.variableDefinitions.forEach(function(i){q(i,n)}),e.definitions&&e.definitions.forEach(function(i){q(i,n)})}var Z={};(function(){G.definitions.forEach(function(n){if(n.name){var a=new Set;q(n,a),Z[n.name.value]=a}})})();function ke(e,n){for(var a=0;a<e.definitions.length;a++){var i=e.definitions[a];if(i.name&&i.name.value==n)return i}}function rn(e,n){var a={kind:e.kind,definitions:[ke(e,n)]};e.hasOwnProperty("loc")&&(a.loc=e.loc);var i=Z[n]||new Set,v=new Set,l=new Set;for(i.forEach(function(s){l.add(s)});l.size>0;){var w=l;l=new Set,w.forEach(function(s){if(!v.has(s)){v.add(s);var o=Z[s]||new Set;o.forEach(function(k){l.add(k)})}})}return v.forEach(function(s){var o=ke(e,s);o&&a.definitions.push(o)}),a}rn(G,"GetCustomerReviews");async function on(e){const{storeId:n}=ee,{data:a}=await ne.query({query:G,variables:{storeId:n,entityId:e.entityId,entityType:e.entityType,first:e.first,after:e.after,sort:e.sort}});return a.customerReviews}var j={kind:"Document",definitions:[{kind:"OperationDefinition",operation:"query",name:{kind:"Name",value:"CanLeaveFeedback"},variableDefinitions:[{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"storeId"}},type:{kind:"NonNullType",type:{kind:"NamedType",name:{kind:"Name",value:"String"}}},directives:[]},{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"entityId"}},type:{kind:"NonNullType",type:{kind:"NamedType",name:{kind:"Name",value:"String"}}},directives:[]},{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"entityType"}},type:{kind:"NonNullType",type:{kind:"NamedType",name:{kind:"Name",value:"String"}}},directives:[]}],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"canLeaveFeedback"},arguments:[{kind:"Argument",name:{kind:"Name",value:"storeId"},value:{kind:"Variable",name:{kind:"Name",value:"storeId"}}},{kind:"Argument",name:{kind:"Name",value:"entityId"},value:{kind:"Variable",name:{kind:"Name",value:"entityId"}}},{kind:"Argument",name:{kind:"Name",value:"entityType"},value:{kind:"Variable",name:{kind:"Name",value:"entityType"}}}],directives:[]}]}}],loc:{start:0,end:172}};j.loc.source={body:`query CanLeaveFeedback($storeId: String!, $entityId: String!, $entityType: String!) {
  canLeaveFeedback(storeId: $storeId, entityId: $entityId, entityType: $entityType)
}
`,name:"GraphQL request",locationOffset:{line:1,column:1}};function B(e,n){if(e.kind==="FragmentSpread")n.add(e.name.value);else if(e.kind==="VariableDefinition"){var a=e.type;a.kind==="NamedType"&&n.add(a.name.value)}e.selectionSet&&e.selectionSet.selections.forEach(function(i){B(i,n)}),e.variableDefinitions&&e.variableDefinitions.forEach(function(i){B(i,n)}),e.definitions&&e.definitions.forEach(function(i){B(i,n)})}var X={};(function(){j.definitions.forEach(function(n){if(n.name){var a=new Set;B(n,a),X[n.name.value]=a}})})();function pe(e,n){for(var a=0;a<e.definitions.length;a++){var i=e.definitions[a];if(i.name&&i.name.value==n)return i}}function dn(e,n){var a={kind:e.kind,definitions:[pe(e,n)]};e.hasOwnProperty("loc")&&(a.loc=e.loc);var i=X[n]||new Set,v=new Set,l=new Set;for(i.forEach(function(s){l.add(s)});l.size>0;){var w=l;l=new Set,w.forEach(function(s){if(!v.has(s)){v.add(s);var o=X[s]||new Set;o.forEach(function(k){l.add(k)})}})}return v.forEach(function(s){var o=pe(e,s);o&&a.definitions.push(o)}),a}dn(j,"CanLeaveFeedback");async function ge(e){const{storeId:n}=ee,{data:a}=await ne.query({query:j,variables:{...e,storeId:n}});return a.canLeaveFeedback}function z(){const e=p(!1),n=p(P),a=p(0),i=p(1),v=p(),l=p();async function w(k){e.value=!0;try{const d=await on({...k,first:P,after:((k.page-1)*P).toString()});v.value=d==null?void 0:d.items,i.value=k.page,a.value=Math.ceil(((d==null?void 0:d.totalCount)??0)/P)}catch(d){throw K.error(`${z.name}.${w.name}`,d),d}finally{e.value=!1}}async function s(k,d){try{const I=await ge({entityId:k,entityType:d});return qe(I)&&I}catch(I){throw K.error(`${z.name}.${ge.name}`),I}}async function o(k){e.value=!0;try{const d=await ln(k);l.value=d==null?void 0:d.validationErrors}catch{K.error(`${z.name}.${o.name}`)}finally{e.value=!1}}return{reviews:ye(()=>v.value),fetching:C(e),itemsPerPage:C(n),pagesCount:C(a),pageNumber:C(i),errors:C(l),fetchCustomerReviews:w,canLeaveFeedback:s,createCustomerReview:o}}const un={class:"mb-4 lg:flex lg:justify-between"},cn={key:0,class:"flex"},mn={class:"mr-2 content-center"},vn={key:1,class:"max-lg:mt-3 lg:flex"},fn={class:"mr-2 content-center font-bold max-lg:hidden"},kn={class:"divide-y rounded border"},pn={class:"flex items-start justify-between gap-2"},gn={class:"text-neutral-400"},yn={key:0,class:"flex items-center justify-between"},bn={class:"mb-6 mt-5 justify-end text-center sm:flex sm:flex-wrap sm:items-center sm:gap-3"},wn={key:1},Nn={key:0,class:"flex items-center gap-3 text-lg font-bold"},Sn={class:"flex justify-between"},hn={class:"text-lg font-bold"},_n={class:"mb-2 font-bold"},Vn={class:"mt-4"},Rn={class:"mt-4 flex flex-wrap justify-between gap-3 max-xs:justify-center"},H="Product",Tn=Be({__name:"product-reviews",props:{productId:{},productRating:{}},setup(e){const n=e,{t:a}=ze(),{isAuthenticated:i}=Ze(),{files:v,options:l,uploadedFiles:w,fetchOptions:s,addFiles:o,validateFiles:k,uploadFiles:d,removeFiles:I}=tn(an),{fetching:Q,pagesCount:ae,pageNumber:M,reviews:$,canLeaveFeedback:be,createCustomerReview:we,fetchCustomerReviews:x}=z(),Ne=Ue(Ge),ie=[{id:"createddate:desc",label:a("common.labels.date_new_to_old")},{id:"createddate:asc",label:a("common.labels.date_old_to_new")}],te=je(n,"productId"),se=p(ie[0].id),L=p(!1),E=p(0),F=p(""),T=p(!1),D=p(!1),h=p({entityId:te.value,entityType:H,page:1,sort:"createddate:desc"}),Se=p(null),he=[We,Ye],_e=Ne.smaller("lg"),W=ye(()=>_e.value?Xe:en);async function Ve(t){h.value.page=1,h.value.sort=t,await x(h.value)}async function Re(t){h.value.page=t,await x(h.value)}function Ie(t){E.value=t}async function $e(){var t;await we({entityId:te.value,entityType:H,review:F.value,rating:E.value,imageUrls:(t=w.value)==null?void 0:t.map(f=>f.url)}),await x(h.value),F.value="",E.value=0,L.value=!0}async function Ee(t){o(t),k(),await d()}async function Fe(t){await I(t)}return Qe(async()=>{var t;await x(h.value),i.value&&(T.value=await be(n.productId,H),D.value=!((t=$.value)!=null&&t.length),T.value&&await s())}),(t,f)=>{var de;const Te=N("VcSelect"),le=N("VcRating"),re=N("VcNavButton"),De=N("VcImage"),Y=N("VcButton"),Ce=N("VcPagination"),xe=N("VcIcon"),Le=N("VcTextarea"),Ae=N("VcFileUploader"),oe=N("VcWidget");return(de=u($))!=null&&de.length||T.value?(c(),_(oe,{key:0,title:t.$t("common.labels.feedback"),"prepend-icon":"chat",size:"lg",class:"text-sm"},{default:V(()=>{var ue,ce;return[(ue=u($))!=null&&ue.length?(c(),S(A,{key:0},[m("div",un,[t.productRating?(c(),S("div",cn,[m("span",mn,y(t.$t("common.labels.rating"))+":",1),b(nn,{rating:t.productRating,class:"font-bold"},null,8,["rating"])])):g("",!0),u($).length?(c(),S("div",vn,[m("span",fn,y(t.$t("common.labels.sort_by_date")),1),b(Te,{modelValue:se.value,"onUpdate:modelValue":f[0]||(f[0]=r=>se.value=r),items:ie,disabled:u(Q),"text-field":"label","value-field":"id",onChange:Ve},null,8,["modelValue","disabled"])])):g("",!0)]),m("div",kn,[(c(!0),S(A,null,ve(u($),r=>{var me;return c(),S("div",{key:r.id,class:"space-y-2 p-4"},[m("div",pn,[m("div",null,[R(y(r.userName)+" ",1),m("div",gn,y(t.$d(r.createdDate,"short")),1)]),b(le,{mode:"full",size:"sm",value:r.rating,"with-text":!1,"read-only":""},null,8,["value"])]),m("div",null,y(r.review),1),(me=r.images)!=null&&me.length?(c(),S("div",yn,[r.images.length>W.value?(c(),_(re,{key:0,id:`images_${r.id}_prev`,label:t.$t("common.buttons.previous"),size:"xs",direction:"left"},null,8,["id","label"])):g("",!0),b(u(Me),{"slides-per-view":W.value,thumbs:{swiper:Se.value},modules:he,navigation:{prevEl:`#images_${r.id}_prev`,nextEl:`#images_${r.id}_next`},"wrapper-class":"items-center",class:"mx-0 w-full p-1","data-te-lightbox-init":""},{default:V(()=>[(c(!0),S(A,null,ve(r.images,(Pe,Oe)=>(c(),_(u(Ke),{key:Oe,class:"cursor-pointer p-2"},{default:V(()=>[b(De,{src:Pe.url,alt:t.$t("common.labels.product_review_image"),"size-suffix":"sm",lazy:""},null,8,["src","alt"])]),_:2},1024))),128))]),_:2},1032,["slides-per-view","thumbs","navigation"]),r.images.length>W.value?(c(),_(re,{key:1,id:`images_${r.id}_next`,label:t.$t("common.buttons.next"),size:"xs",direction:"right"},null,8,["id","label"])):g("",!0)])):g("",!0)])}),128))]),m("div",bn,[u(i)&&T.value&&!D.value&&!L.value?(c(),_(Y,{key:0,variant:"outline",class:"max-sm:mb-10 max-sm:w-[18.125rem] sm:order-last",onClick:f[1]||(f[1]=r=>D.value=!0)},{default:V(()=>[R(y(t.$t("common.buttons.leave_feedback")),1)]),_:1})):g("",!0),u(ae)>1?(c(),_(Ce,{key:1,page:u(M),"onUpdate:page":[f[2]||(f[2]=r=>He(M)?M.value=r:null),Re],pages:u(ae),class:"grow max-sm:flex max-sm:justify-center"},null,8,["page","pages"])):g("",!0)])],64)):g("",!0),u(i)&&T.value?(c(),S("div",wn,[L.value?(c(),S("div",Nn,[b(xe,{name:"check-circle",size:48,class:"block fill-success"}),R(" "+y(t.$t("common.messages.thanks_for_feedback")),1)])):g("",!0),D.value&&!L.value?(c(),S(A,{key:1},[m("div",Sn,[m("div",hn,y(t.$t("common.labels.item_as_described_by_vendor")),1),m("div",null,[m("div",_n,[R(y(t.$t("common.labels.rate_product"))+" ",1),f[5]||(f[5]=m("span",{class:"text-danger"},"*",-1))]),b(le,{mode:"full",size:"sm","read-only":!1,value:E.value,"with-text":!1,onSetRating:Ie},null,8,["value"])])]),b(Le,{modelValue:F.value,"onUpdate:modelValue":f[3]||(f[3]=r=>F.value=r),label:t.$t("common.labels.comments"),required:"",class:"mt-4"},null,8,["modelValue","label"]),m("div",Vn,[f[6]||(f[6]=m("span",{class:"text-danger"},"*",-1)),R(" "+y(t.$t("common.labels.fields_required")),1)]),b(oe,{class:"mt-4"},{default:V(()=>[b(Ae,Je(u(l),{files:u(v),removable:"",onAddFiles:Ee,onRemoveFiles:Fe}),null,16,["files"])]),_:1}),m("div",Rn,[(ce=u($))!=null&&ce.length?(c(),_(Y,{key:0,disabled:u(Q),color:"neutral",variant:"outline","min-width":"12rem",onClick:f[4]||(f[4]=r=>D.value=!1)},{default:V(()=>[R(y(t.$t("common.buttons.cancel")),1)]),_:1},8,["disabled"])):g("",!0),b(Y,{disabled:!F.value||E.value===0,loading:u(Q),variant:"solid","min-width":"12rem",onClick:$e},{default:V(()=>[R(y(t.$t("common.buttons.submit")),1)]),_:1},8,["disabled","loading"])])],64)):g("",!0)])):g("",!0)]}),_:1},8,["title"])):g("",!0)}}});export{Tn as default};
//# sourceMappingURL=product-reviews-BSmga2C1.js.map
