import{V as f}from"./vueComponentNormalizer.58b0a173.js";import{i as u,f as l,g as c,s as r}from"./index.9d9c8f08.js";import{c as d,g as p}from"./attachments.4aad9de1.js";const _=()=>{var t;let e=0;return(u()||l())&&(e=parseInt((t=document.getElementById("post_author_override"))==null?void 0:t.value)),c()&&(e=window.wp.data.select("core/editor").getEditedPostAttribute("author")),e},I=()=>{const e=document.querySelector("#set-post-thumbnail img");return e?e.getAttribute("src"):""},m=async(e=!1)=>{const t=window.wp.data.select("core/editor"),a=e?t.getEditedPostAttribute("featured_media"):t.getCurrentPost().featured_media;return typeof a>"u"?new Promise(i=>setTimeout(()=>i(m(e)),1e3)):a},g=async()=>{if(u()||l())return I();if(c()){const e=await m(!0).then(t=>t);return isNaN(e)||e===0?"":await r.dispatch("getMediaData",{mediaId:e}).then(t=>t.source_url)}return""},P={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(){const e=this.imageSourceOptions.map(t=>(t.value==="default"&&(t.label=this.$t.__("Default Image Source (Set in Social Networks)",this.$td)),t)).concat({label:this.$t.__("Custom Image",this.$td),value:"custom_image"});return this.currentPost.context==="term"?e.filter(t=>!this.excludedTermOptions.includes(t.value)):this.currentPost.context==="post"&&this.currentPost.postType==="attachment"?e.filter(t=>!this.excludedAttachmentOptions.includes(t.value)):this.$aioseo.integration?(this.$aioseo.integration==="seedprod"&&this.excludedPageBuilderOptions.push("featured","custom"),e.filter(t=>!this.excludedPageBuilderOptions.includes(t.value))):e}},methods:{getTermImageSourceOptions(){return this.imageSourceOptions.filter(e=>!this.excludedTermOptions.includes(e.value))},getImageSourceOption(e){return this.imageSourceOptions.find(t=>t.value===e)},getImageSourceOptionFiltered(e){return this.imageSourceOptionsFiltered.find(t=>t.value===e)}}},h=()=>{let e=null;const t=/<img.*?src=['"](.*?)['"].*?>/i.exec(p());return t&&t[1]&&(e=t[1]),e},$=async(e,t,a)=>{let i=d(e[`${a}image_custom_fields`]);return i||await g().then(s=>{i=s}),i||await r.dispatch("getFirstAttachedImage",{postId:e.id}).then(s=>{i=s}),i||(i=h()),i||(i=globalThis.options.social[t].homePage.image),i},b=()=>{const e=_(),t=f.prototype.$aioseo.user.siteAuthors.find(a=>e===a.id);if(t&&t.gravatar){const a=new URL(t.gravatar);return`${a.origin+a.pathname}.jpg${a.search}`}return""},O={data(){return{imageUrl:"",loading:!1}},async mounted(){await this.setImageUrl()},methods:{async setImageUrl(e=""){var n;const t=this.currentPost,a=e||((n=this.metaBoxTabs)==null?void 0:n.social)||"facebook",i=a==="facebook"||a==="twitter"&&t.twitter_use_og?"og_":"twitter_";let s=t[`${i}image_type`]||"default";switch(s==="default"&&(s=this.options.social[a].general.defaultImageSourcePosts),this.imageUrl="",s){case"featured":this.loading=!0,await g().then(o=>{this.imageUrl=o,this.loading=!1});break;case"attach":this.loading=!0,await r.dispatch("getFirstAttachedImage",{postId:t.id}).then(o=>{this.imageUrl=o,this.loading=!1});break;case"content":this.imageUrl=h();break;case"author":this.imageUrl=b();break;case"auto":this.loading=!0,await $(t,a,i).then(o=>{this.imageUrl=o,this.loading=!1});break;case"custom":this.imageUrl=d(t[`${i}image_custom_fields`]);break;case"custom_image":this.imageUrl=t[`${i}image_custom_url`];break;case"default":default:this.imageUrl=this.options.social[a].general.defaultImagePosts;break}!this.imageUrl&&this.$aioseo.urls.siteLogo&&(this.imageUrl=this.$aioseo.urls.siteLogo),this.$bus.$emit("updateSocialImagePreview",{social:a,image:this.imageUrl})}}},S={data(){return{customUploader:{}}},methods:{openUploadModal(e,t){const a=()=>{const i=this.customUploader[e].state().get("selection").first().toJSON();t(i.url)};if(this.customUploader[e]){this.customUploader[e].open();return}this.customUploader[e]=window.wp.media({title:this.$t.__("Choose Image",this.$td),button:{text:this.$t.__("Choose Image",this.$td)},multiple:!1}),this.customUploader[e].on("select",a),this.customUploader[e].open()}}};export{P as I,S as U,O as a,g};
