import{i as u,b as l,d as c,s as r}from"./index.7b63dad7.js";import{c as d,g as f}from"./attachments.e5102eba.js";const p=()=>{var e;let t=0;return(u()||l())&&(t=parseInt((e=document.getElementById("post_author_override"))==null?void 0:e.value)),c()&&(t=window.wp.data.select("core/editor").getEditedPostAttribute("author")),t},_=()=>{const t=document.querySelector("#set-post-thumbnail img");return t?t.getAttribute("src"):""},m=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(m(t)),1e3)):i},g=async()=>{if(u()||l())return _();if(c()){const t=await m(!0).then(e=>e);return isNaN(t)||t===0?"":await r.dispatch("getMediaData",{mediaId:t}).then(e=>e.source_url)}return""},U={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,i)=>{let a=d(t[`${i}image_custom_fields`]);return a||await g().then(s=>{a=s}),a||await r.dispatch("getFirstAttachedImage",{postId:t.id}).then(s=>{a=s}),a||(a=h()),a||(a=globalThis.options.social[e].homePage.image),a},b=async()=>{const t=p();let e="";return await r.dispatch("getUserImage",{userId:t}).then(i=>{e=i}),e},v={data(){return{imageUrl:"",loading:!1}},async mounted(){await this.setImageUrl()},methods:{async setImageUrl(t=""){var n;const e=this.currentPost,i=t||((n=this.metaBoxTabs)==null?void 0:n.social)||"facebook",a=i==="facebook"||i==="twitter"&&e.twitter_use_og?"og_":"twitter_";let s=e[`${a}image_type`]||"default";switch(s==="default"&&(s=this.options.social[i].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:e.id}).then(o=>{this.imageUrl=o,this.loading=!1});break;case"content":this.imageUrl=h();break;case"author":this.loading=!0,await b().then(o=>{this.imageUrl=o,this.loading=!1});break;case"auto":this.loading=!0,await I(e,i,a).then(o=>{this.imageUrl=o,this.loading=!1});break;case"custom":this.imageUrl=d(e[`${a}image_custom_fields`]);break;case"custom_image":this.imageUrl=e[`${a}image_custom_url`];break;case"default":default:this.imageUrl=this.options.social[i].general.defaultImagePosts;break}!this.imageUrl&&this.$aioseo.urls.siteLogo&&(this.imageUrl=this.$aioseo.urls.siteLogo),this.$bus.$emit("updateSocialImagePreview",{social:i,image:this.imageUrl})}}},P={data(){return{customUploader:{}}},methods:{openUploadModal(t,e){const i=()=>{const a=this.customUploader[t].state().get("selection").first().toJSON();e(a.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",i),this.customUploader[t].open()}}};export{U as I,P as U,v as a};
