import{t as g,v as m,s as h,j as u,w,x as E,u as f,e as p,d as v}from"./links.4e9269a4.js";import{g as $,a as P,c as _,b as O}from"./postContent.164a8a2e.js";const x=()=>{var e;let t=0;return(g()||m())&&(t=parseInt((e=document.getElementById("post_author_override"))==null?void 0:e.value)),h()&&(t=window.wp.data.select("core/editor").getEditedPostAttribute("author")),t},y=()=>{const t=document.querySelector("#set-post-thumbnail img");return t?t.getAttribute("src"):""},I=async(t=!1)=>{const e=window.wp.data.select("core/editor"),i=t?e.getEditedPostAttribute("featured_media"):e.getCurrentPost().featured_media;return typeof i>"u"?new Promise(a=>setTimeout(()=>a(I(t)),1e3)):i},S=async()=>{if(g()||m())return y();if(h()){const t=await I(!0).then(i=>i);return isNaN(t)||t===0?"":u().getMediaData({mediaId:t}).then(i=>i.source_url)}return w()?$().featuredImage:E()?P().featuredImage:""},B={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 a,s,r;const t=u(),e=this.imageSourceOptions.map(o=>(o.value==="default"&&(o.label=this.$t.__("Default Image Source (Set in Social Networks)",this.$td)),o)).concat({label:this.$t.__("Custom Image",this.$td),value:"custom_image"});if(((a=t.currentPost)==null?void 0:a.context)==="term")return e.filter(o=>!this.excludedTermOptions.includes(o.value));if(((s=t.currentPost)==null?void 0:s.context)==="post"&&((r=t.currentPost)==null?void 0:r.postType)==="attachment")return e.filter(o=>!this.excludedAttachmentOptions.includes(o.value));const i=f();return i.aioseo.integration?(i.aioseo.integration==="seedprod"&&this.excludedPageBuilderOptions.push("featured","custom"),e.filter(o=>!this.excludedPageBuilderOptions.includes(o.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(O());return e&&e[1]&&(t=e[1]),t},U=async(t,e,i)=>{let a=_(t[`${i}image_custom_fields`]);return a||await S().then(s=>{a=s}),a||await u().getFirstAttachedImage({postId:t.id}).then(r=>{a=r}),a||(a=b()),a||(a=p().options.social[e].homePage.image),a},A=async()=>{let t="";const e=x();return await u().getUserImage({userId:e}).then(a=>{t=a}),t},C={data(){return{imageUrl:"",loading:!1}},async mounted(){await this.setImageUrl()},methods:{async setImageUrl(t=""){var d;const e=p(),i=u(),a=v(),s=i.currentPost,r=t||((d=a.metaBoxTabs)==null?void 0:d.social)||"facebook",o=r==="facebook"||r==="twitter"&&s.twitter_use_og?"og_":"twitter_";let l=s[`${o}image_type`]||"default";switch(l==="default"&&(l=e.options.social[r].general.defaultImageSourcePosts),this.imageUrl="",l){case"featured":this.loading=!0,await S().then(n=>{this.imageUrl=n,this.loading=!1});break;case"attach":this.loading=!0,await i.getFirstAttachedImage({postId:s.id}).then(n=>{this.imageUrl=n,this.loading=!1});break;case"content":this.imageUrl=b();break;case"author":this.loading=!0,await A().then(n=>{this.imageUrl=n,this.loading=!1});break;case"auto":this.loading=!0,await U(s,r,o).then(n=>{this.imageUrl=n,this.loading=!1});break;case"custom":this.imageUrl=_(s[`${o}image_custom_fields`]);break;case"custom_image":this.imageUrl=s[`${o}image_custom_url`];break;case"default":default:this.imageUrl=e.options.social[r].general.defaultImagePosts;break}const c=f();!this.imageUrl&&c.aioseo.urls.siteLogo&&(this.imageUrl=c.aioseo.urls.siteLogo),window.aioseoBus.$emit("updateSocialImagePreview",{social:r,image:this.imageUrl})}}};export{B as I,C as a};
