(()=>{"use strict";const e=window.React,n=window.wp.i18n,t=window.wp.components,o=window.wp.blocks,l=window.wp.element,r=window.wp.primitives,i=(0,e.createElement)(r.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,e.createElement)(r.Path,{d:"M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z"})),a=(0,e.createElement)(r.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,e.createElement)(r.Path,{d:"M17.031 4.703 15.576 4l-1.56 3H14v.03l-2.324 4.47H9.5V13h1.396l-1.502 2.889h-.95a3.694 3.694 0 0 1 0-7.389H10V7H8.444a5.194 5.194 0 1 0 0 10.389h.17L7.5 19.53l1.416.719L15.049 8.5h.507a3.694 3.694 0 0 1 0 7.39H14v1.5h1.556a5.194 5.194 0 0 0 .273-10.383l1.202-2.304Z"})),s=(window.wp.data,window.wp.blockEditor),c="noreferrer noopener",u="nofollow",w=window.wp.url;function p({rel:e="",url:n="",opensInNewTab:t,nofollow:o}){let l,r=e;if(t)l="_blank",r=r?.includes(c)?r:r+` ${c}`;else{const e=new RegExp(`\\b${c}\\s*`,"g");r=r?.replace(e,"").trim()}if(o)r=r?.includes(u)?r:(r+` ${u}`).trim();else{const e=new RegExp(`\\b${u}\\s*`,"g");r=r?.replace(e,"").trim()}return{url:(0,w.prependHTTP)(n),linkTarget:l,rel:r||void 0}}const m=[...s.__experimentalLinkControl.DEFAULT_LINK_SETTINGS,{id:"nofollow",title:(0,n.__)("Mark as nofollow")}],_=JSON.parse('{"UU":"gutenify/link-wrapper"}'),d="gutenify",f=window?.[`_${d}_vars`]?window[`_${d}_vars`]:{},{is_pro_activated:k,pro_account_url:v,pro_license_status:b,title:g,prefix:h,slug:E,authorWebSite:T,authorDemoWebSite:I,authorWebSiteProPage:S,defaultTheme:B,authorWebSiteSupport:H,plugin_directory_url:C,brand_color:L,plugin_main_version:x,documentationsURL:N,pro_title:P,active_blocks:$,plugin_main_camel_case_name:U}=f,{map:R}=(f?.siteUrl?f.siteUrl:f.site_url,(0,n.sprintf)("Want to enjoy all feature of blocks? Checkout %1$s%2$s%3$s.",'<a href="'+S+'" target="_blank">',P,"</a>"),window?.[`_${h}_vars`]?.components?.Icons),{UU:A}=_,M={icon:(0,e.createElement)(t.Icon,{icon:R}),edit:o=>{const{attributes:r,isSelected:c,setAttributes:u}=o,{linkTarget:w,rel:_,url:d}=r,f=(0,l.useRef)(),[k,v]=(0,l.useState)(!1),[b,g]=(0,l.useState)(null),h=!!d,E="_blank"===w,T=!!_?.includes("nofollow");function I(){u({url:void 0,linkTarget:void 0,rel:void 0}),v(!1)}(0,l.useEffect)((()=>{c||v(!1)}),[c]);const S=(0,l.useMemo)((()=>({url:d,opensInNewTab:E,nofollow:T})),[d,E,T]),B=(0,s.useBlockProps)(),H=(0,s.useInnerBlocksProps)(B,{renderAppender:s.InnerBlocks.DefaultBlockAppender});return(0,e.createElement)("div",{...H},c&&(0,e.createElement)(s.BlockControls,{group:"block"},!h&&(0,e.createElement)(t.ToolbarButton,{name:"link",icon:i,title:(0,n.__)("Link"),onClick:function(e){e.preventDefault(),v(!0)},ref:f}),h&&(0,e.createElement)(t.ToolbarButton,{name:"link",icon:a,title:(0,n.__)("Unlink"),onClick:I,isActive:!0,ref:f})),c&&(k||h)&&(0,e.createElement)(t.Popover,{placement:"bottom",onClose:()=>{v(!1)},anchor:b,focusOnMount:!!k&&"firstElement",__unstableSlotName:"__unstable-block-tools-after",shift:!0},(0,e.createElement)(s.__experimentalLinkControl,{value:S,onChange:({url:e,opensInNewTab:n,nofollow:t})=>u(p({rel:_,url:e,opensInNewTab:n,nofollow:t})),onRemove:()=>{I()},forceIsEditingLink:k,settings:m})),c&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)(s.InspectorControls,null,(0,e.createElement)(s.__experimentalLinkControl,{value:S,onChange:({url:e,opensInNewTab:n,nofollow:t})=>u(p({rel:_,url:e,opensInNewTab:n,nofollow:t})),onRemove:()=>{I()},forceIsEditingLink:k,settings:m}))),H.children)},save:function(n){const{attributes:t}=n,{url:o,linkTarget:l,rel:r}=t,i=s.useBlockProps.save(),a=s.useInnerBlocksProps.save(i);return(0,e.createElement)("a",{...a,href:o,target:l,rel:r},a.children)}};(0,o.registerBlockType)(A,{...M})})();