import{i as g,D as H,e as w,H as S,h as M,I as A,O as B,N as _,g as E,E as C,U as P,z as U,P as z,R as I,k as F,_ as O,r as k,o,c as r,a as i,d as s,b as m,F as d,y as v,t as x,G as j,A as W,f as q}from"./index-20f16f2f.js";import{I as G}from"./InputResourceMultiSelect-514edc39.js";function L(p){return{startTime:E.combine(p,C()),endTime:E.combine(B(p,_({days:1})),C())}}const J={name:"PagemasterTimetableResourcehourcopy",components:{InputResourceMultiSelect:G},setup(){const p=g(F.errorHandler).handleErrorAsync,n=g(F.notification),T=g(F.resourceStore),e=g(F.resourceHourStore),R=H.today(),b=w(()=>T.resources.value.filter(t=>!t.disabled)),D=S([]),y=M([]),f=S([A(R),A(B(R,_({days:1})))]),c=w(()=>I(D.value,t=>t.weekday()).filter(t=>t.items.length>1).map(t=>({code:"duplicateSrcDayOfWeek",param:t.items}))),u=p(async()=>{if(c.value.length){n.add("error","入力欄にエラーがあります");return}const t=Array.from({length:7},(a,l)=>l).map(a=>D.value.find(l=>l.weekday()==a)??null),h=await Promise.all(t.map(a=>a?Promise.all(y.value.map(l=>e.query({resource:l.id,startTime:E.combine(a,C()),endTime:E.combine(B(a,_({days:1})),C())}))):null));await e.mutate([...P(...f.value,_({days:1}))].filter(a=>h[a.weekday()]).flatMap(a=>y.value.flatMap((l,N)=>[{opcode:"unfill",param:{resource:l.id,...L(a)}},...h[a.weekday()][N].map(V=>({opcode:"fill",param:{resource:l.id,startTime:E.combine(a,V.startTime.timetz()),endTime:E.combine(a,V.endTime.timetz())}}))]))),n.add("info","完了しました")});return{cmp:U,add:B,timedelta:_,getResourceDisplayText:z,resources:b,srcDates:D,targetResources:y,dstDateRange:f,errors:c,submit:u}}},K=i("h1",null,"可能時間曜日別一括複製",-1),Q={key:0},X={key:1},Y={key:0},Z={key:1},$={key:2},ee=i("p",null,[i("button",null,"実行")],-1);function ue(p,n,T,e,R,b){const D=k("input-multi-dates"),y=k("input-resource-multi-select"),f=k("input-date-range"),c=k("date-time");return o(),r(d,null,[K,i("form",{onSubmit:n[3]||(n[3]=j((...u)=>e.submit&&e.submit(...u),["prevent"]))},[i("p",null,[s(" コピー元日付（複数選択可） "),m(D,{modelValue:e.srcDates,"onUpdate:modelValue":n[0]||(n[0]=u=>e.srcDates=u)},null,8,["modelValue"])]),i("p",null,[i("label",null,[s(" リソース "),m(y,{modelValue:e.targetResources,"onUpdate:modelValue":n[1]||(n[1]=u=>e.targetResources=u),options:e.resources},null,8,["modelValue","options"])])]),i("p",null,[s(" コピー先日付範囲 "),m(f,{modelValue:e.dstDateRange,"onUpdate:modelValue":n[2]||(n[2]=u=>e.dstDateRange=u)},null,8,["modelValue"])]),e.errors.length?(o(),r("ul",Q,[(o(!0),r(d,null,v(e.errors,u=>(o(),r("li",null,[u.code==="duplicateSrcDayOfWeek"?(o(),r(d,{key:0},[s(" コピー元日付に同じ曜日の日付、"),(o(!0),r(d,null,v(u.param,t=>(o(),W(c,{value:t},null,8,["value"]))),256)),s("が含まれています。 ")],64)):q("",!0)]))),256))])):(o(),r("p",X,[e.srcDates.length===0?(o(),r("output",Y,"コピー元日付を一つ以上選択してください。")):e.targetResources.length===0?(o(),r("output",Z," リソースを一つ以上選択してください。 ")):(o(),r("output",$,[s(x(e.targetResources.map(e.getResourceDisplayText).join(", "))+"について、 ",1),m(c,{value:e.dstDateRange[0]},null,8,["value"]),s("～"),m(c,{value:e.add(e.dstDateRange[1],e.timedelta({days:-1}))},null,8,["value"]),s("の "),(o(!0),r(d,null,v(e.srcDates.sort((u,t)=>e.cmp(u,t)),u=>(o(),r(d,{key:u.isoFormat()},[s(x(["月","火","水","木","金","土","日"][u.weekday()])+"曜日の可能時間を",1),m(c,{value:u},null,8,["value"]),s("から、 ")],64))),128)),s("コピーします。 ")]))])),ee],32)],64)}const oe=O(J,[["render",ue]]);export{oe as default};
