import{r as k,ab as C,m as fe,h as Le,F as Pe,ag as Ae,aK as Oe,aL as qe,cg as Be,P as w,_ as h,W as g,e as d,R as u,a1 as V,Q as S,a6 as P,T as m,X as N,a0 as y,a7 as de,a2 as R,aU as Ue,aX as ze,aY as je,aS as Ge,Y as Me,a8 as Qe,aO as We}from"./vendor-CB-jpi5M.js";import{g as ee,q as ne,L as K,dk as A,a3 as Ye,dl as Ke,dm as Xe,dn as Ze}from"./index-B-IqqSSt.js";import{u as He}from"./useFiles-CYRJwe3o.js";import{_ as Je}from"./product-C7HpVDCV.js";import"./useBreadcrumbs-C3iwaFYZ.js";import"./index-o5FTalq2.js";import"./filters-popup-sidebar.vue_vue_type_style_index_0_lang-DjsHEVNn.js";import"./save-changes-modal.vue_vue_type_script_setup_true_lang-BZBeVhR9.js";import"./index-UTlpq3_r.js";import"./add-to-cart.vue_vue_type_script_setup_true_lang-d8UtPiCE.js";import"./useXPickup-CCtKxCXp.js";var z={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}};z.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 Z={};(function(){z.definitions.forEach(function(n){if(n.name){var a=new Set;O(n,a),Z[n.name.value]=a}})})();function ue(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 en(e,n){var a={kind:e.kind,definitions:[ue(e,n)]};e.hasOwnProperty("loc")&&(a.loc=e.loc);var i=Z[n]||new Set,c=new Set,l=new Set;for(i.forEach(function(t){l.add(t)});l.size>0;){var b=l;l=new Set,b.forEach(function(t){if(!c.has(t)){c.add(t);var o=Z[t]||new Set;o.forEach(function(v){l.add(v)})}})}return c.forEach(function(t){var o=ue(e,t);o&&a.definitions.push(o)}),a}en(z,"CreateReview");async function nn(e){const{storeId:n}=ee,{data:a}=await ne.mutate({mutation:z,variables:{command:{...e,storeId:n}}});return a?.createReview}var j={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}};j.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 H={};(function(){j.definitions.forEach(function(n){if(n.name){var a=new Set;q(n,a),H[n.name.value]=a}})})();function ce(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 an(e,n){var a={kind:e.kind,definitions:[ce(e,n)]};e.hasOwnProperty("loc")&&(a.loc=e.loc);var i=H[n]||new Set,c=new Set,l=new Set;for(i.forEach(function(t){l.add(t)});l.size>0;){var b=l;l=new Set,b.forEach(function(t){if(!c.has(t)){c.add(t);var o=H[t]||new Set;o.forEach(function(v){l.add(v)})}})}return c.forEach(function(t){var o=ce(e,t);o&&a.definitions.push(o)}),a}an(j,"GetCustomerReviews");async function tn(e){const{storeId:n}=ee,{data:a}=await ne.query({query:j,variables:{storeId:n,entityId:e.entityId,entityType:e.entityType,first:e.first,after:e.after,sort:e.sort}});return a.customerReviews}var G={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}};G.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 J={};(function(){G.definitions.forEach(function(n){if(n.name){var a=new Set;B(n,a),J[n.name.value]=a}})})();function me(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:[me(e,n)]};e.hasOwnProperty("loc")&&(a.loc=e.loc);var i=J[n]||new Set,c=new Set,l=new Set;for(i.forEach(function(t){l.add(t)});l.size>0;){var b=l;l=new Set,b.forEach(function(t){if(!c.has(t)){c.add(t);var o=J[t]||new Set;o.forEach(function(v){l.add(v)})}})}return c.forEach(function(t){var o=me(e,t);o&&a.definitions.push(o)}),a}sn(G,"CanLeaveFeedback");async function ve(e){const{storeId:n}=ee,{data:a}=await ne.query({query:G,variables:{...e,storeId:n}});return a.canLeaveFeedback}function U(){const e=k(!1),n=k(A),a=k(0),i=k(1),c=k(),l=k();async function b(v){e.value=!0;try{const p=await tn({...v,first:A,after:((v.page-1)*A).toString()});c.value=p?.items,i.value=v.page,a.value=Math.ceil((p?.totalCount??0)/A)}catch(p){throw K.error(`${U.name}.${b.name}`,p),p}finally{e.value=!1}}async function t(v,p){try{const I=await ve({entityId:v,entityType:p});return Le(I)&&I}catch(I){throw K.error(`${U.name}.${ve.name}`),I}}async function o(v){e.value=!0;try{const p=await nn(v);l.value=p?.validationErrors}catch(p){K.error(`${U.name}.${o.name}`,p)}finally{e.value=!1}}return{reviews:fe(()=>c.value),fetching:C(e),itemsPerPage:C(n),pagesCount:C(a),pageNumber:C(i),errors:C(l),fetchCustomerReviews:b,canLeaveFeedback:t,createCustomerReview:o}}const ln={class:"mb-4 lg:flex lg:justify-between"},rn={key:1,class:"max-lg:mt-3 lg:flex"},on={class:"mr-2 content-center font-bold max-lg:hidden"},dn={class:"divide-y rounded border"},un={class:"flex items-start justify-between gap-2"},cn={class:"text-neutral-400"},mn={key:0,class:"flex items-center justify-between"},vn={class:"mb-6 mt-5 justify-end text-center sm:flex sm:flex-wrap sm:items-center sm:gap-3"},fn={key:1},kn={key:0,class:"flex items-center gap-3 text-lg font-bold"},pn={class:"flex justify-between"},gn={class:"text-lg font-bold"},yn={class:"mb-2 font-bold"},bn={class:"mt-4"},wn={class:"mt-4 flex flex-wrap justify-between gap-3 max-xs:justify-center"},X="Product",Dn=Pe({__name:"product-reviews",props:{productId:{},productRating:{}},setup(e){const n=e,{t:a}=Ae(),{isAuthenticated:i}=Ye(),{files:c,options:l,uploadedFiles:b,fetchOptions:t,addFiles:o,validateFiles:v,uploadFiles:p,removeFiles:I}=He(Ze),{fetching:M,pagesCount:ae,pageNumber:Q,reviews:$,canLeaveFeedback:ke,createCustomerReview:pe,fetchCustomerReviews:x}=U(),ge=qe(We),ie=[{id:"createddate:desc",label:a("common.labels.date_new_to_old")},{id:"createddate:asc",label:a("common.labels.date_old_to_new")}],te=Oe(n,"productId"),se=k(ie[0].id),L=k(!1),F=k(0),E=k(""),T=k(!1),D=k(!1),_=k({entityId:te.value,entityType:X,page:1,sort:"createddate:desc"}),ye=k(null),be=[ze,je],we=ge.smaller("lg"),W=fe(()=>we.value?Ke:Xe);async function Ne(s){_.value.page=1,_.value.sort=s,await x(_.value)}async function Se(s){_.value.page=s,await x(_.value)}function he(s){F.value=s}async function _e(){await pe({entityId:te.value,entityType:X,review:E.value,rating:F.value,imageUrls:b.value?.map(s=>s.url)}),await x(_.value),E.value="",F.value=0,L.value=!0}function Ve(s){o(s),v(),p()}async function Re(s){await I(s)}return Be(async()=>{await x(_.value),i.value&&(T.value=await ke(n.productId,X),D.value=!$.value?.length,T.value&&await t())}),(s,f)=>{const Ie=w("VcSelect"),le=w("VcRating"),re=w("VcNavButton"),$e=w("VcImage"),Y=w("VcButton"),Fe=w("VcPagination"),Ee=w("VcIcon"),Te=w("VcTextarea"),De=w("VcFileUploader"),oe=w("VcWidget");return d($)?.length||T.value?(u(),h(oe,{key:0,title:s.$t("common.labels.feedback"),"prepend-icon":"chat",size:"lg",class:"text-sm"},{default:V(()=>[d($)?.length?(u(),S(P,{key:0},[m("div",ln,[e.productRating?(u(),h(Je,{key:0,rating:e.productRating},null,8,["rating"])):g("",!0),d($).length?(u(),S("div",rn,[m("span",on,y(s.$t("common.labels.sort_by_date")),1),N(Ie,{modelValue:se.value,"onUpdate:modelValue":f[0]||(f[0]=r=>se.value=r),items:ie,disabled:d(M),"text-field":"label","value-field":"id",onChange:Ne},null,8,["modelValue","disabled"])])):g("",!0)]),m("div",dn,[(u(!0),S(P,null,de(d($),r=>(u(),S("div",{key:r.id,class:"space-y-2 p-4"},[m("div",un,[m("div",null,[R(y(r.userName)+" ",1),m("div",cn,y(s.$d(r.createdDate,"short")),1)]),N(le,{mode:"full",size:"sm",value:r.rating,"with-text":!1,"read-only":""},null,8,["value"])]),m("div",null,y(r.review),1),r.images?.length?(u(),S("div",mn,[r.images.length>W.value?(u(),h(re,{key:0,id:`images_${r.id}_prev`,label:s.$t("common.buttons.previous"),size:"xs",direction:"left"},null,8,["id","label"])):g("",!0),N(d(Ue),{"slides-per-view":W.value,thumbs:{swiper:ye.value},modules:be,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(()=>[(u(!0),S(P,null,de(r.images,(Ce,xe)=>(u(),h(d(Ge),{key:xe,class:"cursor-pointer p-2"},{default:V(()=>[N($e,{src:Ce.url,alt:s.$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?(u(),h(re,{key:1,id:`images_${r.id}_next`,label:s.$t("common.buttons.next"),size:"xs",direction:"right"},null,8,["id","label"])):g("",!0)])):g("",!0)]))),128))]),m("div",vn,[d(i)&&T.value&&!D.value&&!L.value?(u(),h(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(s.$t("common.buttons.leave_feedback")),1)]),_:1})):g("",!0),d(ae)>1?(u(),h(Fe,{key:1,page:d(Q),"onUpdate:page":[f[2]||(f[2]=r=>Me(Q)?Q.value=r:null),Se],pages:d(ae),class:"grow max-sm:flex max-sm:justify-center"},null,8,["page","pages"])):g("",!0)])],64)):g("",!0),d(i)&&T.value?(u(),S("div",fn,[L.value?(u(),S("div",kn,[N(Ee,{name:"check-circle",size:48,class:"block fill-success"}),R(" "+y(s.$t("common.messages.thanks_for_feedback")),1)])):g("",!0),D.value&&!L.value?(u(),S(P,{key:1},[m("div",pn,[m("div",gn,y(s.$t("common.labels.item_as_described_by_vendor")),1),m("div",null,[m("div",yn,[R(y(s.$t("common.labels.rate_product"))+" ",1),f[5]||(f[5]=m("span",{class:"text-danger"},"*",-1))]),N(le,{mode:"full",size:"sm","read-only":!1,value:F.value,"with-text":!1,onSetRating:he},null,8,["value"])])]),N(Te,{modelValue:E.value,"onUpdate:modelValue":f[3]||(f[3]=r=>E.value=r),label:s.$t("common.labels.comments"),required:"",class:"mt-4"},null,8,["modelValue","label"]),m("div",bn,[f[6]||(f[6]=m("span",{class:"text-danger"},"*",-1)),R(" "+y(s.$t("common.labels.fields_required")),1)]),N(oe,{class:"mt-4"},{default:V(()=>[N(De,Qe(d(l),{files:d(c),removable:"",onAddFiles:Ve,onRemoveFiles:Re}),null,16,["files"])]),_:1}),m("div",wn,[d($)?.length?(u(),h(Y,{key:0,disabled:d(M),color:"neutral",variant:"outline","min-width":"12rem",onClick:f[4]||(f[4]=r=>D.value=!1)},{default:V(()=>[R(y(s.$t("common.buttons.cancel")),1)]),_:1},8,["disabled"])):g("",!0),N(Y,{disabled:!E.value||F.value===0,loading:d(M),variant:"solid","min-width":"12rem",onClick:_e},{default:V(()=>[R(y(s.$t("common.buttons.submit")),1)]),_:1},8,["disabled","loading"])])],64)):g("",!0)])):g("",!0)]),_:1},8,["title"])):g("",!0)}}});export{Dn as default};
//# sourceMappingURL=product-reviews-DYIan9BV.js.map
