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