import{d as l,f as c,i as d,s as n,j as p,k as _}from"./index.02a5ed9a.js";import{f as I,e as $,h as m,i as b}from"./postContent.bb42e0a8.js";const w=()=>{var e;let t=0;return(l()||c())&&(t=parseInt((e=document.getElementById("post_author_override"))==null?void 0:e.value)),d()&&(t=window.wp.data.select("core/editor").getEditedPostAttribute("author")),t},v=()=>{const t=document.querySelector("#set-post-thumbnail img");return t?t.getAttribute("src"):""},g=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(g(t)),1e3)):i},h=async()=>{if(l()||c())return v();if(d()){const t=await g(!0).then(e=>e);return isNaN(t)||t===0?"":await n.dispatch("getMediaData",{mediaId:t}).then(e=>e.source_url)}return p()?I().featuredImage:_()?$().featuredImage:""},y={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(){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)}}},f=()=>{let t=null;const e=/<img.*?src=['"](.*?)['"].*?>/i.exec(b());return e&&e[1]&&(t=e[1]),t},P=async(t,e,i)=>{let a=m(t[`${i}image_custom_fields`]);return a||await h().then(s=>{a=s}),a||await n.dispatch("getFirstAttachedImage",{postId:t.id}).then(s=>{a=s}),a||(a=f()),a||(a=globalThis.options.social[e].homePage.image),a},U=async()=>{const t=w();let e="";return await n.dispatch("getUserImage",{userId:t}).then(i=>{e=i}),e},O={data(){return{imageUrl:"",loading:!1}},async mounted(){await this.setImageUrl()},methods:{async setImageUrl(t=""){var u;const e=this.currentPost,i=t||((u=this.metaBoxTabs)==null?void 0:u.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 h().then(o=>{this.imageUrl=o,this.loading=!1});break;case"attach":this.loading=!0,await n.dispatch("getFirstAttachedImage",{postId:e.id}).then(o=>{this.imageUrl=o,this.loading=!1});break;case"content":this.imageUrl=f();break;case"author":this.loading=!0,await U().then(o=>{this.imageUrl=o,this.loading=!1});break;case"auto":this.loading=!0,await P(e,i,a).then(o=>{this.imageUrl=o,this.loading=!1});break;case"custom":this.imageUrl=m(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})}}},r={},E={methods:{async openUploadModal(t,e){const i=()=>{const a=r[t].state().get("selection").first().toJSON();e(a.url)};if(r[t]){r[t].open();return}r[t]=window.wp.media({title:this.$t.__("Choose Image",this.$td),button:{text:this.$t.__("Choose Image",this.$td)},multiple:!1}),r[t].on("select",i),await this.$nextTick(),r[t].open()}}};export{O as I,E as U,y as a};
