import{r as p,aa as x,m as ke,h as Pe,F as Ae,ai as Oe,aL as qe,aM as Be,ch as ze,P as N,_ as $,W as b,e as d,R as u,a1 as k,Q as _,a5 as Z,T as y,X as m,a2 as h,a0 as w,a6 as ue,aV as Ue,aY as je,aZ as Me,aT as Ge,Y as Qe,$ as We,a7 as Ye,aP as Ze}from"./vendor-DtjVbdLs.js";import{g as ae,q as ne,L as K,dj as A,a3 as Ke,dk as Xe,dl as He,dm as Je}from"./index-D5bkQlXq.js";import{u as ea}from"./useFiles-CqpDzCl1.js";import{_ as aa}from"./product-CxoGMiCA.js";import"./useBreadcrumbs-Cz9PK6XQ.js";import"./index-o5FTalq2.js";import"./save-changes-modal.vue_vue_type_script_setup_true_lang-B9dr7zgx.js";import"./index-DWK19vdO.js";import"./add-to-cart.vue_vue_type_script_setup_true_lang-1xw1csfb.js";import"./useXPickup-BDZm3J2B.js";import"./filters-popup-sidebar.vue_vue_type_style_index_0_lang-DIaYtU9X.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,a){if(e.kind==="FragmentSpread")a.add(e.name.value);else if(e.kind==="VariableDefinition"){var n=e.type;n.kind==="NamedType"&&a.add(n.name.value)}e.selectionSet&&e.selectionSet.selections.forEach(function(i){O(i,a)}),e.variableDefinitions&&e.variableDefinitions.forEach(function(i){O(i,a)}),e.definitions&&e.definitions.forEach(function(i){O(i,a)})}var H={};(function(){U.definitions.forEach(function(a){if(a.name){var n=new Set;O(a,n),H[a.name.value]=n}})})();function me(e,a){for(var n=0;n<e.definitions.length;n++){var i=e.definitions[n];if(i.name&&i.name.value==a)return i}}function na(e,a){var n={kind:e.kind,definitions:[me(e,a)]};e.hasOwnProperty("loc")&&(n.loc=e.loc);var i=H[a]||new Set,c=new Set,l=new Set;for(i.forEach(function(s){l.add(s)});l.size>0;){var S=l;l=new Set,S.forEach(function(s){if(!c.has(s)){c.add(s);var o=H[s]||new Set;o.forEach(function(v){l.add(v)})}})}return c.forEach(function(s){var o=me(e,s);o&&n.definitions.push(o)}),n}na(U,"CreateReview");async function ia(e){const{storeId:a}=ae,{data:n}=await ne.mutate({mutation:U,variables:{command:{...e,storeId:a}}});return n?.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,a){if(e.kind==="FragmentSpread")a.add(e.name.value);else if(e.kind==="VariableDefinition"){var n=e.type;n.kind==="NamedType"&&a.add(n.name.value)}e.selectionSet&&e.selectionSet.selections.forEach(function(i){q(i,a)}),e.variableDefinitions&&e.variableDefinitions.forEach(function(i){q(i,a)}),e.definitions&&e.definitions.forEach(function(i){q(i,a)})}var J={};(function(){j.definitions.forEach(function(a){if(a.name){var n=new Set;q(a,n),J[a.name.value]=n}})})();function ce(e,a){for(var n=0;n<e.definitions.length;n++){var i=e.definitions[n];if(i.name&&i.name.value==a)return i}}function ta(e,a){var n={kind:e.kind,definitions:[ce(e,a)]};e.hasOwnProperty("loc")&&(n.loc=e.loc);var i=J[a]||new Set,c=new Set,l=new Set;for(i.forEach(function(s){l.add(s)});l.size>0;){var S=l;l=new Set,S.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=ce(e,s);o&&n.definitions.push(o)}),n}ta(j,"GetCustomerReviews");async function sa(e){const{storeId:a}=ae,{data:n}=await ne.query({query:j,variables:{storeId:a,entityId:e.entityId,entityType:e.entityType,first:e.first,after:e.after,sort:e.sort}});return n.customerReviews}var M={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}};M.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,a){if(e.kind==="FragmentSpread")a.add(e.name.value);else if(e.kind==="VariableDefinition"){var n=e.type;n.kind==="NamedType"&&a.add(n.name.value)}e.selectionSet&&e.selectionSet.selections.forEach(function(i){B(i,a)}),e.variableDefinitions&&e.variableDefinitions.forEach(function(i){B(i,a)}),e.definitions&&e.definitions.forEach(function(i){B(i,a)})}var ee={};(function(){M.definitions.forEach(function(a){if(a.name){var n=new Set;B(a,n),ee[a.name.value]=n}})})();function ve(e,a){for(var n=0;n<e.definitions.length;n++){var i=e.definitions[n];if(i.name&&i.name.value==a)return i}}function la(e,a){var n={kind:e.kind,definitions:[ve(e,a)]};e.hasOwnProperty("loc")&&(n.loc=e.loc);var i=ee[a]||new Set,c=new Set,l=new Set;for(i.forEach(function(s){l.add(s)});l.size>0;){var S=l;l=new Set,S.forEach(function(s){if(!c.has(s)){c.add(s);var o=ee[s]||new Set;o.forEach(function(v){l.add(v)})}})}return c.forEach(function(s){var o=ve(e,s);o&&n.definitions.push(o)}),n}la(M,"CanLeaveFeedback");async function fe(e){const{storeId:a}=ae,{data:n}=await ne.query({query:M,variables:{...e,storeId:a}});return n.canLeaveFeedback}function z(){const e=p(!1),a=p(A),n=p(0),i=p(1),c=p(),l=p();async function S(v){e.value=!0;try{const g=await sa({...v,first:A,after:((v.page-1)*A).toString()});c.value=g?.items,i.value=v.page,n.value=Math.ceil((g?.totalCount??0)/A)}catch(g){throw K.error(`${z.name}.${S.name}`,g),g}finally{e.value=!1}}async function s(v,g){try{const I=await fe({entityId:v,entityType:g});return Pe(I)&&I}catch(I){throw K.error(`${z.name}.${fe.name}`),I}}async function o(v){e.value=!0;try{const g=await ia(v);l.value=g?.validationErrors}catch(g){K.error(`${z.name}.${o.name}`,g)}finally{e.value=!1}}return{reviews:ke(()=>c.value),fetching:x(e),itemsPerPage:x(a),pagesCount:x(n),pageNumber:x(i),errors:x(l),fetchCustomerReviews:S,canLeaveFeedback:s,createCustomerReview:o}}const ra={class:"mb-4 lg:flex lg:justify-between"},oa={key:1,class:"max-lg:mt-3 lg:flex"},da={class:"sr-only"},ua=["aria-label"],ma={class:"flex items-start justify-between gap-2"},ca={key:0,class:"flex items-center justify-between"},va=["aria-label"],fa={class:"mb-6 mt-5 justify-end text-center sm:flex sm:flex-wrap sm:items-center sm:gap-3"},ka={key:1},pa={key:0,class:"flex items-center gap-3 text-lg font-bold"},ga={class:"flex justify-between"},ba={class:"mt-4 flex flex-wrap justify-between gap-3 max-xs:justify-center"},X="Product",Fa=Ae({__name:"product-reviews",props:{productId:{},productRating:{}},setup(e){const a=e,{t:n}=Oe(),{isAuthenticated:i}=Ke(),{files:c,options:l,uploadedFiles:S,fetchOptions:s,addFiles:o,validateFiles:v,uploadFiles:g,removeFiles:I}=ea(Je),{fetching:G,pagesCount:ie,pageNumber:Q,reviews:T,canLeaveFeedback:pe,createCustomerReview:ge,fetchCustomerReviews:L}=z(),be=Be(Ze),te=[{id:"createddate:desc",label:n("common.labels.date_new_to_old")},{id:"createddate:asc",label:n("common.labels.date_old_to_new")}],se=qe(a,"productId"),le=p(te[0].id),P=p(!1),F=p(0),E=p(""),D=p(!1),C=p(!1),V=p({entityId:se.value,entityType:X,page:1,sort:"createddate:desc"}),ye=p(null),we=[je,Me],Ne=be.smaller("lg"),W=ke(()=>Ne.value?Xe:He);async function he(t){V.value.page=1,V.value.sort=t,await L(V.value)}async function Se(t){V.value.page=t,await L(V.value)}function _e(t){F.value=t}async function $e(){await ge({entityId:se.value,entityType:X,review:E.value,rating:F.value,imageUrls:S.value?.map(t=>t.url)}),await L(V.value),E.value="",F.value=0,P.value=!0}function Ve(t){o(t),v(),g()}async function Re(t){await I(t)}return ze(async()=>{await L(V.value),i.value&&(D.value=await pe(a.productId,X),C.value=!T.value?.length,D.value&&await s())}),(t,f)=>{const R=N("VcTypography"),Ie=N("VcSelect"),re=N("VcRating"),oe=N("VcNavButton"),Te=N("VcImage"),Y=N("VcButton"),Fe=N("VcPagination"),Ee=N("VcIcon"),De=N("VcTextarea"),Ce=N("VcFileUploader"),de=N("VcWidget");return d(T)?.length||D.value?(u(),$(de,{key:0,title:t.$t("common.labels.feedback"),"prepend-icon":"chat",size:"lg",class:"text-sm"},{default:k(()=>[d(T)?.length?(u(),_(Z,{key:0},[y("div",ra,[e.productRating?(u(),$(aa,{key:0,rating:e.productRating},null,8,["rating"])):b("",!0),d(T).length?(u(),_("div",oa,[m(R,{tag:"span",class:"mr-2 content-center text-sm font-bold max-lg:hidden"},{default:k(()=>[h(w(t.$t("common.labels.sort_by_date")),1)]),_:1}),y("span",da,w(t.$t("common.labels.sort_by_date")),1),m(Ie,{modelValue:le.value,"onUpdate:modelValue":f[0]||(f[0]=r=>le.value=r),items:te,disabled:d(G),"text-field":"label","value-field":"id",onChange:he},null,8,["modelValue","disabled"])])):b("",!0)]),y("section",{class:"divide-y rounded border","aria-label":t.$t("common.labels.product_reviews")},[(u(!0),_(Z,null,ue(d(T),r=>(u(),_("article",{key:r.id,class:"space-y-2 p-4"},[y("div",ma,[y("div",null,[m(R,{tag:"h3",variant:"base",class:"text-sm"},{default:k(()=>[h(w(r.userName),1)]),_:2},1024),m(R,{tag:"span",variant:"base",class:"text-sm text-neutral-500"},{default:k(()=>[h(w(t.$d(r.createdDate,"short")),1)]),_:2},1024)]),m(re,{mode:"full",size:"sm",value:r.rating,"with-text":!1,"read-only":""},null,8,["value"])]),m(R,{tag:"p",class:"text-sm"},{default:k(()=>[h(w(r.review),1)]),_:2},1024),r.images?.length?(u(),_("div",ca,[r.images.length>W.value?(u(),$(oe,{key:0,id:`images_${r.id}_prev`,"aria-label":`${t.$t("common.buttons.previous")} ${t.$t("common.labels.product_review_image")}`,label:t.$t("common.buttons.previous"),size:"xs",tabindex:"0",direction:"left"},null,8,["id","aria-label","label"])):b("",!0),y("section",{"aria-label":t.$t("common.labels.product_review_image")},[m(d(Ue),{"slides-per-view":W.value,thumbs:{swiper:ye.value},modules:we,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:k(()=>[(u(!0),_(Z,null,ue(r.images,(xe,Le)=>(u(),$(d(Ge),{key:Le,class:"cursor-pointer p-2"},{default:k(()=>[m(Te,{src:xe.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"])],8,va),r.images.length>W.value?(u(),$(oe,{key:1,id:`images_${r.id}_next`,"aria-label":`${t.$t("common.buttons.next")} ${t.$t("common.labels.product_review_image")} - ${r.userName}`,label:t.$t("common.buttons.next"),size:"xs",tabindex:"0",direction:"right"},null,8,["id","aria-label","label"])):b("",!0)])):b("",!0)]))),128))],8,ua),y("div",fa,[d(i)&&D.value&&!C.value&&!P.value?(u(),$(Y,{key:0,variant:"outline",tabindex:"0",class:"max-sm:mb-10 max-sm:w-[18.125rem] sm:order-last",onClick:f[1]||(f[1]=r=>C.value=!0)},{default:k(()=>[h(w(t.$t("common.buttons.leave_feedback")),1)]),_:1})):b("",!0),d(ie)>1?(u(),$(Fe,{key:1,page:d(Q),"onUpdate:page":[f[2]||(f[2]=r=>Qe(Q)?Q.value=r:null),Se],pages:d(ie),class:"grow max-sm:flex max-sm:justify-center"},null,8,["page","pages"])):b("",!0)])],64)):b("",!0),d(i)&&D.value?(u(),_("div",ka,[P.value?(u(),_("div",pa,[m(Ee,{name:"check-circle",size:48,class:"block fill-success","aria-hidden":"true"}),h(" "+w(t.$t("common.messages.thanks_for_feedback")),1)])):b("",!0),C.value&&!P.value?(u(),_("form",{key:1,onSubmit:We($e,["prevent"])},[y("div",ga,[m(R,{tag:"h3",variant:"h4","text-transform":"none"},{default:k(()=>[h(w(t.$t("common.labels.item_as_described_by_vendor")),1)]),_:1}),y("div",null,[m(R,{tag:"span",class:"text-sm font-bold"},{default:k(()=>[h(w(t.$t("common.labels.rate_product"))+" ",1),f[5]||(f[5]=y("span",{class:"text-danger"},"*",-1))]),_:1}),m(re,{mode:"full",size:"sm",class:"mt-2","read-only":!1,value:F.value,"with-text":!1,onSetRating:_e},null,8,["value"])])]),m(De,{modelValue:E.value,"onUpdate:modelValue":f[3]||(f[3]=r=>E.value=r),label:t.$t("common.labels.comments"),required:"",class:"my-4","aria-label":t.$t("common.labels.comments")},null,8,["modelValue","label","aria-label"]),m(R,{tag:"span",class:"text-sm"},{default:k(()=>[f[6]||(f[6]=y("span",{class:"text-danger"},"*",-1)),h(" "+w(t.$t("common.labels.fields_required")),1)]),_:1}),m(de,{class:"mt-4"},{default:k(()=>[m(Ce,Ye(d(l),{files:d(c),removable:"",onAddFiles:Ve,onRemoveFiles:Re}),null,16,["files"])]),_:1}),y("div",ba,[d(T)?.length?(u(),$(Y,{key:0,disabled:d(G),color:"neutral",variant:"outline","min-width":"12rem",tabindex:"0",onClick:f[4]||(f[4]=r=>C.value=!1)},{default:k(()=>[h(w(t.$t("common.buttons.cancel")),1)]),_:1},8,["disabled"])):b("",!0),m(Y,{disabled:!E.value||F.value===0,loading:d(G),variant:"solid",type:"submit",tabindex:"0","min-width":"12rem"},{default:k(()=>[h(w(t.$t("common.buttons.submit")),1)]),_:1},8,["disabled","loading"])])],32)):b("",!0)])):b("",!0)]),_:1},8,["title"])):b("",!0)}}});export{Fa as default};
//# sourceMappingURL=product-reviews-JvqtDcQ7.js.map
