1import{e as O,E as Q,f as R,F as Y,l as G,o as p,c as w,a as t,b as H,t as C,Q as J,d as A,g as k,P as D,M as K,h as f,N as P,i as W,r as i,S as X}from"./B3M9xUHO.js";import{u as Z}from"./v5jEvINh.js";import{t as ee,b as te}from"./BvZ-KzoQ.js";import{_ as ae,a as oe,b as se}from"./CdBbDbn2.js";import"./DYOCIWzF.js";import"./BkyDRfcT.js";const ne={key:0,class:"flex flex-col px-10 py-4"},re={class:"flex items-center justify-between mb-4"},le={class:"flex gap-2"},ie={key:0,class:"modal modal-open"},ue={class:"modal-box max-w-md"},de={class:"text-lg font-bold"},ce={class:"form-control"},me=["readonly"],pe={class:"form-control"},fe={class:"form-control"},ve=["max"],be={key:0,class:"text-error text-sm"},ge={class:"modal-action mt-2"},he=["disabled"],$e=O({__name:"DataProvidersPage",setup(ye){const y=Q(),N=R(),_=Y(),I=W(()=>N.idTokenClaims),{fetchDataProviders:V,createDataProvider:$,updateDataProvider:T,deleteDataProvider:S}=Z(),c=i([]),v=i(!1),b=i(!1),r=i(null),l=i(null),g=i(!1),u=i(""),F=[{key:"id",label:"ID"},{key:"name",label:"Name"},{key:"dataCompleteThrough",label:"Data complete through"},{key:"lastImportedAt",label:"Last imported"}],E=["id","name","dataCompleteThrough"],s=X({id:"",name:"",dataCompleteThrough:void 0});async function h(){c.value=await V()}function B(){r.value=null,s.id="",s.name="",s.dataCompleteThrough=void 0,u.value="",v.value=!0}function M(a){const e=c.value.find(o=>o.id===String(a.id))??a;r.value=e,s.id=e.id,s.name=e.name,s.dataCompleteThrough=e.dataCompleteThrough,u.value="",v.value=!0}function U(a){l.value=a}function x(){v.value=!1,r.value=null}async function q(){u.value="",g.value=!0;try{const a=await y.$getAccessToken();r.value?await T(s.id,{...s},a):await $({...s},a),x(),await h()}catch(a){u.value=a instanceof Error?a.message:"An error occurred."}finally{g.value=!1}}async function j(){if(l.value)try{const a=await y.$getAccessToken();await S(l.value.id,a),l.value=null,await h()}catch(a){_.error(a instanceof Error?a.message:"Delete failed.")}}function z(){const a=new Date().toISOString().slice(0,10),e=ee(c.value,E);te(e,`data-providers-${a}.csv`)}async function L(a){const e=[];try{const o=await y.$getAccessToken();for(const d of a.added){const n=d;try{await $(n,o)}catch(m){e.push(`Add ${n.id??"?"}: ${m instanceof Error?m.message:"failed"}`)}}for(const d of a.modified){const n=d;try{await T(n.id,n,o)}catch(m){e.push(`Update ${n.id}: ${m instanceof Error?m.message:"failed"}`)}}for(const d of a.deleted)try{await S(String(d.id),o)}catch(n){e.push(`Delete ${d.id}: ${n instanceof Error?n.message:"failed"}`)}}catch(o){e.push(o instanceof Error?o.message:"Import failed.")}finally{b.value=!1,await h()}e.length&&_.error(`Import: ${e.length} error(s) â ${e.join("; ")}`)}return G(h),(a,e)=>I.value?(p(),w("div",ne,[t("div",re,[e[6]||(e[6]=t("h2",{class:"text-xl font-semibold"},"Data Providers",-1)),t("div",le,[t("button",{class:"btn btn-sm btn-info btn-outline",onClick:z}," Export CSV "),t("button",{class:"btn btn-sm btn-info btn-outline",onClick:e[0]||(e[0]=o=>b.value=!0)}," Import CSV "),t("button",{class:"btn btn-sm btn-primary",onClick:B}," + New Data Provider ")])]),H(ae,{columns:F,rows:c.value,onEdit:M,onDelete:U},null,8,["rows"]),v.value?(p(),w("div",ie,[t("div",ue,[t("h3",de,C(r.value?"Edit Data Provider":"New Data Provider"),1),t("form",{class:"mt-3 flex flex-col gap-3",onSubmit:J(q,["prevent"])},[t("label",ce,[e[7]||(e[7]=t("span",{class:"text-sm font-medium"},[A("ID "),t("span",{class:"text-error"},"*")],-1)),k(t("input",{"onUpdate:modelValue":e[1]||(e[1]=o=>s.id=o),type:"text",class:K(["input input-sm input-bordered input-info",{"bg-gray-100":!!r.value}]),readonly:!!r.value,required:""},null,10,me),[[D,s.id]])]),t("label",pe,[e[8]||(e[8]=t("span",{class:"text-sm font-medium"},[A("Name "),t("span",{class:"text-error"},"*")],-1)),k(t("input",{"onUpdate:modelValue":e[2]||(e[2]=o=>s.name=o),type:"text",class:"input input-sm input-bordered input-info",required:""},null,512),[[D,s.name]])]),t("label",fe,[e[9]||(e[9]=t("span",{class:"text-sm font-medium"},"Data complete through (year)",-1)),k(t("input",{"onUpdate:modelValue":e[3]||(e[3]=o=>s.dataCompleteThrough=o),type:"number",class:"input input-sm input-bordered input-info",placeholder:"e.g. 2024",min:"2000",max:new Date().getFullYear()},null,8,ve),[[D,s.dataCompleteThrough,void 0,{number:!0}]])]),u.value?(p(),w("p",be,C(u.value),1)):f("",!0),t("div",ge,[t("button",{type:"button",class:"btn btn-sm btn-ghost",onClick:x}," Cancel "),t("button",{type:"submit",class:"btn btn-sm btn-primary",disabled:g.value},C(g.value?"Savingâ¦":"Save"),9,he)])],32)]),t("div",{class:"modal-backdrop",onClick:x})])):f("",!0),l.value?(p(),P(oe,{key:1,"record-label":l.value.name,onConfirm:j,onCancel:e[4]||(e[4]=o=>l.value=null)},null,8,["record-label"])):f("",!0),b.value?(p(),P(se,{key:2,"required-headers":E,"current-rows":c.value,"key-fn":o=>String(o.id),onApplied:L,onCancel:e[5]||(e[5]=o=>b.value=!1)},null,8,["current-rows","key-fn"])):f("",!0)])):f("",!0)}});
1export{$e as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.