(()=>{"use strict";const e=window.wp.blocks,t=window.wp.blockEditor,a=window.wp.components,l=window.wp.i18n,n=JSON.parse('{"UU":"gateway/string"}'),o=window.ReactJSXRuntime;(0,e.registerBlockType)(n.UU,{edit:({attributes:e,setAttributes:n,context:i})=>{const{contextNamespace:r,fieldKey:s,useAdvancedPath:p,propertyPath:c,fallbackText:d,wrapperElement:h}=e,y=(0,t.useBlockProps)(),g=i["gateway/itemName"]||"item",w=i["gateway/inLoop"]||!1,_=i["gateway/availableFields"]||[],u=i["gateway/fieldDefinitions"]||{},x=i["gateway/previewItems"]||[];let m="";p&&c?m=`context.${c}`:s&&(m=w?`context.${g}.${s}`:`context.${s}`);let v=null;s&&x.length>0&&(v=x[0][s]);const b=[{value:"",label:(0,l.__)("— Select a field —","gateway")},..._.map(e=>{const t=u[e];let a=e;if(t){const l=t.label||e,n=t.type?` (${t.type})`:"";a=l!==e?`${l}${n} — ${e}`:`${e}${n}`}return{value:e,label:a}})];return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.InspectorControls,{children:(0,o.jsxs)(a.PanelBody,{title:(0,l.__)("Field Settings","gateway"),children:[_.length>0?(0,o.jsx)(a.SelectControl,{label:(0,l.__)("Field Key","gateway"),help:w?(0,l.__)(`Select the field to display. Will access: ${g}.fieldname`,"gateway"):(0,l.__)("Select the field to display from the data context","gateway"),value:s,options:b,onChange:e=>n({fieldKey:e})}):(0,o.jsx)(a.TextControl,{label:(0,l.__)("Field Key","gateway"),help:w?(0,l.__)(`Enter the field name (e.g., "title"). Will access: ${g}.fieldname`,"gateway"):(0,l.__)("Enter the field name to display from the data context","gateway"),value:s,onChange:e=>n({fieldKey:e}),placeholder:"title"}),(0,o.jsx)(a.TextControl,{label:(0,l.__)("Fallback Text","gateway"),help:(0,l.__)("Text to display when data is not yet loaded","gateway"),value:d,onChange:e=>n({fallbackText:e}),placeholder:(0,l.__)("Loading...","gateway")}),(0,o.jsx)(a.SelectControl,{label:(0,l.__)("Wrapper Element (optional)","gateway"),help:(0,l.__)("Choose an HTML element to wrap the string. Leave empty for no wrapper.","gateway"),value:h,options:[{value:"",label:(0,l.__)("None (span only)","gateway")},{value:"div",label:"div"},{value:"p",label:"p"},{value:"h1",label:"h1"},{value:"h2",label:"h2"},{value:"h3",label:"h3"},{value:"h4",label:"h4"},{value:"h5",label:"h5"},{value:"h6",label:"h6"},{value:"strong",label:"strong"},{value:"em",label:"em"},{value:"li",label:"li"}],onChange:e=>n({wrapperElement:e})}),(0,o.jsx)(a.ToggleControl,{label:(0,l.__)("Use Advanced Property Path","gateway"),help:(0,l.__)("Enable to manually specify the full property path","gateway"),checked:p,onChange:e=>n({useAdvancedPath:e})}),p&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(a.TextControl,{label:(0,l.__)("Property Path","gateway"),help:(0,l.__)('Full property path in context (e.g., "item.title", "items[0].name")',"gateway"),value:c,onChange:e=>n({propertyPath:e}),placeholder:"item.title"}),(0,o.jsx)(a.TextControl,{label:(0,l.__)("Context Namespace (optional)","gateway"),help:(0,l.__)("Override the interactivity namespace. Leave empty to use parent context.","gateway"),value:r,onChange:e=>n({contextNamespace:e}),placeholder:"gateway/data-source"})]})]})}),(0,o.jsx)("div",{...y,children:v||d||(s?`{${s}}`:(0,l.__)("[Dynamic String]","gateway"))})]})},save:({attributes:e})=>{const{contextNamespace:a,fieldKey:l,useAdvancedPath:n,propertyPath:i,fallbackText:r,wrapperElement:s}=e,p=t.useBlockProps.save();let c="";if(n&&i?c=`context.${i}`:l&&(c=`context.item.${l}`),!c){const e=s||"span";return(0,o.jsx)(e,{...p,children:r})}const d={"data-wp-text":c};a&&(d["data-wp-interactive"]=a);const h=(0,o.jsx)("span",{...d,children:r});if(s){const e=s;return(0,o.jsx)(e,{...p,children:h})}return(0,o.jsx)("span",{...p,...d,children:r})}})})();