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