(()=>{"use strict";const e=window.wp.blocks,t=window.wp.i18n,n=JSON.parse('{"u2":"wpseopress/faq-block-v2"}'),r=window.wp.blockEditor,o=window.wp.data,s=window.wp.element,a=window.wp.url,c=window.wp.components,l=function(e){var n=e.rootClientId;return React.createElement(r.Inserter,{rootClientId:n,renderToggle:function(e){var n=e.onToggle,r=e.disabled;return React.createElement(c.Button,{className:"components-button block-editor-button-block-appender question-button-appender",onClick:n,disabled:r,label:(0,t.__)("Add a question","wp-seopress"),icon:"plus"},(0,t.__)("Add a question","wp-seopress"))},isAppender:!0})};function i(e){var n=e.attributes,o=e.setAttributes,s=n.printSchema;return React.createElement(r.InspectorControls,null,React.createElement(c.PanelBody,{title:(0,t.__)("FAQ Settings","wp-seopress")},React.createElement(c.PanelRow,{className:"wpseopress-faqs-seo-settings"},React.createElement(c.ToggleControl,{label:(0,t.__)("Enable FAQ schema","wp-seopress"),checked:!!s,onChange:function(e){o({printSchema:!s})}}))))}var u=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).reduce((function(t,n){var r;return t.push(null!==(r=(0,e.getBlockContent)(n))&&void 0!==r?r:""),t}),[]).filter((function(e){return"<p></p>"!==e}))};(0,e.registerBlockType)(n.u2,{title:(0,t.__)("FAQ","wp-seopress"),description:(0,t.__)("Allows to easily build FAQs.","wp-seopress"),keywords:[(0,t.__)("FAQ","wp-seopress")],edit:function(e){var n=e.attributes,c=e.setAttributes,p=e.clientId,d=(0,o.useSelect)((function(e){return e("core/editor").getPermalink()||""}),[d]),w=(0,o.useSelect)((function(e){var t;return(null===(t=e("core/block-editor").getBlock(p))||void 0===t?void 0:t.innerBlocks)||[]}),[w]),m=(0,o.dispatch)("core/block-editor").updateBlockAttributes,b=w.map((function(e){var t;if("core/details"!==e.name)return{};var n=(null===(t=e.attributes)||void 0===t||null===(t=t.summary)||void 0===t?void 0:t.text)||"",r=(0,a.cleanForSlug)(n);return{"@type":"Question",url:"".concat(d,"#").concat(r),name:n,answerCount:1,acceptedAnswer:{"@type":"Answer",text:u((null==e?void 0:e.innerBlocks)||[]).join("")}}})),v={"@context":"https://schema.org","@type":"FAQPage",url:d,"@id":d,mainEntity:b||[]};(0,s.useEffect)((function(){JSON.stringify(n.schema)!==JSON.stringify(v)&&c({schema:v}),w.forEach((function(e){var t,n=(null===(t=e.attributes)||void 0===t||null===(t=t.summary)||void 0===t?void 0:t.text)||"",r=(0,a.cleanForSlug)(n);r!==e.attributes.anchor&&m(e.clientId,{anchor:r})}))}),[w,d]);var f={name:"core/details",attributes:{placeholder:(0,t.__)("Type a question","wp-seopress")},innerBlocks:[{name:"core/paragraph",attributes:{placeholder:(0,t.__)("Add your answer","wp-seopress")}}]},g=[["core/details",{placeholder:(0,t.__)("Type a question","wp-seopress")},[["core/paragraph",{placeholder:(0,t.__)("Add your answer","wp-seopress")}]]]];return React.createElement(React.Fragment,null,React.createElement(i,{attributes:n,setAttributes:c}),React.createElement("div",(0,r.useBlockProps)(),React.createElement(r.InnerBlocks,{template:g,defaultBlock:f,directInsert:!0,renderAppender:function(){return React.createElement(l,{rootClientId:p})}})))},save:function(e){var t=e.attributes,n=JSON.stringify((null==t?void 0:t.schema)||"");return React.createElement("div",r.useBlockProps.save(),React.createElement(r.InnerBlocks.Content,null),t.printSchema&&n&&React.createElement("script",{type:"application/ld+json"},n))}})})();