import{n as _}from"./NProgress-l2LCo1nA-v4.7.11.js";import{f as y}from"./functions-Cxk2NqT8-v4.7.11.js";import{m}from"./alpinejs-S4M4TpEG-v4.7.11.js";import{t as b}from"./wysiwyg-CUosvmnj-v4.7.11.js";import{E}from"./Errors-CUe_UZOJ-v4.7.11.js";import"./nprogress-ByFQqwB7-v4.7.11.js";import"./@popperjs-IQGopUey-v4.7.11.js";import"./tinymce-ClL__6Gw-v4.7.11.js";window.Alpine=m;let n,d;m.data("postEdit",({formData:o={},meta:r={},tags:c=[]})=>({formSubmitting:!1,formSubmissionType:null,form:{...o,featured_image:Array.isArray(o.featured_image)?{}:o.featured_image},errors:new E,init(){this.form.meta={...r.meta_title&&{meta_title:r.meta_title},...r.meta_description&&{meta_description:r.meta_description}},_(),y(),n=this.initTinyMce(),d=this.initTagsSelectize(),d[0].selectize.setValue(c.map(e=>e.id))},initTinyMce(){return b({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,onChange:e=>{this.form.tags=e}})},focusDescriptionField(){n.get("description").focus()},addFeaturedImage(){new MediaPicker({type:"image"}).on("select",({id:i,path:t})=>{this.form.featured_image={id:+i,path:t}})},removeFeaturedImage(){this.form.featured_image={}},focusFirstErrorField(e){const i=Object.keys(this.errors.errors),t=[...e].find(a=>i.includes(a.name));if(t.classList.contains("wysiwyg")){n.get(t.getAttribute("name")).focus();return}t.focus()},handleSubmit({submissionType:e}){this.formSubmitting=!0,this.formSubmissionType=e;const{id:i,title:t,description:a,slug:f,meta:u,featured_image:l,publish_status:g,blog_category_id:p,tags:h}=this.form;axios.put(`/blog/posts/${this.form.id}`,{id:i,title:t,description:a,slug:f,meta:u,publish_status:g,blog_category_id:p,tags:h,files:{featured_image:l.id?[l.id]:[]}},{params:{...e==="save_and_exit"&&{exit_flash:!0}}}).then(s=>{if(e==="save_and_exit"){location.href="/admin/blog/posts";return}success(s.data.message)}).catch(({response:s})=>{this.errors.reset(),this.errors.record(s.data.errors),this.focusFirstErrorField(this.$refs.form.elements),error(s.data.message)}).finally(()=>{this.formSubmitting=!1,this.formSubmissionType=null})}}));m.start();
