var g=(u,f,a)=>new Promise((i,l)=>{var d=o=>{try{s(a.next(o))}catch(m){l(m)}},c=o=>{try{s(a.throw(o))}catch(m){l(m)}},s=o=>o.done?i(o.value):Promise.resolve(o.value).then(d,c);s((a=a.apply(u,f)).next())});import{u as A}from"./useEntityForm-CMwp7TbN.js";import{b6 as t,c8 as w}from"./bootstrap-Bqxdt4iG.js";import{A as p}from"./announcements-BeK93bSh.js";import{a1 as P,ai as R,aj as x,a9 as S}from"../jse/index-index-BUJ_4tQs.js";const O=P({__name:"announcement-form",props:{announcement:{default:null},mode:{}},emits:["cancel","submit"],setup(u,{expose:f,emit:a}){const i=u,l=a,d=()=>{const e=new Date,n=r=>String(r).padStart(2,"0");return`${e.getFullYear()}-${n(e.getMonth()+1)}-${n(e.getDate())} ${n(e.getHours())}:${n(e.getMinutes())}:00`},c=(e,n)=>{if(e==null||e==="")return null;if(typeof e=="string")return`${e.slice(0,16)}:${n}`;if(typeof(e==null?void 0:e.format)=="function")return`${e.format("YYYY-MM-DD HH:mm")}:${n}`;if(e instanceof Date){const r=y=>String(y).padStart(2,"0");return`${e.getFullYear()}-${r(e.getMonth()+1)}-${r(e.getDate())} ${r(e.getHours())}:${r(e.getMinutes())}:${n}`}return null},s={title:"",content:"",priority:p.NORMAL,visibleToRoles:[],publishedAt:d(),expiresAt:null},o=[{value:p.NORMAL,label:t("page.announcements.priority.normal")},{value:p.IMPORTANT,label:t("page.announcements.priority.important")},{value:p.URGENT,label:t("page.announcements.priority.urgent")}],m=w.map(e=>({value:e.value,label:e.label})),b=[{component:"Input",componentProps:{placeholder:t("page.announcements.form.titlePlaceholder")},fieldName:"title",formItemClass:"col-span-2",label:t("page.announcements.form.title"),rules:"required"},{component:"Textarea",componentProps:{placeholder:t("page.announcements.form.contentPlaceholder"),autoSize:{minRows:4,maxRows:10}},fieldName:"content",formItemClass:"col-span-2",label:t("page.announcements.form.content"),rules:"required"},{component:"Select",componentProps:{options:o},fieldName:"priority",formItemClass:"col-span-2",label:t("page.announcements.form.priority"),rules:"selectRequired"},{component:"Select",componentProps:{mode:"multiple",options:m,placeholder:t("page.announcements.form.visibleToRolesPlaceholder"),allowClear:!0},fieldName:"visibleToRoles",formItemClass:"col-span-2",label:t("page.announcements.form.visibleToRoles")},{component:"DatePicker",componentProps:{showTime:{format:"HH:mm"},format:"DD/MM/YYYY HH:mm",valueFormat:"YYYY-MM-DD HH:mm:ss",class:"w-full"},fieldName:"publishedAt",label:t("page.announcements.form.publishedAt"),rules:"required"},{component:"DatePicker",componentProps:{showTime:{format:"HH:mm"},format:"DD/MM/YYYY HH:mm",valueFormat:"YYYY-MM-DD HH:mm:ss",class:"w-full",allowClear:!0},fieldName:"expiresAt",label:t("page.announcements.form.expiresAt")}],{Form:Y,focus:h,isDirty:D,resetForm:M,submitForm:H,watchEntity:$}=A({emptyValues:s,schema:b,wrapperClass:"grid-cols-2 gap-x-6"});return $(()=>i.announcement,()=>i.mode),f({cancel:()=>l("cancel"),focus:h,isDirty:D,resetForm:M,submit:()=>g(null,null,function*(){const e=yield H();e&&(e.publishedAt=c(e.publishedAt,"00"),e.expiresAt=c(e.expiresAt,"59"),l("submit",e))})}),(e,n)=>(x(),R(S(Y)))}});export{O as _};
