"use strict";(globalThis.webpackChunkextendify=globalThis.webpackChunkextendify||[]).push([[346],{8530:(e,t,a)=>{var n=a(9196),l=a(2175),r=a(4981),i=a(5609),o=a(9818);const s=window.wp.editPost;var c=a(9307),m=a(2694),d=a(5736),u=a(8817);const g=window.wp.editor;var p=a(424);const f=({completion:e})=>{const t=(0,r.pasteHandler)({plainText:e}),a=(0,c.useRef)();return(0,n.createElement)("div",{ref:a,style:{fontSize:"clamp(1em 1em 1em)"},className:"completion relative max-h-60 overflow-y-auto break-words px-5 pt-4","data-test":"completion-input"},Array.isArray(t)?(0,n.createElement)("div",{dangerouslySetInnerHTML:{__html:(0,r.serialize)(t)}}):(0,n.createElement)("div",{dangerouslySetInnerHTML:{__html:t}}))};var y=a(8824);const x=({disabled:e,setInputText:t,setReady:a})=>{const l=[{label:(0,d.__)("A paragraph …","extendify-local"),onClickText:(0,d.__)("Write a paragraph about","extendify-local")},{label:(0,d.__)("Blog post …","extendify-local"),onClickText:(0,d.__)("Write a blog post about","extendify-local")},{label:(0,d.__)("An informative article …","extendify-local"),onClickText:(0,d.__)("Write an informative article about","extendify-local")},{label:(0,d.__)("Headline …","extendify-local"),onClickText:(0,d.__)("Write a headline for","extendify-local")},{label:(0,d.__)("List …","extendify-local"),onClickText:(0,d.__)("Write a list of","extendify-local")}];return(0,n.createElement)(i.MenuGroup,null,l.map((({label:l,onClickText:r})=>(0,n.createElement)(i.MenuItem,{key:l,onClick:()=>(t(`${r} `),void a(!1)),disabled:e,icon:y.Z,iconPosition:"left"},l))))};var h=a(1984),_=a(7157),w=a(9696),E=a(9454),b=a(5621);const v=()=>{const{getBlockInsertionPoint:e}=(0,o.useSelect)((e=>e("core/block-editor")),[]),{toggleBlockHighlight:t,showInsertionPoint:a,hideInsertionPoint:n}=(0,o.useDispatch)("core/block-editor");return{toggleHighlight:(e,{isHighlighted:a})=>{t(e[0],a)},toggleInsertionPoint:({isVisible:t})=>{if(!t)return void n();const{rootClientId:l,index:r}=e();a(l,r)}}},C=()=>{const{getSelectedBlockClientIds:e,getBlocksByClientId:t}=(0,o.useSelect)((e=>e(l.store)),[]),a=e();return{selectedText:(0,c.useCallback)((()=>t(a).map((({attributes:e})=>e.content)).join("\n\n")),[t,a])()}},k=((0,n.createElement)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{d:"M8.79508 15.8769L4.62508 11.7069L3.20508 13.1169L8.79508 18.7069L20.7951 6.70687L19.3851 5.29688L8.79508 15.8769Z"})),(0,n.createElement)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{d:"M14 17H4V19H14V17ZM20 9H4V11H20V9ZM4 15H20V13H4V15ZM4 5V7H20V5H4Z"})),(0,n.createElement)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{d:"M17.0909 9.81818L18 7.81818L20 6.90909L18 6L17.0909 4L16.1818 6L14.1818 6.90909L16.1818 7.81818L17.0909 9.81818Z",fill:"currentColor"}),(0,n.createElement)("path",{d:"M17.0909 14.1818L16.1818 16.1818L14.1818 17.0909L16.1818 18L17.0909 20L18 18L20 17.0909L18 16.1818L17.0909 14.1818Z",fill:"currentColor"}),(0,n.createElement)("path",{d:"M11.6364 10.1818L9.81818 6.18182L8 10.1818L4 12L8 13.8182L9.81818 17.8182L11.6364 13.8182L15.6364 12L11.6364 10.1818ZM10.5382 12.72L9.81818 14.3055L9.09818 12.72L7.51273 12L9.09818 11.28L9.81818 9.69455L10.5382 11.28L12.1236 12L10.5382 12.72Z",fill:"currentColor"}))),L=((0,n.createElement)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{d:"M12 14.5C13.66 14.5 15 13.16 15 11.5V5.5C15 3.84 13.66 2.5 12 2.5C10.34 2.5 9 3.84 9 5.5V11.5C9 13.16 10.34 14.5 12 14.5Z"}),(0,n.createElement)("path",{d:"M17 11.5C17 14.26 14.76 16.5 12 16.5C9.24 16.5 7 14.26 7 11.5H5C5 15.03 7.61 17.93 11 18.42V21.5H13V18.42C16.39 17.93 19 15.03 19 11.5H17Z"})),(0,n.createElement)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{d:"M2.99902 21.0025H6.74902L17.809 9.9425L14.059 6.1925L2.99902 17.2525V21.0025ZM4.99902 18.0825L14.059 9.0225L14.979 9.9425L5.91902 19.0025H4.99902V18.0825Z"}),(0,n.createElement)("path",{d:"M18.369 3.2925C17.979 2.9025 17.349 2.9025 16.959 3.2925L15.129 5.1225L18.879 8.8725L20.709 7.0425C21.099 6.6525 21.099 6.0225 20.709 5.6325L18.369 3.2925Z"})),(0,n.createElement)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{d:"M4 9H20V11H4V9ZM4 13H14V15H4V13Z"})),(0,n.createElement)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{d:"M19.5005 7.5L20.4405 5.44L22.5005 4.5L20.4405 3.56L19.5005 1.5L18.5605 3.56L16.5005 4.5L18.5605 5.44L19.5005 7.5Z"}),(0,n.createElement)("path",{d:"M8.00055 7.5L8.94055 5.44L11.0005 4.5L8.94055 3.56L8.00055 1.5L7.06055 3.56L5.00055 4.5L7.06055 5.44L8.00055 7.5Z"}),(0,n.createElement)("path",{d:"M19.5005 13L18.5605 15.06L16.5005 16L18.5605 16.94L19.5005 19L20.4405 16.94L22.5005 16L20.4405 15.06L19.5005 13Z"}),(0,n.createElement)("path",{d:"M17.2105 9.62L14.3805 6.79C14.1805 6.6 13.9305 6.5 13.6705 6.5C13.4105 6.5 13.1605 6.6 12.9605 6.79L1.79055 17.96C1.40055 18.35 1.40055 18.98 1.79055 19.37L4.62055 22.2C4.82055 22.4 5.07055 22.5 5.33055 22.5C5.59055 22.5 5.84055 22.4 6.04055 22.21L17.2105 11.04C17.6005 10.65 17.6005 10.01 17.2105 9.62ZM13.6705 8.92L15.0805 10.33L13.9105 11.5L12.5005 10.09L13.6705 8.92ZM5.33055 20.09L3.92055 18.68L11.0905 11.5L12.5005 12.91L5.33055 20.09Z"})),(0,n.createElement)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{d:"M3.5,10.5C3.5,12.95 5.26,14.97 7.58,15.41L6.09,13.92L7.5,12.5L11.5,16.51L7.5,20.5L6.09,19.09L7.67,17.51L7.67,17.45C4.2,17.04 1.5,14.08 1.5,10.5C1.5,6.63 4.63,3.5 8.5,3.5L11.5,3.5L11.5,5.5L8.5,5.5C5.74,5.5 3.5,7.74 3.5,10.5Z"}),(0,n.createElement)("path",{d:"M22.5,10.5L22.5,3.5L13.5,3.5L13.5,10.5L22.5,10.5ZM20.5,8.5L15.5,8.5L15.5,5.5L20.5,5.5L20.5,8.5Z"}),(0,n.createElement)("rect",{x:"13.5",y:"12.5",width:"9",height:"7"})),(0,n.createElement)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{d:"M18.6 19.5008H21V21.5008H15V15.5008H17V18.2308C18.83 16.7608 20 14.5208 20 12.0008C20 7.93078 16.94 4.56078 13 4.07078V2.05078C18.05 2.55078 22 6.81078 22 12.0008C22 14.9908 20.68 17.6708 18.6 19.5008ZM4 12.0008C4 9.48078 5.17 7.23078 7 5.77078V8.50078H9V2.50078H3V4.50078H5.4C3.32 6.33078 2 9.01078 2 12.0008C2 17.1908 5.95 21.4508 11 21.9508V19.9308C7.06 19.4408 4 16.0708 4 12.0008ZM16.24 8.11078L10.58 13.7708L7.75 10.9408L6.34 12.3508L10.58 16.5908L17.65 9.52078L16.24 8.11078Z"})),(0,n.createElement)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{d:"M12 6V2L7 7L12 12V8C15.31 8 18 10.69 18 14C18 17.31 15.31 20 12 20C8.69 20 6 17.31 6 14H4C4 18.42 7.58 22 12 22C16.42 22 20 18.42 20 14C20 9.58 16.42 6 12 6Z"})),(0,n.createElement)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{d:"M16 9V19H8V9H16ZM14.5 3H9.5L8.5 4H5V6H19V4H15.5L14.5 3ZM18 7H6V19C6 20.1 6.9 21 8 21H16C17.1 21 18 20.1 18 19V7Z"})),(0,n.createElement)(i.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24"},(0,n.createElement)(i.Path,{d:"M4 10.5h16V9H4v1.5ZM4 15h9v-1.5H4V15Z"}))),N=({disabled:e,setPrompt:t})=>{const{toggleHighlight:a}=v(),{selectedText:l}=C(),r=(0,o.useSelect)((e=>e("core/block-editor").getSelectedBlockClientIds()),[]);(0,c.useEffect)((()=>()=>{a(r,{isHighlighted:!1})}),[r,a]);const s=[{label:(0,d.__)("Improve writing","extendify-local"),promptType:"improve-writing",systemMessageKey:"edit",icon:(0,n.createElement)(h.Z,{icon:_.Z})},{label:(0,d.__)("Fix spelling & grammar","extendify-local"),promptType:"fix-spelling-grammar",icon:(0,n.createElement)(h.Z,{icon:w.Z})},{label:(0,d.__)("Simplify language","extendify-local"),promptType:"simplify-language",icon:(0,n.createElement)(h.Z,{icon:E.Z})},{label:(0,d.__)("Make shorter","extendify-local"),promptType:"make-shorter",icon:(0,n.createElement)(h.Z,{icon:L})},{label:(0,d.__)("Make longer","extendify-local"),promptType:"make-longer",icon:(0,n.createElement)(h.Z,{icon:b.Z})}];return(0,n.createElement)(i.MenuGroup,null,s.map((({label:o,promptType:s,icon:c})=>(0,n.createElement)(i.MenuItem,{key:`${s}-${s}-edit`,onClick:()=>(e=>{t({text:l,promptType:e,systemMessageKey:"edit"})})(s),onMouseEnter:()=>a(r,{isHighlighted:!0}),onMouseLeave:()=>a(r,{isHighlighted:!1}),icon:c,iconPosition:"left",disabled:e,className:"group"},(0,n.createElement)("span",{className:"whitespace-normal text-left rtl:text-right"},o)))))};var I=a(2278),S=a(3708),T=a(3967),M=a.n(T),B=a(3689),P=a(3773);const Z=({value:e,className:t,onChange:a,onKeyDown:l,disabled:r,placeholder:i})=>{const o=(0,c.useRef)(null),[s,m]=(0,c.useState)("auto");return(0,c.useLayoutEffect)((()=>{const t=document.createElement("textarea");t.value=e||i,t.rows=1;const a=window.getComputedStyle(o.current);["paddingTop","paddingBottom","paddingLeft","paddingRight","width","fontFamily","fontSize","borderWidth"].forEach((e=>t.style[e]=a[e])),Object.assign(t.style,{position:"absolute",left:"-9999px"}),document.body.appendChild(t),m(`${t.scrollHeight}px`),document.body.removeChild(t)}),[e,i]),(0,c.useEffect)((()=>{const e=o.current;if(!e)return;if(document.activeElement===e)return;const t=e.value.length;e.focus(),e.setSelectionRange(t,t)}),[e]),(0,n.createElement)(B.M,null,(0,n.createElement)(P.E.div,{className:"m-0.5 w-full",key:"input",animate:{height:s},transition:{duration:.2},style:{lineHeight:0}},(0,n.createElement)("label",{htmlFor:"draft-ai-textarea",className:"sr-only"},i),(0,n.createElement)("textarea",{ref:o,id:"draft-ai-textarea",disabled:r,className:t,value:e,rows:1,onChange:a,onKeyDown:l,onScroll:e=>{e.target.scrollTop=0},placeholder:i})))},A=({inputText:e,setInputText:t,ready:a,setReady:l,setPrompt:r,loading:o})=>{const{selectedText:s}=C(),c=n=>{n.preventDefault(),a&&!o&&(t(""),l(!1),r({text:s||e,promptType:s?"custom-requests":"create",systemMessageKey:s?"edit":"generate",details:{followup:s?e:void 0}}))};return(0,n.createElement)("form",{className:"relative flex items-start",onSubmit:c},(0,n.createElement)(h.Z,{icon:k,className:"absolute left-2 top-3.5 h-5 w-5 fill-current text-wp-theme-main rtl:left-auto rtl:right-2"}),(0,n.createElement)(Z,{disabled:o,placeholder:o?(0,d.__)("AI is writing...","extendify-local"):s?(0,d.__)("Ask AI to edit","extendify-local"):(0,d.__)("Ask AI to generate text","extendify-local"),value:e,className:"h-full w-full resize-none overflow-hidden rounded-none border-transparent bg-transparent px-10 py-3 outline-none focus:ring-1 focus:ring-wp-theme-main",onChange:e=>{t(e.target.value),l(e.target.value.length>0)},onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),c(e))}}),o&&(0,n.createElement)("div",{className:"absolute right-4 top-3.5 h-4 w-4 p-1 text-gray-700 rtl:left-4 rtl:right-auto"},(0,n.createElement)(i.Spinner,{style:{margin:"0"}})),!o&&(0,n.createElement)("button",{type:"submit",disabled:!a,"aria-label":(0,d.__)("Submit","extendify-local"),className:M()("absolute right-2 top-3.5 border-none bg-transparent p-0 rtl:left-2 rtl:right-auto",{"cursor-pointer text-gray-700 hover:text-design-main":a,"text-gray-500":!a})},(0,n.createElement)(h.Z,{icon:(0,d.isRTL)()?I.Z:S.Z,onClick:c,className:"h-6 w-6 fill-current"})))};var H=a(3970),D=a(9596),R=a(2913),F=a(7755),V=a(5661);const G=({prompt:e,completion:t,loading:a,setPrompt:s,setInputText:m})=>{const{toggleHighlight:u,toggleInsertionPoint:g}=v(),{insertBlocks:p,replaceBlocks:f}=(0,o.useDispatch)(l.store),{getSelectedBlock:y,getSelectedBlockClientIds:x,getBlockRootClientId:_,getBlockIndex:w,getBlock:E}=(0,o.useSelect)((e=>e(l.store)),[]),b=y(),C=x(),k=e=>{const t=(0,r.pasteHandler)({plainText:e});return Array.isArray(t)?t:[(0,r.createBlock)("core/paragraph",{content:t})]},L=({replaceContent:e=!1,position:a})=>{s({text:"",promptType:"",systemMessageKey:""});const n=b?b?.clientId:C[0],l=E(n),r=k(t);if(!n||"end"===a)return void p(r);if("top"===a)return void p(r,0);const i=""===l?.attributes?.content,o=_(n),c=w(C.at(-1),o);if(!e&&!i)return void p(r,c+1,o);const m=(e,t)=>Object.prototype.hasOwnProperty.call(e?.attributes,"content")&&Object.prototype.hasOwnProperty.call(t?.attributes,"content"),d=1===r.length&&m(l,r[0]),u=r.map((e=>({...e,name:d?l.name:e.name,attributes:{...l.attributes,content:(m(e,l),e?.attributes?.content)}})));f(C,u)};return(0,c.useEffect)((()=>()=>{u(C,{isHighlighted:!1})}),[C,u]),(0,n.createElement)(i.MenuGroup,null,(0,n.createElement)(i.MenuItem,{onClick:()=>L({replaceContent:!0}),onMouseEnter:()=>u(C,{isHighlighted:!0}),onMouseLeave:()=>u(C,{isHighlighted:!1}),disabled:a||!(()=>{const e=b||E(C[0]);if(!e)return!1;if(["core/list-item","core/button"].includes(e?.name)){const a=k(t);return a[0]?.name===e?.name}return!0})(),icon:H.Z,iconPosition:"left","data-test":"replace-selected"},(0,d.__)("Replace selected block text","extendify-local")),(0,n.createElement)(i.MenuItem,{onClick:()=>L({replaceContent:!1,position:"top"}),disabled:a,iconPosition:"left","data-test":"insert-top"},(0,n.createElement)("div",{className:(0,d.isRTL)()?"-mr-1":"-ml-1"},(0,n.createElement)(h.Z,{icon:D.Z,className:"rotate-180"})),(0,n.createElement)("div",{className:"px-1"},(0,d.__)("Insert at top","extendify-local"))),(0,n.createElement)(i.MenuItem,{onClick:()=>L({replaceContent:!1}),onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),disabled:a||!(()=>{const e=b||E(C[0]);return!e||!["core/list-item","core/button"].includes(e?.name)})(),icon:R.Z,iconPosition:"left","data-test":"insert-after"},(0,d.__)("Insert after the selected text","extendify-local")),(0,n.createElement)(i.MenuItem,{onClick:()=>L({replaceContent:!1,position:"end"}),disabled:a,icon:D.Z,iconPosition:"left","data-test":"insert-bottom"},(0,d.__)("Insert at bottom","extendify-local")),(0,n.createElement)(i.__experimentalDivider,null),(0,n.createElement)(i.MenuItem,{onClick:()=>{m(""),s({text:"",promptType:"",systemMessageKey:""}),setTimeout((()=>s(e)))},disabled:a,icon:F.Z,iconPosition:"left","data-test":"try-again-button"},(0,d.__)("Try again","extendify-local")),(0,n.createElement)(i.MenuItem,{onClick:()=>{m(""),s({text:"",promptType:"",systemMessageKey:""})},disabled:a,icon:V.Z,iconPosition:"left","data-test":"discard-button"},(0,d.__)("Discard","extendify-local")))};var O=a(4896);const j=({loading:e})=>{const[t,a]=(0,c.useState)(),{clearSelectedBlock:r}=(0,o.useDispatch)(l.store),{selectedText:s}=C();if((0,c.useEffect)((()=>{a(s)}),[a,s]),t)return(0,n.createElement)("div",{className:"mb-4 flex space-x-2 overflow-hidden rounded-sm border-none bg-gray-100 p-3","data-test":"existing-text-container"},(0,n.createElement)("div",null,(0,n.createElement)(h.Z,{icon:O.Z,className:"fill-current"})),(0,n.createElement)("div",null,(0,n.createElement)("div",{className:"mb-1 hyphens-auto text-pretty text-gray-800",dangerouslySetInnerHTML:{__html:t.split(" ").length<=20?t:`${t.split(" ",14).join(" ")}... ${t.slice(t.lastIndexOf(" ")-14)}`}}),(0,n.createElement)("div",{className:"mt-3 flex w-full justify-end"},(0,n.createElement)(i.Button,{size:"compact",onClick:r,disabled:e,icon:V.Z,iconPosition:(0,d.isRTL)()?"right":"left",className:"relative cursor-pointer flex-row-reverse rounded bg-gray-300 text-gray-800 hover:bg-gray-400","data-test":"remove-selection"},(0,d.__)("Remove selection","extendify-local")))))};var z=a(2200),K=a(6989),q=a.n(K),$=a(7403),U=a(270),W=a(782);const J="/extendify/v1/draft/user-settings",Y={getItem:async()=>await q()({path:J}),setItem:async(e,t)=>await q()({path:J,method:"POST",data:{state:t}})},X={aiImageOptions:{prompt:"",style:"vivid",size:"1024x1024"},imageCredits:{remaining:10,total:10,refresh:void 0}},Q=(0,W.mW)((e=>({...X,...(0,$.a)(window.extDraftData?.globalState)?.state,updateImageCredits({remaining:t,total:a,refresh:n}){e((e=>({imageCredits:{...e.imageCredits,...t&&{remaining:t},...a&&{total:a},...n&&{refresh:n}}})))},subtractOneCredit(){e((e=>({imageCredits:{...e.imageCredits,remaining:e.imageCredits.remaining-1,refresh:new Date(Date.now()+864e5).getTime()}})))},resetImageCredits(){e({imageCredits:X.imageCredits})},setAiImageOption(t,a){e((e=>({aiImageOptions:{...e.aiImageOptions,[t]:a}})))}})),{name:"Extendify Draft Globals"}),ee=(0,W.tJ)(Q,{name:"extendify_draft_settings",storage:(0,W.FL)((()=>Y)),skipHydration:!0,partialize:e=>({...e,aiImageOptions:{...e.aiImageOptions,prompt:""}})}),te=(0,U.Ue)(ee),ae=["siteId","partnerId","wpVersion","wpLanguage","devbuild","isBlockTheme","userId","siteProfile"],{showAIConsent:ne,userGaveConsent:le}=p.y.getState(),re={...Object.fromEntries(Object.entries(window.extSharedData).filter((([e])=>ae.includes(e)))),showAIConsent:ne,userGaveConsent:le};var ie=a(6993);const oe=(0,n.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)("path",{fillRule:"evenodd",d:"M1.33333 1h9.33337c.1841 0 .3333.14924.3333.33333v5.57118L9.0152 4.97484c-.19406-.18867-.50302-.18867-.69708 0L5.93734 7.28948 3.98622 6.02487c-.17383-.11267-.39915-.10648-.56653.01557L1 7.8048V1.33333C1 1.14924 1.14924 1 1.33333 1ZM1 9.04241v1.62429c0 .1841.14924.3333.33333.3333h9.33337c.1841 0 .3333-.1492.3333-.3333V8.26877l-.0152.01565-2.31814-2.25373-2.31813 2.25373c-.16726.16261-.42473.18796-.62049.06108L3.73095 7.05109 1 9.04241ZM0 1.33333C0 .596954.596954 0 1.33333 0h9.33337C11.403 0 12 .596954 12 1.33333v9.33337C12 11.403 11.403 12 10.6667 12H1.33333C.596954 12 0 11.403 0 10.6667V1.33333Z",clipRule:"evenodd"})),se=({usedCredits:e,total:t})=>e{const{imageCredits:a,resetImageCredits:l,aiImageOptions:r,setAiImageOption:o}=te(),s=a.total-a.remaining,[m,u]=(0,c.useState)(0),{size:g,prompt:p}=r;return(0,c.useEffect)((()=>{const e=()=>{u((e=>e+1)),a.refresh&&(new Date(Number(a.refresh))>new Date||l())};0===m&&e();const t=setTimeout(e,1e3);return()=>clearTimeout(t)}),[a,l,m]),(0,n.createElement)(n.Fragment,null,e?null:(0,n.createElement)("div",null,(0,n.createElement)(i.TextareaControl,{id:"draft-ai-image-textarea",autoFocus:!0,placeholder:(0,d.__)("Tell AI about the image you would like to create","extendify-local"),label:(0,d.__)("Image Prompt","extendify-local"),hideLabelFromVision:!0,rows:"7",value:p,onChange:e=>o("prompt",e)}),(0,n.createElement)(i.__experimentalToggleGroupControl,{isBlock:!0,label:(0,d.__)("Aspect Ratio","extendify-local"),onChange:e=>o("size",e),value:g},(0,n.createElement)(i.__experimentalToggleGroupControlOptionIcon,{className:"m-auto",type:"button",icon:ue,label:(0,d.__)("Square: 1:1","extendify-local"),value:"1024x1024"}),(0,n.createElement)(i.__experimentalToggleGroupControlOptionIcon,{className:"m-auto",type:"button",icon:me,label:(0,d.__)("Landscape: 4:3","extendify-local"),value:"1792x1024"}),(0,n.createElement)(i.__experimentalToggleGroupControlOptionIcon,{className:"m-auto",type:"button",icon:de,label:(0,d.__)("Portrait: 3:4","extendify-local"),value:"1024x1792"}))),t.length>0&&(0,n.createElement)("p",{className:"mb-0 text-red-500"},t),(0,n.createElement)(i.Button,{type:"submit",className:"w-full justify-center",variant:"primary",__next40pxDefaultSize:!0,disabled:e||!p||s>=a.total},e?(0,d.__)("Generating image...","extendify-local"):(0,d.__)("Generate image","extendify-local")),e?null:(0,n.createElement)(se,{usedCredits:s,total:a.total}))},me=(0,n.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",style:{padding:"7px 4px"}},(0,n.createElement)("path",{fillRule:"evenodd",d:"M0 1c0-.552285.447715-1 1-1h14c.5523 0 1 .447715 1 1v8c0 .55228-.4477 1-1 1H1c-.552285 0-1-.44772-1-1V1Z",clipRule:"evenodd"})),de=(0,n.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",style:{padding:"4px 6px"}},(0,n.createElement)("path",{fillRule:"evenodd",d:"M9.66669 3.5e-7C10.219 3.7e-7 10.6667.447716 10.6667 1v14c0 .5523-.4477 1-1.00001 1h-8c-.55229 0-1.000003-.4477-1.000003-1L.666688 1C.666688.447715 1.1144-2e-8 1.66669 0l8 3.5e-7Z",clipRule:"evenodd"})),ue=(0,n.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",style:{padding:"6px"}},(0,n.createElement)("path",{fillRule:"evenodd",d:"M11.3333-4e-8c.5523 2e-8 1 .44771504 1 1.00000004v10c0 .5523-.4477 1-1 1H1.33333c-.552283 0-.999998-.4477-.999998-1V.999999C.333332.447715.781047-5e-7 1.33333-4.8e-7L11.3333-4e-8Z",clipRule:"evenodd"})),ge=e=>new Promise(((t,a)=>{e.onload=()=>t(e),e.onerror=e=>a(e)})),pe=async(e,t,a,n,l={alt:"",caption:""})=>{let r;await((e,t,a={})=>fetch(`${z.Yy}/api/draft/image/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,source:t,...a})}))(e,a,{unsplashId:n});try{r=await(async(e,t={})=>{var a,n;const l=new Image;l.src=e,l.crossOrigin="anonymous",await ge(l);const r=document.createElement("canvas");r.width=l.width,r.height=l.height;const i=r.getContext("2d");if(!i)return;i.drawImage(l,0,0);const o=await new Promise((e=>{r.toBlob((t=>{t&&e(t)}),"image/jpeg")})),s=new FormData;return s.append("file",new File([o],t.filename)),s.append("alt_text",null!==(a=t.alt)&&void 0!==a?a:""),s.append("caption",null!==(n=t.caption)&&void 0!==n?n:""),s.append("status","publish"),await q()({path:"wp/v2/media",method:"POST",body:s})})(t,{alt:l.alt,filename:"image.jpg",caption:l.caption})}catch(e){r=await(async(e,t={})=>{var a,n;const l=new FormData;return l.append("source",e),l.append("alt_text",null!==(a=t.alt)&&void 0!==a?a:""),l.append("caption",null!==(n=t.caption)&&void 0!==n?n:""),await q()({path:"/extendify/v1/draft/upload-image",method:"POST",body:l})})(t,{alt:l.alt,filename:"image.jpg",caption:l.caption})}return r},fe=(e,t,a)=>{if("core/image"===e.name&&a(e.clientId,{id:t.id,caption:t.caption.raw,url:t.source_url,alt:t.alt_text}),"core/media-text"===e.name&&a(e.clientId,{mediaId:t.id,caption:t.caption.raw,mediaUrl:t.source_url,mediaAlt:t.alt_text,mediaType:"image"}),"core/gallery"===e.name){const a=(0,r.createBlock)("core/image",{id:t.id,caption:t.caption.raw,url:t.source_url,alt:t.alt_text});(0,r.insertBlock)(a,null,e.clientId)}"core/cover"===e.name&&a(e.clientId,{id:t.id,url:t.source_url,alt:t.alt_text,backgroundType:"image",dimRatio:50,hasParallax:!1,isDark:!0,isRepeated:!1,layout:{type:"constrained"},tagName:"div",useFeaturedImage:!1})},ye=({prompt:e,size:t,isGenerating:a,id:r,src:m,clearImageResponse:u})=>{const{openGeneralSidebar:g}=(0,o.useDispatch)(s.store),{updateBlockAttributes:p}=(0,o.useDispatch)(l.store),[f,y]=(0,c.useState)(!1),x=(0,o.useSelect)((e=>e(l.store).getSelectedBlock()),[]),[h,_]=t.split("x");return""!==m||a?(0,n.createElement)("div",{className:"flex flex-col gap-5"},(0,n.createElement)(B.M,null,a?(0,n.createElement)(P.E.div,{initial:{opacity:1},exit:{opacity:0},className:"flex aspect-square w-full items-center justify-center",style:{background:"linear-gradient(135deg, #E8E8E8 47.92%, #F3F3F3 60.42%, #E8E8E8 72.92%)"}},(0,n.createElement)(i.Spinner,{style:{height:"48px",width:"48px"}})):(0,n.createElement)(P.E.div,{initial:{opacity:0},animate:{opacity:1},className:"bg-gray-100",style:{aspectRatio:Number(h)/Number(_)}},(0,n.createElement)("img",{alt:e,src:m,className:"block w-full",style:{aspectRatio:Number(h)/Number(_)}}))),a?(0,n.createElement)("p",null,(0,d.__)("Generating your image: ","extendify-local"),(0,n.createElement)("span",{className:"font-bold"},'"',e,'"')):(0,n.createElement)("form",{onSubmit:async e=>{e.preventDefault(),y(!0);const t=await pe(r,m,"ai-generated");t&&(await fe(x,t,p),y(!1),g("edit-post/block"),u())},className:"flex flex-col gap-5"},(0,n.createElement)(i.Button,{type:"submit",autoFocus:!0,className:"w-full justify-center",variant:"primary",disabled:f},f? // translators: "Importing image" means the image is being added to the WordPress post editor (0,d.__)("Importing image...","extendify-local"):(0,d.__)("Use this image","extendify-local")),(0,n.createElement)(i.Button,{className:"w-full justify-center bg-gray-200 text-gray-800 disabled:bg-gray-300 disabled:text-gray-700",onClick:u,disabled:f},(0,d.__)("Delete image","extendify-local")))):null},xe=(0,n.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"8",height:"12",fill:"none"},(0,n.createElement)("path",{fill:"#1E1E1E",fillRule:"evenodd",d:"M6.445 12.004.986 6l5.46-6.005 1.109 1.01L3.014 6l4.541 4.995-1.11 1.01Z",clipRule:"evenodd"})),he=("AI Image",_e=e=>({imageDetails:{src:"",id:void 0},setImageDetails:t=>{e((e=>({...e,imageDetails:t})))}}),(0,U.Ue)((0,W.mW)(_e,{name:"Extendify Draft AI Image"})));var _e;const we=[{slug:"ai-image",title:(0,d.__)("AI Image","extendify-local"),component:()=>{const{imageCredits:e,updateImageCredits:t,subtractOneCredit:a,aiImageOptions:l}=te(),[r,o]=(0,c.useState)(!1),[s,m]=(0,c.useState)(""),u=(0,c.useRef)(null),g=0===e.remaining,{imageDetails:p,setImageDetails:f}=he(),{goBack:y}=Be();return(0,c.useEffect)((()=>{p.src||r||document.getElementById("draft-ai-image-textarea")?.focus()}),[p.src,r]),(0,n.createElement)(i.Panel,null,(0,n.createElement)("div",{className:"flex h-12 items-center gap-1 pl-1"},(0,n.createElement)("button",{className:"h-9 w-9 cursor-pointer border-0 bg-transparent",onClick:y,type:"button","aria-label":(0,d.__)("Go Back","extendify-local")},xe),(0,n.createElement)(i.__experimentalHeading,{className:"mb-0"},(0,d.__)("AI Image Generator","extendify-local"))),(0,n.createElement)(i.PanelBody,{className:"-mt-4 border-t-0"},(0,n.createElement)(i.BaseControl,{label:(0,d.__)("Image Description","extendify-local")},(0,n.createElement)(ye,{prompt:l.prompt,size:l.size,isGenerating:r,id:p?.id,src:p?.src,clearImageResponse:()=>f({src:"",id:void 0})}),p.src?null:(0,n.createElement)("form",{onSubmit:async n=>{if(n.preventDefault(),m(""),g)u.current?.abort();else try{o(!0),a(),u.current=new AbortController;const{imageCredits:e,images:n,id:r}=await(async(e,t)=>{const a=await fetch(`${z.Yy}/api/draft/image`,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},signal:t,body:JSON.stringify({...e,globalState:te.getState(),...re})}),n=await a.json(),l={remaining:a.headers.get("x-ratelimit-remaining"),total:a.headers.get("x-ratelimit-limit"),refresh:a.headers.get("x-ratelimit-reset")};if(!a.ok){if(n.status&&"content-policy-violation"===n.status)throw{message:(0,d.__)("Your request was rejected as a result of our safety system. Your prompt may contain text that is not allowed by our safety system.","extendify-local"),imageCredits:l};throw{message:(0,d.__)("Service temporarily unavailable","extendify-local"),imageCredits:l}}return{images:n,imageCredits:l,id:a.headers.get("x-request-id")}})(l,u.current.signal);t(e),f({src:n[0].url,id:r})}catch(a){if(20===a?.code)return;if(!a?.imageCredits)return await new Promise((e=>setTimeout(e,1e3))),m(a.message),void t({remaining:e.remaining});t(a.imageCredits),m(a.message)}finally{o(!1)}},className:"flex flex-col gap-5"},(0,n.createElement)(ce,{isGenerating:r,errorMessage:s})))))}}],Ee=[{slug:"home",title:(0,d.__)("Home","extendify-local"),component:()=>{const{navigateTo:e}=Be();return(0,n.createElement)(i.PanelBody,null,(0,n.createElement)(i.BaseControl,{id:"extendify-draft-image-gen",label:(0,d.__)("AI Image Generator","extendify-local"),help:(0,d.__)("Use AI to generate custom images based on your description.","extendify-local")},(0,n.createElement)(i.Button,{variant:"primary",__next40pxDefaultSize:!0,id:"extendify-draft-image-gen-button",className:"w-full justify-center",onClick:()=>e("ai-image")},(0,d.__)("Add a prompt","extendify-local"))),(0,n.createElement)(i.__experimentalSpacer,{marginY:"5"}),(0,n.createElement)(i.__experimentalDivider,null),(0,n.createElement)(i.BaseControl,{id:"extendify-draft-image-stock-photos",label:(0,d.__)("Discover Stock Photos","extendify-local"),help:(0,d.__)("Search and add free stock photos from Unsplash.com","extendify-local")},(0,n.createElement)(i.Button,{variant:"primary",__next40pxDefaultSize:!0,className:"w-full justify-center",onClick:()=>e("unsplash")},(0,d.__)("Search Unsplash","extendify-local"))))}}],be=({image:e,skeletonHeight:t,isInsertingImage:a,onClick:l})=>{const[r,o]=(0,c.useState)(""),[s,m]=(0,c.useState)(!1),d=e?.width?Number(e?.width)/Number(e?.height):122/t;return(0,c.useEffect)((()=>{if(!e?.user?.links?.html)return void o("");const t=new URL(e.user.links.html);t.searchParams.set("utm_source","extendify"),t.searchParams.set("utm_medium","referral"),o(t.toString())}),[e]),(0,c.useInsertionEffect)((()=>{if(!e?.urls||s)return;const t=new Image;t.src=e.urls.thumb||e.urls.small,ge(t).then((()=>m(!0)))}),[e,s]),(0,n.createElement)(P.E.div,{className:"relative mb-1",initial:{aspectRatio:d},animate:{aspectRatio:d}},(0,n.createElement)(B.M,null,s?null:(0,n.createElement)(P.E.div,{className:"absolute inset-0 z-10 bg-white",initial:{opacity:1},animate:{opacity:1},exit:{opacity:0}},(0,n.createElement)("div",{className:"animate-pulse absolute inset-0 z-10 bg-gray-150"}))),(0,n.createElement)("div",{className:"group relative"},(0,n.createElement)("button",{type:"button",className:M()("relative block border-0 p-0",{"cursor-pointer bg-transparent":!a,"bg-black":a}),onClick:()=>l(e),disabled:a},a&&a?.id===e?.id&&(0,n.createElement)("div",{className:"absolute inset-0 flex items-center justify-center"},(0,n.createElement)(i.Spinner,{style:{height:"24px",width:"24px"}})),(0,n.createElement)("img",{src:e?.urls?.thumb||e?.urls?.small,className:M()("block transition-opacity duration-300",{"opacity-50":a}),alt:e?.alt_description})),e?.user?.name&&r?(0,n.createElement)("a",{href:r,target:"_blank",className:M()("absolute bottom-1 bg-black/70 px-1 text-white no-underline opacity-0",{"group-focus-within:opacity-100 group-hover:opacity-100":!a}),rel:"noopener noreferrer"},`${e.user?.name}`):null))},ve=({images:e,isInsertingImage:t,onClick:a,loading:l})=>{var r;const i=null!==(r=e?.length)&&void 0!==r?r:10;return l||e.length?(0,n.createElement)("div",{className:"columns-2 gap-1"},Array.from({length:i}).map(((l,r)=>{var i;const o=[150,175,200];return(0,n.createElement)(be,{key:null!==(i=e?.[r]?.id)&&void 0!==i?i:r,image:e?.[r],skeletonHeight:o[r%o.length],isInsertingImage:t,onClick:a})}))):(0,d.__)("No images found.","extendify-local")};var Ce=a(9272),ke=a(619),Le=a(9870);const Ne=async e=>{const t=ke.f.getState();return"unsplash"!==e||t.isEmpty()||t.hasExpired()?await(0,Ce._)(e):t.images},Ie=[...Ee,...we,{slug:"unsplash",title:(0,d.__)("Unsplash","extendify-local"),component:()=>{const{goBack:e}=Be(),[t,a]=(0,c.useState)(""),[r,s]=(0,c.useState)(""),[m,u]=(0,c.useState)(!1),{data:g,loading:p}=(e=>{const{data:t,error:a}=(0,Le.Z)(e||"unsplash",Ne);return{data:t,error:a,loading:!t&&!a}})(r),[f,y]=(0,c.useState)(null),x=(0,o.useSelect)((e=>e(l.store).getSelectedBlock()),[]),{updateBlockAttributes:h}=(0,o.useDispatch)(l.store);return(0,c.useEffect)((()=>{u(!1)}),[r]),(0,c.useEffect)((()=>{if(!t)return s("");const e=setTimeout((()=>s(t)),750);return()=>clearTimeout(e)}),[t]),(0,n.createElement)(n.Fragment,null,(0,n.createElement)("div",{className:"flex h-12 items-center gap-1 pl-1"},(0,n.createElement)("button",{className:"h-9 w-9 cursor-pointer border-0 bg-transparent",onClick:e,type:"button","aria-label":(0,d.__)("Go Back","extendify-local")},xe),(0,n.createElement)(i.__experimentalHeading,{className:"mb-0"},(0,d.__)("Photos from Unsplash","extendify-local"))),(0,n.createElement)(i.__experimentalDivider,{className:"my-0 border-gray-150"}),(0,n.createElement)("div",{className:"flex flex-col gap-2 p-4"},(0,n.createElement)(i.SearchControl,{autoFocus:!0,className:M()({"pointer-events-none bg-gray-150 opacity-50":f}),disabled:f,"aria-disabled":f,onChange:e=>{f||a(e)},value:t}),(0,n.createElement)(ve,{images:g,isInsertingImage:f,onClick:async e=>{if(!f){y(e);try{const t=await pe(e.requestMetadata?.id,e.urls?.regular,"unsplash",e.id);fe(x,t,h)}catch(e){console.log(e)}finally{y(null)}}},loading:p||m})))}}],Se="/extendify/v1/draft/router-data",Te={getItem:async()=>await q()({path:Se}),setItem:async(e,t)=>await q()({path:Se,method:"POST",data:{state:t}})},Me=(0,U.Ue)((0,W.tJ)((0,W.mW)(((e,t)=>({history:[],viewedPages:[],current:null,goBack:()=>{if(t().history.length<2)return;const a=t().history[1];ie.j.getState().incrementActivity(`draft-${a.slug}-back`),e((e=>({history:e.history.slice(1),current:a})))},setCurrent:a=>{a&&t().history[0]?.slug!==a.slug&&e((e=>{const t=(new Date).toISOString(),n=t,l=e.viewedPages.find((e=>e.slug===a.slug));return{history:[a,...e.history].filter(Boolean),current:a,viewedPages:[...e.viewedPages.filter((e=>e.slug!==a.slug)),l?{...l,count:l.count+1,lastViewedAt:t}:{slug:a.slug,firstViewedAt:n,lastViewedAt:t,count:1}]}}))}})),{name:"Extendify Draft Router"}),{name:"extendify-draft-router",storage:(0,W.FL)((()=>Te)),skipHydration:!0,partialize:({viewedPages:e})=>({viewedPages:e})})),Be=()=>{var e;const{current:t,setCurrent:a,history:l,goBack:r}=Me(),i=null!==(e=t?.component)&&void 0!==e?e:()=>null;return(0,c.useEffect)((()=>{t||a(Ie[0])}),[t,a]),{current:t,CurrentPage:(0,c.useCallback)((()=>(0,n.createElement)("div",{role:"region","aria-live":"polite",className:"h-full"},(0,n.createElement)("h1",{className:"sr-only"},t?.title),(0,n.createElement)(i,null))),[t]),navigateTo:e=>{const t=Ie.find((t=>t.slug===e));if(!t)return a(Ie[0]);ie.j.getState().incrementActivity(`draft-${t.slug}`),a(t)},goBack:r,history:l}},Pe=()=>{const{consentTermsHTML:e,setUserGaveConsent:t}=(0,p.y)();return(0,n.createElement)(i.Panel,null,(0,n.createElement)("div",{className:"p-4"},(0,n.createElement)("h2",{className:"mb-2 mt-0 text-lg"},(0,d.__)("Terms of Use","extendify-local")),(0,n.createElement)("p",{className:"m-0",dangerouslySetInnerHTML:{__html:e}}),(0,n.createElement)("button",{className:"mt-4 w-full cursor-pointer rounded border-0 bg-wp-theme-main px-4 py-2 text-center text-white",type:"button",onClick:()=>t(!0),"data-test":"draft-terms-button"},(0,d.__)("Accept","extendify-local"))))},Ze=()=>{var e;const{selectedText:t}=C(),[a,r]=(0,c.useState)(""),[s,m]=(0,c.useState)(!1),[u,g]=(0,c.useState)({text:"",promptType:"",systemMessageKey:"",details:{}}),{completion:y,loading:h,error:_}=((e,t,a,n)=>{const[l,r]=(0,c.useState)(""),[i,o]=(0,c.useState)(null),[s,m]=(0,c.useState)(!1);return(0,c.useEffect)((()=>{let l,i=!1;const s=new TextDecoder;return e?((async()=>{r(""),o(!1),m(!0);const c=await(async(e,t,a,n)=>{const l=await fetch(`${z.Yy}/api/draft/completion`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,promptType:t,systemMessageKey:a,details:n,globalState:te.getState(),...re})});if(!l.ok)throw new Error((0,d.__)("Service temporarily unavailable","extendify-local"));return l})(e,t,a,n);l=c.body.getReader();let u=!1;for(;!u;){const{value:e,done:t}=await l.read();if(u=t,e&&!i){const t=s.decode(e);r((e=>e+t))}}})().finally((()=>{i||m(!1)})).catch((e=>{i||o(e)})),()=>{i=!0,l&&l.cancel()}):(m(!1),r(""),void(i=!0))}),[e,a,t,n]),{completion:l,error:i,loading:s}})(u.text,u.promptType,u.systemMessageKey,u.details),{selectedBlockClientIds:w,getBlock:E}=(0,o.useSelect)((e=>{const t=e(l.store);return{selectedBlockClientIds:t.getSelectedBlockClientIds(),getBlock:t.getBlock,getBlocks:t.getBlocks}}),[]),{CurrentPage:b}=Be(),v=(0,p.y)((e=>e.shouldShowAIConsent("draft")));(0,c.useEffect)((()=>{const e=e=>{v||g(e.detail)};return window.addEventListener("extendify-draft:set-prompt",e),()=>window.removeEventListener("extendify-draft:set-prompt",e)}),[v]),(0,c.useEffect)((()=>{_&&r(u.text)}),[_,u.text]);const k=()=>{if(0===w.length)return!1;const e=E(w[0]);return!!e&&void 0!==e?.attributes?.content&&""!==e?.attributes?.content};return v?(0,n.createElement)(Pe,null):(()=>{if(0===w.length)return!1;const e=E(w[0]);return!!e&&["core/image","core/media-text","core/gallery","core/cover"].includes(e.name)})()?(0,n.createElement)(b,null):(0,n.createElement)(n.Fragment,null,(0,n.createElement)(i.Panel,null,(0,n.createElement)(i.PanelBody,null,t&&(0,n.createElement)(j,{loading:h}),(0,n.createElement)("div",{className:"mb-4 overflow-hidden rounded-sm border-none bg-gray-100"},!y&&(0,n.createElement)(A,{inputText:a,setInputText:r,ready:s,setReady:m,setPrompt:g,loading:h}),y&&(0,n.createElement)(f,{completion:y}),_&&(0,n.createElement)("div",{className:"mb-4 mt-2 px-4"},(0,n.createElement)("p",{className:"m-0 text-xs font-semibold text-red-500"},_.message))),(y||h)&&!_&&(0,n.createElement)(G,{prompt:u,completion:y,setPrompt:g,setInputText:r,loading:h}),!h&&!y&&k()&&(0,n.createElement)(i.BaseControl,null,(0,n.createElement)(N,{completion:y,disabled:h,setInputText:r,setPrompt:g})),!h&&!y&&!k()&&(0,n.createElement)(i.BaseControl,{label:(0,d.__)("Suggested prompts","extendify-local")},(0,n.createElement)(x,{disabled:h,setInputText:r,setReady:m})))),window.extSharedData?.devbuild&&(0,n.createElement)(i.Panel,null,(0,n.createElement)(i.PanelBody,{title:"Debug",initialOpen:!1},(0,n.createElement)("label",null,"prompt text:"),(0,n.createElement)("pre",{className:"whitespace-pre-wrap"},u.text),(0,n.createElement)("label",null,"prompt system message:"),(0,n.createElement)("pre",{className:"whitespace-pre-wrap"},u.systemMessageKey),(0,n.createElement)("label",null,"completion:"),(0,n.createElement)("pre",{className:"whitespace-pre-wrap"},y),(0,n.createElement)("label",null,"error:"),(0,n.createElement)("pre",{className:"whitespace-pre-wrap"},null!==(e=_?.message)&&void 0!==e?e:""),(0,n.createElement)("label",null,"loading: ",h?(0,n.createElement)("span",null,"true"):(0,n.createElement)("span",null,"false")))))},Ae=(e,t)=>"function"==typeof c.createRoot?(0,c.createRoot)(t).render(e):((0,c.render)(e,t),{unmount:()=>{(0,c.unmountComponentAtNode)(t)}}),He=["core/image","core/media-text","core/gallery","core/cover"],De=()=>{const{openGeneralSidebar:e}=(0,o.useDispatch)(s.store);return(0,n.createElement)(i.MenuItem,{icon:k,onClick:async()=>{e("extendify-draft/draft"),await new Promise((e=>requestAnimationFrame(e)));const t=document.getElementById("extendify-draft-image-gen-button");t?.focus(),t?.classList.add("animate-pulse-flash")}},(0,d.__)("Get Personalized Image","extendify-local"))},Re=()=>{const{openGeneralSidebar:e}=(0,o.useDispatch)(s.store);return(0,n.createElement)(i.ToolbarGroup,{className:"extendify-draft"},(0,n.createElement)(i.ToolbarButton,{className:"py-1.5 pl-2 pr-3 text-white before:bg-editor-main before:content-[''] hover:before:bg-editor-main-darker",icon:k,onClick:async()=>{e("extendify-draft/draft"),await new Promise((e=>requestAnimationFrame(e)));const t=document.getElementById("extendify-draft-image-gen-button");t?.focus(),t?.classList.add("animate-pulse-flash")}},(0,d.__)("Ask AI","extendify-local")))},Fe=({name:e,attributes:t})=>((0,c.useEffect)((()=>{if(!He.includes(e))return;let t,a,l,r,i;return(async()=>{await new Promise((e=>r=requestAnimationFrame(e)));const e=Array.from(document.querySelectorAll('[data-toolbar-item="true"]'))?.find((e=>e.textContent===(0,d.__)("Replace")||e.textContent===(0,d.__)("Add")));e&&(i=new MutationObserver((e=>{if("true"===e[0].target.getAttribute("aria-expanded")){const e=".block-editor-media-replace-flow__media-upload-menu",r=document.querySelector(e);if(!r)return;return t=document.createElement("div"),r.prepend(t),void(l=requestAnimationFrame((()=>{a=Ae((0,n.createElement)(De,null),t)})))}cancelAnimationFrame(l),a?.unmount(),t?.remove()})),i.observe(e,{attributes:!0,childList:!1,subtree:!1}))})(),()=>{[l,r].forEach(cancelAnimationFrame),a?.unmount(),t?.remove(),i?.disconnect()}}),[e,t]),He.includes(e)?(0,n.createElement)(Re,null):null);var Ve=a(4461),Ge=a(4310),Oe=a(5024);const je=({text:e,closePopup:t,openDraft:a,updatePrompt:l})=>{const r=[{language:(0,d.__)("Arabic","extendify-local"),code:"ar",languageName:"Arabic"},{language:(0,d.__)("Arabic (Morocco)","extendify-local"),code:"ary",languageName:"Arabic (Morocco)"},{language:(0,d.__)("Bulgarian","extendify-local"),code:"bg_BG",languageName:"Bulgarian"},{language:(0,d.__)("Catalan","extendify-local"),code:"ca",languageName:"Catalan"},{language:(0,d.__)("Czech","extendify-local"),code:"cs_CZ",languageName:"Czech"},{language:(0,d.__)("Danish","extendify-local"),code:"da_DK",languageName:"Danish"},{language:(0,d.__)("Dutch","extendify-local"),code:"nl_NL",languageName:"Dutch"},{language:(0,d.__)("Dutch (Belgium)","extendify-local"),code:"de_BE",languageName:"Dutch (Belgium)"},{language:(0,d.__)("English","extendify-local"),code:"en",languageName:"English"},{language:(0,d.__)("English (UK)","extendify-local"),code:"en_GB",languageName:"English (UK)"},{language:(0,d.__)("Estonian","extendify-local"),code:"et",languageName:"Estonian"},{language:(0,d.__)("Finnish","extendify-local"),code:"fi",languageName:"Finnish"},{language:(0,d.__)("French (Belgium)","extendify-local"),code:"fr_BE",languageName:"French (Belgium)"},{language:(0,d.__)("French (Canada)","extendify-local"),code:"fr_CA",languageName:"French (Canada)"},{language:(0,d.__)("French (France)","extendify-local"),code:"fr_FR",languageName:"French (France)"},{language:(0,d.__)("German","extendify-local"),code:"de_DE",languageName:"German"},{language:(0,d.__)("German (Switzerland)","extendify-local"),code:"de_CH",languageName:"German (Switzerland)"},{language:(0,d.__)("Greek","extendify-local"),code:"el",languageName:"Greek"},{language:(0,d.__)("Hindi","extendify-local"),code:"hi_IN",languageName:"Hindi"},{language:(0,d.__)("Hungarian","extendify-local"),code:"hu_HU",languageName:"Hungarian"},{language:(0,d.__)("Indonesian","extendify-local"),code:"id_ID",languageName:"Indonesian"},{language:(0,d.__)("Italian","extendify-local"),code:"it_IT",languageName:"Italian"},{language:(0,d.__)("Japanese","extendify-local"),code:"jp",languageName:"Japanese"},{language:(0,d.__)("Lithuanian","extendify-local"),code:"lt_LT",languageName:"Lithuanian"},{language:(0,d.__)("Norwegian","extendify-local"),code:"nb_NO",languageName:"Norwegian"},{language:(0,d.__)("Polish","extendify-local"),code:"pl_PL",languageName:"Polish"},{language:(0,d.__)("Portuguese (Brazil)","extendify-local"),code:"pt_BR",languageName:"Portuguese (Brazil)"},{language:(0,d.__)("Portuguese (Portugal)","extendify-local"),code:"pt_PT",languageName:"Portuguese (Portugal)"},{language:(0,d.__)("Romanian","extendify-local"),code:"ro_RO",languageName:"Romanian"},{language:(0,d.__)("Russian","extendify-local"),code:"ru_RU",languageName:"Russian"},{language:(0,d.__)("Slovak","extendify-local"),code:"sk_SK",languageName:"Slovak"},{language:(0,d.__)("Spanish (Spain)","extendify-local"),code:"es_ES",languageName:"Spanish (Spain)"},{language:(0,d.__)("Spanish (Colombia)","extendify-local"),code:"es_CO",languageName:"Spanish (Colombia)"},{language:(0,d.__)("Spanish (Mexico)","extendify-local"),code:"es_MX",languageName:"Spanish (Mexico)"},{language:(0,d.__)("Swedish","extendify-local"),code:"sv_SE",languageName:"Swedish"},{language:(0,d.__)("Turkish","extendify-local"),code:"tr_TR",languageName:"Turkish"},{language:(0,d.__)("Ukrainian","extendify-local"),code:"uk",languageName:"Ukrainian"},{language:(0,d.__)("Vietnamese","extendify-local"),code:"vi",languageName:"Vietnamese"}];return(0,n.createElement)(i.Dropdown,{className:"my-container-class-name flex w-full items-center justify-between",contentClassName:"my-dropdown-content-classname",popoverProps:{placement:"right-start"},renderToggle:({isOpen:e,onToggle:t})=>(0,n.createElement)("div",{className:"group flex w-full items-center justify-between hover:text-design-main"},(0,n.createElement)(i.MenuItem,{className:"flex w-full justify-between",icon:Ve.Z,iconPosition:(0,d.isRTL)()?"left":"right",variant:void 0,onClick:t,"aria-expanded":e},(0,d.__)("Translate","extendify-local")),(0,n.createElement)(h.Z,{icon:(0,d.isRTL)()?Ge.Z:Oe.Z,size:24,className:"fill-current group-hover:text-current"})),renderContent:()=>(0,n.createElement)(i.MenuGroup,{className:"extendify-draft",label:(0,n.createElement)("div",{className:"flex items-center gap-2"},(0,n.createElement)(h.Z,{className:"fill-gray-900",size:16,icon:k}),(0,d.__)("Translate to...","extendify-local"))},r.map((({language:r,code:o,languageName:s,promptType:c="translate",systemMessageKey:m="edit"})=>(0,n.createElement)(i.MenuItem,{key:`${c}-${o}-${m}`,style:{width:"100%"},isSelected:!1,disabled:!1,variant:void 0,onClick:()=>{a?.(),t?.(),window.requestAnimationFrame((()=>window.requestAnimationFrame((()=>l({text:e,promptType:c,systemMessageKey:m,details:{languageInto:s}})))))}},r))))})},ze=["core/paragraph","core/list-item","core/verse","core/preformatted","core/heading"],Ke=(e,t)=>{const{clientId:a}=t,{getBlockName:r,getBlock:c}=(0,o.useSelect)((e=>e(l.store)),[]),{getActiveGeneralSidebarName:m}=(0,o.useSelect)((e=>e(s.store)),[]),{openGeneralSidebar:u}=(0,o.useDispatch)(s.store);if(!ze.includes(r(a)))return(0,n.createElement)(e,{...t});const g=c(a)?.attributes?.content||"",p=()=>u("extendify-draft/draft"),f=e=>window.dispatchEvent(new CustomEvent("extendify-draft:set-prompt",{detail:e}));return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(e,{...t}),(0,n.createElement)(l.BlockControls,null,(0,n.createElement)(i.ToolbarGroup,{className:"extendify-draft"},(0,n.createElement)(i.Dropdown,{renderContent:({onClose:e})=>(0,n.createElement)(qe,{text:g,closePopup:e,openDraft:p,updatePrompt:f}),renderToggle:({isOpen:e,onToggle:t})=>(0,n.createElement)(i.ToolbarButton,{className:"py-1.5 pl-2 pr-3 text-white before:bg-editor-main before:content-[''] hover:before:bg-editor-main-darker",onClick:()=>{if(!g)return"extendify-draft/draft"===m()?u("edit-post/block"):p();t()},"aria-expanded":e,"aria-haspopup":"true",iconPosition:(0,d.isRTL)()?"right":"left",icon:k},(0,d.__)("Ask AI","extendify-local"))}))))},qe=({text:e,closePopup:t,openDraft:a,updatePrompt:l})=>{const r=[{label:(0,d.__)("Improve writing","extendify-local"),promptType:"improve-writing",systemMessageKey:"edit",icon:(0,n.createElement)(h.Z,{icon:_.Z}),disabled:()=>!1},{label:(0,d.__)("Fix spelling & grammar","extendify-local"),promptType:"fix-spelling-grammar",systemMessageKey:"edit",icon:(0,n.createElement)(h.Z,{icon:w.Z}),disabled:()=>!1},{label:(0,d.__)("Simplify language","extendify-local"),promptType:"simplify-language",systemMessageKey:"edit",icon:(0,n.createElement)(h.Z,{icon:E.Z}),disabled:()=>!1},{label:(0,d.__)("Make shorter","extendify-local"),promptType:"make-shorter",systemMessageKey:"edit",icon:(0,n.createElement)(h.Z,{icon:L}),disabled:()=>!1},{label:(0,d.__)("Make longer","extendify-local"),promptType:"make-longer",systemMessageKey:"edit",icon:(0,n.createElement)(h.Z,{icon:b.Z}),disabled:()=>!1}];return(0,n.createElement)(i.NavigableMenu,{orientation:"vertical",role:"menu",style:{minWidth:"200px"}},(0,n.createElement)(i.MenuGroup,{className:"extendify-draft"},(0,n.createElement)(i.MenuItem,{key:"custom-prompt",style:{width:"100%"},isSelected:!1,disabled:!1,iconPosition:"left",icon:k,variant:void 0,onClick:()=>{a?.(),t?.(),window.requestAnimationFrame((()=>window.requestAnimationFrame((()=>document.getElementById("draft-ai-textarea").focus()))))}},(0,d.__)("Custom prompt","extendify-local")),r.map((({label:r,promptType:o,systemMessageKey:s,disabled:c,icon:m})=>(0,n.createElement)(i.MenuItem,{key:`${o}-${o}-${s}`,style:{width:"100%"},isSelected:!1,disabled:c(),iconPosition:(0,d.isRTL)()?"left":"right",icon:m,variant:void 0,onClick:()=>{a?.(),t?.(),window.requestAnimationFrame((()=>window.requestAnimationFrame((()=>l({text:e,promptType:o,systemMessageKey:s})))))}},r))),(0,n.createElement)(je,{text:e,closePopup:t,openDraft:a,updatePrompt:l})))};(0,u.registerPlugin)("extendify-draft",{render:()=>(0,n.createElement)($e,null,(0,n.createElement)(s.PluginSidebarMoreMenuItem,{target:"draft"},(0,d.__)("AI Tools","extendify-local")),(0,n.createElement)(s.PluginSidebar,{name:"draft",icon:k,title:(0,d.__)("AI Tools","extendify-local"),className:"extendify-draft h-full"},(0,n.createElement)(i.Flex,{direction:"column",expanded:!0,justify:"space-between"},(0,n.createElement)(i.FlexBlock,null,(0,n.createElement)(Ze,null)))))});const $e=({children:e})=>{const{insertBlocks:t,selectBlock:a}=(0,o.useDispatch)(l.store),{navigateTo:n}=Be(),{openGeneralSidebar:i}=(0,o.useDispatch)(s.store),m=(0,o.useSelect)((e=>e(s.store).getActiveGeneralSidebarName())),d=(()=>{const[e,t]=(0,c.useState)(!1),a=(0,o.useSelect)((e=>e(l.store).__unstableIsEditorReady||e(l.store).getBlockCount()>0||e(l.store).getSelectedBlockClientId())),n=(0,o.useSelect)((e=>e(g.store).__unstableIsEditorReady||e(g.store).isCleanNewPost()));return(0,c.useEffect)((()=>{const e=(0,o.subscribe)((()=>{(a||n)&&(t(!0),e())}))}),[a,n]),e})(),u=(0,c.useRef)(!1),{getBlocks:p}=(0,o.useSelect)((e=>e(l.store)),[]);return(0,c.useEffect)((()=>{const e=new URLSearchParams(window.location.search);if(!e.has("ext-add-image-block"))return;e.delete("ext-add-image-block"),window.history.replaceState({},"",window.location.pathname+"?"+e.toString()),n("ai-image");const l=p()?.find((e=>"core/image"===e.name));requestAnimationFrame((()=>l?a(l.clientId):t([(0,r.createBlock)("core/image")]))),setTimeout((()=>{document.getElementById("draft-ai-image-textarea")?.focus()}),300)}),[a,t,n,p]),(0,c.useEffect)((()=>{if(!d||u.current)return;const e=requestAnimationFrame((()=>{"extendify-draft/draft"!==m?i("extendify-draft/draft"):u.current=!0}));return()=>cancelAnimationFrame(e)}),[i,m,d]),e};(0,m.addFilter)("editor.BlockEdit","extendify-draft/draft-toolbar",(e=>t=>Ke(e,t))),(0,m.addFilter)("editor.BlockEdit","extendify-draft/draft-image",(e=>t=>((e,t)=>{const{openGeneralSidebar:a}=(0,o.useDispatch)(s.store),{clientId:r,name:m}=t;return(0,c.useEffect)((()=>{if(!He.includes(m))return;const e=document.querySelector('iframe[name="editor-canvas"]')?.contentDocument,t=e?e.querySelector(`[data-block="${r}"]`):document.querySelector(`[data-block="${r}"]`);if(!t)return;const l=Object.assign(document.createElement("div"),{className:"components-form-file-upload"});let o;t.querySelector(".block-editor-media-placeholder .components-form-file-upload")?.after(l);const s=(0,n.createElement)(n.Fragment,null,(0,n.createElement)(i.Button,{variant:"primary",__next40pxDefaultSize:!0,onClick:async()=>{a("extendify-draft/draft"),await new Promise((e=>requestAnimationFrame(e)));const e=document.getElementById("extendify-draft-image-gen-button");e?.focus(),e?.classList.add("animate-pulse-flash")}},(0,d.__)("Get Personalized Image","extendify-local")),(0,n.createElement)("span",{"aria-hidden":"true"})),c=requestAnimationFrame((()=>{o=Ae(s,l)}));return()=>{cancelAnimationFrame(c),o?.unmount(),l?.remove()}}),[r,a,m]),(0,n.createElement)(n.Fragment,null,(0,n.createElement)(e,{...t}),(0,n.createElement)(l.BlockControls,null,(0,n.createElement)(Fe,{...t})))})(e,t)))},9196:e=>{e.exports=window.React},6989:e=>{e.exports=window.wp.apiFetch},2175:e=>{e.exports=window.wp.blockEditor},4981:e=>{e.exports=window.wp.blocks},5609:e=>{e.exports=window.wp.components},9818:e=>{e.exports=window.wp.data},9307:e=>{e.exports=window.wp.element},2694:e=>{e.exports=window.wp.hooks},5736:e=>{e.exports=window.wp.i18n},8817:e=>{e.exports=window.wp.plugins},444:e=>{e.exports=window.wp.primitives}},e=>{e.O(0,[746,857],(()=>(8530,e(e.s=8530)))),e.O()}]);