"use strict";(globalThis.webpackChunkstackable=globalThis.webpackChunkstackable||[]).push([[545],{7977:(e,t,i)=>{i.r(t),i.d(t,{default:()=>v});var a=i(2610),n=i(910),o=i(1205),c=i(8003),s=i(7537),l=i(2527),r=i(2814);let d=!1,u={status:null===n.cimo||void 0===n.cimo?void 0:n.cimo.status,action:null===n.cimo||void 0===n.cimo?void 0:n.cimo.action};const m=e=>{const{inMediaLibrary:t=!1}=e,[i,o]=(0,a.useState)(u),l=(0,a.useRef)(0),m=function(e,t){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];d||(d=!0,fetch(n.ajaxUrl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"stackable_check_cimo_status",user_action:e,nonce:n.cimo.nonce}),credentials:"same-origin"}).then((e=>e.json())).then((a=>{if(d=!1,!a.success){var n;o({status:"error",action:""});const e=null!=a&&null!==(n=a.data)&&void 0!==n&&n.message?a.data.message:"Server error";throw new Error("Stackable: "+e)}0===l.current&&t&&window.open(t,"_blank"),l.current+=1;const c=a.data;var s;if(i||l.current>=3||"install"===e&&("installed"===c.status||"activated"===c.status)||"activate"===e&&"activated"===c.status)return u=c,o(u),void("undefined"!=typeof window&&null!==(s=window.stackable)&&void 0!==s&&s.cimo&&(window.stackable.cimo.status=c.status,window.stackable.cimo.action=c.action));setTimeout((()=>{m(e)}),3e3*l.current)})).catch((e=>{console.error(e.message)})).finally((()=>{d=!1})))};return(0,a.useEffect)((()=>{if(t)return;const e=wp.media,i=e.view.MediaFrame.Select;e.view.MediaFrame.Select=i.extend({initialize(){i.prototype.initialize.apply(this,arguments),this.on("close",(()=>{l.current=0;const e="installing"===u.status?"install":"activating"===u.status&&"activate";e&&(o(u),setTimeout((()=>{m(e,null)}),1e3))}))}})}),[]),(0,a.createElement)(a.Fragment,null,(0,a.createElement)("button",{"aria-label":"dismiss",onClick:()=>{var t,i;new r.models.Settings({stackable_hide_cimo_notice:!0}).save(),n.cimo&&(n.cimo.hideNotice=!0),"undefined"!=typeof window&&null!==(t=window.stackable)&&void 0!==t&&t.cimo&&(window.stackable.cimo.hideNotice=!0),null==e||null===(i=e.onDismiss)||void 0===i||i.call(e)}},(0,a.createElement)(s.Dashicon,{icon:"no"})),"activated"===i.status?(0,a.createElement)("p",null,(0,c.__)("Cimo Image Optimizer has been activated. Please refresh this page to begin optimizing your images automatically.",n.i18n)):(0,a.createElement)("p",null," ",(0,c.__)("Instantly optimize images as you upload them with Cimo Image Optimizer.",n.i18n)," ","installing"===i.status?(0,a.createElement)("span",null," ",(0,c.__)("Installing",n.i18n)):"activating"===i.status?(0,a.createElement)("span",null,(0,c.__)("Activating",n.i18n)," "):(0,a.createElement)("a",{href:i.action,target:"_blank",rel:"noreferrer",onClick:e=>{if(e.preventDefault(),l.current=0,"not_installed"===i.status)return u={status:"installing",action:""},o(u),void m("install",e.currentTarget.href);u={status:"activating",action:""},o(u),m("activate",e.currentTarget.href)}},"installed"===i.status?(0,c.__)("Activate now",n.i18n):(0,c.__)("Install now",n.i18n))))},v=e=>(0,a.createElement)("div",{className:"stk-cimo-notice"}," ",(0,a.createElement)(m,e)," ");(0,l.Z)((()=>{var e,t,i,c;if(!n.cimo||"activated"===n.cimo.status||n.cimo.hideNotice||"undefined"==typeof wp||null===(e=wp)||void 0===e||null===(t=e.media)||void 0===t||null===(i=t.view)||void 0===i||null===(c=i.Attachment)||void 0===c||!c.Details)return;const s=wp.media.view.Attachment.Details,l=s.extend({render(){const e=s.prototype.render.apply(this,arguments);if(null!==n.cimo&&void 0!==n.cimo&&n.cimo.hideNotice)return e;const t=this.el.querySelector(".attachment-info .details");if(t&&!this.el.querySelector(".stk-cimo-notice")){const e=document.createElement("div");e.className="stk-cimo-notice";const i=()=>{e&&e.parentNode&&e.parentNode.removeChild(e)};(0,o.createRoot)(e).render((0,a.createElement)(m,{onDismiss:i,inMediaLibrary:!0})),t.insertAdjacentElement("afterend",e)}return e}});wp.media.view.Attachment.Details=l}))}}]);