(()=>{"use strict";const e=window.wp.blocks,s=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"seopulse/toc","version":"3.0.0","title":"SEOPulse Table of Contents","category":"text","description":"Auto-generate Table of Contents from post headings with internal anchor links.","keywords":["toc","table of contents","headings","navigation","seo"],"textdomain":"seopulse","attributes":{"includeH1":{"type":"boolean","default":false},"minHeadings":{"type":"number","default":3},"collapsible":{"type":"boolean","default":false},"showNumbers":{"type":"boolean","default":true}},"supports":{"html":false,"align":["wide","full"],"anchor":true,"className":true,"multiple":false},"editorScript":"file:../../../build/toc-block.js","editorStyle":"file:../../../build/toc-block.css","style":"file:../../../build/toc-block.css","viewScript":"file:../../../build/toc-frontend.js"}'),t=window.wp.i18n,l=window.wp.blockEditor,o=window.wp.components,n=window.wp.element,a=window.wp.data;const i=window.ReactJSXRuntime;function c({headings:e,showNumbers:s}){const t=s?"ol":"ul",l=Math.min(...e.map(e=>e.level));return(0,i.jsx)(t,{className:"wp-block-seopulse-toc__list",children:e.map((e,s)=>{const t=e.level-l;return(0,i.jsx)("li",{className:"wp-block-seopulse-toc__item",style:{marginLeft:16*t+"px"},children:(0,i.jsx)("a",{href:`#${e.anchor}`,className:"wp-block-seopulse-toc__link",onClick:e=>e.preventDefault(),children:e.text})},s)})})}(0,e.registerBlockType)(s.name,{...s,icon:"list-view",edit:({attributes:e,setAttributes:s})=>{const{includeH1:r,minHeadings:u,collapsible:p,showNumbers:d}=e,m=(0,l.useBlockProps)({className:"wp-block-seopulse-toc"}),h=function(e,s){const t=(0,a.useSelect)(e=>e("core/block-editor").getBlocks(),[]);return(0,n.useMemo)(()=>{const l=[];!function e(s){for(const t of s){if("core/heading"===t.name){const e=t.attributes?.level??2,s=t.attributes?.content??"",o=t.attributes?.anchor||"",n=s.replace(/<[^>]+>/g,"").trim();n&&l.push({level:e,text:n,existingId:o||void 0})}t.innerBlocks?.length&&e(t.innerBlocks)}}(t);const o=e?l:l.filter(e=>e.level>1);if(o.length<s)return[];const n=function(e){const s=new Map;return e.map(e=>{const t=s.get(e)??0;return s.set(e,t+1),0===t?e:`${e}-${t+1}`})}(o.map(e=>e.existingId||e.text.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")));return o.map((e,s)=>({level:e.level,text:e.text,anchor:n[s]}))},[t,e,s])}(r,u);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(l.InspectorControls,{children:(0,i.jsxs)(o.PanelBody,{title:(0,t.__)("ToC Settings","seopulse"),children:[(0,i.jsx)(o.ToggleControl,{label:(0,t.__)("Include H1","seopulse"),checked:r,onChange:e=>s({includeH1:e}),__nextHasNoMarginBottom:!0}),(0,i.jsx)(o.RangeControl,{label:(0,t.__)("Minimum headings","seopulse"),value:u,onChange:e=>s({minHeadings:e??3}),min:1,max:10,__nextHasNoMarginBottom:!0}),(0,i.jsx)(o.ToggleControl,{label:(0,t.__)("Collapsible","seopulse"),checked:p,onChange:e=>s({collapsible:e}),__nextHasNoMarginBottom:!0}),(0,i.jsx)(o.ToggleControl,{label:(0,t.__)("Show numbers","seopulse"),checked:d,onChange:e=>s({showNumbers:e}),__nextHasNoMarginBottom:!0})]})}),(0,i.jsxs)("div",{...m,children:[(0,i.jsxs)("div",{className:"wp-block-seopulse-toc__header",children:[(0,i.jsx)("span",{className:"wp-block-seopulse-toc__icon","aria-hidden":"true",children:"📑"}),(0,i.jsx)("span",{className:"wp-block-seopulse-toc__title",children:(0,t.__)("Table of Contents","seopulse")})]}),0===h.length?(0,i.jsx)("p",{className:"wp-block-seopulse-toc__empty",children:u>1?`${(0,t.__)("Not enough headings detected (minimum:","seopulse")} ${u}).`:(0,t.__)("No headings detected in this post.","seopulse")}):(0,i.jsx)("nav",{className:"wp-block-seopulse-toc__nav","aria-label":(0,t.__)("Table of Contents","seopulse"),children:(0,i.jsx)(c,{headings:h,showNumbers:d})}),(0,i.jsx)("div",{className:"wp-block-seopulse-toc__schema-badge",children:(0,i.jsxs)("small",{children:[h.length," ",(0,t.__)("headings","seopulse"),p&&` · ${(0,t.__)("collapsible","seopulse")}`]})})]})]})},save:()=>null,deprecated:[{attributes:s.attributes,save:({attributes:e})=>{const{includeH1:s,minHeadings:t,collapsible:o,showNumbers:a}=e,i=l.useBlockProps.save({"data-include-h1":s?"true":"false","data-min-headings":String(t),"data-collapsible":o?"true":"false","data-show-numbers":a?"true":"false"});return(0,n.createElement)("div",i)}}]})})();