JezK
Edit File: products-by-attribute.js
(()=>{var e,t,r,s={8122:(e,t,r)=>{"use strict";var s=r(3450),o=r(2024);const i=window.wp.blocks,n=window.wc.wcSettings;r(4747);const l=JSON.parse('{"name":"woocommerce/products-by-attribute","title":"Products by Attribute","category":"woocommerce","keywords":["WooCommerce"],"description":"Display a grid of products with selected attributes.","supports":{"interactivity":{"clientNavigation":false},"align":["wide","full"],"html":false,"inserter":false},"attributes":{"attributes":{"type":"array","default":[]},"attrOperator":{"type":"string","enum":["all","any"],"default":"any"},"columns":{"type":"number","default":3},"contentVisibility":{"type":"object","default":{"image":true,"title":true,"price":true,"rating":true,"button":true},"properties":{"image":{"type":"boolean","default":true},"title":{"type":"boolean","default":true},"price":{"type":"boolean","default":true},"rating":{"type":"boolean","default":true},"button":{"type":"boolean","default":true}}},"orderby":{"type":"string","enum":["date","popularity","price_asc","price_desc","rating","title","menu_order"],"default":"date"},"rows":{"type":"number","default":3},"alignButtons":{"type":"boolean","default":false},"isPreview":{"type":"boolean","default":false},"stockStatus":{"type":"array"}},"textdomain":"woocommerce","apiVersion":3,"$schema":"https://schemas.wp.org/trunk/block.json"}'),c=window.wp.blockEditor,a=window.wp.components;var d=r(6087),m=r(7723),u=r(790);const h=(e,t,r)=>r?Math.min(e,t)===e?t:Math.max(e,r)===e?r:e:Math.max(e,t)===t?e:t,x=({columns:e,rows:t,setAttributes:r,alignButtons:s,minColumns:o=1,maxColumns:i=6,minRows:n=1,maxRows:l=6})=>(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(a.RangeControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,label:(0,m.__)("Columns","woocommerce"),value:e,onChange:e=>{const t=h(e,o,i);r({columns:Number.isNaN(t)?"":t})},min:o,max:i}),(0,u.jsx)(a.RangeControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,label:(0,m.__)("Rows","woocommerce"),value:t,onChange:e=>{const t=h(e,n,l);r({rows:Number.isNaN(t)?"":t})},min:n,max:l}),(0,u.jsx)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,m.__)("Align the last block to the bottom","woocommerce"),help:s?(0,m.__)("Align the last block to the bottom.","woocommerce"):(0,m.__)("The last inner block will follow other content.","woocommerce"),checked:s,onChange:()=>r({alignButtons:!s})})]}),p=({onChange:e,settings:t})=>{const{image:r,button:s,price:o,rating:i,title:n}=t,l=!1!==r;return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(a.ToggleControl,{label:(0,m.__)("Product image","woocommerce"),checked:l,onChange:()=>e({...t,image:!l})}),(0,u.jsx)(a.ToggleControl,{label:(0,m.__)("Product title","woocommerce"),checked:n,onChange:()=>e({...t,title:!n})}),(0,u.jsx)(a.ToggleControl,{label:(0,m.__)("Product price","woocommerce"),checked:o,onChange:()=>e({...t,price:!o})}),(0,u.jsx)(a.ToggleControl,{label:(0,m.__)("Product rating","woocommerce"),checked:i,onChange:()=>e({...t,rating:!i})}),(0,u.jsx)(a.ToggleControl,{label:(0,m.__)("Add to Cart button","woocommerce"),checked:s,onChange:()=>e({...t,button:!s})})]})};var g=r(4921);function w(e,t,r){const s=new Set(t.map(e=>e[r]));return e.filter(e=>!s.has(e[r]))}const b=window.wp.htmlEntities,_={clear:(0,m.__)("Clear all selected items","woocommerce"),noItems:(0,m.__)("No items found.","woocommerce"), /* Translators: %s search term */ noResults:(0,m.__)("No results for %s","woocommerce"),search:(0,m.__)("Search for items","woocommerce"),selected:e=>(0,m.sprintf)(/* translators: Number of items selected from list. */ /* translators: Number of items selected from list. */ (0,m._n)("%d item selected","%d items selected",e,"woocommerce"),e),updated:(0,m.__)("Search results updated.","woocommerce")},f=(e,t)=>null!==t&&(e.id===t||!!(Array.isArray(e.children)&&e.children.length>0)&&e.children.some(e=>f(e,t))),j=(e,t=e)=>{const r=e.reduce((e,t)=>{const r=t.parent||0;return e[r]||(e[r]=[]),e[r].push(t),e},{}),s=t.reduce((e,t)=>(e[String(t.id)]=t,e),{});const o=["0"],i=(e={})=>e.parent?[...i(s[e.parent]),e.name]:e.name?[e.name]:[],n=e=>e.map(e=>{const t=r[e.id];return o.push(""+e.id),{...e,breadcrumbs:i(s[e.parent]),children:t&&t.length?n(t):[]}}),l=n(r[0]||[]);return Object.entries(r).forEach(([e,t])=>{o.includes(e)||l.push(...n(t||[]))}),l},E=(e,t)=>{if(!t)return e;const r=new RegExp(`(${t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")})`,"ig");return e.split(r).map((e,t)=>r.test(e)?(0,u.jsx)("strong",{children:e},t):(0,u.jsx)(d.Fragment,{children:e},t))},y=e=>{const t=e.children?.map(e=>[e,...y(e)]);return t?t.flat():[]},v=(e,t)=>y(e).some(e=>t.find(t=>t.id===e.id)),C=(e,t)=>y(e).every(e=>t.find(t=>t.id===e.id)),k=({label:e})=>(0,u.jsx)("span",{className:"woocommerce-search-list__item-count",children:e}),S=e=>{const{item:t,search:r}=e,s=t.breadcrumbs&&t.breadcrumbs.length;return(0,u.jsxs)("span",{className:"woocommerce-search-list__item-label",children:[s?(0,u.jsx)("span",{className:"woocommerce-search-list__item-prefix",children:(o=t.breadcrumbs,1===o.length?o.slice(0,1).toString():2===o.length?o.slice(0,1).toString()+" › "+o.slice(-1).toString():o.slice(0,1).toString()+" … "+o.slice(-1).toString())}):null,(0,u.jsx)("span",{className:"woocommerce-search-list__item-name",children:E((0,b.decodeEntities)(t.name),r)})]});var o},N=({countLabel:e,className:t,depth:r=0,controlId:s="",disabled:o=!1,item:i,isSelected:n,isSelectable:l=!0,isSingle:c,onSelect:m,search:h="",selected:x,useExpandedPanelId:p,..._})=>{const[j,N]=p,O=null!=e&&void 0!==i.count&&null!==i.count,A=!!i.breadcrumbs?.length,P=!!i.children?.length,I=f(i,j),B=(0,g.A)(["woocommerce-search-list__item",`depth-${r}`,t],{"has-breadcrumbs":A,"has-children":P,"has-count":O,"is-expanded":I,"is-radio-button":c}),M=_.name||`search-list-item-${s}`,T=`${M}-${i.id}`,R=(0,d.useCallback)(()=>{I||"number"!=typeof i.id&&"string"!=typeof i.id?!i.parent||"number"!=typeof i.parent&&"string"!=typeof i.parent?N(null):N(i.parent):N(i.id)},[I,i.id,i.parent,N]),$=(n||!l)&&C(i,x);return P?(0,u.jsx)("div",{className:B,onClick:R,onKeyDown:e=>"Enter"===e.key||" "===e.key?R():null,role:"treeitem",tabIndex:0,children:c?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("input",{type:"radio",id:T,name:M,value:i.value,onChange:()=>{m(i)(),I||N(i.id)},onClick:e=>e.stopPropagation(),checked:n,disabled:o,className:"woocommerce-search-list__item-input",..._}),(0,u.jsx)(S,{item:i,search:h}),O?(0,u.jsx)(k,{label:e||i.count}):null]}):(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(a.CheckboxControl,{className:"woocommerce-search-list__item-input",checked:$,disabled:o,indeterminate:!$&&(n||v(i,x)),label:E((0,b.decodeEntities)(i.name),h),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),onChange:()=>{const e=y(i),t=l?[i,...e]:[...e],r=C(i,x);l&&n||!l&&r?m(w(x,t,"id"))():(m(function(e,t){const r=w(t,e,"id");return[...e,...r]}(x,t))(),I||N(i.id))},__nextHasNoMarginBottom:!0}),O?(0,u.jsx)(k,{label:e||i.count}):null]})}):(0,u.jsxs)("div",{className:B,onClick:o?void 0:m(i),children:[c?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("input",{..._,type:"radio",id:T,name:M,value:i.value,onChange:m(i),checked:n,disabled:o,className:"woocommerce-search-list__item-input",onClick:e=>e.stopPropagation()}),(0,u.jsx)("label",{htmlFor:T,children:(0,u.jsx)(S,{item:i,search:h})})]}):(0,u.jsx)(a.CheckboxControl,{..._,id:T,name:M,className:"woocommerce-search-list__item-input",value:(0,b.decodeEntities)(i.value),label:E((0,b.decodeEntities)(i.name),h),onChange:()=>{m(i)(),I||N(i.id)},checked:n,disabled:o,__nextHasNoMarginBottom:!0,onClick:e=>e.stopPropagation()}),O?(0,u.jsx)(k,{label:e||i.count}):null]})},O=N;var A=r(7051),P=r(9491),I=r(1884);r(5022);const B=({id:e,label:t,popoverContents:r,remove:o,screenReaderLabel:i,className:n=""})=>{const[l,c]=(0,d.useState)(!1),h=(0,P.useInstanceId)(B);if(i=i||t,!t)return null;t=(0,b.decodeEntities)(t);const x=(0,g.A)("woocommerce-tag",n,{"has-remove":!!o}),p=`woocommerce-tag__label-${h}`,w=(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:x,children:[r?(0,u.jsx)(a.Button,{className:"woocommerce-tag__text",id:p,onClick:()=>c(!0),children:w}):(0,u.jsx)("span",{className:"woocommerce-tag__text",id:p,children:w}),r&&l&&(0,u.jsx)(a.Popover,{onClose:()=>c(!1),children:r}),o&&(0,u.jsx)(a.Button,{className:"woocommerce-tag__remove",onClick:o(e),label:(0,m.sprintf)( // Translators: %s label. // Translators: %s label. (0,m.__)("Remove %s","woocommerce"),t),"aria-describedby":p,children:(0,u.jsx)(s.A,{icon:I.A,size:20,className:"clear-icon",role:"img"})})]})},M=B;r(1939);const T=e=>(0,u.jsx)(O,{...e}),R=e=>{const{list:t,selected:r,renderItem:s,depth:o=0,loadMoreChildrenText:i,onLoadMoreChildren:n,totalChildren:l,onSelect:c,instanceId:a,isSingle:h,search:x,useExpandedPanelId:p}=e,[g]=p;return t?(0,u.jsx)(u.Fragment,{children:t.map(t=>{const w=t.children?.length??0,b=!!r.find(({id:e})=>e===t.id),_=f(t,g),j=l?.[t.id],E="number"==typeof j&&w<j;return(0,u.jsxs)(d.Fragment,{children:[(0,u.jsx)("li",{children:s({item:t,isSelected:b,onSelect:c,isSingle:h,selected:r,search:x,depth:o,useExpandedPanelId:p,controlId:a})}),_?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(R,{...e,list:t.children,depth:o+1}),n&&E?(0,u.jsx)("li",{children:(0,u.jsx)("button",{type:"button",className:"woocommerce-search-list__item woocommerce-search-list__item-load-more",onClick:()=>n(),children:i||(0,m.__)("Load more","woocommerce")})}):null]}):null]},t.id)})}):null},$=({isLoading:e,isSingle:t,selected:r,messages:s,onChange:o,onRemove:i})=>{if(e||t||!r)return null;const n=r.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:s.selected(n)}),n>0?(0,u.jsx)(a.Button,{variant:"link",isDestructive:!0,onClick:()=>o([]),"aria-label":s.clear,children:(0,m.__)("Clear all","woocommerce")}):null]}),n>0?(0,u.jsx)("ul",{children:r.map((e,t)=>(0,u.jsx)("li",{children:(0,u.jsx)(M,{label:e.name,id:e.id,remove:i})},t))}):null]})},L=({filteredList:e,search:t,onSelect:r,instanceId:o,useExpandedPanelId:i,...n})=>{const{messages:l,renderItem:c,selected:a,isSingle:d,loadMoreChildrenText:h,onLoadMoreChildren:x,totalChildren:p}=n,g=c||T;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:A.A,role:"img"})}),(0,u.jsx)("span",{className:"woocommerce-search-list__not-found-text",children:t?(0,m.sprintf)(l.noResults,t):l.noItems})]}):(0,u.jsx)("ul",{className:"woocommerce-search-list__list",children:(0,u.jsx)(R,{useExpandedPanelId:i,list:e,selected:a,renderItem:g,loadMoreChildrenText:h,onLoadMoreChildren:x,totalChildren:p,onSelect:r,instanceId:o,isSingle:d,search:t})})},F=e=>{const{className:t="",isCompact:r,isHierarchical:s,isLoading:o,isSingle:i,list:n,messages:l=_,onChange:c,onSearch:h,selected:x,type:p="text",debouncedSpeak:w}=e,[b,f]=(0,d.useState)(""),E=(0,d.useState)(null),y=(0,P.useInstanceId)(F),v=(0,d.useMemo)(()=>({..._,...l}),[l]),C=(0,d.useMemo)(()=>((e,t,r)=>{if(!t)return r?j(e):e;const s=new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i"),o=e.map(e=>!!s.test(e.name)&&e).filter(Boolean);return r?j(o,e):o})(n,b,s),[n,b,s]);(0,d.useEffect)(()=>{w&&w(v.updated)},[w,v]),(0,d.useEffect)(()=>{"function"==typeof h&&h(b)},[b,h]);const k=(0,d.useCallback)(e=>()=>{i&&c([]);const t=x.findIndex(({id:t})=>t===e);c([...x.slice(0,t),...x.slice(t+1)])},[i,x,c]),S=(0,d.useCallback)(e=>()=>{Array.isArray(e)?c(e):-1===x.findIndex(({id:t})=>t===e.id)?c(i?[e]:[...x,e]):k(e.id)()},[i,k,c,x]),N=(0,d.useCallback)(e=>{const[t]=x.filter(t=>!e.find(e=>t.id===e.id));k(t.id)()},[k,x]);return(0,u.jsxs)("div",{className:(0,g.A)("woocommerce-search-list",t,{"is-compact":r,"is-loading":o,"is-token":"token"===p}),children:["text"===p&&(0,u.jsx)($,{...e,onRemove:k,messages:v}),(0,u.jsx)("div",{className:"woocommerce-search-list__search",children:"text"===p?(0,u.jsx)(a.TextControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,label:v.search,type:"search",value:b,onChange:e=>f(e)}):(0,u.jsx)(a.FormTokenField,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,disabled:o,label:v.search,onChange:N,onInputChange:e=>f(e),suggestions:[],__experimentalValidateInput:()=>!1,value:o?[(0,m.__)("Loading…","woocommerce")]:x.map(e=>({...e,value:e.name})),__experimentalShowHowTo:!1})}),o?(0,u.jsx)("div",{className:"woocommerce-search-list__list",children:(0,u.jsx)(a.Spinner,{})}):(0,u.jsx)(L,{...e,search:b,filteredList:C,messages:v,onSelect:S,instanceId:y,useExpandedPanelId:E})]})},H=((0,a.withSpokenMessages)(F),window.wp.url,window.wp.apiFetch);var D=r.n(H);const z=e=>D()({path:`wc/store/v1/products/attributes/${e}/terms`});const V=window.wp.escapeHtml,J=({message:e,type:t})=>e?"general"===t?(0,u.jsxs)("span",{children:[(0,m.__)("The following error was returned","woocommerce"),(0,u.jsx)("br",{}),(0,u.jsx)("code",{children:(0,V.escapeHTML)(e)})]}):"api"===t?(0,u.jsxs)("span",{children:[(0,m.__)("The following error was returned from the API","woocommerce"),(0,u.jsx)("br",{}),(0,u.jsx)("code",{children:(0,V.escapeHTML)(e)})]}):e:(0,m.__)("An error has prevented the block from being updated.","woocommerce"),W=({error:e})=>(0,u.jsx)("div",{className:"wc-block-error-message",children:J(e)});var G=r(1609);const K=({className:e,item:t,isSelected:r,isLoading:s,onSelect:o,disabled:i,...n})=>(0,u.jsxs)(u.Fragment,{children:[(0,G.createElement)(N,{...n,key:t.id,...e&&{className:e},isSelected:r,item:t,onSelect:o,...i&&{disabled:i}}),r&&s&&(0,u.jsx)("div",{className:(0,g.A)("woocommerce-search-list__item","woocommerce-product-attributes__item","depth-1","is-loading","is-not-active"),children:(0,u.jsx)(a.Spinner,{})},"loading")]}),X=window.wc.wcTypes,Y=((window.wp.data,(0,n.getSetting)("attributes",[])).reduce((e,t)=>{const r=(s=t)&&s.attribute_name?{id:parseInt(s.attribute_id,10),name:s.attribute_name,taxonomy:"pa_"+s.attribute_name,label:s.attribute_label,orderby:s.attribute_orderby}:null;var s;return r&&r.id&&e.push(r),e},[]),e=>{const{count:t,id:r,name:s,parent:o}=e;return{count:t,id:r,name:s,parent:o,breadcrumbs:[],children:[],value:(0,X.isAttributeTerm)(e)?e.attr_slug:""}});r(2663);const q=e=>({...Y(e),id:-e.id,parent:0}),Q=(0,P.withInstanceId)(({onChange:e,onOperatorChange:t,instanceId:r,isCompact:s=!1,messages:o={},operator:i="any",selected:n,type:l="text"})=>{const{errorLoadingAttributes:c,isLoadingAttributes:h,productsAttributes:x}=function(e){const[t,r]=(0,d.useState)(null),[s,o]=(0,d.useState)(!1),[i,n]=(0,d.useState)([]),l=(0,d.useRef)(!1);return(0,d.useEffect)(()=>{if(e&&!s&&!l.current)return async function(){o(!0);try{const e=await D()({path:"wc/store/v1/products/attributes"}),t=[];for(const r of e){const e=await z(r.id);t.push({...r,parent:0,terms:e.map(e=>({...e,attr_slug:r.taxonomy,parent:r.id}))})}n(t),l.current=!0}catch(e){e instanceof Error&&r(await(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"}}})(e))}finally{o(!1)}}(),()=>{l.current=!0}},[s,e]),{errorLoadingAttributes:t,isLoadingAttributes:s,productsAttributes:i}}(!0),p=x.reduce((e,t)=>{const{terms:r,...s}=t;return[...e,q(s),...r.map(e=>((e,t)=>({...Y(e),parent:-t}))(e,s.id))]},[]);return o={clear:(0,m.__)("Clear all product attributes","woocommerce"),noItems:(0,m.__)("Your store doesn't have any product attributes.","woocommerce"),search:(0,m.__)("Search for product attributes","woocommerce"),selected:e=>(0,m.sprintf)(/* translators: %d is the count of attributes selected. */ /* translators: %d is the count of attributes selected. */ (0,m._n)("%d attribute selected","%d attributes selected",e,"woocommerce"),e),updated:(0,m.__)("Product attribute search results updated.","woocommerce"),...o},c?(0,u.jsx)(W,{error:c}):(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(F,{className:"woocommerce-product-attributes",isCompact:s,isHierarchical:!0,isLoading:h,isSingle:!1,list:p,messages:o,onChange:e,renderItem:e=>{const{item:t,search:s,depth:o=0}=e,i=t.count||0,n=["woocommerce-product-attributes__item","woocommerce-search-list__item",{"is-searching":s.length>0,"is-skip-level":0===o&&0!==t.parent}];if(!t.breadcrumbs.length)return(0,u.jsx)(K,{...e,className:(0,g.A)(n),item:t,isLoading:h,isSelectable:!1,disabled:0===t.count,name:`attributes-${r}`,countLabel:(0,m.sprintf)(/* translators: %d is the count of terms. */ /* translators: %d is the count of terms. */ (0,m._n)("%d term","%d terms",i,"woocommerce"),i),"aria-label":(0,m.sprintf)(/* translators: %1$s is the item name, %2$d is the count of terms for the item. */ /* translators: %1$s is the item name, %2$d is the count of terms for the item. */ (0,m._n)("%1$s, has %2$d term","%1$s, has %2$d terms",i,"woocommerce"),t.name,i)});const l=`${t.breadcrumbs[0]}: ${t.name}`;return(0,u.jsx)(N,{...e,name:`terms-${r}`,className:(0,g.A)(...n,"has-count"),countLabel:(0,m.sprintf)(/* translators: %d is the count of products. */ /* translators: %d is the count of products. */ (0,m._n)("%d product","%d products",i,"woocommerce"),i),"aria-label":(0,m.sprintf)(/* translators: %1$s is the attribute name, %2$d is the count of products for that attribute. */ /* translators: %1$s is the attribute name, %2$d is the count of products for that attribute. */ (0,m._n)("%1$s, has %2$d product","%1$s, has %2$d products",i,"woocommerce"),l,i)})},selected:n.map(({id:e})=>p.find(t=>t.id===e)).filter(Boolean),type:l}),!!t&&(0,u.jsx)("div",{hidden:n.length<2,children:(0,u.jsx)(a.SelectControl,{className:"woocommerce-product-attributes__operator",label:(0,m.__)("Display products matching","woocommerce"),help:(0,m.__)("Pick at least two attributes to use this setting.","woocommerce"),value:i,onChange:t,options:[{label:(0,m.__)("Any selected attributes","woocommerce"),value:"any"},{label:(0,m.__)("All selected attributes","woocommerce"),value:"all"}]})})]})}),U=({value:e,setAttributes:t})=>(0,u.jsx)(a.SelectControl,{label:(0,m.__)("Order products by","woocommerce"),value:e,options:[{label:(0,m.__)("Newness - newest first","woocommerce"),value:"date"},{label:(0,m.__)("Price - low to high","woocommerce"),value:"price_asc"},{label:(0,m.__)("Price - high to low","woocommerce"),value:"price_desc"},{label:(0,m.__)("Rating - highest first","woocommerce"),value:"rating"},{label:(0,m.__)("Sales - most first","woocommerce"),value:"popularity"},{label:(0,m.__)("Title - alphabetical","woocommerce"),value:"title"},{label:(0,m.__)("Menu Order","woocommerce"),value:"menu_order"}],onChange:e=>t({orderby:e})}),Z=(0,n.getSetting)("hideOutOfStockItems",!1),ee=(0,n.getSetting)("stockStatusOptions",{}),te=({value:e,setAttributes:t})=>{const{outofstock:r,...s}=ee,o=Z?s:ee,i=Object.entries(o).map(([e,t])=>({value:e,label:t})).filter(e=>!!e.label),n=Object.keys(o).filter(e=>!!e),[l,c]=(0,d.useState)(e||n);(0,d.useEffect)(()=>{t({stockStatus:["",...l]})},[l,t]);const h=(0,d.useCallback)(e=>{const t=l.includes(e),r=l.filter(t=>t!==e);t||(r.push(e),r.sort()),c(r)},[l]);return(0,u.jsx)(u.Fragment,{children:i.map(e=>{const t=l.includes(e.value)?/* translators: %s stock status. */ /* translators: %s stock status. */(0,m.__)('Stock status "%s" visible.',"woocommerce"):/* translators: %s stock status. */ /* translators: %s stock status. */(0,m.__)('Stock status "%s" hidden.',"woocommerce");return(0,u.jsx)(a.ToggleControl,{label:e.label,help:(0,m.sprintf)(t,e.label),checked:l.includes(e.value),onChange:()=>h(e.value)},e.value)})})},re=e=>{const{setAttributes:t}=e,{attributes:r,attrOperator:s,columns:o,contentVisibility:i,orderby:l,rows:d,alignButtons:h,stockStatus:g}=e.attributes;return(0,u.jsxs)(c.InspectorControls,{children:[(0,u.jsx)(a.PanelBody,{title:(0,m.__)("Layout","woocommerce"),initialOpen:!0,children:(0,u.jsx)(x,{columns:o,rows:d,alignButtons:h,setAttributes:t,minColumns:(0,n.getSetting)("minColumns",1),maxColumns:(0,n.getSetting)("maxColumns",6),minRows:(0,n.getSetting)("minRows",1),maxRows:(0,n.getSetting)("maxRows",6)})}),(0,u.jsx)(a.PanelBody,{title:(0,m.__)("Content","woocommerce"),initialOpen:!0,children:(0,u.jsx)(p,{settings:i,onChange:e=>t({contentVisibility:e})})}),(0,u.jsx)(a.PanelBody,{title:(0,m.__)("Filter by Product Attribute","woocommerce"),initialOpen:!1,children:(0,u.jsx)(Q,{selected:r,onChange:(e=[])=>{const r=e.map(({id:e,value:t})=>({id:e,attr_slug:t}));t({attributes:r})},operator:s,onOperatorChange:(e="any")=>t({attrOperator:e}),isCompact:!0})}),(0,u.jsx)(a.PanelBody,{title:(0,m.__)("Order By","woocommerce"),initialOpen:!1,children:(0,u.jsx)(U,{setAttributes:t,value:l})}),(0,u.jsx)(a.PanelBody,{title:(0,m.__)("Filter by stock status","woocommerce"),initialOpen:!1,children:(0,u.jsx)(te,{setAttributes:t,value:g})})]},"inspector")},se=e=>{const{attributes:t,setAttributes:r,setIsEditing:i,isEditing:n,debouncedSpeak:l}=e;return(0,u.jsxs)(a.Placeholder,{icon:(0,u.jsx)(s.A,{icon:o.A}),label:(0,m.__)("Products by Attribute","woocommerce"),className:"wc-block-products-grid wc-block-products-by-attribute",children:[(0,m.__)("Display a grid of products from your selected attributes.","woocommerce"),(0,u.jsxs)("div",{className:"wc-block-products-by-attribute__selection",children:[(0,u.jsx)(Q,{selected:t.attributes,onChange:(e=[])=>{const t=e.map(({id:e,value:t})=>({id:e,attr_slug:t}));r({attributes:t})},operator:t.attrOperator,onOperatorChange:(e="any")=>r({attrOperator:e})}),(0,u.jsx)(a.Button,{variant:"primary",onClick:()=>{i(!n),l((0,m.__)("Showing Products by Attribute block preview.","woocommerce"))},children:(0,m.__)("Done","woocommerce")})]})]})},oe=window.wp.serverSideRender;var ie=r.n(oe);const ne=(0,u.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 230 250",style:{width:"100%"},children:[(0,u.jsx)("title",{children:"Grid Block Preview"}),(0,u.jsx)("rect",{width:"65.374",height:"65.374",x:".162",y:".779",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"47.266",height:"5.148",x:"9.216",y:"76.153",fill:"#E1E3E6",rx:"2.574"}),(0,u.jsx)("rect",{width:"62.8",height:"15",x:"1.565",y:"101.448",fill:"#E1E3E6",rx:"5"}),(0,u.jsx)("rect",{width:"65.374",height:"65.374",x:".162",y:"136.277",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"47.266",height:"5.148",x:"9.216",y:"211.651",fill:"#E1E3E6",rx:"2.574"}),(0,u.jsx)("rect",{width:"62.8",height:"15",x:"1.565",y:"236.946",fill:"#E1E3E6",rx:"5"}),(0,u.jsx)("rect",{width:"65.374",height:"65.374",x:"82.478",y:".779",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"47.266",height:"5.148",x:"91.532",y:"76.153",fill:"#E1E3E6",rx:"2.574"}),(0,u.jsx)("rect",{width:"62.8",height:"15",x:"83.882",y:"101.448",fill:"#E1E3E6",rx:"5"}),(0,u.jsx)("rect",{width:"65.374",height:"65.374",x:"82.478",y:"136.277",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"47.266",height:"5.148",x:"91.532",y:"211.651",fill:"#E1E3E6",rx:"2.574"}),(0,u.jsx)("rect",{width:"62.8",height:"15",x:"83.882",y:"236.946",fill:"#E1E3E6",rx:"5"}),(0,u.jsx)("rect",{width:"65.374",height:"65.374",x:"164.788",y:".779",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"47.266",height:"5.148",x:"173.843",y:"76.153",fill:"#E1E3E6",rx:"2.574"}),(0,u.jsx)("rect",{width:"62.8",height:"15",x:"166.192",y:"101.448",fill:"#E1E3E6",rx:"5"}),(0,u.jsx)("rect",{width:"65.374",height:"65.374",x:"164.788",y:"136.277",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"47.266",height:"5.148",x:"173.843",y:"211.651",fill:"#E1E3E6",rx:"2.574"}),(0,u.jsx)("rect",{width:"62.8",height:"15",x:"166.192",y:"236.946",fill:"#E1E3E6",rx:"5"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"13.283",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"21.498",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"29.713",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"37.927",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"46.238",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"95.599",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"103.814",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"112.029",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"120.243",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"128.554",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"177.909",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"186.124",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"194.339",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"202.553",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"210.864",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"13.283",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"21.498",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"29.713",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"37.927",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"46.238",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"95.599",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"103.814",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"112.029",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"120.243",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"128.554",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"177.909",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"186.124",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"194.339",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"202.553",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,u.jsx)("rect",{width:"6.177",height:"6.177",x:"210.864",y:"221.798",fill:"#E1E3E6",rx:"3"})]}),le=e=>{const{attributes:t,name:r}=e;return t.isPreview?ne:(0,u.jsx)(ie(),{block:r,attributes:t})},ce=(0,a.withSpokenMessages)(e=>{const t=(0,c.useBlockProps)(),{attributes:{attributes:r}}=e,[s,o]=(0,d.useState)(!r.length);return(0,u.jsxs)("div",{...t,children:[(0,u.jsx)(c.BlockControls,{children:(0,u.jsx)(a.ToolbarGroup,{controls:[{icon:"edit",title:(0,m.__)("Edit selected attribute","woocommerce"),onClick:()=>o(!s),isActive:s}]})}),(0,u.jsx)(re,{...e}),s?(0,u.jsx)(se,{isEditing:s,setIsEditing:o,...e}):(0,u.jsx)(a.Disabled,{children:(0,u.jsx)(le,{...e})})]})});(0,i.registerBlockType)(l,{icon:{src:(0,u.jsx)(s.A,{icon:o.A,className:"wc-block-editor-components-block-icon"})},attributes:{...l.attributes,columns:{type:"number",default:(0,n.getSetting)("defaultColumns",3)},rows:{type:"number",default:(0,n.getSetting)("defaultRows",3)},stockStatus:{type:"array",default:Object.keys((0,n.getSetting)("stockStatusOptions",[]))}},edit:ce,save:()=>null})},4747:()=>{},2663:()=>{},1939:()=>{},5022:()=>{},1609:e=>{"use strict";e.exports=window.React},790:e=>{"use strict";e.exports=window.ReactJSXRuntime},9491:e=>{"use strict";e.exports=window.wp.compose},6087:e=>{"use strict";e.exports=window.wp.element},7723:e=>{"use strict";e.exports=window.wp.i18n},5573:e=>{"use strict";e.exports=window.wp.primitives}},o={};function i(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return s[e](r,r.exports,i),r.exports}i.m=s,e=[],i.O=(t,r,s,o)=>{if(!r){var n=1/0;for(d=0;d<e.length;d++){for(var[r,s,o]=e[d],l=!0,c=0;c<r.length;c++)(!1&o||n>=o)&&Object.keys(i.O).every(e=>i.O[e](r[c]))?r.splice(c--,1):(l=!1,o<n&&(n=o));if(l){e.splice(d--,1);var a=s();void 0!==a&&(t=a)}}return t}o=o||0;for(var d=e.length;d>0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[r,s,o]},i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,i.t=function(e,s){if(1&s&&(e=this(e)),8&s)return e;if("object"==typeof e&&e){if(4&s&&e.__esModule)return e;if(16&s&&"function"==typeof e.then)return e}var o=Object.create(null);i.r(o);var n={};t=t||[null,r({}),r([]),r(r)];for(var l=2&s&&e;"object"==typeof l&&!~t.indexOf(l);l=r(l))Object.getOwnPropertyNames(l).forEach(t=>n[t]=()=>e[t]);return n.default=()=>e,i.d(o,n),o},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},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=8848,(()=>{var e={8848:0};i.O.j=t=>0===e[t];var t=(t,r)=>{var s,o,[n,l,c]=r,a=0;if(n.some(t=>0!==e[t])){for(s in l)i.o(l,s)&&(i.m[s]=l[s]);if(c)var d=c(i)}for(t&&t(r);a<n.length;a++)o=n[a],i.o(e,o)&&e[o]&&e[o][0](),e[o]=0;return i.O(d)},r=globalThis.webpackChunkwebpackWcBlocksMainJsonp=globalThis.webpackChunkwebpackWcBlocksMainJsonp||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var n=i.O(void 0,[94],()=>i(8122));n=i.O(n),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["products-by-attribute"]=n})();