import{_ as g,i as v,h as V,e as B,o as r,c as i,a as e,F as m,y as h,u as E,t as k,l as C,v as I,B as U,f as $,k as _}from"./index-20f16f2f.js";const w={name:"PageMasterConfigClassroom",setup(){const b=v(_.notification),n=v(_.errorHandler).handleErrorAsync,u=v(_.resourceStore),o=V([]),f=B(()=>{const a=o.value.filter(s=>!s.deleted),p=[];return p.push(...a.filter(s=>!s.label).map(s=>({item:s,code:"novalue",property:"label"}))),p}),c=n(async()=>{await u.load(),o.value=u.resources.value.filter(a=>a.type==="classroom").map(a=>({id:a.id,disabled:a.disabled,label:a.label,deleted:!1}))});c();function t(){o.value.push({id:null,disabled:!1,label:"",deleted:!1})}function d(){o.value.sort(E(a=>a.label))}const y=n(async()=>{if(f.value.length){b.add("error","入力欄にエラーがあります。修正してください。");return}const a=o.value.filter(l=>l.id==null&&!l.deleted),p=o.value.filter(l=>l.id!=null&&!l.deleted),s=o.value.filter(l=>l.id!=null&&l.deleted);s.length&&!confirm("いくつかの教室が削除されます。削除する教室が指定されたイベントがある場合、それらのイベントにアクセスする手段は無くなります。本当に削除しますか？")||(await u.mutate(a.map(l=>({opcode:"add_resource",param:{multiplicity:-1,disabled:l.disabled,type:"classroom",label:l.label}})).concat(p.map(l=>({opcode:"update_resource",param:{id:l.id,multiplicity:1,disabled:l.disabled,type:"classroom",label:l.label}})),s.map(l=>({opcode:"remove_resource",param:{id:l.id}})))),b.add("info","保存しました。"),await c())});return{resources:o,resourceErrors:f,load:c,add:t,sort:d,save:y}}},D=e("h1",null,"教室登録",-1),M=e("p",null,"「チェックして保存」ボタンを押さない限り変更は保存されません！",-1),S=e("thead",null,[e("tr",null,[e("th",null,"ID"),e("th",null,"名前"),e("th",null,"非表示"),e("th",null,"操作")])],-1),A={key:0},F=["title"],N=["onUpdate:modelValue"],j=["onUpdate:modelValue"],H=["onClick"];function K(b,n,u,o,f,c){return r(),i(m,null,[D,M,e("table",null,[S,e("tbody",null,[(r(!0),i(m,null,h(o.resources,t=>(r(),i(m,{key:t.id},[t.deleted?$("",!0):(r(),i("tr",A,[e("th",{title:t.id},k(t.id?`...${t.id.slice(-4)}`:"[未割当]"),9,F),e("td",null,[C(e("input",{"onUpdate:modelValue":d=>t.label=d},null,8,N),[[I,t.label]])]),e("td",null,[C(e("input",{type:"checkbox","onUpdate:modelValue":d=>t.disabled=d},null,8,j),[[U,t.disabled]])]),e("td",null,[e("button",{type:"button",onClick:d=>{t.deleted=!0}},"削除",8,H)])]))],64))),128))])]),e("button",{type:"button",onClick:n[0]||(n[0]=t=>o.add())},"追加"),e("button",{type:"button",onClick:n[1]||(n[1]=t=>o.sort())},"ソート"),e("ul",null,[(r(!0),i(m,null,h(o.resourceErrors,(t,d)=>(r(),i("li",{key:d},k(`${o.resources.filter(y=>!y.deleted).indexOf(t.item)+1}番目の${{label:"名前"}[t.property]}が指定されていません`),1))),128))]),e("p",null,[e("button",{type:"button",onClick:n[2]||(n[2]=t=>o.save())},"チェックして保存")]),e("p",null,[e("button",{type:"button",onClick:n[3]||(n[3]=t=>o.load())},"リセット")])],64)}const O=g(w,[["render",K]]);export{O as default};
