import{A as e,D as t,E as n,K as r,M as i,X as a,b as o,c as s,gt as c,j as l,jt as u,mt as d,ot as f,p,st as m,v as h,w as g,wt as _}from"./dist-B4ulKgpj.js";import{n as v}from"./usetoast-BF8L6V7u.js";import{t as y}from"./toast-CIOCHy8g.js";import{t as b}from"./Label-CFnMyEie.js";import{t as x}from"./button-DVjHqmFH.js";import{t as S}from"./fileupload-C5smBi_R.js";import{t as C}from"./inputtext-BlE0mOXw.js";import{t as w}from"./textarea-BEctI9xX.js";import{t as T}from"./InputError-whMZ-BCS.js";var E={class:`grid gap-2`},D={class:`grid gap-2`},O={class:`grid gap-2`},k={key:0,class:`relative flex items-center gap-2 pt-2`},A={class:`absolute card flex justify-center right-4 top-[-2.5rem]`},j={class:`rounded-2xl border-2 border-blue-950 p-0`},M={class:`grid gap-2`},N={class:`grid gap-2`},P={class:`flex flex-wrap items-center gap-6`},F={class:`flex items-center gap-2 text-sm`},I={class:`flex items-center gap-2 text-sm`},L={class:`flex justify-end`},R=i({__name:`CreateArticle`,setup(i){let R=v(),z=s().props;c(null);let B=d({title:``,subtitle:``,articleContent:``,articleImage:``,articleImageName:``,link:``,isFeatured:!1,isActive:!0}),V=c(!1),H=c(``),U=c(``),W=c(``),G=c(``),K=c(``),q=c(!1),J=()=>{H.value=``,U.value=``,W.value=``,G.value=``,K.value=``};function Y(){J(),V.value=!0,u.post(`/article-management`,B,{onSuccess:()=>{V.value=!1,R.add({severity:`success`,summary:`Success`,detail:`Article created successfully`,life:2500}),setTimeout(()=>u.visit(`/article-management`),800)},onError:e=>{V.value=!1,H.value=e.title||``,U.value=e.subtitle||``,W.value=e.articleContent||``,G.value=e.articleImage||``,K.value=e.link||``}})}let X=e=>{let t=d({uploadedFile:e.target.files,actionType:`article image`});u.post(`/upload-file`,t,{onSuccess:e=>{V.value=!1,R.add({severity:`success`,summary:`Success`,detail:`File uploaded`,life:2500}),B.articleImage=e.flash.message.file_path,B.articleImageName=e.flash.message.file_name,q.value=!0},onError:e=>{R.add({severity:`error`,summary:`Error`,detail:z.errors?.error,life:2500})}})},Z=()=>{B.articleImage=``,B.articleImageName=``};return(i,s)=>{let c=a(`Image`);return r(),t(o,null,[l(_(y)),g(`form`,{onSubmit:h(Y,[`prevent`]),class:`space-y-4`},[g(`div`,E,[l(_(b),{for:`title`},{default:f(()=>[...s[8]||=[e(`Title `,-1),g(`span`,{class:`text-red-600`},`*`,-1)]]),_:1}),l(_(C),{id:`title`,modelValue:B.title,"onUpdate:modelValue":s[0]||=e=>B.title=e,invalid:!!H.value},null,8,[`modelValue`,`invalid`]),l(T,{message:H.value},null,8,[`message`])]),g(`div`,D,[l(_(b),{for:`subtitle`},{default:f(()=>[...s[9]||=[e(`Subtitle`,-1)]]),_:1}),l(_(C),{id:`subtitle`,modelValue:B.subtitle,"onUpdate:modelValue":s[1]||=e=>B.subtitle=e,invalid:!!U.value},null,8,[`modelValue`,`invalid`]),l(T,{message:U.value},null,8,[`message`])]),g(`div`,O,[l(_(b),{for:`articleImage`},{default:f(()=>[...s[10]||=[e(`Article Image`,-1)]]),_:1}),l(_(C),{id:`articleImage`,modelValue:B.articleImageName,"onUpdate:modelValue":s[2]||=e=>B.articleImageName=e,invalid:!!G.value,readonly:``,disabled:``},null,8,[`modelValue`,`invalid`]),l(T,{message:G.value},null,8,[`message`]),q.value?(r(),t(`div`,k,[g(`div`,A,[g(`span`,{onClick:s[3]||=e=>Z(),class:`rounded-xl bg-gray-300 pr-1 pl-1 hover:cursor-pointer`},[...s[11]||=[g(`i`,{class:`pi pi-times`,style:{color:`red`,"font-size":`10px`}},null,-1)]]),l(c,{src:`/assets/image-icon.png`,alt:`Image`,imageClass:`rounded-xl`,width:`53`})])])):n(``,!0)]),g(`div`,j,[l(_(S),{multiple:!1,maxFileSize:1e6,name:`uploadedFile`,auto:!0,mode:`basic`,onInput:X})]),g(`div`,M,[l(_(b),{for:`link`},{default:f(()=>[...s[12]||=[e(`External Link`,-1)]]),_:1}),l(_(C),{id:`link`,modelValue:B.link,"onUpdate:modelValue":s[4]||=e=>B.link=e,invalid:!!K.value},null,8,[`modelValue`,`invalid`]),l(T,{message:K.value},null,8,[`message`])]),g(`div`,N,[l(_(b),{for:`articleContent`},{default:f(()=>[...s[13]||=[e(`Article Content `,-1),g(`span`,{class:`text-red-600`},`*`,-1)]]),_:1}),l(_(w),{id:`articleContent`,modelValue:B.articleContent,"onUpdate:modelValue":s[5]||=e=>B.articleContent=e,rows:`7`,invalid:!!W.value},null,8,[`modelValue`,`invalid`]),l(T,{message:W.value},null,8,[`message`])]),g(`div`,P,[g(`label`,F,[m(g(`input`,{"onUpdate:modelValue":s[6]||=e=>B.isFeatured=e,type:`checkbox`},null,512),[[p,B.isFeatured]]),s[14]||=e(` Featured `,-1)]),g(`label`,I,[m(g(`input`,{"onUpdate:modelValue":s[7]||=e=>B.isActive=e,type:`checkbox`},null,512),[[p,B.isActive]]),s[15]||=e(` Active `,-1)])]),g(`div`,L,[l(_(x),{type:`submit`,loading:V.value},{default:f(()=>[...s[16]||=[g(`span`,null,[g(`i`,{class:`pi pi-save`})],-1),g(`span`,null,` Save Article`,-1)]]),_:1},8,[`loading`])])],32)],64)}}});export{R as t};