(()=>{"use strict";var e={n:t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var l in o)e.o(o,l)&&!e.o(t,l)&&Object.defineProperty(t,l,{enumerable:!0,get:o[l]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,o=window.wp.blockEditor,l=window.wp.serverSideRender;var n=e.n(l);const a=window.wp.components,s=window.wp.element,r=window.wp.apiFetch;var c=e.n(r);const i=window.ReactJSXRuntime;function u({value:e,onChange:t,label:o}){const[l,n]=(0,s.useState)([]),[r,u]=(0,s.useState)(!1);function d(e){u(!0);const t=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";c()({path:t}).then(e=>{n(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>n([])).finally(()=>u(!1))}return(0,s.useEffect)(()=>{d("")},[]),(0,s.useEffect)(()=>{e&&!l.find(t=>t.value===e)&&c()({path:`/ggmc/v1/products/${e}`}).then(e=>{n(t=>t.find(t=>t.value===e.id)?t:[{value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name},...t])}).catch(()=>{})},[e]),(0,i.jsx)(a.ComboboxControl,{label:o||"Product",value:e,options:l,onChange:t,onFilterValueChange:e=>d(e),__nextHasNoMarginBottom:!0})}const d=JSON.parse('{"UU":"ggmc/product-rating"}');(0,t.registerBlockType)(d.UU,{edit:({attributes:e,setAttributes:t})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(o.InspectorControls,{children:(0,i.jsxs)(a.PanelBody,{title:"Content",children:[(0,i.jsx)(a.SelectControl,{label:"Product Source",value:e.productSource,options:[{label:"Current Product (Auto-detect)",value:"current"},{label:"Select Product",value:"custom"}],onChange:e=>t({productSource:e})}),"custom"===e.productSource&&(0,i.jsx)(u,{value:e.productId,onChange:e=>t({productId:e})}),(0,i.jsx)(a.SelectControl,{label:"Display Style",value:e.displayStyle,options:[{label:"Stars Only",value:"stars_only"},{label:"Stars + Review Count",value:"stars_count"},{label:"Stars + Average Rating",value:"stars_average"},{label:"Stars + Average + Count",value:"stars_full"}],onChange:e=>t({displayStyle:e})}),(0,i.jsx)(a.SelectControl,{label:"Star Style",value:e.starStyle,options:[{label:"Filled Stars",value:"filled"},{label:"Outline Stars",value:"outline"}],onChange:e=>t({starStyle:e})}),(0,i.jsx)(a.ToggleControl,{label:"Show Empty Stars",checked:"yes"===e.showEmptyStars,onChange:e=>t({showEmptyStars:e?"yes":""})}),(0,i.jsx)(a.ToggleControl,{label:"Link to Reviews",checked:"yes"===e.linkToReviews,onChange:e=>t({linkToReviews:e?"yes":""})}),"yes"===e.linkToReviews&&(0,i.jsx)(a.TextControl,{label:"Reviews Section ID",value:e.reviewsAnchor,onChange:e=>t({reviewsAnchor:e}),help:"The ID of the reviews section to scroll to."}),(0,i.jsx)(a.TextControl,{label:"No Reviews Text",value:e.noReviewsText,onChange:e=>t({noReviewsText:e})}),(0,i.jsx)(a.ToggleControl,{label:"Hide if No Reviews",checked:"yes"===e.hideIfNoReviews,onChange:e=>t({hideIfNoReviews:e?"yes":""})})]})}),(0,i.jsx)(n(),{block:d.UU,attributes:e})]}),save:()=>null})})();