JezK
Edit File: reviews-by-product.js
(()=>{var e,t,o,r={55566:(e,t,o)=>{"use strict";const r=window.wp.blocks;var s=o(93450),i=o(69863),n=(o(14809),o(27723));const a=window.wp.blockEditor;var c=o(4921);const l=window.wp.components;var d=o(86087);function m(e,t,o){const r=new Set(t.map(e=>e[o]));return e.filter(e=>!r.has(e[o]))}const h=window.wp.htmlEntities;var u=o(10790);const w={clear:(0,n.__)("Clear all selected items","woocommerce"),noItems:(0,n.__)("No items found.","woocommerce"), /* Translators: %s search term */ noResults:(0,n.__)("No results for %s","woocommerce"),search:(0,n.__)("Search for items","woocommerce"),selected:e=>(0,n.sprintf)(/* translators: Number of items selected from list. */ /* translators: Number of items selected from list. */ (0,n._n)("%d item selected","%d items selected",e,"woocommerce"),e),updated:(0,n.__)("Search results updated.","woocommerce")},p=(e,t)=>null!==t&&(e.id===t||!!(Array.isArray(e.children)&&e.children.length>0)&&e.children.some(e=>p(e,t))),g=(e,t=e)=>{const o=e.reduce((e,t)=>{const o=t.parent||0;return e[o]||(e[o]=[]),e[o].push(t),e},{}),r=t.reduce((e,t)=>(e[String(t.id)]=t,e),{});const s=["0"],i=(e={})=>e.parent?[...i(r[e.parent]),e.name]:e.name?[e.name]:[],n=e=>e.map(e=>{const t=o[e.id];return s.push(""+e.id),{...e,breadcrumbs:i(r[e.parent]),children:t&&t.length?n(t):[]}}),a=n(o[0]||[]);return Object.entries(o).forEach(([e,t])=>{s.includes(e)||a.push(...n(t||[]))}),a},v=(e,t)=>{if(!t)return e;const o=new RegExp(`(${t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")})`,"ig");return e.split(o).map((e,t)=>o.test(e)?(0,u.jsx)("strong",{children:e},t):(0,u.jsx)(d.Fragment,{children:e},t))},_=e=>{const t=e.children?.map(e=>[e,..._(e)]);return t?t.flat():[]},b=(e,t)=>_(e).some(e=>t.find(t=>t.id===e.id)),f=(e,t)=>_(e).every(e=>t.find(t=>t.id===e.id)),x=({label:e})=>(0,u.jsx)("span",{className:"woocommerce-search-list__item-count",children:e}),y=e=>{const{item:t,search:o}=e,r=t.breadcrumbs&&t.breadcrumbs.length;return(0,u.jsxs)("span",{className:"woocommerce-search-list__item-label",children:[r?(0,u.jsx)("span",{className:"woocommerce-search-list__item-prefix",children:(s=t.breadcrumbs,1===s.length?s.slice(0,1).toString():2===s.length?s.slice(0,1).toString()+" › "+s.slice(-1).toString():s.slice(0,1).toString()+" … "+s.slice(-1).toString())}):null,(0,u.jsx)("span",{className:"woocommerce-search-list__item-name",children:v((0,h.decodeEntities)(t.name),o)})]});var s},j=({countLabel:e,className:t,depth:o=0,controlId:r="",disabled:s=!1,item:i,isSelected:n,isSelectable:a=!0,isSingle:w,onSelect:g,search:j="",selected:R,useExpandedPanelId:S,...k})=>{const[N,C]=S,I=null!=e&&void 0!==i.count&&null!==i.count,P=!!i.breadcrumbs?.length,L=!!i.children?.length,O=p(i,N),T=(0,c.A)(["woocommerce-search-list__item",`depth-${o}`,t],{"has-breadcrumbs":P,"has-children":L,"has-count":I,"is-expanded":O,"is-radio-button":w}),A=k.name||`search-list-item-${r}`,M=`${A}-${i.id}`,E=(0,d.useCallback)(()=>{O||"number"!=typeof i.id&&"string"!=typeof i.id?!i.parent||"number"!=typeof i.parent&&"string"!=typeof i.parent?C(null):C(i.parent):C(i.id)},[O,i.id,i.parent,C]),D=(n||!a)&&f(i,R);return L?(0,u.jsx)("div",{className:T,onClick:E,onKeyDown:e=>"Enter"===e.key||" "===e.key?E():null,role:"treeitem",tabIndex:0,children:w?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("input",{type:"radio",id:M,name:A,value:i.value,onChange:()=>{g(i)(),O||C(i.id)},onClick:e=>e.stopPropagation(),checked:n,disabled:s,className:"woocommerce-search-list__item-input",...k}),(0,u.jsx)(y,{item:i,search:j}),I?(0,u.jsx)(x,{label:e||i.count}):null]}):(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(l.CheckboxControl,{className:"woocommerce-search-list__item-input",checked:D,disabled:s,indeterminate:!D&&(n||b(i,R)),label:v((0,h.decodeEntities)(i.name),j),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),onChange:()=>{const e=_(i),t=a?[i,...e]:[...e],o=f(i,R);a&&n||!a&&o?g(m(R,t,"id"))():(g(function(e,t){const o=m(t,e,"id");return[...e,...o]}(R,t))(),O||C(i.id))},__nextHasNoMarginBottom:!0}),I?(0,u.jsx)(x,{label:e||i.count}):null]})}):(0,u.jsxs)("div",{className:T,onClick:s?void 0:g(i),children:[w?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("input",{...k,type:"radio",id:M,name:A,value:i.value,onChange:g(i),checked:n,disabled:s,className:"woocommerce-search-list__item-input",onClick:e=>e.stopPropagation()}),(0,u.jsx)("label",{htmlFor:M,children:(0,u.jsx)(y,{item:i,search:j})})]}):(0,u.jsx)(l.CheckboxControl,{...k,id:M,name:A,className:"woocommerce-search-list__item-input",value:(0,h.decodeEntities)(i.value),label:v((0,h.decodeEntities)(i.name),j),onChange:()=>{g(i)(),O||C(i.id)},checked:n,disabled:s,__nextHasNoMarginBottom:!0,onClick:e=>e.stopPropagation()}),I?(0,u.jsx)(x,{label:e||i.count}):null]})},R=j,S=window.wc.wcTypes;var k=o(19432),N=o(29491),C=o(31884);o(75022);const I=({id:e,label:t,popoverContents:o,remove:r,screenReaderLabel:i,className:a=""})=>{const[m,w]=(0,d.useState)(!1),p=(0,N.useInstanceId)(I);if(i=i||t,!t)return null;t=(0,h.decodeEntities)(t);const g=(0,c.A)("woocommerce-tag",a,{"has-remove":!!r}),v=`woocommerce-tag__label-${p}`,_=(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("span",{className:"screen-reader-text",children:i}),(0,u.jsx)("span",{"aria-hidden":"true",children:t})]});return(0,u.jsxs)("span",{className:g,children:[o?(0,u.jsx)(l.Button,{className:"woocommerce-tag__text",id:v,onClick:()=>w(!0),children:_}):(0,u.jsx)("span",{className:"woocommerce-tag__text",id:v,children:_}),o&&m&&(0,u.jsx)(l.Popover,{onClose:()=>w(!1),children:o}),r&&(0,u.jsx)(l.Button,{className:"woocommerce-tag__remove",onClick:r(e),label:(0,n.sprintf)( // Translators: %s label. // Translators: %s label. (0,n.__)("Remove %s","woocommerce"),t),"aria-describedby":v,children:(0,u.jsx)(s.A,{icon:C.A,size:20,className:"clear-icon",role:"img"})})]})},P=I;o(71939);const L=e=>(0,u.jsx)(R,{...e}),O=e=>{const{list:t,selected:o,renderItem:r,depth:s=0,loadMoreChildrenText:i,onLoadMoreChildren:a,totalChildren:c,onSelect:l,instanceId:m,isSingle:h,search:w,useExpandedPanelId:g}=e,[v]=g;return t?(0,u.jsx)(u.Fragment,{children:t.map(t=>{const _=t.children?.length??0,b=!!o.find(({id:e})=>e===t.id),f=p(t,v),x=c?.[t.id],y="number"==typeof x&&_<x;return(0,u.jsxs)(d.Fragment,{children:[(0,u.jsx)("li",{children:r({item:t,isSelected:b,onSelect:l,isSingle:h,selected:o,search:w,depth:s,useExpandedPanelId:g,controlId:m})}),f?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(O,{...e,list:t.children,depth:s+1}),a&&y?(0,u.jsx)("li",{children:(0,u.jsx)("button",{type:"button",className:"woocommerce-search-list__item woocommerce-search-list__item-load-more",onClick:()=>a(),children:i||(0,n.__)("Load more","woocommerce")})}):null]}):null]},t.id)})}):null},T=({isLoading:e,isSingle:t,selected:o,messages:r,onChange:s,onRemove:i})=>{if(e||t||!o)return null;const a=o.length;return(0,u.jsxs)("div",{className:"woocommerce-search-list__selected",children:[(0,u.jsxs)("div",{className:"woocommerce-search-list__selected-header",children:[(0,u.jsx)("strong",{children:r.selected(a)}),a>0?(0,u.jsx)(l.Button,{variant:"link",isDestructive:!0,onClick:()=>s([]),"aria-label":r.clear,children:(0,n.__)("Clear all","woocommerce")}):null]}),a>0?(0,u.jsx)("ul",{children:o.map((e,t)=>(0,u.jsx)("li",{children:(0,u.jsx)(P,{label:e.name,id:e.id,remove:i})},t))}):null]})},A=({filteredList:e,search:t,onSelect:o,instanceId:r,useExpandedPanelId:i,...a})=>{const{messages:c,renderItem:l,selected:d,isSingle:m,loadMoreChildrenText:h,onLoadMoreChildren:w,totalChildren:p}=a,g=l||L;return 0===e.length?(0,u.jsxs)("div",{className:"woocommerce-search-list__list is-not-found",children:[(0,u.jsx)("span",{className:"woocommerce-search-list__not-found-icon",children:(0,u.jsx)(s.A,{icon:k.A,role:"img"})}),(0,u.jsx)("span",{className:"woocommerce-search-list__not-found-text",children:t?(0,n.sprintf)(c.noResults,t):c.noItems})]}):(0,u.jsx)("ul",{className:"woocommerce-search-list__list",children:(0,u.jsx)(O,{useExpandedPanelId:i,list:e,selected:d,renderItem:g,loadMoreChildrenText:h,onLoadMoreChildren:w,totalChildren:p,onSelect:o,instanceId:r,isSingle:m,search:t})})},M=e=>{const{className:t="",isCompact:o,isHierarchical:r,isLoading:s,isSingle:i,list:a,messages:m=w,onChange:h,onSearch:p,selected:v,type:_="text",debouncedSpeak:b}=e,[f,x]=(0,d.useState)(""),y=(0,d.useState)(null),j=(0,N.useInstanceId)(M),R=(0,d.useMemo)(()=>({...w,...m}),[m]),S=(0,d.useMemo)(()=>((e,t,o)=>{if(!t)return o?g(e):e;const r=new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i"),s=e.map(e=>!!r.test(e.name)&&e).filter(Boolean);return o?g(s,e):s})(a,f,r),[a,f,r]);(0,d.useEffect)(()=>{b&&b(R.updated)},[b,R]),(0,d.useEffect)(()=>{"function"==typeof p&&p(f)},[f,p]);const k=(0,d.useCallback)(e=>()=>{i&&h([]);const t=v.findIndex(({id:t})=>t===e);h([...v.slice(0,t),...v.slice(t+1)])},[i,v,h]),C=(0,d.useCallback)(e=>()=>{Array.isArray(e)?h(e):-1===v.findIndex(({id:t})=>t===e.id)?h(i?[e]:[...v,e]):k(e.id)()},[i,k,h,v]),I=(0,d.useCallback)(e=>{const[t]=v.filter(t=>!e.find(e=>t.id===e.id));k(t.id)()},[k,v]);return(0,u.jsxs)("div",{className:(0,c.A)("woocommerce-search-list",t,{"is-compact":o,"is-loading":s,"is-token":"token"===_}),children:["text"===_&&(0,u.jsx)(T,{...e,onRemove:k,messages:R}),(0,u.jsx)("div",{className:"woocommerce-search-list__search",children:"text"===_?(0,u.jsx)(l.TextControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,label:R.search,type:"search",value:f,onChange:e=>x(e)}):(0,u.jsx)(l.FormTokenField,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,disabled:s,label:R.search,onChange:I,onInputChange:e=>x(e),suggestions:[],__experimentalValidateInput:()=>!1,value:s?[(0,n.__)("Loading…","woocommerce")]:v.map(e=>({...e,value:e.name})),__experimentalShowHowTo:!1})}),s?(0,u.jsx)("div",{className:"woocommerce-search-list__list",children:(0,u.jsx)(l.Spinner,{})}):(0,u.jsx)(A,{...e,search:f,filteredList:S,messages:R,onSelect:C,instanceId:j,useExpandedPanelId:y})]})},E=((0,l.withSpokenMessages)(M),e=>t=>{let{selected:o}=t;o=void 0===o?null:o;const r=null===o;return Array.isArray(o)?(0,u.jsx)(e,{...t}):(0,u.jsx)(e,{...t,selected:r?[]:[o]})}),D=window.wc.wcSettings,B=(0,D.getSetting)("wcBlocksConfig",{pluginUrl:"",productCount:0,defaultAvatar:"",restApiRoutes:{},wordCountType:"words"}),H=(B.pluginUrl,B.pluginUrl,D.STORE_PAGES.shop,D.STORE_PAGES.checkout,D.STORE_PAGES.checkout,D.STORE_PAGES.privacy,D.STORE_PAGES.privacy,D.STORE_PAGES.terms,D.STORE_PAGES.terms,D.STORE_PAGES.cart,D.STORE_PAGES.cart,D.STORE_PAGES.myaccount?.permalink?D.STORE_PAGES.myaccount.permalink:(0,D.getSetting)("wpLoginUrl","/wp-login.php"),(0,D.getSetting)("localPickupEnabled",!1),(0,D.getSetting)("shippingMethodsExist",!1),(0,D.getSetting)("shippingEnabled",!0),(0,D.getSettingWithCoercion)("countries",{},S.isObject)),V=(0,D.getSetting)("countryData",{}),$={...Object.fromEntries(Object.keys(V).filter(e=>!0===V[e].allowBilling).map(e=>{const t=H[e];return[e,(0,S.isString)(t)?t:""]})),...Object.fromEntries(Object.keys(V).filter(e=>!0===V[e].allowShipping).map(e=>{const t=H[e];return[e,(0,S.isString)(t)?t:""]}))},F=(Object.fromEntries(Object.keys($).map(e=>[e,V[e].states||{}])),Object.fromEntries(Object.keys($).map(e=>[e,V[e].locale||{}])),{address:["first_name","last_name","company","address_1","address_2","city","postcode","country","state","phone"],contact:["email"],order:[]}),G=((0,D.getSetting)("addressFieldsLocations",F).address,(0,D.getSetting)("addressFieldsLocations",F).contact,(0,D.getSetting)("addressFieldsLocations",F).order,(0,D.getSetting)("additionalOrderFields",{}),(0,D.getSetting)("additionalContactFields",{}),(0,D.getSetting)("additionalAddressFields",{}),window.wp.url),z=window.wp.apiFetch;var U=o.n(z);const W=({selected:e=[],search:t="",queryArgs:o={}})=>{const r=(({selected:e=[],search:t="",queryArgs:o={}})=>{const r=B.productCount>100&&e.length>0,s=[(0,G.addQueryArgs)("/wc/store/v1/products",{per_page:100,catalog_visibility:"any",search:t,orderby:"title",order:"asc",exclude:r?e:[],...o})];if(r){const t=Math.ceil(e.length/100);for(let o=1;o<=t;o++)s.push((0,G.addQueryArgs)("/wc/store/v1/products",{catalog_visibility:"any",include:e,per_page:100,page:o}))}return s})({selected:e,search:t,queryArgs:o});return Promise.all(r.map(e=>U()({path:e}))).then(e=>[...new Map(e.flatMap(e=>e.map(e=>[e.id,{...e,parent:0}]))).values()])};var J=o(64347);const q=async e=>{if(!("json"in e))return{code:e.code||"",message:e.message,type:e.type||"general"};try{const t=await e.json();return{code:t.code||"",message:t.message,type:t.type||"api"}}catch(e){return{message:e.message,type:"general"}}};var Q=o(20923),K=o.n(Q);const Y=(0,N.createHigherOrderComponent)(e=>{class t extends d.Component{state={error:null,loading:!1,variations:{},totalVariations:{}};componentDidMount(){const{selected:e,showVariations:t}=this.props;e&&t&&this.loadVariations()}componentDidUpdate(e){const{isLoading:t,selected:o,showVariations:r}=this.props;r&&(!K()(e.selected,o)||e.isLoading&&!t)&&this.loadVariations()}loadVariations=({offset:e=0}={})=>{const{products:t}=this.props,{loading:o,variations:r,totalVariations:s}=this.state;if(o)return;const i=this.getExpandedProduct();if(!i)return;if(!e&&r?.[i])return;if(r?.[i]&&s?.[i]&&r[i].length>=s[i])return;const n=t.find(e=>e.id===i);if(!n?.variations||0===n.variations.length)return void this.setState({variations:{...this.state.variations,[i]:null},loading:!1,error:null});this.setState({loading:!0});const a=this.state.variations[i]||[];((e,t={})=>U()({path:(0,G.addQueryArgs)("wc/store/v1/products",{type:"variation",parent:e,orderby:"title",per_page:25,...t}),parse:!1}).then(e=>e.json().then(t=>{const o=e.headers.get("x-wp-total");return{variations:t,total:o?Number(o):null}})))(i,{offset:e}).then(({variations:e,total:t})=>{const o=e.map(e=>({...e,parent:i}));this.setState({variations:{...this.state.variations,[i]:[...a,...o]},totalVariations:{...this.state.totalVariations,[i]:t},loading:!1,error:null})}).catch(async e=>{const t=await q(e);this.setState({variations:{...this.state.variations,[i]:null},totalVariations:{...this.state.totalVariations,[i]:null},loading:!1,error:t})})};isProductId(e){const{products:t}=this.props;return t.some(t=>t.id===e)}findParentProduct(e){const{products:t}=this.props,o=t.filter(t=>t.variations&&t.variations.find(({id:t})=>t===e));return o[0]?.id}getExpandedProduct(){const{isLoading:e,selected:t,showVariations:o}=this.props;if(!o)return null;let r=t&&t.length?t[0]:null;return r?this.prevSelectedItem=r:!this.prevSelectedItem||e||this.isProductId(this.prevSelectedItem)||(r=this.prevSelectedItem),!e&&r?this.isProductId(r)?r:this.findParentProduct(r):null}render(){const{error:t,isLoading:o}=this.props,{error:r,loading:s,variations:i,totalVariations:n}=this.state,a=this.getExpandedProduct(),c=a&&i[a]?.length||0;return(0,u.jsx)(e,{...this.props,error:r||t,onLoadMoreVariations:()=>this.loadVariations({offset:c}),expandedProduct:this.getExpandedProduct(),isLoading:o,totalVariations:n,variations:i,variationsLoading:s})}}return t},"withProductVariations"),X=e=>{const{id:t,name:o,parent:r}=e;return{id:t,name:o,parent:r,breadcrumbs:[],children:[],details:e,value:e.slug}},Z=window.wp.escapeHtml,ee=({message:e,type:t})=>e?"general"===t?(0,u.jsxs)("span",{children:[(0,n.__)("The following error was returned","woocommerce"),(0,u.jsx)("br",{}),(0,u.jsx)("code",{children:(0,Z.escapeHTML)(e)})]}):"api"===t?(0,u.jsxs)("span",{children:[(0,n.__)("The following error was returned from the API","woocommerce"),(0,u.jsx)("br",{}),(0,u.jsx)("code",{children:(0,Z.escapeHTML)(e)})]}):e:(0,n.__)("An error has prevented the block from being updated.","woocommerce"),te=({error:e})=>(0,u.jsx)("div",{className:"wc-block-error-message",children:ee(e)});var oe=o(51609);const re=({className:e,item:t,isSelected:o,isLoading:r,onSelect:s,disabled:i,...n})=>(0,u.jsxs)(u.Fragment,{children:[(0,oe.createElement)(j,{...n,key:t.id,...e&&{className:e},isSelected:o,item:t,onSelect:s,...i&&{disabled:i}}),o&&r&&(0,u.jsx)("div",{className:(0,c.A)("woocommerce-search-list__item","woocommerce-product-attributes__item","depth-1","is-loading","is-not-active"),children:(0,u.jsx)(l.Spinner,{})},"loading")]});o(20415);const se={list:(0,n.__)("Products","woocommerce"),noItems:(0,n.__)("Your store doesn't have any products.","woocommerce"),search:(0,n.__)("Search for a product to display","woocommerce"),updated:(0,n.__)("Product search results updated.","woocommerce")},ie=E((ne=Y((0,N.withInstanceId)(e=>{const{expandedProduct:t=null,error:o,instanceId:r,isCompact:s=!1,isLoading:i,onChange:a,onLoadMoreVariations:l,totalVariations:d,onSearch:m,products:h,renderItem:w,selected:g=[],showVariations:v=!1,variations:_,variationsLoading:b}=e;if(o)return(0,u.jsx)(te,{error:o});const f=[...h,..._&&t&&_[t]?_[t]:[]].map(X);return(0,u.jsx)(M,{className:"woocommerce-products",list:f,isCompact:s,isLoading:i,isSingle:!0,selected:f.filter(({id:e})=>g.includes(Number(e))),onChange:a,loadMoreChildrenText:v?(0,n.__)("Load more variations","woocommerce"):void 0,onLoadMoreChildren:v?l:void 0,totalChildren:v?d:void 0,renderItem:w||(v?e=>{const{item:t,search:o,depth:s=0,isSelected:a,onSelect:l,useExpandedPanelId:d}=e,[m,h]=d??[null,()=>{}],w=p(t,m),g=t.details?.variations&&Array.isArray(t.details.variations)?t.details.variations.length:0,v=(0,c.A)("woocommerce-search-product__item","woocommerce-search-list__item",`depth-${s}`,"has-count",{"is-searching":o.length>0,"is-skip-level":0===s&&0!==t.parent,"is-variable":g>0});if(!t.breadcrumbs.length){const o=t.details?.variations&&t.details.variations.length>0;return(0,u.jsx)(re,{...e,className:(0,c.A)(v,{"is-selected":a}),isSelected:a,item:t,onSelect:()=>()=>{l(t)(),w||h(t.id)},isLoading:i||b,countLabel:o?(0,n.sprintf)(/* translators: %1$d is the number of variations of a product product. */ /* translators: %1$d is the number of variations of a product product. */ (0,n.__)("%1$d variations","woocommerce"),t.details?.variations.length):null,name:`products-${r}`,"aria-label":o?(0,n.sprintf)(/* translators: %1$s is the product name, %2$d is the number of variations of that product. */ /* translators: %1$s is the product name, %2$d is the number of variations of that product. */ (0,n._n)("%1$s, has %2$d variation","%1$s, has %2$d variations",t.details?.variations?.length,"woocommerce"),t.name,t.details?.variations.length):void 0})}const _=(0,S.isEmpty)(t.details?.variation)?e:{...e,item:{...e.item,name:t.details?.variation},"aria-label":`${t.breadcrumbs[0]}: ${t.details?.variation}`};return(0,u.jsx)(j,{..._,className:v,name:`variations-${r}`})}:void 0),onSearch:m,messages:{...se,...e.messages},isHierarchical:!0})})),({selected:e,...t})=>{const[o,r]=(0,d.useState)(!0),[s,i]=(0,d.useState)(null),[n,a]=(0,d.useState)([]),c=B.productCount>100,l=async e=>{const t=await q(e);i(t),r(!1)},m=(0,d.useRef)(e);(0,d.useEffect)(()=>{W({selected:m.current}).then(e=>{a(e),r(!1)}).catch(l)},[m]);const h=(0,J.YQ)(t=>{W({selected:e,search:t}).then(e=>{a(e),r(!1)}).catch(l)},400),w=(0,d.useCallback)(e=>{r(!0),h(e)},[r,h]);return(0,u.jsx)(ne,{...t,selected:e,error:s,products:n,isLoading:o,onSearch:c?w:null})}));var ne,ae=o(62748);o(63120);const ce=({className:e="",error:t,isLoading:o=!1,onRetry:r})=>(0,u.jsxs)(l.Placeholder,{icon:(0,u.jsx)(s.A,{icon:ae.A}),label:(0,n.__)("Sorry, an error occurred","woocommerce"),className:(0,c.A)("wc-block-api-error",e),children:[(0,u.jsx)(te,{error:t}),r&&(0,u.jsx)(u.Fragment,{children:o?(0,u.jsx)(l.Spinner,{}):(0,u.jsx)(l.Button,{variant:"secondary",onClick:r,children:(0,n.__)("Retry","woocommerce")})})]}),le=window.wc.sanitize,de=({label:e,screenReaderLabel:t,wrapperElement:o,wrapperProps:r={},allowHTML:s=!1})=>{let i;const n=null!=e,a=null!=t;return!n&&a?(i=o||"span",r={...r,className:(0,c.A)(r.className,"screen-reader-text")},(0,u.jsx)(i,{...r,children:t})):(i=o||d.Fragment,n&&a&&e!==t?(0,u.jsxs)(i,{...r,children:[s?(0,u.jsx)(d.RawHTML,{children:(0,le.sanitizeHTML)(e,{tags:["b","em","i","strong","p","br","span"],attr:["style"]})}):(0,u.jsx)("span",{"aria-hidden":"true",children:e}),(0,u.jsx)("span",{className:"screen-reader-text",children:t})]}):(0,u.jsx)(i,{...r,children:e}))};o(16919);const me=({onClick:e,label:t=(0,n.__)("Load more","woocommerce"),screenReaderLabel:o=(0,n.__)("Load more","woocommerce")})=>(0,u.jsx)("div",{className:"wp-block-button wc-block-load-more wc-block-components-load-more",children:(0,u.jsx)("button",{className:"wp-block-button__link",onClick:e,children:(0,u.jsx)(de,{label:t,screenReaderLabel:o})})}),he=window.wc.blocksComponents;o(56878);const ue=({onChange:e,readOnly:t,value:o})=>(0,u.jsx)(he.SortSelect,{className:"wc-block-review-sort-select wc-block-components-review-sort-select",label:(0,n.__)("Order by","woocommerce"),onChange:e,options:[{key:"most-recent",label:(0,n.__)("Most recent","woocommerce")},{key:"highest-rating",label:(0,n.__)("Highest rating","woocommerce")},{key:"lowest-rating",label:(0,n.__)("Lowest rating","woocommerce")}],readOnly:t,screenReaderLabel:(0,n.__)("Order reviews by","woocommerce"),value:o});function we(e){let t,o,r,s=[];for(let i=0;i<e.length;i++)t=e.substring(i),o=t.match(/^&[a-z0-9#]+;/),o?(r=o[0],s.push(r),i+=r.length-1):s.push(e[i]);return s}const pe=(e,t,o="...")=>{const r=function(e,t){const o=(t=t||{}).limit||100,r=void 0===t.preserveTags||t.preserveTags,s=void 0!==t.wordBreak&&t.wordBreak,i=t.suffix||"...",n=t.moreLink||"",a=t.moreText||"»",c=t.preserveWhiteSpace||!1,l=e.replace(/</g,"\n<").replace(/>/g,">\n").replace(/\n\n/g,"\n").replace(/^\n/g,"").replace(/\n$/g,"").split("\n");let d,m,h,u,w,p,g=0,v=[],_=!1;for(let e=0;e<l.length;e++){if(d=l[e],u=c?d:d.replace(/[ ]+/g," "),!d.length)continue;const t=we(u);if("<"!==d[0])if(g>=o)d="";else if(g+t.length>=o){if(m=o-g," "===t[m-1])for(;m&&(m-=1," "===t[m-1]););else h=t.slice(m).indexOf(" "),s||(-1!==h?m+=h:m=d.length);if(d=t.slice(0,m).join("")+i,n){const e=document.createElement("a");e.href=n,e.style.display="inline",e.textContent=a,d+=e.outerHTML}g=o,_=!0}else g+=t.length;else if(r){if(g>=o)if(w=d.match(/[a-zA-Z]+/),p=w?w[0]:"",p)if("</"!==d.substring(0,2))v.push(p),d="";else{for(;v[v.length-1]!==p&&v.length;)v.pop();v.length&&(d=""),v.pop()}else d=""}else d="";l[e]=d}return{html:l.join("\n").replace(/\n/g,""),more:_}}(e,{suffix:o,limit:t});return r.html},ge=(e,t,o)=>(t<=o?e.start=e.middle+1:e.end=e.middle-1,e),ve=(e,t,o,r)=>{const s=((e,t,o)=>{let r={start:0,middle:0,end:e.length};for(;r.start<=r.end;)r.middle=Math.floor((r.start+r.end)/2),t.innerHTML=pe(e,r.middle),r=ge(r,t.clientHeight,o);return r.middle})(e,t,o);return pe(e,s-r.length,r)},_e={className:"read-more-content",ellipsis:"…",lessText:(0,n.__)("Read less","woocommerce"),maxLines:3,moreText:(0,n.__)("Read more","woocommerce")};class be extends d.Component{static defaultProps=_e;constructor(e){super(e),this.state={isExpanded:!1,clampEnabled:null,content:e.children,summary:"."},this.reviewContent=(0,d.createRef)(),this.reviewSummary=(0,d.createRef)(),this.getButton=this.getButton.bind(this),this.onClick=this.onClick.bind(this)}componentDidMount(){this.setSummary()}componentDidUpdate(e){e.maxLines===this.props.maxLines&&e.children===this.props.children||this.setState({clampEnabled:null,summary:"."},this.setSummary)}setSummary(){if(this.props.children){const{maxLines:e,ellipsis:t}=this.props;if(!this.reviewSummary.current||!this.reviewContent.current)return;const o=(this.reviewSummary.current.clientHeight+1)*e+1,r=this.reviewContent.current.clientHeight+1>o;this.setState({clampEnabled:r}),r&&this.setState({summary:ve(this.reviewContent.current.innerHTML,this.reviewSummary.current,o,t)})}}getButton(){const{isExpanded:e}=this.state,{className:t,lessText:o,moreText:r}=this.props,s=e?o:r;if(s)return(0,u.jsx)("a",{href:"#more",className:t+"__read_more",onClick:this.onClick,"aria-expanded":!e,role:"button",children:s})}onClick(e){e.preventDefault();const{isExpanded:t}=this.state;this.setState({isExpanded:!t})}render(){const{className:e}=this.props,{content:t,summary:o,clampEnabled:r,isExpanded:s}=this.state;return t?!1===r?(0,u.jsx)("div",{className:e,children:(0,u.jsx)("div",{ref:this.reviewContent,children:t})}):(0,u.jsxs)("div",{className:e,children:[(!s||null===r)&&(0,u.jsx)("div",{ref:this.reviewSummary,"aria-hidden":s,dangerouslySetInnerHTML:{__html:o}}),(s||null===r)&&(0,u.jsx)("div",{ref:this.reviewContent,"aria-hidden":!s,children:t}),this.getButton()]}):null}}const fe=be;function xe(e,t,o){return o||!e?(0,u.jsx)("div",{className:"wc-block-review-list-item__image wc-block-components-review-list-item__image"}):(0,u.jsxs)("div",{className:"wc-block-review-list-item__image wc-block-components-review-list-item__image",children:["product"===t?(0,u.jsx)("img",{"aria-hidden":"true",alt:e.product_image?.alt||"",src:e.product_image?.thumbnail||""}):(0,u.jsx)("img",{"aria-hidden":"true",alt:"",src:e.reviewer_avatar_urls[96]||""}),e.verified&&(0,u.jsx)("div",{className:"wc-block-review-list-item__verified wc-block-components-review-list-item__verified",title:(0,n.__)("Verified buyer","woocommerce"),children:(0,n.__)("Verified buyer","woocommerce")})]})}function ye(e){return(0,u.jsx)(fe,{maxLines:10,moreText:(0,n.__)("Read full review","woocommerce"),lessText:(0,n.__)("Hide full review","woocommerce"),className:"wc-block-review-list-item__text wc-block-components-review-list-item__text",children:(0,u.jsx)("div",{dangerouslySetInnerHTML:{__html:e.review||""}})})}function je(e,t){return(0,u.jsx)("div",{className:"wc-block-review-list-item__product wc-block-components-review-list-item__product",children:(0,u.jsx)("a",{href:e.product_permalink,"aria-labelledby":t,children:(0,h.decodeEntities)(e.product_name)})})}function Re(e){const{reviewer:t=""}=e;return(0,u.jsx)("div",{className:"wc-block-review-list-item__author wc-block-components-review-list-item__author",children:t})}function Se(e){const{date_created:t,formatted_date_created:o}=e;return(0,u.jsx)("time",{className:"wc-block-review-list-item__published-date wc-block-components-review-list-item__published-date",dateTime:t,children:o})}function ke(e,t){const{rating:o}=e,r={width:o/5*100+"%"},s=(0,n.sprintf)(/* translators: %f is referring to the average rating value */ /* translators: %f is referring to the average rating value */ (0,n.__)("Rated %f out of 5","woocommerce"),o),i={__html:(0,n.sprintf)(/* translators: %s is referring to the average rating value */ /* translators: %s is referring to the average rating value */ (0,n.__)("Rated %s out of 5","woocommerce"),(0,n.sprintf)('<strong class="rating">%f</strong>',o))};return(0,u.jsx)("div",{id:t,"aria-label":`${(0,h.decodeEntities)(e.product_name)} ${s}`,className:"wc-block-review-list-item__rating wc-block-components-review-list-item__rating",children:(0,u.jsx)("div",{"aria-hidden":"true",className:`wc-block-review-list-item__rating__stars wc-block-components-review-list-item__rating__stars wc-block-review-list-item__rating__stars--${o}`,role:"img",children:(0,u.jsx)("span",{style:r,dangerouslySetInnerHTML:i})})})}o(47313);const Ne=({attributes:e,review:t={}})=>{const{imageType:o,showReviewDate:r,showReviewerName:s,showReviewImage:i,showReviewRating:n,showReviewContent:a,showProductName:l}=e,{rating:m}=t,h=!(Object.keys(t).length>0),w=Number.isFinite(m)&&n,p=(0,d.useId)();return(0,u.jsxs)("li",{className:(0,c.A)("wc-block-review-list-item__item","wc-block-components-review-list-item__item",{"is-loading":h,"wc-block-components-review-list-item__item--has-image":i}),"aria-hidden":h,children:[(l||r||s||i||w)&&(0,u.jsxs)("div",{className:"wc-block-review-list-item__info wc-block-components-review-list-item__info",children:[i&&xe(t,o,h),(l||s||w||r)&&(0,u.jsxs)("div",{className:"wc-block-review-list-item__meta wc-block-components-review-list-item__meta",children:[w&&ke(t,p),l&&je(t,p),s&&Re(t),r&&Se(t)]})]}),a&&ye(t)]})};o(95183);const Ce=({attributes:e,reviews:t})=>{const o=(0,D.getSetting)("showAvatars",!0),r=(0,D.getSetting)("reviewRatingsEnabled",!0),s=(o||"product"===e.imageType)&&e.showReviewImage,i=r&&e.showReviewRating,n={...e,showReviewImage:s,showReviewRating:i};return(0,u.jsx)("ul",{className:"wc-block-review-list wc-block-components-review-list",children:0===t.length?(0,u.jsx)(Ne,{attributes:n}):t.map((e,t)=>(0,u.jsx)(Ne,{attributes:n,review:e},e.id??`review-placeholder-${t}`))})},Ie=e=>{const{className:t,categoryIds:o,productId:r,showReviewDate:s,showReviewerName:i,showReviewContent:n,showProductName:a,showReviewImage:l,showReviewRating:d}=e;let m="wc-block-all-reviews";return r&&(m="wc-block-reviews-by-product"),Array.isArray(o)&&(m="wc-block-reviews-by-category"),(0,c.A)(m,t,{"has-image":l,"has-name":i,"has-date":s,"has-rating":d,"has-content":n,"has-product-name":a})},Pe=e=>{const{categoryIds:t,imageType:o,offset:r,orderby:s,productId:i,reviewsOnPageLoad:n,reviewsOnLoadMore:a,showLoadMore:c,showOrderby:l}=e,d={"data-image-type":o,"data-orderby":s,"data-reviews-on-page-load":n,"data-reviews-on-load-more":a,"data-show-load-more":c,"data-show-orderby":l},m=Number(r);return Number.isInteger(m)&&m>0&&(d["data-offset"]=m),i&&(d["data-product-id"]=i),Array.isArray(t)&&(d["data-category-ids"]=t.join(",")),d};class Le extends d.Component{render(){const{attributes:e,error:t,hasReviewsHiddenByOffset:o,isLoading:r,noReviewsPlaceholder:s,reviews:i,totalReviews:a}=this.props;if(t)return(0,u.jsx)(ce,{className:"wc-block-featured-product-error",error:t,isLoading:r});if(0===i.length&&!r)return(0,u.jsx)(s,{attributes:e,reason:o?"offset":"no-reviews"});const c=(0,D.getSetting)("reviewRatingsEnabled",!0);return(0,u.jsxs)(l.Disabled,{children:[e.showOrderby&&c&&(0,u.jsx)(ue,{readOnly:!0,value:e.orderby,onChange:()=>null}),(0,u.jsx)(Ce,{attributes:e,reviews:i}),e.showLoadMore&&a>i.length&&(0,u.jsx)(me,{screenReaderLabel:(0,n.__)("Load more reviews","woocommerce"),onClick:()=>null})]})}}const Oe=(e=>{class t extends d.Component{isPreview=!!this.props.attributes.previewReviews;delayedAppendReviews=(this.props.delayFunction??(e=>e))(this.appendReviews);isMounted=!1;state={error:null,hasReviewsHiddenByOffset:!1,loading:!0,reviews:this.isPreview&&this.props.attributes?.previewReviews?this.props.attributes.previewReviews:[],totalReviews:this.isPreview&&this.props.attributes?.previewReviews?this.props.attributes.previewReviews.length:0};componentDidMount(){this.isMounted=!0,this.replaceReviews()}componentDidUpdate(e){this.shouldReplaceReviews(e,this.props)?this.replaceReviews():e.reviewsToDisplay<this.props.reviewsToDisplay&&this.delayedAppendReviews()}shouldReplaceReviews(e,t){return e.orderby!==t.orderby||e.order!==t.order||this.getOffset(e)!==this.getOffset(t)||e.productId!==t.productId||!K()(e.categoryIds,t.categoryIds)}componentWillUnmount(){this.isMounted=!1,"cancel"in this.delayedAppendReviews&&"function"==typeof this.delayedAppendReviews.cancel&&this.delayedAppendReviews.cancel()}getOffset(e=this.props){const t=Number(e.offset??0);return Number.isInteger(t)&&t>=0?t:0}getArgs(e){const{categoryIds:t,order:o,orderby:r,productId:s,reviewsToDisplay:i}=this.props,n={order:o,orderby:r,per_page:i-e,offset:this.getOffset()+e};if(t){const e=Array.isArray(t)?t:JSON.parse(t);n.category_id=Array.isArray(e)?e.join(","):e}return s&&(n.product_id=s),n}replaceReviews(){if(this.isPreview)return;const e=this.props.onReviewsReplaced??(()=>{});this.updateListOfReviews().then(e)}appendReviews(){if(this.isPreview)return;const e=this.props.onReviewsAppended??(()=>{}),{reviewsToDisplay:t}=this.props,{reviews:o}=this.state;t<=o.length||this.updateListOfReviews(o).then(e)}updateListOfReviews(e=[]){const{reviewsToDisplay:t}=this.props,{totalReviews:o}=this.state,r=this.getOffset(),s=Math.min(o,t)-e.length;return this.setState({loading:!0,reviews:e.concat(Array(s).fill({}))}),(i=this.getArgs(e.length),U()({path:"/wc/store/v1/products/reviews?"+Object.entries(i).map(e=>e.join("=")).join("&"),parse:!1}).then(e=>e.json().then(t=>({reviews:t,totalReviews:parseInt(e.headers.get("x-wp-total"),10)})))).then(({reviews:t,totalReviews:o})=>{const s=Math.max(o-r,0);return this.isMounted&&this.setState({hasReviewsHiddenByOffset:r>0&&o>0&&0===s,reviews:e.filter(e=>Object.keys(e).length).concat(t),totalReviews:s,loading:!1,error:null}),{newReviews:t}}).catch(this.setError);var i}setError=async e=>{if(!this.isMounted)return;const t=this.props.onReviewsLoadError??(()=>{}),o=await q(e);this.setState({reviews:[],loading:!1,error:o}),t(o)};render(){const{reviewsToDisplay:t}=this.props,{error:o,hasReviewsHiddenByOffset:r,loading:s,reviews:i,totalReviews:n}=this.state;return(0,u.jsx)(e,{...this.props,error:o,hasReviewsHiddenByOffset:r,isLoading:s,reviews:i.slice(0,t),totalReviews:n})}}const{displayName:o=e.name||"Component"}=e;return t.displayName=`WithReviews(${o})`,t})(Le),Te=({attributes:e,icon:t,name:o,noReviewsPlaceholder:r})=>{const{categoryIds:s,productId:i,reviewsOnPageLoad:a,showProductName:c,showReviewDate:d,showReviewerName:m,showReviewContent:h,showReviewImage:w,showReviewRating:p}=e,{order:g,orderby:v}=(e=>{if((0,D.getSetting)("reviewRatingsEnabled",!0)){if("lowest-rating"===e)return{order:"asc",orderby:"rating"};if("highest-rating"===e)return{order:"desc",orderby:"rating"}}return{order:"desc",orderby:"date_gmt"}})(e.orderby);return h||p||d||m||w||c?(0,u.jsx)(u.Fragment,{children:(0,u.jsx)(Oe,{attributes:e,categoryIds:s,delayFunction:e=>(e=>{let t,o=null;const r=(...r)=>{o=r,t&&clearTimeout(t),t=setTimeout(()=>{t=null,o&&e(...o)},400)};return r.flush=()=>{t&&o&&(e(...o),clearTimeout(t),t=null)},r.clear=()=>{t&&clearTimeout(t),t=null},r})(e),noReviewsPlaceholder:r,offset:e.offset??0,orderby:v,order:g,productId:i,reviewsToDisplay:a})}):(0,u.jsx)(l.Placeholder,{icon:t,label:o,children:(0,n.__)("The content for this block is hidden due to block settings.","woocommerce")})},Ae=(0,N.createHigherOrderComponent)(e=>class extends d.Component{state={error:null,loading:!1,product:"preview"===this.props.attributes.productId?this.props.attributes.previewProduct:null};componentDidMount(){this.loadProduct()}componentDidUpdate(e){e.attributes.productId!==this.props.attributes.productId&&this.loadProduct()}loadProduct=()=>{const{productId:e}=this.props.attributes;"preview"!==e&&(e?(this.setState({loading:!0}),(e=>U()({path:`/wc/store/v1/products/${e}`}))(e).then(e=>{this.setState({product:e,loading:!1,error:null})}).catch(async e=>{const t=await q(e);this.setState({product:null,loading:!1,error:t})})):this.setState({product:null,loading:!1,error:null}))};render(){const{error:t,loading:o,product:r}=this.state;return(0,u.jsx)(e,{...this.props,error:t,getProduct:this.loadProduct,isLoading:o,product:r})}},"withProduct")(({error:e,getProduct:t,isLoading:o,product:r,reason:a})=>{if(e)return(0,u.jsx)(ce,{className:"wc-block-featured-product-error",error:e,isLoading:o,onRetry:t});let c="offset"===a?(0,n.__)("No reviews are visible with the current offset. Reduce the offset to display reviews.","woocommerce"):void 0;return c||(c=!r||o?(0,u.jsx)(l.Spinner,{}):(0,n.sprintf)(/* translators: %s is the product name. */ /* translators: %s is the product name. */ (0,n.__)("This block lists reviews for a selected product. %s doesn't have any reviews yet, but they will show up here when it does.","woocommerce"),(0,h.decodeEntities)(r.name))),(0,u.jsx)(l.Placeholder,{className:"wc-block-reviews-by-product",icon:(0,u.jsx)(s.A,{icon:i.A,className:"block-editor-block-icon"}),label:(0,n.__)("Reviews by Product","woocommerce"),children:c})}),Me=e=>{const t=Number.parseInt(e,10),o=Number.isNaN(t)?10:t;return Math.max(1,Math.min(20,o))},Ee=(e,t,o)=>(0,u.jsx)(a.BlockControls,{children:(0,u.jsx)(l.ToolbarGroup,{controls:[{icon:"edit",title:o,onClick:()=>t({editMode:!e}),isActive:e}]})}),De=(e,t)=>{const o=(0,D.getSetting)("showAvatars",!0),r=(0,D.getSetting)("reviewRatingsEnabled",!0);return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(l.__experimentalToolsPanelItem,{hasValue:()=>!e.showReviewRating,label:(0,n.__)("Product rating","woocommerce"),onDeselect:()=>t({showReviewRating:!0}),isShownByDefault:!0,children:(0,u.jsxs)("div",{className:"wc-block-reviews__tools-panel-item-container",children:[(0,u.jsx)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,n.__)("Product rating","woocommerce"),checked:e.showReviewRating,onChange:()=>t({showReviewRating:!e.showReviewRating})}),e.showReviewRating&&!r&&(0,u.jsx)(l.Notice,{className:"wc-block-base-control-notice",isDismissible:!1,children:(0,d.createInterpolateElement)((0,n.__)("Product rating is disabled in your <a>store settings</a>.","woocommerce"),{a:(0,u.jsx)("a",{href:(0,D.getAdminLink)("admin.php?page=wc-settings&tab=products"),target:"_blank",rel:"noopener noreferrer"})})})]})}),(0,u.jsx)(l.__experimentalToolsPanelItem,{hasValue:()=>!e.showReviewerName,label:(0,n.__)("Reviewer name","woocommerce"),onDeselect:()=>t({showReviewerName:!0}),isShownByDefault:!0,children:(0,u.jsx)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,n.__)("Reviewer name","woocommerce"),checked:e.showReviewerName,onChange:()=>t({showReviewerName:!e.showReviewerName})})}),(0,u.jsx)(l.__experimentalToolsPanelItem,{hasValue:()=>!e.showReviewDate,label:(0,n.__)("Review date","woocommerce"),onDeselect:()=>t({showReviewDate:!0}),isShownByDefault:!0,children:(0,u.jsx)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,n.__)("Review date","woocommerce"),checked:e.showReviewDate,onChange:()=>t({showReviewDate:!e.showReviewDate})})}),(0,u.jsx)(l.__experimentalToolsPanelItem,{hasValue:()=>!e.showReviewContent,label:(0,n.__)("Review content","woocommerce"),onDeselect:()=>t({showReviewContent:!0}),isShownByDefault:!0,children:(0,u.jsx)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,n.__)("Review content","woocommerce"),checked:e.showReviewContent,onChange:()=>t({showReviewContent:!e.showReviewContent})})}),(0,u.jsx)(l.__experimentalToolsPanelItem,{hasValue:()=>!e.showReviewImage||"reviewer"!==e.imageType,label:(0,n.__)("Image","woocommerce"),onDeselect:()=>t({showReviewImage:!0,imageType:"reviewer"}),isShownByDefault:!0,children:(0,u.jsxs)("div",{className:"wc-block-reviews__tools-panel-item-container",children:[(0,u.jsx)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,n.__)("Image","woocommerce"),checked:e.showReviewImage,onChange:()=>t({showReviewImage:!e.showReviewImage})}),e.showReviewImage&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(l.__experimentalToggleGroupControl,{label:(0,n.__)("Review image","woocommerce"),isBlock:!0,value:e.imageType,onChange:e=>t({imageType:e}),children:[(0,u.jsx)(l.__experimentalToggleGroupControlOption,{value:"reviewer",label:(0,n.__)("Reviewer photo","woocommerce")}),(0,u.jsx)(l.__experimentalToggleGroupControlOption,{value:"product",label:(0,n.__)("Product","woocommerce")})]}),"reviewer"===e.imageType&&!o&&(0,u.jsx)(l.Notice,{className:"wc-block-base-control-notice",isDismissible:!1,children:(0,d.createInterpolateElement)((0,n.__)("Reviewer photo is disabled in your <a>site settings</a>.","woocommerce"),{a:(0,u.jsx)("a",{href:(0,D.getAdminLink)("options-discussion.php"),target:"_blank",rel:"noopener noreferrer"})})})]})]})})]})},Be=(e,t,{showOffset:o=!1}={})=>(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(l.__experimentalToolsPanelItem,{hasValue:()=>"most-recent"!==e.orderby,label:(0,n.__)("Default sort order","woocommerce"),onDeselect:()=>t({orderby:"most-recent"}),isShownByDefault:!0,children:(0,u.jsx)(l.SelectControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,label:(0,n.__)("Default sort order","woocommerce"),value:e.orderby,options:[{label:(0,n.__)("Most recent","woocommerce"),value:"most-recent"},{label:(0,n.__)("Highest rating","woocommerce"),value:"highest-rating"},{label:(0,n.__)("Lowest rating","woocommerce"),value:"lowest-rating"}],onChange:e=>t({orderby:e})})}),(0,u.jsx)(l.__experimentalToolsPanelItem,{hasValue:()=>!e.showOrderby,label:(0,n.__)('Show "Order by" dropdown',"woocommerce"),onDeselect:()=>t({showOrderby:!0}),isShownByDefault:!0,children:(0,u.jsx)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,n.__)('Show "Order by" dropdown',"woocommerce"),checked:e.showOrderby,onChange:()=>t({showOrderby:!e.showOrderby})})}),(0,u.jsx)(l.__experimentalToolsPanelItem,{hasValue:()=>10!==e.reviewsOnPageLoad,label:(0,n.__)("Number of reviews","woocommerce"),onDeselect:()=>t({reviewsOnPageLoad:10}),isShownByDefault:!0,children:(0,u.jsx)(l.__experimentalInputControl,{__next40pxDefaultSize:!0,label:(0,n.__)("Number of reviews","woocommerce"),value:String(e.reviewsOnPageLoad),onChange:e=>{t({reviewsOnPageLoad:Me(e)})},type:"number",max:20,min:1,step:1})}),o&&(0,u.jsx)(l.__experimentalToolsPanelItem,{hasValue:()=>0!==(e.offset??0),label:(0,n.__)("Offset","woocommerce"),onDeselect:()=>t({offset:0}),isShownByDefault:!0,children:(0,u.jsx)(l.__experimentalNumberControl,{__next40pxDefaultSize:!0,__unstableStateReducer:e=>Object.is(Number(e.value),-0)?{...e,value:String(0)}:e,label:(0,n.__)("Offset","woocommerce"),help:(0,n.__)("Number of reviews to skip","woocommerce"),value:e.offset??0,onChange:e=>{if(""===e)return;const o=Number(e);!Number.isInteger(o)||o<0||t({offset:o})},min:0,step:1})}),(0,u.jsx)(l.__experimentalToolsPanelItem,{hasValue:()=>!e.showLoadMore||10!==e.reviewsOnLoadMore,label:(0,n.__)('Show "Load more" button',"woocommerce"),onDeselect:()=>t({showLoadMore:!0,reviewsOnLoadMore:10}),isShownByDefault:!0,children:(0,u.jsxs)("div",{className:"wc-block-reviews__tools-panel-item-container",children:[(0,u.jsx)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,n.__)('Show "Load more" button',"woocommerce"),checked:e.showLoadMore,onChange:()=>t({showLoadMore:!e.showLoadMore})}),e.showLoadMore&&(0,u.jsx)(l.__experimentalInputControl,{__next40pxDefaultSize:!0,label:(0,n.__)("Load more reviews","woocommerce"),value:String(e.reviewsOnLoadMore),onChange:e=>t({reviewsOnLoadMore:Me(e)}),type:"number",max:20,min:1,step:1})]})})]}),He=(0,l.withSpokenMessages)(({attributes:e,debouncedSpeak:t,setAttributes:o})=>{const{editMode:r,productId:c}=e,d=(0,a.useBlockProps)(),m=e=>{const{item:t=0}=e;return(0,u.jsx)(j,{...e,item:{...t,count:t.details.review_count},countLabel:(0,n.sprintf)(/* translators: %d is the review count. */ /* translators: %d is the review count. */ (0,n._n)("%d review","%d reviews",t.details.review_count,"woocommerce"),t.details.review_count),"aria-label":(0,n.sprintf)(/* translators: %1$s is the item name, and %2$d is the number of reviews for the item. */ /* translators: %1$s is the item name, and %2$d is the number of reviews for the item. */ (0,n._n)("%1$s, has %2$d review","%1$s, has %2$d reviews",t.details.review_count,"woocommerce"),(0,h.decodeEntities)(t.name),t.details.review_count)})};if(!c||r)return(0,u.jsxs)(l.Placeholder,{icon:(0,u.jsx)(s.A,{icon:i.A,className:"block-editor-block-icon"}),label:(0,n.__)("Reviews by Product","woocommerce"),className:"wc-block-reviews-by-product",children:[(0,n.__)("Show reviews of your product to build trust","woocommerce"),(0,u.jsxs)("div",{className:"wc-block-reviews__selection",children:[(0,u.jsx)(ie,{selected:e.productId?[e.productId]:[],onChange:(e=[])=>{const t=e[0]?e[0].id:0;o({productId:t})},queryArgs:{orderby:"comment_count",order:"desc"},renderItem:m}),(0,u.jsx)(l.Button,{variant:"primary",onClick:()=>{o({editMode:!1}),t((0,n.__)("Showing Reviews by Product block preview.","woocommerce"))},children:(0,n.__)("Done","woocommerce")})]})]});const w=(0,n.__)("Edit selected product","woocommerce");return(0,u.jsxs)("div",{...d,children:[Ee(r,o,w),(0,u.jsxs)(a.InspectorControls,{children:[(0,u.jsx)(l.__experimentalToolsPanel,{label:(0,n.__)("Content","woocommerce"),resetAll:()=>o({showReviewRating:!0,showReviewerName:!0,showReviewImage:!0,showReviewDate:!0,showReviewContent:!0,imageType:"reviewer"}),children:De(e,o)}),(0,u.jsx)(l.__experimentalToolsPanel,{label:(0,n.__)("List Settings","woocommerce"),resetAll:()=>o({showOrderby:!0,orderby:"most-recent",reviewsOnPageLoad:10,offset:0,showLoadMore:!0,reviewsOnLoadMore:10}),children:Be(e,o,{showOffset:!0})}),(0,u.jsx)(l.__experimentalToolsPanel,{label:(0,n.__)("Product","woocommerce"),resetAll:()=>o({productId:0}),children:(0,u.jsx)(l.__experimentalToolsPanelItem,{hasValue:()=>!!e.productId,label:(0,n.__)("Product","woocommerce"),onDeselect:()=>o({productId:0}),isShownByDefault:!0,children:(0,u.jsx)(ie,{selected:e.productId?[e.productId]:[],onChange:(e=[])=>{const t=e[0]?e[0].id:0;o({productId:t})},renderItem:m,isCompact:!0})})})]},"inspector"),(0,u.jsx)(Te,{attributes:e,icon:(0,u.jsx)(s.A,{icon:i.A,className:"block-editor-block-icon"}),name:(0,n.__)("Reviews by Product","woocommerce"),noReviewsPlaceholder:Ae})]})}),Ve={attributes:{editMode:!1,imageType:"reviewer",orderby:"most-recent",reviewsOnLoadMore:10,reviewsOnPageLoad:10,showLoadMore:!0,showOrderby:!0,showReviewDate:!0,showReviewerName:!0,showReviewImage:!0,showReviewRating:!0,showReviewContent:!0,previewReviews:[{id:1,date_created:"2019-07-15T17:05:04",formatted_date_created:(0,n.__)("July 15, 2019","woocommerce"),date_created_gmt:"2019-07-15T15:05:04",product_id:0,product_name:(0,n.__)("WordPress Pennant","woocommerce"),product_permalink:"#", /* translators: An example person name used for the block previews. */ reviewer:(0,n.__)("Alice","woocommerce"),review:`<p>${(0,n.__)("I bought this product last week and I'm very happy with it.","woocommerce")}</p>\n`,reviewer_avatar_urls:{48:B.defaultAvatar,96:B.defaultAvatar},rating:5,verified:!0},{id:2,date_created:"2019-07-12T12:39:39",formatted_date_created:(0,n.__)("July 12, 2019","woocommerce"),date_created_gmt:"2019-07-12T10:39:39",product_id:0,product_name:(0,n.__)("WordPress Pennant","woocommerce"),product_permalink:"#", /* translators: An example person name used for the block previews. */ reviewer:(0,n.__)("Bob","woocommerce"),review:`<p>${(0,n.__)("This product is awesome, I love it!","woocommerce")}</p>\n`,reviewer_avatar_urls:{48:B.defaultAvatar,96:B.defaultAvatar},rating:null,verified:!1}]}},$e=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"woocommerce/reviews-by-product","title":"Reviews by Product","category":"woocommerce","keywords":["WooCommerce"],"description":"Display reviews for your products.","textdomain":"woocommerce","supports":{"html":false,"interactivity":{"clientNavigation":true},"color":{"background":false},"typography":{"fontSize":true}}}');(0,r.registerBlockType)($e,{icon:{src:(0,u.jsx)(s.A,{icon:i.A,className:"wc-block-editor-components-block-icon"})},example:{...Ve,attributes:{...Ve.attributes,productId:1}},attributes:{editMode:{type:"boolean",default:!0},imageType:{type:"string",default:"reviewer"},orderby:{type:"string",default:"most-recent"},reviewsOnLoadMore:{type:"number",default:10},reviewsOnPageLoad:{type:"number",default:10},showLoadMore:{type:"boolean",default:!0},showOrderby:{type:"boolean",default:!0},showReviewDate:{type:"boolean",default:!0},showReviewerName:{type:"boolean",default:!0},showReviewImage:{type:"boolean",default:!0},showReviewRating:{type:"boolean",default:!0},showReviewContent:{type:"boolean",default:!0},previewReviews:{type:"array",default:null},offset:{type:"number",default:0},productId:{type:"number"}},edit:e=>(0,u.jsx)(He,{...e}),save:({attributes:e})=>(0,u.jsx)("div",{...a.useBlockProps.save({className:Ie(e)}),...Pe(e)})})},16919:()=>{},47313:()=>{},95183:()=>{},56878:()=>{},14809:()=>{},63120:()=>{},20415:()=>{},71939:()=>{},75022:()=>{},51609:e=>{"use strict";e.exports=window.React},10790:e=>{"use strict";e.exports=window.ReactJSXRuntime},29491:e=>{"use strict";e.exports=window.wp.compose},86087:e=>{"use strict";e.exports=window.wp.element},27723:e=>{"use strict";e.exports=window.wp.i18n},20923:e=>{"use strict";e.exports=window.wp.isShallowEqual},5573:e=>{"use strict";e.exports=window.wp.primitives}},s={};function i(e){var t=s[e];if(void 0!==t)return t.exports;var o=s[e]={exports:{}};return r[e](o,o.exports,i),o.exports}i.m=r,e=[],i.O=(t,o,r,s)=>{if(!o){var n=1/0;for(d=0;d<e.length;d++){for(var[o,r,s]=e[d],a=!0,c=0;c<o.length;c++)(!1&s||n>=s)&&Object.keys(i.O).every(e=>i.O[e](o[c]))?o.splice(c--,1):(a=!1,s<n&&(n=s));if(a){e.splice(d--,1);var l=r();void 0!==l&&(t=l)}}return t}s=s||0;for(var d=e.length;d>0&&e[d-1][2]>s;d--)e[d]=e[d-1];e[d]=[o,r,s]},i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},o=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,i.t=function(e,r){if(1&r&&(e=this(e)),8&r)return e;if("object"==typeof e&&e){if(4&r&&e.__esModule)return e;if(16&r&&"function"==typeof e.then)return e}var s=Object.create(null);i.r(s);var n={};t=t||[null,o({}),o([]),o(o)];for(var a=2&r&&e;"object"==typeof a&&!~t.indexOf(a);a=o(a))Object.getOwnPropertyNames(a).forEach(t=>n[t]=()=>e[t]);return n.default=()=>e,i.d(s,n),s},i.d=(e,t)=>{for(var o in t)i.o(t,o)&&!i.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.j=1890,(()=>{var e={1890:0};i.O.j=t=>0===e[t];var t=(t,o)=>{var r,s,[n,a,c]=o,l=0;if(n.some(t=>0!==e[t])){for(r in a)i.o(a,r)&&(i.m[r]=a[r]);if(c)var d=c(i)}for(t&&t(o);l<n.length;l++)s=n[l],i.o(e,s)&&e[s]&&e[s][0](),e[s]=0;return i.O(d)},o=globalThis.webpackChunkwebpackWcBlocksMainJsonp=globalThis.webpackChunkwebpackWcBlocksMainJsonp||[];o.forEach(t.bind(null,0)),o.push=t.bind(null,o.push.bind(o))})();var n=i.O(void 0,[94],()=>i(55566));n=i.O(n),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["reviews-by-product"]=n})();