(()=>{"use strict";const t=window.wp.editor,e=window.wp.blockEditor,o=window.wp.plugins,i=window.wp.components,n=window.wp.data,a=window.wp.element,s=window.wp.i18n,r=window.wp.dom,l=window._activityPubOptions?.noteLength||500,u=["youtube","vimeo","dailymotion","tiktok","videopress"],d=["spotify","soundcloud","mixcloud"],c=["core/paragraph","core/heading","core/list-item","core/preformatted","core/verse","core/pullquote"],m=["core/gallery","jetpack/tiled-gallery","jetpack/slideshow"],p=(t,e)=>"core/pullquote"===t?e?.value||"":e?.content||"",g=t=>{const e={imageCount:0,galleryCount:0,videoCount:0,audioCount:0,textLength:0,textBlockCount:0};if(!t||!t.length)return e;for(const o of t){const{name:t,attributes:i,innerBlocks:n}=o;if("core/image"===t)e.imageCount++;else if(m.includes(t))e.galleryCount++;else if("core/video"===t)e.videoCount++;else if("core/audio"===t)e.audioCount++;else if("core/embed"===t){const t=(i?.providerNameSlug||"").toLowerCase();u.includes(t)?e.videoCount++:d.includes(t)&&e.audioCount++}if(c.includes(t)){const o=(0,r.__unstableStripHTML)(p(t,i));e.textLength+=o.length,e.textBlockCount++}if(n&&n.length){const t=g(n);e.imageCount+=t.imageCount,e.galleryCount+=t.galleryCount,e.videoCount+=t.videoCount,e.audioCount+=t.audioCount,e.textLength+=t.textLength,e.textBlockCount+=t.textBlockCount}}return e},h=window.ReactJSXRuntime;(0,o.registerPlugin)("activitypub-pre-publish",{render:()=>{const{blocks:o,postFormat:r}=(0,n.useSelect)(o=>({blocks:o(e.store).getBlocks(),postFormat:o(t.store).getEditedPostAttribute("format")}),[]),{editPost:u}=(0,n.useDispatch)(t.store),d=(0,a.useMemo)(()=>((t,e)=>{if(e&&"standard"!==e)return null;const o=g(t),i=o.imageCount>0||o.galleryCount>0||o.videoCount>0||o.audioCount>0;return(o.galleryCount>0||o.imageCount>1)&&o.textLength<l?{format:"gallery",message:(0,s.__)("This post contains multiple images. Setting the format to Gallery will share it as a media post, making it visible on platforms like Pixelfed.","activitypub")}:o.videoCount>0&&o.textLength<l?{format:"video",message:(0,s.__)("This post contains a video. Setting the format to Video will share it as a media post, improving compatibility with video-focused platforms.","activitypub")}:o.audioCount>0&&o.textLength<l?{format:"audio",message:(0,s.__)("This post contains audio content. Setting the format to Audio will share it as a media post, improving compatibility with audio-focused platforms.","activitypub")}:1===o.imageCount&&0===o.videoCount&&0===o.audioCount&&o.textLength<l?{format:"image",message:(0,s.__)("This post contains an image. Setting the format to Image will share it as a media post, making it visible on platforms like Pixelfed.","activitypub")}:!i&&o.textLength>0&&o.textLength<280&&o.textBlockCount<=3?{format:"status",message:(0,s.__)("This is a short post with no media. Setting the format to Status will share it as a Note, which is the standard format on platforms like Mastodon.","activitypub")}:null})(o,r),[o,r]);return"wordpress-post-format"!==window._activityPubOptions?.objectType?null:d?(0,h.jsxs)(t.PluginPrePublishPanel,{title:(0,s.__)("Fediverse ⁂","activitypub"),initialOpen:!0,children:[(0,h.jsx)("p",{children:d.message}),(0,h.jsx)(i.Button,{variant:"secondary",onClick:()=>u({format:d.format}),children:(0,s.sprintf)(/* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */
(0,s.__)("Set format to %s","activitypub"),d.format.charAt(0).toUpperCase()+d.format.slice(1))})]}):null}})})();