import{d as x,r as p,H as g,m as k,o as n,c as i,a as e,z as I,A as w,e as m,F as _,j as C,k as N,v as V,t as B,f as P,S as j,D as f,I as A,J as D,K as F,_ as J}from"../index.js";import{S as O}from"./SelectableItemViewModel-BTB_zqjq.js";import"../vendor.js";const l=d=>(D("data-v-253cb07d"),d=d(),F(),d),T={class:"card"},U={class:"card-header"},$=l(()=>e("h2",null,"Grid Profiles Import",-1)),E=l(()=>e("span",{class:"fa fa-arrow-left"},null,-1)),M={class:"card-body"},R=l(()=>e("p",{class:"text-muted"},"Select export bundle file to import",-1)),z=l(()=>e("br",null,null,-1)),G={class:"row"},H=l(()=>e("div",{class:"col-8 d-flex"},[e("h5",{class:"mt-auto"},"Available Items")],-1)),K={class:"col mx-auto"},L=["disabled"],q=l(()=>e("span",{class:"fa fa-file-import"},null,-1)),Q={class:"row"},W={key:0,class:"table table-responsive-md"},X={class:"fit"},Y=l(()=>e("th",null," Name ",-1)),Z={class:"w-auto"},ee=["onUpdate:modelValue"],te={key:1,class:"text-muted"},se=x({__name:"Import",setup(d){const r=p(!1),a=p([]),h=g(()=>{var o;return((o=a.value)==null?void 0:o.some(t=>t.selected))??!1});async function v(o){var s;if(r.value=!1,a.value=[],o.length==0)return;const t=o.item(0),c=await(t==null?void 0:t.text());if(c){const u=JSON.parse(c);a.value=((s=u.gridProfiles)==null?void 0:s.map(S=>new O(S)))??[],r.value=!0}}function b(o){a.value.forEach(t=>t.selected=o)}async function y(){const o=a.value.map(t=>t.item);fetch(`${j.gridProfilesBaseUrl}/import`,{method:"POST",body:JSON.stringify(o)}).then(t=>{t.ok?(f({type:"info",text:"Successfully imported items"}),A.push("/grid-profiles")):f({type:"error",text:`Import failed. Reason: ${t.statusText}`})})}return(o,t)=>{const c=k("router-link");return n(),i("div",T,[e("div",U,[$,I(c,{to:"/grid-profiles"},{default:w(()=>[E,m(" Return to list ")]),_:1})]),e("div",M,[e("input",{type:"file",onChange:t[0]||(t[0]=s=>v(s.target.files)),accept:".json"},null,32),R,z,r.value?(n(),i(_,{key:0},[e("div",G,[H,e("div",K,[e("button",{type:"button",class:"btn btn-primary mb-2 float-right",disabled:!h.value,onClick:t[1]||(t[1]=s=>y())},[q,m(" Import Selected Items ")],8,L)])]),e("div",Q,[a.value&&a.value.length>0?(n(),i("table",W,[e("thead",null,[e("tr",null,[e("th",X,[e("input",{type:"checkbox",onChange:t[2]||(t[2]=s=>b(s.target.checked))},null,32)]),Y])]),e("tbody",null,[(n(!0),i(_,null,C(a.value,s=>(n(),i("tr",{key:s.item.name},[e("td",Z,[N(e("input",{type:"checkbox","onUpdate:modelValue":u=>s.selected=u},null,8,ee),[[V,s.selected]])]),e("td",null,B(s.item.name),1)]))),128))])])):(n(),i("p",te,"No items available for import"))])],64)):P("",!0)])])}}}),ne=J(se,[["__scopeId","data-v-253cb07d"]]);export{ne as default};
