File: /home/aprilnet/public_html/operationreality.org/wp-content/plugins/imageseo/dist/adminv2/index.js
(()=>{"use strict";var e={n:t=>{var a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},d:(t,a)=>{for(var n in a)e.o(a,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:a[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};window.React;const t=window.wp.components,a=window.wp.element,n=window.wp.i18n,i=window.wp.apiFetch;var o=e.n(i);const s=async e=>{try{return await o()({path:"imageseo/v1/optimize-image/",method:"POST",data:e})}catch(e){console.error("Error calling the api:",e)}},r=async e=>{try{return await o()({path:"imageseo/v1/save-property/",method:"POST",data:e})}catch(e){console.error("Error calling the api:",e)}},c=new class{constructor(){this.listeners={}}subscribe(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}publish(e,t){this.listeners[e]&&this.listeners[e].forEach((e=>e(t)))}unsubscribe(e,t){this.listeners[e]&&(this.listeners[e]=this.listeners[e].filter((e=>e!==t)))}};function l({attachmentId:e,alt:i}){const[o,l]=(0,a.useState)(i),[m,u]=(0,a.useState)(!1),[d,p]=(0,a.useState)(!1),[h,g]=(0,a.useState)(null),[b,_]=(0,a.useState)("");return React.createElement(t.Flex,{direction:"column"},React.createElement(t.FlexItem,null,React.createElement(t.TextControl,{label:(0,n.__)("Alt","imageseo"),value:o||"",onChange:l})),React.createElement(t.FlexItem,null,React.createElement(t.ButtonGroup,null,React.createElement(t.Button,{style:{margin:"0 6px"},onClick:async()=>{m||(u(!0),g(!1),_("save"),r({id:e,action:"saveAlt",value:o}).then((e=>{u(!1),e?.error||(l(e.altText||""),p(!0),g(!0),c.publish("snackbar",{content:(0,n.__)("Alt saved","imageseo"),status:"info"}))})).catch((e=>{console.error(e),u(!1),p(!0),g(!1),c.publish("snackbar",{content:(0,n.__)("Something went wrong!","imageseo"),status:"error"})})))},variant:"primary",isBusy:m},"save"===b&&d&&h?(0,n.__)("Saved","imageseo"):(0,n.__)("Save","imageseo")),React.createElement(t.Button,{variant:"tertiary",onClick:async()=>{m||(u(!0),g(!1),_("optimize"),s({id:e,action:"optimizeAlt"}).then((e=>{u(!1),e?.error||(l(e.altText||""),p(!0),g(!0),c.publish("snackbar",{content:(0,n.__)("Alt optimized","imageseo"),status:"info"}))})).catch((e=>{c.publish("snackbar",{content:(0,n.__)("Something went wrong!","imageseo"),status:"error"}),console.error(e),u(!1),p(!0),g(!1)})))},isBusy:m},"optimize"===b&&d&&h?(0,n.__)("Optimized","imageseo"):(0,n.__)("Optimize","imageseo")))))}function m({attachmentId:e,filename:i}){const[o,l]=(0,a.useState)(i),[m,u]=(0,a.useState)(!1),[d,p]=(0,a.useState)(!1),[h,g]=(0,a.useState)(null),[b,_]=(0,a.useState)("");return React.createElement(React.Fragment,null,React.createElement(t.Flex,{direction:"column"},React.createElement(t.FlexItem,null,React.createElement(t.TextControl,{label:(0,n.__)("Filename","imageseo"),value:o||"",onChange:l})),React.createElement(t.FlexItem,null,React.createElement(t.ButtonGroup,null,React.createElement(t.Button,{style:{margin:"0 6px"},onClick:async()=>{m||(u(!0),g(!1),_("save"),r({id:e,action:"saveFilename",value:o}).then((e=>{u(!1),e?.error||(p(!0),g(!0),l(e.filename||""),c.publish("snackbar",{content:(0,n.__)("Filename saved","imageseo"),status:"info"}))})).catch((e=>{console.error(e),p(!0),g(!1),u(!1),c.publish("snackbar",{content:(0,n.__)("Something went wrong!","imageseo"),status:"error"})})))},variant:"primary",isBusy:m},"save"===b&&d&&h?(0,n.__)("Saved","imageseo"):(0,n.__)("Save","imageseo")),React.createElement(t.Button,{variant:"tertiary",onClick:async()=>{m||(_("optimize"),u(!0),g(!1),s({id:e,action:"optimizeFilename"}).then((e=>{u(!1),e?.error||(l(e.filename||""),p(!0),g(!0),c.publish("snackbar",{content:(0,n.__)("Filename optimized","imageseo"),status:"info"}))})).catch((e=>{console.error(e),u(!1),g(!1),p(!0),c.publish("snackbar",{content:(0,n.__)("Something went wrong!","imageseo"),status:"error"})})))},isBusy:m},"optimize"===b&&d&&h?(0,n.__)("Optimized","imageseo"):(0,n.__)("Optimize","imageseo"))))))}function u(){const[e,n]=(0,a.useState)([]),i=(0,a.useCallback)((e=>{const t={id:(new Date).getTime(),...e,content:e?.content||"",politeness:e?.politeness||"polite",actions:e?.actions||[],explicitDismiss:e?.explicitDismiss||!1};n((e=>[...e,t]))}),[]),o=(0,a.useCallback)((e=>{n((t=>t.filter((t=>t.id!==e))))}),[]);return(0,a.useEffect)((()=>(console.log("Snackbar mounted"),c.subscribe("snackbar",i),()=>{c.unsubscribe("snackbar",i)})),[i]),React.createElement(t.SnackbarList,{notices:e,onRemove:o})}document.addEventListener("DOMContentLoaded",(()=>{const e=document.querySelectorAll(".media-column-imageseo-alt"),t=document.querySelectorAll(".media-column-imageseo-filename");e.forEach((e=>{const t=(0,a.createRoot)(e),n=e.getAttribute("data-id"),i=window[`mediaColumnImageSeoAlt${n}`],o=i?.alt?(new DOMParser).parseFromString(i.alt,"text/html").body.textContent:"";t.render(React.createElement(l,{attachmentId:n,alt:o}))})),t.forEach((e=>{const t=(0,a.createRoot)(e),n=e.getAttribute("data-id"),i=e.getAttribute("data-filename");t.render(React.createElement(m,{attachmentId:n,filename:i}))}));const n=document.getElementById("wpbody-content"),i=document.createElement("div"),o=document.createElement("div");o.setAttribute("id","imageseo-snackbar-wrapper"),i.setAttribute("id","imageseo-snackbar-root"),o.style.position="fixed",o.style.left="10px",o.style.right="10px",o.style.bottom="10px",o.style.zIndex="1000",o.style.textAlign="center",o.style.width="100%",o.style.height="50px",o.style.pointerEvents="none",n.prepend(o),o.appendChild(i),(0,a.createRoot)(document.getElementById("imageseo-snackbar-root")).render(React.createElement(u,null))}))})();