import{_ as k,a2 as w,i as d,e as S,H as c,J as h,z as b,g as _,E as y,r as R,o as r,c as i,F as I,G as V,b as j,a as g,k as m}from"./index-20f16f2f.js";import{I as x}from"./InputEvent-63c6d026.js";import"./InputResourceMultiSelect-514edc39.js";import"./InputCourseDate-b1a3edff.js";import"./InputEventColor-ff50e1eb.js";const B={name:"PageMasterTimetableEventsIdEdit",components:{InputEvent:x},setup(){const p=w(),n=d(m.notification),v=d(m.errorHandler).handleErrorAsync,t=d(m.eventStore),o=d(m.generalTimetableScope),l=S(()=>p.params.id),s=c(!1),e=c(null),f=c(!1);h([l,o.classroom,o.dateRange],v(async()=>{s.value=!0;const u=await t.query({id:l.value});s.value=!1;const a=u.find(T=>T.id===l.value)??null;if(!a){e.value=null;return}if(!(b(_.combine(o.dateRange.value[0],y()),a.startTime)<=0&&b(a.endTime,_.combine(o.dateRange.value[1],y()))<=0)){e.value=null;return}e.value={...a}}),{immediate:!0});const E=v(async()=>{var u;if(f.value){n.add("error","イベントの入力欄にエラーがあります");return}await t.mutate([{opcode:"update_event",param:{id:l.value,type:e.value.type,resources:[...new Set([...e.value.resources.map(a=>a.id)])],startTime:e.value.startTime,endTime:e.value.endTime,timeLabel:((u=e.value.timeLabel)==null?void 0:u.id)??null,color:e.value.color,memo:e.value.memo,...e.value.type==="lesson"?{subject:e.value.subject,frame:e.value.frame}:{}}}]),n.add("info","イベントを更新しました")});return{loading:s,event:e,eventInputInvalid:f,submit:E}}},F=g("h1",null,"イベント編集",-1),H={key:0},L=g("button",null,"編集確定",-1),M={key:1};function N(p,n,v,t,o,l){const s=R("InputEvent");return r(),i(I,null,[F,t.loading?(r(),i("p",H,"読み込み中")):(r(),i(I,{key:1},[t.event?(r(),i("form",{key:0,onSubmit:n[2]||(n[2]=V(e=>t.submit(),["prevent"]))},[j(s,{modelValue:t.event,"onUpdate:modelValue":n[0]||(n[0]=e=>t.event=e),invalid:t.eventInputInvalid,"onUpdate:invalid":n[1]||(n[1]=e=>t.eventInputInvalid=e)},null,8,["modelValue","invalid"]),L],32)):(r(),i("p",M,"イベントが見つかりません"))],64))],64)}const D=k(B,[["render",N]]);export{D as default};
