(()=>{"use strict";var e,n={511:(e,n,t)=>{const i=window.wp.blocks,r=window.wp.plugins,o=window.wp.element,l=window.wp.components,s=window.wp.data,a=window.wp.blockEditor,c=window.wp.compose,d=window.wp.hooks,p=window.wp.apiFetch;var u=t.n(p);const h=window.ReactJSXRuntime;let f={isOpen:!1,setOpen:null};function g(){const[e,n]=(0,o.useState)(!1),[t,i]=(0,o.useState)(""),[r,a]=(0,o.useState)([]),[c,d]=(0,o.useState)(!1),[p,g]=(0,o.useState)(""),[w,k]=(0,o.useState)(""),{createBlock:m}=wp.blocks,{insertBlocks:v}=(0,s.useDispatch)("core/block-editor");(0,o.useEffect)((()=>(f.setOpen=n,()=>{f.setOpen=null})),[]),(0,o.useEffect)((()=>{f.isOpen=e}),[e]),(0,o.useEffect)((()=>{if(!t.trim())return void a([]);const e=setTimeout((()=>{x(t)}),500);return()=>clearTimeout(e)}),[t]);const x=async e=>{d(!0);try{const n=await u()({path:`/linkfiliate/v1/search-link?s=${encodeURIComponent(e)}`});a(n.data||[])}catch(e){console.error("Search error:",e),a([])}finally{d(!1)}},b=()=>{i(""),a([]),g(""),k(""),n(!1)};return e?(0,h.jsxs)(l.Modal,{title:"Select LinkFiliate Link",onRequestClose:b,className:"linkfiliate-modal",children:[(0,h.jsx)(l.TextControl,{label:"Search For a Link:",value:t,onChange:e=>i(e),placeholder:"Type to search..."}),c&&(0,h.jsx)("div",{style:{padding:"1rem",textAlign:"center"},children:(0,h.jsx)(l.Spinner,{})}),!c&&r.length>0&&(0,h.jsx)("div",{style:{marginTop:"1rem",maxHeight:"300px",overflowY:"auto"},children:r.map((e=>(0,h.jsxs)("div",{onClick:()=>{g(e.name),k(e.slug)},style:{padding:"0.75rem",border:"1px solid #ddd",borderRadius:"4px",marginBottom:"0.5rem",cursor:"pointer",backgroundColor:w===e.slug?"#e0f2fe":"#fff"},children:[(0,h.jsx)("strong",{children:e.name}),(0,h.jsxs)("div",{style:{fontSize:"0.875rem",color:"#666"},children:["Slug : (",e.slug,")"]})]},e.slug)))}),!c&&t&&0===r.length&&(0,h.jsx)("div",{style:{padding:"1rem",textAlign:"center",color:"#666"},children:"No links found"}),(0,h.jsxs)("div",{style:{marginTop:"1rem",textAlign:"right"},children:[(0,h.jsx)(l.Button,{variant:"secondary",style:{marginRight:"0.5rem"},onClick:b,children:"Cancel"}),(0,h.jsx)(l.Button,{variant:"primary",onClick:()=>{if(!w)return;const e=r.find((e=>e.slug===w)),n=e?.settings||{},{no_follow:t=!1,sponsored:i=!1,parameter_forwarding:o=!1,tracking:l=!0,redirect_type:s="302"}=n,a=[];t&&a.push("nofollow"),i&&a.push("sponsored");const c=a.length?` rel="${a.join(" ")}"`:"",d=l?' target="_blank"':"",u=`${window.location.origin}/${w}`,h=m("core/paragraph",{content:`<a href="${u}" class="linkfiliate-link"${d}${c}>${p}</a>`});v([h]),b()},disabled:!w,children:"Apply Link"})]})]}):null}const w=(0,c.createHigherOrderComponent)((e=>n=>(0,h.jsxs)(o.Fragment,{children:[(0,h.jsx)(e,{...n}),(0,h.jsx)(a.BlockControls,{children:(0,h.jsx)(l.ToolbarButton,{label:"Insert LinkFiliate",onClick:()=>{f.setOpen&&f.setOpen(!0)},style:{color:"#000",borderRight:"1px solid #1e1e1e"},children:(0,h.jsx)("img",{src:"/wp-content/plugins/linkfiliate/assets/icons/icon-128x128.png",alt:"LinkFiliate",style:{width:40,height:40}})})})]})),"addLinkfiliateButton");(0,d.addFilter)("editor.BlockEdit","linkfiliate/add-toolbar-button",w);const k=window.wp.i18n,m=JSON.parse('{"UU":"linkfiliate/block-1"}');(0,i.registerBlockType)(m.UU,{edit:function(){return(0,h.jsx)("p",{...(0,a.useBlockProps)(),children:(0,k.__)("Hello from the editor!","wordpress-plugin-boilerplate")})},save:function(){return(0,h.jsx)("p",{...a.useBlockProps.save(),children:"Hello from the saved content!"})}}),(0,r.registerPlugin)("linkfiliate-toolbar",{render:function(){return(0,h.jsx)(g,{})}})}},t={};function i(e){var r=t[e];if(void 0!==r)return r.exports;var o=t[e]={exports:{}};return n[e](o,o.exports,i),o.exports}i.m=n,e=[],i.O=(n,t,r,o)=>{if(!t){var l=1/0;for(d=0;d<e.length;d++){for(var[t,r,o]=e[d],s=!0,a=0;a<t.length;a++)(!1&o||l>=o)&&Object.keys(i.O).every((e=>i.O[e](t[a])))?t.splice(a--,1):(s=!1,o<l&&(l=o));if(s){e.splice(d--,1);var c=r();void 0!==c&&(n=c)}}return n}o=o||0;for(var d=e.length;d>0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[t,r,o]},i.n=e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return i.d(n,{a:n}),n},i.d=(e,n)=>{for(var t in n)i.o(n,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:n[t]})},i.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),(()=>{var e={57:0,350:0};i.O.j=n=>0===e[n];var n=(n,t)=>{var r,o,[l,s,a]=t,c=0;if(l.some((n=>0!==e[n]))){for(r in s)i.o(s,r)&&(i.m[r]=s[r]);if(a)var d=a(i)}for(n&&n(t);c<l.length;c++)o=l[c],i.o(e,o)&&e[o]&&e[o][0](),e[o]=0;return i.O(d)},t=globalThis.webpackChunkLinkFiliate=globalThis.webpackChunkLinkFiliate||[];t.forEach(n.bind(null,0)),t.push=n.bind(null,t.push.bind(t))})();var r=i.O(void 0,[350],(()=>i(511)));r=i.O(r)})();