(()=>{"use strict";const e=window.wp.blocks,t=window.wp.i18n,a=window.wp.blockEditor,n=window.wp.components,o=(window.wp.data,window.React),l=window.wp.primitives,i=(0,o.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(l.Path,{d:"M6 5V18.5911L12 13.8473L18 18.5911V5H6Z"})),s=(0,o.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(l.Path,{d:"m9.99609 14v-.2251l.00391.0001v6.225h1.5v-14.5h2.5v14.5h1.5v-14.5h3v-1.5h-8.50391c-2.76142 0-5 2.23858-5 5 0 2.7614 2.23858 5 5 5z"})),r=JSON.parse('{"UU":"gateway/gts-bound-string"}'),c=window.ReactJSXRuntime,d=[{label:(0,t.__)("Span","gateway"),value:"span"},{label:(0,t.__)("Paragraph","gateway"),value:"p"},{label:(0,t.__)("Div","gateway"),value:"div"},{label:(0,t.__)("Heading 1","gateway"),value:"h1"},{label:(0,t.__)("Heading 2","gateway"),value:"h2"},{label:(0,t.__)("Heading 3","gateway"),value:"h3"},{label:(0,t.__)("Heading 4","gateway"),value:"h4"},{label:(0,t.__)("Strong","gateway"),value:"strong"},{label:(0,t.__)("Emphasis","gateway"),value:"em"}];(0,e.registerBlockType)(r.UU,{edit:function({attributes:e,setAttributes:o,context:l}){const{content:r,tagName:g,placeholder:w}=e,h=l?.["gateway/collection-records/collection"],_=l?.["gateway/collection-records/recordId"],p=l?.postId,u=e?.metadata?.bindings?.content,x=(0,a.useBlockProps)({className:"wp-block-gateway-bound-string"});return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(a.BlockControls,{children:(0,c.jsx)(n.ToolbarGroup,{children:(0,c.jsx)(n.ToolbarDropdownMenu,{icon:g.startsWith("h")?i:s,label:(0,t.__)("Change tag","gateway"),controls:d.map(e=>({title:e.label,isActive:g===e.value,onClick:()=>o({tagName:e.value})}))})})}),(0,c.jsxs)(a.InspectorControls,{children:[(0,c.jsxs)(n.PanelBody,{title:(0,t.__)("Settings","gateway"),children:[(0,c.jsx)(n.SelectControl,{label:(0,t.__)("HTML Tag","gateway"),value:g,options:d,onChange:e=>o({tagName:e}),__nextHasNoMarginBottom:!0}),(0,c.jsx)(n.TextControl,{label:(0,t.__)("Placeholder","gateway"),value:w,onChange:e=>o({placeholder:e}),help:(0,t.__)("Shown when content is empty","gateway"),__nextHasNoMarginBottom:!0})]}),(0,c.jsxs)(n.PanelBody,{title:(0,t.__)("Binding Info","gateway"),initialOpen:!1,children:[u?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:(0,t.__)("Source:","gateway")})," ",e.metadata.bindings.content.source]}),(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:(0,t.__)("Field:","gateway")})," ",e.metadata.bindings.content.args?.field||"content"]}),(_||p)&&(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:(0,t.__)("Context ID:","gateway")})," ",_||p]})]}):(0,c.jsx)("p",{children:(0,t.__)("No binding configured. Use the block toolbar or Attributes panel to add a binding.","gateway")}),h&&(0,c.jsxs)("p",{style:{marginTop:"12px",color:"#666",fontSize:"12px"},children:[(0,t.__)("Inside Collection Records loop:","gateway")," ",(0,c.jsx)("code",{children:h})]})]})]}),(0,c.jsx)("div",{...x,children:u?(()=>{if(u){const t=e.metadata.bindings.content,a=t.source||"unknown",n=t.args?.field||"content",o=t.args?.id||_||p;return(0,c.jsx)("span",{className:"wp-block-gateway-bound-string__indicator",children:`[${a}: ${n}${o?` #${o}`:""}]`})}return null})():(0,c.jsx)(a.RichText,{tagName:g,value:r,onChange:e=>o({content:e}),placeholder:w||(0,t.__)("Add text or use bindings...","gateway"),allowedFormats:["core/bold","core/italic","core/link"]})})]})},save:function({attributes:e}){const{content:t,tagName:n}=e,o=a.useBlockProps.save(),l=n;return(0,c.jsx)(l,{...o,children:(0,c.jsx)(a.RichText.Content,{value:t})})}})})();