import{_ as q,i as f,e as b,H as _,J as F,Z as P,$ as A,P as J,r as k,o as x,c as B,a as i,b as v,w as h,d as l,l as g,V as C,W as E,F as L,U as H,N,g as z,E as u,a0 as I,a1 as y,t as O,k as T}from"./index-20f16f2f.js";import{u as W}from"./emphasize-element-of-url-hash-94a2bd41.js";const Z={name:"PageMasterTimetableResourcesIdResourcehours",props:{id:{type:String,required:!0}},setup(V){W();const t=f(T.notification),S=f(T.resourceStore),e=f(T.resourceHourStore),c=f(T.generalTimetableScope),r=b(()=>S.resources.value.find(s=>s.id===V.id)??null),m=c.dateRange,p=b(()=>[...H(...c.dateRange.value,N({days:1}))]),d=_([]),o=_(!1),M=_("daily");async function D(){r.value&&(d.value=await e.query({resource:r.value.id,startTime:z.combine(m.value[0],u()),endTime:z.combine(m.value[1],u())}))}F([r,p],async()=>{await D()},{immediate:!0});const R=b({get:()=>{const s=new I;for(const a of d.value)s.add(a.startTime,a.endTime,!0);return[...H(...c.dateRange.value,N({days:1}))].map(a=>({date:a,timeRanges:s.get(...y(a,u(),u())).filter(n=>n.items.has(!0)).map(n=>({startTime:n.start.timetz(),endTime:n.end.timetz()}))}))},set:s=>{const a=new I;for(const{date:n,timeRanges:j}of s)for(const U of j)a.add(...y(n,U.startTime,U.endTime),!0);d.value=a.get().filter(n=>n.items.has(!0)).map(n=>({startTime:n.start,endTime:n.end}))}});async function w(){function s(a){return{startTime:a[0],endTime:a[1]}}return o.value?(t.add("error","日付別時間帯入力欄にエラーがあります"),!1):(await e.mutate([...R.value.map(a=>({opcode:"unfill",param:{resource:r.value.id,...s(y(a.date,u(),u()))}})),...R.value.flatMap(a=>a.timeRanges.map(n=>({...s(y(a.date,n.startTime,n.endTime))}))).map(a=>({opcode:"fill",param:{resource:r.value.id,...a}}))]),t.add("info","保存しました"),!0)}return P(async(s,a)=>{if(s.params.id!==a.params.id&&!await w())return!1}),A(async()=>{if(!await w())return!1}),{getResourceDisplayText:J,resource:r,dates:p,timeRanges:d,dailyTimeRanges:R,dailyTimeRangesInvalid:o,view:M,load:D,save:w}}},G=i("hr",null,null,-1),K={key:1};function Q(V,t,S,e,c,r){const m=k("router-link"),p=k("input-daily-time-ranges"),d=k("input-weekly-time-ranges");return e.resource?(x(),B(L,{key:0},[i("h1",null,[v(m,{to:"./index"},{default:h(()=>[l(O(e.getResourceDisplayText(e.resource)),1)]),_:1}),l("の可能時間入力 ")]),i("p",null,[l(" 変更は"),v(m,{to:"#savebutton"},{default:h(()=>[l("「保存」ボタン")]),_:1}),l("を押すかページ遷移時に自動で保存されます。 ")]),i("label",null,[g(i("input",{type:"radio",name:"view","onUpdate:modelValue":t[0]||(t[0]=o=>e.view=o),value:"daily"},null,512),[[C,e.view]]),l("日付毎入力")]),i("label",null,[g(i("input",{type:"radio",name:"view","onUpdate:modelValue":t[1]||(t[1]=o=>e.view=o),value:"weekly"},null,512),[[C,e.view]]),l("一括入力")]),g(i("div",null,[v(p,{modelValue:e.timeRanges,"onUpdate:modelValue":t[2]||(t[2]=o=>e.timeRanges=o),dates:e.dates},null,8,["modelValue","dates"])],512),[[E,e.view==="daily"]]),g(v(d,{modelValue:e.timeRanges,"onUpdate:modelValue":t[3]||(t[3]=o=>e.timeRanges=o),dates:e.dates},null,8,["modelValue","dates"]),[[E,e.view==="weekly"]]),G,i("p",null,[i("button",{type:"button",onClick:t[4]||(t[4]=o=>e.save()),id:"savebutton"},"保存")]),i("p",null,[i("button",{type:"button",onClick:t[5]||(t[5]=o=>e.load())},"最後に保存した時の状態にリセット")])],64)):(x(),B("p",K,"無効なリソースIDが指定されています。"))}const $=q(Z,[["render",Q]]);export{$ as default};
