import{D as k,H as g,I as D,J as w,K as I,L as h,z as m,_ as M,i as V,p as x,e as T,r as y,o as v,c as f,d,b,w as O,a as p,l as B,C as E,F as C,y as J,f as L,k as R,M as _,N as S,O as U,t as K}from"./index-20f16f2f.js";function j(s){function o(t,a){const i=s.getItem(t);if(i==null){if(a===void 0)throw new RangeError(`Key "${t}" not found`);return a}return JSON.parse(i)}function c(t){return s.getItem(t)!=null}function e(t,a){s.setItem(t,JSON.stringify(a))}function n(t){s.removeItem(t)}function r(){s.clear()}return{get:o,has:c,set:e,delete:n,clear:r}}function z(){return j(localStorage)}const N="generalTimetableScope";function G(s){const o=k.today(),c=s.get(N,{dateRange:[o.isoFormat(),o.isoFormat()],classroom:""}),e=g(c.dateRange.map(a=>D(k.fromISOFormat(a)))),n=g(c.classroom);w([e,n],()=>{s.set(N,{dateRange:e.value.map(a=>a.isoFormat()),classroom:n.value})});function r(a){if(m(a[0],a[1])>0)throw new Error("Start date should be earlier than end date.");e.value=a.map(i=>D(i))}function t(a){n.value=a}return{dateRange:I(e),classroom:h(n),setDateRange:r,setClassroom:t}}const H={name:"PageMasterTimetable",setup(){const s=V(R.notification),o=V(R.resourceStore),c=z(),e=G(c);x(R.generalTimetableScope,e);const n=T(()=>o.resources.value.filter(u=>u.type==="classroom"&&!u.disabled)),r=g(null),t=g(null),a=g(null);w([e.classroom,e.dateRange],()=>{r.value=n.value.find(F=>F.id===e.classroom.value)??null,r.value||(r.value=n.value[0]??null,l());const u=e.dateRange.value;t.value=u[0],a.value=_(u[1],S({days:1})),m(t.value,a.value)>0&&(a.value=u[0],l())},{immediate:!0}),w(n,()=>{r.value=n.value[0]??null},{immediate:!0});const i=T(()=>{var u;return(((u=r.value)==null?void 0:u.id)??"")!==e.classroom.value||m(t.value,e.dateRange.value[0])!==0||m(a.value,_(e.dateRange.value[1],S({days:1})))!==0});function l(){var u;if(m(t.value,a.value)>0){s.add("error","開始日付が終了日付より後です。");return}if(m(_(a.value,t.value),S({weeks:12}))>0){s.add("error","開始日付と終了日付は12週間以内である必要があります。");return}e.setClassroom(((u=r.value)==null?void 0:u.id)??""),e.setDateRange([t.value,U(a.value,S({days:1}))])}return{classrooms:n,classroom:r,startDate:t,endDate:a,timetableScopeModified:i,submitTimetableScope:l}}},P={key:0},W=["value"];function q(s,o,c,e,n,r){const t=y("router-link"),a=y("input-date"),i=y("router-view");return e.classroom==null?(v(),f("p",P,[d(" 教室が一つも登録されていません。 "),b(t,{to:"/master/config/classroom"},{default:O(()=>[d("ここ")]),_:1}),d("から最低一つ教室を登録してください。 ")])):(v(),f(C,{key:1},[p("p",null,[p("label",null,[d(" 教室 "),B(p("select",{"onUpdate:modelValue":o[0]||(o[0]=l=>e.classroom=l)},[(v(!0),f(C,null,J(e.classrooms,l=>(v(),f("option",{key:l.id,value:l},K(l.label),9,W))),128))],512),[[E,e.classroom]])]),p("label",null,[d(" 開始日付 "),b(a,{modelValue:e.startDate,"onUpdate:modelValue":o[1]||(o[1]=l=>e.startDate=l)},null,8,["modelValue"])]),p("label",null,[d(" 終了日付 "),b(a,{modelValue:e.endDate,"onUpdate:modelValue":o[2]||(o[2]=l=>e.endDate=l)},null,8,["modelValue"])]),e.timetableScopeModified?(v(),f("button",{key:0,type:"button",onClick:o[3]||(o[3]=l=>e.submitTimetableScope())},"変更")):L("",!0)]),b(i)],64))}const Q=M(H,[["render",q]]);export{Q as default};
