!function(){"use strict";var e={n:function(a){var t=a&&a.__esModule?function(){return a.default}:function(){return a};return e.d(t,{a:t}),t},d:function(a,t){for(var n in t)e.o(t,n)&&!e.o(a,n)&&Object.defineProperty(a,n,{enumerable:!0,get:t[n]})},o:function(e,a){return Object.prototype.hasOwnProperty.call(e,a)}},a=window.wp.blocks,t=window.wp.element,n=window.wp.components,i=window.wp.blockEditor,l=window.wp.data,r=window.wp.i18n,s=window.wp.apiFetch,u=e.n(s);var m=({attributes:e,setAttributes:s,clientId:m})=>{const o=wp.data.select("core").getCurrentUser(),{imageSizes:c="1024x1024",imageNumber:d=4}=e,[g,p]=(0,t.useState)(!1),[y,_]=(0,t.useState)(null),[E,h]=(0,t.useState)(null),[w,v]=(0,t.useState)(!1),[b,S]=(0,t.useState)(!1),[f,C]=(0,t.useState)(!1),[N,x]=(0,t.useState)(!1);(0,t.useEffect)((()=>{const e=document.getElementsByClassName("ayudante-ai-image-result"),a=document.getElementById("create-image-input");if(e.length>0)for(let a=0;a<e.length;a++)e[a].classList.remove("ayudante-ai-image-result-selected"),e[a].addEventListener("click",(()=>{var t;x(!0),e[a].classList.add("ayudante-ai-image-result-selected"),t=e[a].src,h(t)}),!1);e.length>0&&a.value.length>0&&!w&&C(a.value)}));return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:(0,r.__)("Settings","ayudanteai-plugin"),initialOpen:!0},(0,t.createElement)(n.RadioControl,{label:(0,r.__)("Images Size","ayudanteai-plugin"),selected:c,options:[{label:"256x256 px",value:"256x256"},{label:"512x512 px",value:"512x512"},{label:"1024x1024 px",value:"1024x1024"}],onChange:e=>{s({imageSizes:e})}}),(0,t.createElement)(n.__experimentalNumberControl,{max:"4",min:"1",label:(0,r.__)("Images Requested per prompt","ayudanteai-plugin"),value:d,onChange:e=>{s({imageNumber:e})}}))),(0,t.createElement)(n.Placeholder,{label:"Image Creator",instructions:(0,r.__)("Choose an Action to get started.","ayudanteai-plugin")},(0,t.createElement)(n.Button,{variant:"secondary",onClick:()=>p(!0)},"Create Image")),g&&(0,t.createElement)(n.Modal,{className:"ayudante-modal",title:`Hey ${o.name}, let's create an image together!`,onRequestClose:()=>p(!1)},(0,t.createElement)("p",null,(0,r.__)("Generate an Image using a description","ayudanteai-plugin")),(0,t.createElement)("input",{id:"create-image-input",type:"text",placeholder:"Type in some Ideas..."}),(0,t.createElement)(n.Button,{variant:"primary",onClick:()=>{const e=document.getElementById("create-image-input");_(null),v(!0),u()({path:"/ayudanteai/v1/generate/images",method:"POST",data:{prompt:e.value,image_number:d,image_size:c}}).then((e=>{_(e),v(!1)}))}},(0,r.__)("Create Images","ayudanteai-plugin")),w&&(0,t.createElement)("div",{className:"ayudante-ai-image-results-container ayudante-ai-image-loading"},(0,t.createElement)("p",{className:"text-images-loading ayudante-ai-help"},(0,r.__)("Creating your images...","ayudanteai-plugin")),(0,t.createElement)(n.Spinner,null),(0,t.createElement)("p",{className:"ayudante-ai-help ayudante-tip"},(0,r.__)("Tip: Large descriptive prompts tend to generate better images.","ayudanteai-plugin"))),b&&(0,t.createElement)("div",{className:"ayudante-ai-image-results-container ayudante-ai-image-loading"},(0,t.createElement)("p",{className:"text-images-loading ayudante-ai-help"},(0,r.__)("Uploading your image...","ayudanteai-plugin")),(0,t.createElement)(n.Spinner,null)),y&&(0,t.createElement)("div",null,(0,t.createElement)("p",{className:"text-images-loading center-ai"},(0,r.__)("Showing images of: ","ayudanteai-plugin"),f),(0,t.createElement)("div",{className:"ayudante-ai-image-results-container"},y.data.map((e=>(0,t.createElement)("img",{className:"ayudante-ai-image-result",src:e.url,width:"256",height:"256"}))),(0,t.createElement)("p",{className:"ayudante-ai-help ayudante-tip"},(0,r.__)("Not getting a good result? Get some inspiration from ","ayudanteai-plugin"),(0,t.createElement)("a",{href:"https://www.reddit.com/r/dalle2"},(0,r.__)("Users","ayudanteai-plugin"))),(0,t.createElement)(n.Button,{variant:"primary",disabled:!N,onClick:()=>{const e=document.getElementById("create-image-input");S(!0),u()({path:"/ayudanteai/v1/create-attachment/images",method:"POST",data:{post_title:e.value,attachment_url:E}}).then((t=>{const n=(0,a.createBlock)("core/image",{url:t.url,alt:e.value,id:t.id});S(!1),(0,l.dispatch)("core/editor").replaceBlock(m,n)}))}},(0,r.__)("Use selected Image","ayudanteai-plugin"))))))},o=JSON.parse('{"title":"Image Creator","description":"Type a prompt and get an image back powered by AI!","name":"ayudanteai/image-creator","icon":"feedback","attributes":{"imageSizes":{"type":"string"},"imageNumber":{"type":"string"}},"editorStyle":"file:../../../../dist/css/image-creator-styles.css","editorScript":"file:../../../../dist/blocks/image-creator/editor.js"}');(0,a.registerBlockType)(o,{edit:m})}();