import{T as v,g as i,_ as E,i as p,h as c,o as F,c as _,a,d as u,b as w,w as C,j as S,l as D,v as I,F as k,m as K,n as O,f as H,k as f,q as L,s as V}from"./index-20f16f2f.js";function G(t){return{timeLabels:t.timeLabels.map(e=>({...e,startTime:e.startTime.isoFormat(),endTime:e.endTime.isoFormat()})),studentGrades:t.studentGrades.map(e=>({...e})),resources:t.resources.map(e=>({...e})),resourceHours:t.resourceHours.map(e=>({...e,startTime:e.startTime.isoFormat(),endTime:e.endTime.isoFormat()})),events:t.events.map(e=>({...e,startTime:e.startTime.isoFormat(),endTime:e.endTime.isoFormat()})),eventChanges:t.eventChanges.map(e=>({...e}))}}function J(t){return{timeLabels:t.timeLabels.map(e=>({id:e.id,label:e.label,disabled:e.disabled,startTime:v.fromISOFormat(e.startTime),endTime:v.fromISOFormat(e.endTime)})),studentGrades:t.studentGrades.map(e=>({id:e.id,label:e.label})),resources:t.resources.map(e=>({id:e.id,multiplicity:e.multiplicity,disabled:e.disabled,type:e.type,...{classroom:{label:e.label},teacher:{firstName:e.firstName,lastName:e.lastName,firstNameKana:e.firstNameKana,lastNameKana:e.lastNameKana},student:{firstName:e.firstName,lastName:e.lastName,grade:e.grade,firstNameKana:e.firstNameKana,lastNameKana:e.lastNameKana}}[e.type]})),resourceHours:t.resourceHours.map(e=>({id:e.id,resource:e.resource,startTime:i.fromISOFormat(e.startTime),endTime:i.fromISOFormat(e.endTime)})),events:t.events.map(e=>({id:e.id,resources:e.resources,startTime:i.fromISOFormat(e.startTime),endTime:i.fromISOFormat(e.endTime),timeLabel:e.timeLabel,memo:e.memo,color:e.color,type:e.type,...{standard:{},lesson:{subject:e.subject,frame:e.frame}}[e.type]})),eventChanges:t.eventChanges.map(e=>({fromEvent:e.fromEvent,toEvent:e.toEvent,causeResources:e.causeResources}))}}const B={name:"PageMasterImportExport",setup(){const t=p(f.notification),e=p(f.database),d=p(f.errorHandler).handleErrorAsync,o=c(""),m=c(!1),T=c("");d(async()=>{const r=await e.query("dataImporterExporter",{});o.value=JSON.stringify(G(r))})();const b=d(async r=>{let n;try{n=JSON.parse(r)}catch(y){if(y instanceof SyntaxError){t.add("error","インポートに失敗しました。不正な形式です。");return}throw y}try{n=J(n)}catch{t.add("error","インポートに失敗しました。不正な形式です。");return}await e.mutate("dataImporterExporter",[{opcode:"import",param:n}]),t.add("info","インポートしました。")});async function N(r){const n=await K(r);await b(n)}function h(){const r=new File([o.value],`zkan-exported-${i.now().strftime("%Y%m%d_%H%M")}.json`,{type:"application/json"});O(r)}async function g(r){m.value=!1,await globalThis.navigator.clipboard.writeText(r),m.value=!0}return{exportedData:o,exportedDataCopied:m,importData:T,exportToFile:h,importFromFile:N,importFromText:b,copyExportedDataToClipboard:g}}},l=t=>(L("data-v-664bdf54"),t=t(),V(),t),M=l(()=>a("h1",null,"データインポート・エクスポート",-1)),q=l(()=>a("h1",null,"エクスポート",-1)),R=["value"],z={key:0,class:"copied"},A=l(()=>a("h1",null,"インポート",-1)),P=l(()=>a("p",null,"インポートすると現在のデータは全て上書きされます。注意してください。",-1));function U(t,e,d,o,m,T){return F(),_(k,null,[M,a("section",null,[q,a("button",{type:"button",onClick:e[0]||(e[0]=s=>o.exportToFile())},"ファイルにエクスポート"),a("p",null,[u(" テキストとしてエクスポート: "),a("input",{readonly:"readonly",value:o.exportedData},null,8,R),a("button",{type:"button",onClick:e[1]||(e[1]=s=>o.copyExportedDataToClipboard(o.exportedData))},"コピー"),w(S,{name:"copied"},{default:C(()=>[o.exportedDataCopied?(F(),_("span",z," コピーしました ")):H("",!0)]),_:1})])]),a("section",null,[A,P,a("p",null,[a("label",null,[u(" ファイルからインポート: "),a("input",{type:"file",accept:".json",onChange:e[2]||(e[2]=s=>{o.importFromFile(s.target.files[0]),s.target.value=""})},null,32)])]),a("p",null,[u(" テキストからインポート: "),D(a("input",{"onUpdate:modelValue":e[3]||(e[3]=s=>o.importData=s)},null,512),[[I,o.importData]]),a("button",{type:"button",onClick:e[4]||(e[4]=s=>o.importFromText(o.importData))},"インポート")])])],64)}const Q=E(B,[["render",U],["__scopeId","data-v-664bdf54"]]);export{Q as default};
