import{r as k,ab as C,m as fe,h as Le,F as Pe,ag as Ae,aL as Oe,aM 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,aP as ze,aS as Ue,aT as je,aO as Ge,Y as Me,a8 as Qe,bH as We}from"./vendor-DJC-2VPc.js";import{g as ee,r as ne,L as H,dd as A,a4 as Ye,de as He,df as Ke,dg as Xe}from"./index-BZco6cza.js";import{u as Ze}from"./useFiles-B2QqjIAy.js";import{_ as Je}from"./product-1pA1cJJk.js";import"./useBreadcrumbs-DNKlvuhT.js";import"./index-o5FTalq2.js";import"./filters-popup-sidebar.vue_vue_type_style_index_0_lang-D7BFDuBe.js";import"./save-changes-modal.vue_vue_type_script_setup_true_lang-xrlo0EgP.js";import"./index-BdUNrkFj.js";import"./useXPickup-DcgOHV4R.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 X={};(function(){U.definitions.forEach(function(n){if(n.name){var a=new Set;O(n,a),X[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=X[n]||new Set,c=new Set,l=new Set;for(i.forEach(function(s){l.add(s)});l.size>0;){var b=l;l=new Set,b.forEach(function(s){if(!c.has(s)){c.add(s);var o=X[s]||new Set;o.forEach(function(v){l.add(v)})}})}return c.forEach(function(s){var o=ue(e,s);o&&a.definitions.push(o)}),a}en(U,"CreateReview");async function nn(e){const{storeId:n}=ee,{data:a}=await ne.mutate({mutation:U,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 Z={};(function(){j.definitions.forEach(function(n){if(n.name){var a=new Set;q(n,a),Z[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=Z[n]||new Set,c=new Set,l=new Set;for(i.forEach(function(s){l.add(s)});l.size>0;){var b=l;l=new Set,b.forEach(function(s){if(!c.has(s)){c.add(s);var o=Z[s]||new Set;o.forEach(function(v){l.add(v)})}})}return c.forEach(function(s){var o=ce(e,s);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(s){l.add(s)});l.size>0;){var b=l;l=new Set,b.forEach(function(s){if(!c.has(s)){c.add(s);var o=J[s]||new Set;o.forEach(function(v){l.add(v)})}})}return c.forEach(function(s){var o=me(e,s);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 z(){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 H.error(`${z.name}.${b.name}`,p),p}finally{e.value=!1}}async function s(v,p){try{const I=await ve({entityId:v,entityType:p});return Le(I)&&I}catch(I){throw H.error(`${z.name}.${ve.name}`),I}}async function o(v){e.value=!0;try{const p=await nn(v);l.value=p?.validationErrors}catch(p){H.error(`${z.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:s,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"},K="Product",En=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:s,addFiles:o,validateFiles:v,uploadFiles:p,removeFiles:I}=Ze(Xe),{fetching:M,pagesCount:ae,pageNumber:Q,reviews:$,canLeaveFeedback:ke,createCustomerReview:pe,fetchCustomerReviews:x}=z(),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),T=k(""),E=k(!1),D=k(!1),_=k({entityId:te.value,entityType:K,page:1,sort:"createddate:desc"}),ye=k(null),be=[Ue,je],we=ge.smaller("lg"),W=fe(()=>we.value?He:Ke);async function Ne(t){_.value.page=1,_.value.sort=t,await x(_.value)}async function Se(t){_.value.page=t,await x(_.value)}function he(t){F.value=t}async function _e(){await pe({entityId:te.value,entityType:K,review:T.value,rating:F.value,imageUrls:b.value?.map(t=>t.url)}),await x(_.value),T.value="",F.value=0,L.value=!0}function Ve(t){o(t),v(),p()}async function Re(t){await I(t)}return Be(async()=>{await x(_.value),i.value&&(E.value=await ke(n.productId,K),D.value=!$.value?.length,E.value&&await s())}),(t,f)=>{const Ie=w("VcSelect"),le=w("VcRating"),re=w("VcNavButton"),$e=w("VcImage"),Y=w("VcButton"),Fe=w("VcPagination"),Te=w("VcIcon"),Ee=w("VcTextarea"),De=w("VcFileUploader"),oe=w("VcWidget");return d($)?.length||E.value?(u(),h(oe,{key:0,title:t.$t("common.labels.feedback"),"prepend-icon":"chat",size:"lg",class:"text-sm"},{default:V(()=>[d($)?.length?(u(),S(P,{key:0},[m("div",ln,[t.productRating?(u(),h(Je,{key:0,rating:t.productRating},null,8,["rating"])):g("",!0),d($).length?(u(),S("div",rn,[m("span",on,y(t.$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(t.$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:t.$t("common.buttons.previous"),size:"xs",direction:"left"},null,8,["id","label"])):g("",!0),N(d(ze),{"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: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?(u(),h(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",vn,[d(i)&&E.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(t.$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)&&E.value?(u(),S("div",fn,[L.value?(u(),S("div",kn,[N(Te,{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?(u(),S(P,{key:1},[m("div",pn,[m("div",gn,y(t.$t("common.labels.item_as_described_by_vendor")),1),m("div",null,[m("div",yn,[R(y(t.$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(Ee,{modelValue:T.value,"onUpdate:modelValue":f[3]||(f[3]=r=>T.value=r),label:t.$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(t.$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(t.$t("common.buttons.cancel")),1)]),_:1},8,["disabled"])):g("",!0),N(Y,{disabled:!T.value||F.value===0,loading:d(M),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{En as default};
//# sourceMappingURL=product-reviews-BDdE0i5i.js.map
