import{m as a}from"./alpinejs-Cm4okMZt-v4.7.2.js";import{t as _}from"./wysiwyg-rmernQLR-v4.7.2.js";import{E as b}from"./Errors-CUe_UZOJ-v4.7.2.js";import{n as E}from"./NProgress-DknqWd__-v4.7.2.js";import"./tinymce-BrdxAF0J-v4.7.2.js";import"./@popperjs-B72wc7VP-v4.7.2.js";import"./nprogress-Ca1BokPv-v4.7.2.js";window.Alpine=a;let l,c;a.data("postEdit",({formData:n={},meta:s={},tags:u=[]})=>({formSubmitting:!1,formSubmissionType:null,form:{...n,featured_image:Array.isArray(n.featured_image)?{}:n.featured_image},errors:new b,init(){this.form.meta={...s.meta_title&&{meta_title:s.meta_title},...s.meta_description&&{meta_description:s.meta_description}},E(),this.fullscreenMode(),l=this.initTinyMce(),c=this.initTagsSelectize(),c[0].selectize.setValue(u.map(e=>e.id))},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 _({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(){l.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")){l.get(r.getAttribute("name")).focus();return}r.focus()},handleSubmit({submissionType:e}){this.formSubmitting=!0,this.formSubmissionType=e;const{id:t,title:r,description:o,slug:d,meta:f,featured_image:m,publish_status:p,blog_category_id:g,tags:h}=this.form;axios.put(`/blog/posts/${this.form.id}`,{id:t,title:r,description:o,slug:d,meta:f,publish_status:p,blog_category_id:g,tags:h,files:{featured_image:m.id?[m.id]:[]}},{params:{...e==="save_and_exit"&&{exit_flash:!0}}}).then(i=>{if(e==="save_and_exit"){location.href="/admin/blog/posts";return}success(i.data.message)}).catch(({response:i})=>{this.errors.reset(),this.errors.record(i.data.errors),this.focusFirstErrorField(this.$refs.form.elements),error(i.data.message)}).finally(()=>{this.formSubmitting=!1,this.formSubmissionType=null})}}));a.start();
