(()=>{"use strict";const e=window.wp.plugins,t=window.wp.components,o=window.wp.i18n,r=window.wp.editPost,s=window.wp.data,i=window.ReactJSXRuntime;(0,e.registerPlugin)("pressforward-nomination-pre-publish-panel",{render:({})=>{const{editPost:e}=(0,s.useDispatch)("core/editor"),{postType:n,sendToDraft:d,subscribeToFeed:a}=(0,s.useSelect)((e=>{const t=e("core/editor").getEditedPostAttribute("meta"),o=t?.send_to_draft||!1,r=t?.subscribe_to_feed||!1;return{postType:e("core/editor").getEditedPostAttribute("type"),sendToDraft:o,subscribeToFeed:r}}));if("nomination"===n)return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(r.PluginPrePublishPanel,{icon:"controls-forward",title:(0,o.__)("Send to Draft","pressforward"),initialOpen:!0,children:[(0,i.jsx)("p",{children:(0,o.__)("Typically, nominated items are sent to Dashboard > Nominations, where they must be promoted to Draft status. Check this box to send this nomination directly to Draft.","pressforward")}),(0,i.jsx)(t.CheckboxControl,{label:(0,o.__)("Send to Draft","pressforward"),onChange:t=>{e({meta:{send_to_draft:t?"1":"0"}})},checked:d})]}),(0,i.jsxs)(r.PluginPrePublishPanel,{icon:"controls-forward",title:(0,o.__)("Subscribe to Feed","pressforward"),initialOpen:!1,children:[(0,i.jsx)("p",{children:(0,o.__)("If PressForward can find a feed associated with this item, the feed will be added to your Subscribed Feeds list.","pressforward")}),(0,i.jsx)(t.CheckboxControl,{label:(0,o.__)("Subscribe to Feed","pressforward"),onChange:t=>{e({meta:{subscribe_to_feed:t?"1":"0"}})},checked:a})]})]})}}),(0,e.registerPlugin)("pressforward-nomination-keywords-control",{render:({})=>{const{keywords:e,postStatus:n,postType:d}=(0,s.useSelect)((e=>{const t=e("core/editor").getEditedPostAttribute("meta");return{keywords:t?.item_tags?t.item_tags.split(","):[],postStatus:e("core/editor").getEditedPostAttribute("status"),postType:e("core/editor").getEditedPostAttribute("type")}})),{nominationPostType:a}=pfBlocks;if(a!==d||"publish"===n)return null;const c=[(0,o.__)("via bookmarklet","pressforward")],l=[...e,...c];return(0,i.jsxs)(r.PluginDocumentSettingPanel,{icon:"controls-forward",name:"pressforward-nomination-keywords-control",title:(0,o.__)("Keywords","pressforward"),children:[e&&e.length>0&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("p",{children:(0,o.__)("PressForward has identified the following keywords on the source item:","pressforward")}),(0,i.jsx)("p",{children:(0,i.jsx)("strong",{children:e.join(", ")})}),(0,i.jsx)("p",{children:(0,o.__)("Often, keywords on source content are not useful for the purposes of PressForward curation, so they are not added as nomination tags by default. You may convert the keywords to tags by clicking the button below.","pressforward")}),(0,i.jsx)(t.Button,{isSecondary:!0,onClick:()=>{(async e=>{try{const t=await(async e=>{const t=wp.api.collections.Tags,o=e.map((e=>new Promise(((o,r)=>{const s=new t,i=e.replace(/&/g,"&amp;");s.fetch({data:{search:i}}).done((t=>{let r={};t.length?(t=t.filter((e=>e.name===i)),r=t.reduce(((e,t)=>(e[t.name]=t.id,e)),{}),o(r)):new wp.api.models.Tag({name:e}).save().done((t=>{r[e]=t.id,o(r)}))})).fail((t=>{console.error(`Failed to fetch tag for ${e}:`,t),r(t)}))})))),r=await Promise.all(o);return Object.assign({},...r)})(e);wp.data.dispatch("core/editor").editPost({tags:Object.values(t)})}catch(e){console.error("Error creating tags:",e)}})(l)},children:(0,o.__)("Add Keywords as Tags","pressforward")})]}),0===e.length&&(0,i.jsx)("p",{children:(0,o.__)('PressForward was unable to identify any keywords on the source item. Use the "Tags" interface to add your own keywords.',"pressforward")})]})}}),function(e){const t=e.data.select,o=e.data.subscribe,r=new URLSearchParams(document.location.search).get("u");o((()=>{if("nomination"!==t("core/editor").getEditedPostAttribute("type"))return;if("publish"!==t("core/editor").getEditedPostAttribute("status"))return;const e=t("core/editor").isSavingPost(),o=t("core/editor").didPostSaveRequestSucceed(),s=t("core/editor").isAutosavingPost(),i=t("core/editor").isEditedPostNew();e&&!s&&o&&!i&&setTimeout((()=>{window.location.href=`${pfNominateThisBlockEditor.nominationSuccessUrl}&nominatedUrl=${r}`}),1e3)}))}(window.wp)})();