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