(()=>{"use strict";const e=window.wp.blocks,s=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"seopulse/review","version":"3.0.0","title":"SEOPulse Review","category":"text","description":"Review snippet block with star rating and automatic Review structured data (JSON-LD).","keywords":["review","rating","stars","schema","structured data","seo"],"textdomain":"seopulse","attributes":{"itemName":{"type":"string","default":""},"ratingValue":{"type":"number","default":5},"bestRating":{"type":"number","default":5},"summary":{"type":"string","default":""},"reviewBody":{"type":"string","default":""},"reviewerName":{"type":"string","default":""}},"supports":{"html":false,"align":["wide","full"],"anchor":true,"className":true},"editorScript":"file:../../../build/review-block.js","editorStyle":"file:../../../build/review-block.css","style":"file:../../../build/review-block.css"}'),a=window.wp.element,l=window.wp.i18n,t=window.wp.blockEditor,i=window.wp.components,r=window.ReactJSXRuntime;function o({value:e,best:s}){const a=[];for(let l=1;l<=s;l++)a.push((0,r.jsx)("span",{className:"wp-block-seopulse-review__star "+(l<=e?"wp-block-seopulse-review__star--filled":""),children:"★"},l));return(0,r.jsx)("div",{className:"wp-block-seopulse-review__stars",children:a})}(0,e.registerBlockType)(s.name,{...s,icon:"star-filled",edit:({attributes:e,setAttributes:s})=>{const{itemName:n,ratingValue:c,bestRating:p,summary:u,reviewBody:w,reviewerName:m}=e,d=(0,t.useBlockProps)({className:"wp-block-seopulse-review"}),v=!!(n&&m&&c),_=(0,a.useCallback)(e=>s({itemName:e}),[s]),b=(0,a.useCallback)(e=>s({reviewerName:e}),[s]);return(0,r.jsxs)("div",{...d,children:[(0,r.jsx)(t.InspectorControls,{children:(0,r.jsxs)(i.PanelBody,{title:(0,l.__)("Review Settings","seopulse"),initialOpen:!0,children:[(0,r.jsx)(i.RangeControl,{label:(0,l.__)("Best Rating","seopulse"),value:p,onChange:e=>s({bestRating:e??5}),min:1,max:10}),(0,r.jsx)(i.RangeControl,{label:(0,l.__)("Rating","seopulse"),value:c,onChange:e=>s({ratingValue:e??5}),min:1,max:p}),(0,r.jsx)(i.TextControl,{label:(0,l.__)("Reviewer Name","seopulse"),value:m,onChange:b}),(0,r.jsx)("p",{className:"components-base-control__help",children:v?"✅ "+(0,l.__)("Review schema will be emitted.","seopulse"):"⚠️ "+(0,l.__)("Fill item name, rating, and reviewer to emit schema.","seopulse")})]})}),(0,r.jsxs)("div",{className:"wp-block-seopulse-review__header",children:[(0,r.jsx)("span",{className:"wp-block-seopulse-review__icon dashicons dashicons-star-filled"}),(0,r.jsx)("span",{className:"wp-block-seopulse-review__title",children:(0,l.__)("Review","seopulse")}),v&&(0,r.jsxs)("span",{className:"wp-block-seopulse-review__schema-badge",children:[(0,l.__)("Schema","seopulse")," ✓"]})]}),(0,r.jsx)(t.RichText,{tagName:"h3",className:"wp-block-seopulse-review__item-name",placeholder:(0,l.__)("Item being reviewed…","seopulse"),value:n,onChange:_,allowedFormats:[]}),(0,r.jsx)(o,{value:c,best:p}),(0,r.jsxs)("span",{className:"wp-block-seopulse-review__rating-label",children:[c,"/",p]}),(0,r.jsx)(t.RichText,{tagName:"p",className:"wp-block-seopulse-review__summary",placeholder:(0,l.__)("Short summary…","seopulse"),value:u,onChange:e=>s({summary:e}),allowedFormats:["core/bold","core/italic"]}),(0,r.jsx)(t.RichText,{tagName:"div",className:"wp-block-seopulse-review__body",placeholder:(0,l.__)("Write your review…","seopulse"),value:w,onChange:e=>s({reviewBody:e}),allowedFormats:["core/bold","core/italic","core/link"]}),m&&(0,r.jsxs)("p",{className:"wp-block-seopulse-review__reviewer",children:["— ",m]})]})},save:({attributes:e})=>{const{itemName:s,ratingValue:a,bestRating:l,summary:i,reviewBody:o,reviewerName:n}=e,c=t.useBlockProps.save({className:"wp-block-seopulse-review"});if(!s)return null;const p=!!(s&&n&&a),u=[];for(let e=1;e<=l;e++)u.push((0,r.jsx)("span",{className:"wp-block-seopulse-review__star "+(e<=a?"wp-block-seopulse-review__star--filled":""),children:"★"},e));const w=p?JSON.stringify({"@context":"https://schema.org","@type":"Review",itemReviewed:{"@type":"Thing",name:s.replace(/<[^>]+>/g,"")},reviewRating:{"@type":"Rating",ratingValue:a,bestRating:l},author:{"@type":"Person",name:n},...i?{name:i.replace(/<[^>]+>/g,"")}:{},...o?{reviewBody:o.replace(/<[^>]+>/g,"")}:{}}):null;return(0,r.jsxs)("div",{...c,children:[(0,r.jsx)(t.RichText.Content,{tagName:"h3",className:"wp-block-seopulse-review__item-name",value:s}),(0,r.jsx)("div",{className:"wp-block-seopulse-review__stars",children:u}),(0,r.jsxs)("span",{className:"wp-block-seopulse-review__rating-label",children:[a,"/",l]}),i&&(0,r.jsx)(t.RichText.Content,{tagName:"p",className:"wp-block-seopulse-review__summary",value:i}),o&&(0,r.jsx)(t.RichText.Content,{tagName:"div",className:"wp-block-seopulse-review__body",value:o}),n&&(0,r.jsxs)("p",{className:"wp-block-seopulse-review__reviewer",children:["— ",n]}),w&&(0,r.jsx)("script",{type:"application/ld+json",dangerouslySetInnerHTML:{__html:w}})]})}})})();