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