import{x as S,az as P,r as g,o as T,I as l,af as I,b as $,w as j,y as r,D as w,n as i,A as o,G as s,S as m,J as b,B as d,z as v,K as c}from"./index-CFvoaD7J.js";import{E as N}from"./EditConfig-Ct-cJfRC.js";import{n as U}from"./index.browser-OxPLOBIU.js";import{b as O,V as C,a as V}from"./VCardText-CpOuj25H.js";import{e as z}from"./VMenu-9pSrU4Fo.js";import{V as _}from"./VList-fGk9SRdf.js";import{V as D}from"./VTextField-DF4u_eMy.js";import{V as x}from"./VSwitch-Cbz5zuOr.js";import{a as F,V as G}from"./VCard-DxLPF-Ra.js";import{v as H,C as J}from"./VListItem-CSPID7yq.js";import"./VExpansionPanels-BsT7TGi_.js";import"./VCheckboxBtn-CRgZyCzV.js";import"./VAlert-CIiIOQza.js";import"./VSlider-ka6goZbo.js";import"./VVirtualScroll-BDBVEoUv.js";import"./VChip-Ccz1-bmn.js";import"./VForm-B86dz_JX.js";import"./VSpacer-UYEiyhN7.js";/* empty css              */import"./VDialog-CdvGeqlS.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";const K={key:0},L=["href"],R={id:"auth",href:"",target:"_blank"},be=S({__name:"EditProvider",props:{instanceId:{}},setup(h){const A=P(),t=g(),k=U(11),p=g(!1),y=g(!1),B=h;T(()=>{const a=l.subscribe(I.AUTH_SESSION,e=>{if(e.object_id!==k)return;const n=e.data;y.value=!0,window.setTimeout(()=>{const u=document.getElementById("auth");u.setAttribute("href",n),u.click()},100)});$(a)}),j(()=>B.instanceId,async a=>{a&&(t.value=await l.getProviderConfig(a))},{immediate:!0});const E=async function(a){p.value=!0,a.enabled=t.value.enabled,a.name=t.value.name||null,l.saveProviderConfig(t.value.domain,a,t.value.instance_id).then(()=>{A.push({name:"providersettings"})}).catch(e=>{alert(e)}).finally(()=>{p.value=!1,y.value=!1})},M=async function(a,e){p.value=!0;for(const n of Object.values(t.value.values))n.value!==void 0&&e[n.key]==null&&(e[n.key]=n.value);e.session_id=k,l.getProviderConfigEntries(t.value.domain,t.value.instance_id,a,e).then(n=>{t.value.values={};for(const u of n)t.value.values[u.key]=u}).catch(n=>{alert(n)}).finally(()=>{p.value=!1,y.value=!1})};return(a,e)=>(r(),w("section",null,[i(O,null,{default:o(()=>{var n,u;return[t.value&&s(l).providerManifests[t.value.domain]?(r(),w("div",K,[i(C,null,{default:o(()=>{var f;return[m(b(a.$t("settings.setup_provider",[t.value.name||((f=s(l).getProvider(t.value.instance_id))==null?void 0:f.name)])),1)]}),_:1}),i(V,{style:{"white-space":"normal"}},{default:o(()=>[m(b(s(l).providerManifests[t.value.domain].description),1)]),_:1}),e[4]||(e[4]=d("br",null,null,-1)),s(l).providerManifests[t.value.domain].codeowners.length?(r(),v(V,{key:0},{default:o(()=>[d("b",null,b(a.$t("settings.codeowners"))+": ",1),m(b(s(l).providerManifests[t.value.domain].codeowners.join(" / ")),1)]),_:1})):c("",!0),s(l).providerManifests[t.value.domain].documentation?(r(),v(V,{key:1},{default:o(()=>[d("b",null,b(a.$t("settings.need_help_setup_provider")),1),e[3]||(e[3]=m("  ")),d("a",{href:s(l).providerManifests[t.value.domain].documentation,target:"_blank"},b(a.$t("settings.check_docs")),9,L)]),_:1})):c("",!0),e[5]||(e[5]=d("br",null,null,-1)),i(_),e[6]||(e[6]=d("br",null,null,-1)),e[7]||(e[7]=d("br",null,null,-1)),"name"in t.value?(r(),v(D,{key:2,modelValue:t.value.name,"onUpdate:modelValue":e[0]||(e[0]=f=>t.value.name=f),placeholder:(n=s(l).getProvider(t.value.instance_id))==null?void 0:n.name,label:a.$t("settings.provider_name"),variant:"outlined",clearable:""},null,8,["modelValue","placeholder","label"])):c("",!0),"enabled"in t.value?(r(),v(x,{key:3,modelValue:t.value.enabled,"onUpdate:modelValue":e[1]||(e[1]=f=>t.value.enabled=f),label:a.$t("settings.enable_provider"),color:"primary",disabled:!((u=s(l).providerManifests[t.value.domain])!=null&&u.allow_disable)},null,8,["modelValue","label","disabled"])):c("",!0)])):c("",!0),i(_),t.value?(r(),v(N,{key:1,"config-entries":Object.values(t.value.values),disabled:!t.value.enabled,onSubmit:E,onAction:M},null,8,["config-entries","disabled"])):c("",!0)]}),_:1}),i(z,{modelValue:p.value,"onUpdate:modelValue":e[2]||(e[2]=n=>p.value=n),scrim:"true",persistent:"",style:{display:"flex","align-items":"center","justify-content":"center"}},{default:o(()=>[y.value?(r(),v(G,{key:0,style:{"background-color":"white"}},{default:o(()=>[i(C,null,{default:o(()=>e[8]||(e[8]=[m("Authenticating...")])),_:1}),i(V,null,{default:o(()=>e[9]||(e[9]=[m("A new tab/popup should be opened where you can authenticate")])),_:1}),i(F,null,{default:o(()=>[d("a",R,[i(H,null,{default:o(()=>e[10]||(e[10]=[m("Click here if the popup did not open")])),_:1})])]),_:1})]),_:1})):(r(),v(J,{key:1,indeterminate:"",size:"64",color:"primary"}))]),_:1},8,["modelValue"])]))}});export{be as default};
