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