(()=>{"use strict";const e=window.wp.blocks,s=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"seopulse/schema","version":"3.0.0","title":"SEOPulse Custom Schema","category":"text","description":"Custom JSON-LD structured data block. Validates and outputs arbitrary schema.org markup.","keywords":["schema","json-ld","structured data","seo"],"textdomain":"seopulse","attributes":{"schemaType":{"type":"string","default":"Thing"},"schemaJson":{"type":"string","default":"{}"},"isValidated":{"type":"boolean","default":false}},"supports":{"html":false,"align":["wide","full"],"anchor":true,"className":true,"multiple":true},"editorScript":"file:../../../build/schema-block.js","editorStyle":"file:../../../build/schema-block.css","style":"file:../../../build/schema-block.css"}'),a=window.wp.element,t=window.wp.i18n,o=window.wp.blockEditor,l=window.wp.components,i=window.ReactJSXRuntime,c=["Thing","Article","Event","LocalBusiness","Organization","Person","Product","Service","WebPage","WebSite","Course","JobPosting","Recipe","SoftwareApplication","VideoObject"];(0,e.registerBlockType)(s.name,{...s,icon:"shortcode",edit:({attributes:e,setAttributes:s})=>{const{schemaType:n,schemaJson:r,isValidated:p}=e,u=(0,o.useBlockProps)({className:"wp-block-seopulse-schema"}),[d,m]=(0,a.useState)(""),h=(0,a.useCallback)(e=>{const a=function(e){if(!e.trim())return{valid:!1,error:(0,t.__)("JSON cannot be empty.","seopulse")};try{const s=JSON.parse(e);return"object"!=typeof s||null===s||Array.isArray(s)?{valid:!1,error:(0,t.__)("Schema must be a JSON object, not an array or primitive.","seopulse")}:{valid:!0,error:""}}catch(e){return{valid:!1,error:e.message||(0,t.__)("Invalid JSON syntax.","seopulse")}}}(e);m(a.error),a.valid!==p&&s({isValidated:a.valid})},[p,s]);(0,a.useEffect)(()=>{h(r)},[]);const b=(0,a.useCallback)(e=>{s({schemaJson:e}),h(e)},[s,h]),_=(0,a.useCallback)(e=>{if(s({schemaType:e}),"{}"===r.trim()||""===r.trim()){const a=JSON.stringify({"@context":"https://schema.org","@type":e},null,2);s({schemaJson:a,isValidated:!0}),m("")}},[r,s]);return(0,i.jsxs)("div",{...u,children:[(0,i.jsx)(o.InspectorControls,{children:(0,i.jsxs)(l.PanelBody,{title:(0,t.__)("Schema Settings","seopulse"),initialOpen:!0,children:[(0,i.jsx)(l.SelectControl,{__next40pxDefaultSize:!0,label:(0,t.__)("Schema Type","seopulse"),value:n,options:c.map(e=>({label:e,value:e})),onChange:_}),(0,i.jsx)("p",{className:"components-base-control__help",children:p?"✅ "+(0,t.__)("JSON is valid","seopulse"):"❌ "+(0,t.__)("JSON is invalid","seopulse")})]})}),(0,i.jsxs)("div",{className:"wp-block-seopulse-schema__header",children:[(0,i.jsx)("span",{className:"wp-block-seopulse-schema__icon dashicons dashicons-shortcode"}),(0,i.jsx)("span",{className:"wp-block-seopulse-schema__title",children:(0,t.__)("Custom Schema","seopulse")}),(0,i.jsx)("span",{className:"wp-block-seopulse-schema__badge",children:n})]}),(0,i.jsx)(l.TextareaControl,{label:(0,t.__)("JSON-LD","seopulse"),value:r,onChange:b,rows:10,className:"wp-block-seopulse-schema__editor"}),d&&(0,i.jsx)(l.Notice,{status:"error",isDismissible:!1,children:d}),p&&(0,i.jsxs)("div",{className:"wp-block-seopulse-schema__status",children:[(0,i.jsx)("span",{className:"dashicons dashicons-yes-alt"}),(0,t.__)("Schema will be output as JSON-LD on the frontend.","seopulse")]}),!p&&(0,i.jsxs)("div",{className:"wp-block-seopulse-schema__status wp-block-seopulse-schema__status--invalid",children:[(0,i.jsx)("span",{className:"dashicons dashicons-warning"}),(0,t.__)("Invalid schema will not be output on the frontend.","seopulse")]})]})},save:()=>null})})();