import{m as n}from"./alpinejs-BVmYX9MG-v4.3.1.js";import{t as f}from"./wysiwyg-BAYziHDN-v4.3.1.js";import{E as g}from"./Errors-Dscm1BJ0-v4.3.1.js";import{n as p}from"./NProgress-BQVJao7--v4.3.1.js";import"./tinymce-D75crZP1-v4.3.1.js";import"./blueimp-md5-ClWCTRan-v4.3.1.js";import"./vue-DkJ1Kgzj-v4.3.1.js";import"./nprogress-DKCYbahp-v4.3.1.js";window.Alpine=n;let s,a;n.data("postCreate",()=>({formSubmitting:!1,formSubmissionType:null,form:{meta:{},featured_image:{},publish_status:"published",blog_category_id:""},errors:new g,init(){p(),this.fullscreenMode(),s=this.initTinyMce(),a=this.initTagsSelectize()},fullscreenMode(){$(".fullscreen-mode-open").on("click",e=>{e.preventDefault(),document.fullscreenElement?($(".fullscreen-mode-open .fullscreen-two").removeClass("enter-full-screen"),$(".fullscreen-mode-open .fullscreen-one").addClass("exit-full-screen"),document.exitFullscreen().catch(t=>{alert(`Error attempting to disable full-screen mode: ${t.message} (${t.name})`)})):($(".fullscreen-mode-open .fullscreen-one").removeClass("exit-full-screen"),$(".fullscreen-mode-open .fullscreen-two").addClass("enter-full-screen"),document.documentElement.requestFullscreen().catch(t=>{alert(`Error attempting to enable full-screen mode: ${t.message} (${t.name})`)}))})},initTinyMce(){return f({setup:e=>{e.on("change",()=>{e.save(),e.getElement().dispatchEvent(new Event("input")),this.errors.clear("description")})}})},initTagsSelectize(){return $(".selectize").selectize({plugins:["remove_button"],delimiter:",",persist:!1,create:function(e){return{value:e,text:e}},onChange:e=>{this.form.tags=e},load:function(e,t){var r=route("admin.blog_tags.index");if(r===void 0||e.length===0)return t();$.get(r+"?query="+e,t,"json")}})},focusDescriptionField(){s.get("description").focus()},addFeaturedImage(){new MediaPicker({type:"image"}).on("select",({id:t,path:r})=>{this.form.featured_image={id:+t,path:r}})},removeFeaturedImage(){this.form.featured_image={}},focusFirstErrorField(e){const t=Object.keys(this.errors.errors),r=[...e].find(o=>t.includes(o.name));if(r.classList.contains("wysiwyg")){s.get(r.getAttribute("name")).focus();return}r.focus()},resetForm(){this.errors.reset(),this.form={meta:{},featured_image:{},publish_status:"published",blog_category_id:""},s.get("description").setContent(""),s.get("description").execCommand("mceCancel"),a[0].selectize.clear()},handleSubmit({submissionType:e}){this.formSubmitting=!0,this.formSubmissionType=e;const{title:t,description:r,meta:o,featured_image:l,publish_status:m,blog_category_id:u,tags:c}=this.form;$.ajax({type:"POST",url:route("admin.blog_posts.store",{...(e==="save_and_edit"||e==="save_and_exit")&&{exit_flash:!0}}),data:{title:t,description:r,meta:o,publish_status:m,blog_category_id:u,tags:c,files:{featured_image:l.id?[l.id]:[]}},dataType:"json",success:({message:i,blog_post_id:d})=>{if(this.formSubmissionType==="save_and_edit"){location.href=route("admin.blog_posts.edit",d);return}if(this.formSubmissionType==="save_and_exit"){location.href=route("admin.blog_posts.index");return}success(i),this.resetForm(),this.$refs.form.elements[0].focus()}}).catch(({responseJSON:i})=>{this.errors.record(i.errors),this.focusFirstErrorField(this.$refs.form.elements),error(i.message)}).always(()=>{this.formSubmitting=!1,this.formSubmissionType=null})}}));n.start();
