(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,s=window.wp.editPost,n=window.wp.plugins,a=window.wp.data,o=window.wp.element,i=window.wp.components,l=window.wp.apiFetch;var r=e.n(l);const c=window.ReactJSXRuntime;function d({saveOnToggle:e=!1}){const{disableAutoAds:s,postId:n,isSaving:l,postBlocks:d}=(0,a.useSelect)((e=>{const{getEditedPostAttribute:t,getCurrentPostId:s,isSavingPost:n}=e("core/editor"),{getBlocks:a}=e("core/block-editor");return{disableAutoAds:t("meta").disable_auto_ads,postId:s(),isSaving:n(),postBlocks:a()}})),{editPost:w,savePost:u}=(0,a.useDispatch)("core/editor"),[p,g]=(0,o.useState)({count:0,label:(0,t.__)("ads","newspack-newsletters")}),[_,h]=(0,o.useState)(!1);(0,o.useEffect)((()=>{let e=!1;d.forEach((t=>{"newspack-newsletters/ad"===t.name&&(e=!0)})),h(e)}),[d]);const[b,f]=(0,o.useState)(!1);return(0,o.useEffect)((()=>{f(!0),r()({path:`/wp/v2/newspack_nl_ads_cpt/config/?postId=${n}`}).then((e=>{g(e)})).catch((e=>{console.warn(e)})).finally((()=>{f(!1)}))}),[n]),(0,c.jsxs)("div",{children:[(0,c.jsx)(i.ToggleControl,{label:(0,t.__)("Enable automatic insertion of ads","newspack-newsletters"),checked:!s&&!_,disabled:l||b||_,onChange:t=>{w({meta:{disable_auto_ads:!t}}),e&&u()}}),_?(0,c.jsx)("p",{children:(0,t.__)("Automatic ads insertion is disabled because this post contain manually inserted ad blocks.","newspack-newsletters")}):null,b?null:(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("p",{children:(0,t.sprintf)(
// Translators: help message showing number of active ads.
// Translators: help message showing number of active ads.
(0,t._n)("There is %1$d active %2$s.","There are %1$d active %2$ss.",p.count,"newspack-newsletters"),p.count,p.label)}),(0,c.jsx)(i.Button,{href:p.manageUrl,rel:p.manageUrlRel,target:p.manageUrlTarget,variant:"secondary",children:
// Translators: "manage ad" message.
// Translators: "manage ad" message.
(0,t.sprintf)((0,t.__)("Manage %ss","newspack-newsletters"),p.label)})]})]})}(0,n.registerPlugin)("newspack-newsletters-ads-settings",{render:function(){return(0,c.jsx)(s.PluginDocumentSettingPanel,{name:"newsletters-ads-settings-panel",title:(0,t.__)("Ads Settings","newspack-newsletters"),children:(0,c.jsx)(d,{})})},icon:null})})();