import{N as y,O as A,m as D,u as v,P as $,Q as C,R as B,S as T,U,V as N,W as L,X as M,Y as R,Z as V,_ as q,$ as G,b as w,a as S,n as Q,G as k,a0 as W}from"./index.6205915e.js";import"./translations.e71e2202.js";import{a1 as I,$ as P}from"./runtime-core.esm-bundler.50cb9e6d.js";import{_ as c}from"./default-i18n.65d58dd6.js";const X=()=>{var a;let e=0;return(y()||A())&&(e=parseInt((a=document.getElementById("post_author_override"))==null?void 0:a.value)),D()&&(e=window.wp.data.select("core/editor").getEditedPostAttribute("author")),e||(e=v().currentPost.postAuthor),e},Y=()=>{var a;const e=[{isEditor:$,getData:C},{isEditor:B,getData:T},{isEditor:U,getData:N},{isEditor:L,getData:M},{isEditor:R,getData:V},{isEditor:q,getData:G}];for(const o of e)if(o.isEditor())return((a=o.getData())==null?void 0:a.featuredImage)??"";return""},Z=()=>{const e=document.querySelector("#set-post-thumbnail img");return e?e.getAttribute("src"):""},F=async(e=!1)=>{var t;const a=window.wp.data.select("core/editor"),o=e&&a?a==null?void 0:a.getEditedPostAttribute("featured_media"):(t=a==null?void 0:a.getCurrentPost())==null?void 0:t.featured_media;return typeof o>"u"?new Promise(r=>setTimeout(()=>r(F(e)),1e3)):o},O=async()=>{if(y()||A())return Z();if(D()){const e=await F(!0).then(o=>o);return isNaN(e)||e===0?"":v().getMediaData({mediaId:e}).then(o=>o.source_url)}return Y()},d="all-in-one-seo-pack",x=()=>{let e=null;const a=/<img.*?src=['"](.*?)['"].*?>/i.exec(W());return a&&a[1]&&(e=a[1]),e},j=async(e,a,o)=>{let t=k(e[`${o}image_custom_fields`]);return t||await O().then(r=>{t=r}),t||await v().getFirstAttachedImage({postId:e.id}).then(p=>{t=p}),t||(t=x()),t||(t=S().options.social[a].homePage.image),t},z=async()=>{let e="";const a=X();return await v().getUserImage({userId:a}).then(t=>{e=t}),e},st=()=>{const e=I(["featured","content","author"]),a=I(["auto"]),o=I(["featured","attach","content","author","auto"]),t=I(""),r=I(!1),p=P(()=>[{label:c("Default Image (Set Below)",d),value:"default"},{label:c("Featured Image",d),value:"featured"},{label:c("Attached Image",d),value:"attach"},{label:c("First Image in Content",d),value:"content"},{label:c("Image from Custom Field",d),value:"custom"},{label:c("Post Author Image",d),value:"author"},{label:c("First Available Image",d),value:"auto"}]),_=P(()=>{var l,u,m;const n=v(),s=p.value.map(i=>(i.value==="default"&&(i.label=c("Default Image Source (Set in Social Networks)",d)),i)).concat({label:c("Custom Image",d),value:"custom_image"});if(((l=n.currentPost)==null?void 0:l.context)==="term")return s.filter(i=>!o.value.includes(i.value));if(((u=n.currentPost)==null?void 0:u.context)==="post"&&((m=n.currentPost)==null?void 0:m.postType)==="attachment")return s.filter(i=>!e.value.includes(i.value));const g=w(),E=S();return g.aioseo.integration?((g.aioseo.integration==="seedprod"||g.aioseo.integration==="wpbakery"&&window.vc_mode==="admin_frontend_editor")&&a.value.push("featured"),g.aioseo.integration==="siteorigin"&&!E.options.searchAppearance.advanced.runShortcodes&&a.value.push("content"),s.filter(i=>!a.value.includes(i.value))):s});return{getImageSourceOption:n=>p.value.find(s=>s.value===n),getImageSourceOptionFiltered:n=>_.value.find(s=>s.value===n),getTermImageSourceOptions:()=>p.value.filter(n=>!o.value.includes(n.value)),imageSourceOptions:p,imageSourceOptionsFiltered:_,imageUrl:t,loading:r,setImageUrl:async(n="")=>{var b;const s=S(),g=v(),E=Q(),l=g.currentPost,u=n||((b=E.metaBoxTabs)==null?void 0:b.social)||"facebook",m=u==="facebook"||u==="twitter"&&l.twitter_use_og?"og_":"twitter_";let i=l[`${m}image_type`]||"default";switch(i==="default"&&(i=s.options.social[u].general.defaultImageSourcePosts),t.value="",i){case"featured":r.value=!0,await O().then(f=>{t.value=f,r.value=!1});break;case"attach":r.value=!0,await g.getFirstAttachedImage({postId:l.id}).then(f=>{t.value=f,r.value=!1});break;case"content":t.value=x();break;case"author":r.value=!0,await z().then(f=>{t.value=f,r.value=!1});break;case"auto":r.value=!0,await j(l,u,m).then(f=>{t.value=f,r.value=!1});break;case"custom":t.value=k(l[`${m}image_custom_fields`]);break;case"custom_image":t.value=l[`${m}image_custom_url`];break;case"default":default:t.value=s.options.social[u].general.defaultImagePosts;break}!t.value&&s.options.social[u].general.defaultImagePosts&&(t.value=s.options.social[u].general.defaultImagePosts);const h=w();!t.value&&h.aioseo.urls.siteLogo&&(t.value=h.aioseo.urls.siteLogo),window.aioseoBus.$emit("updateSocialImagePreview",{social:u,image:t.value})}}};export{O as g,st as u};
