import{d as P,av as S,r as V,o as T,b as l,a9 as j,a as $,H as I,c as r,h as w,f as i,w as o,u as s,D as m,t as b,g as d,e as v,j as c}from"./index-BcUYXcPq.js";import{E as N}from"./EditConfig-Bd-2xNwK.js";import{n as U}from"./index.browser-OxPLOBIU.js";import{b as O,V as C,a as g}from"./VCardText-D-aWL0fz.js";import{c as D}from"./VMenu-7bd_kTRb.js";import{V as h}from"./VList-BKlimdrv.js";import{V as z}from"./VTextField-rtqk6KCF.js";import{V as H}from"./VSwitch-Dl00NZdS.js";import{a as q,V as x}from"./VCard-Dx-t9yLE.js";import{q as F,z as L}from"./VListItem-DC0X47Q4.js";import"./VExpansionPanels-BmCa4cQs.js";import"./VCheckboxBtn-DvMOQpng.js";import"./VAlert-DbYDqcUs.js";import"./VSlider-BStZsw5D.js";import"./VVirtualScroll-BfIwRbDJ.js";import"./VForm-Bi7XwAxc.js";import"./VSpacer-G9Q32ju2.js";/* empty css              */import"./VDialog-Bj6h5fTK.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";const R={key:0},G=["href"],J={id:"auth",href:"",target:"_blank"},pe=P({__name:"EditProvider",props:{instanceId:{}},setup(_){const E=S(),t=V(),k=U(11),f=V(!1),y=V(!1),M=_;T(()=>{const a=l.subscribe(j.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)}),I(()=>M.instanceId,async a=>{a&&(t.value=await l.getProviderConfig(a))},{immediate:!0});const A=async function(a){f.value=!0,a.enabled=t.value.enabled,a.name=t.value.name||null,l.saveProviderConfig(t.value.domain,a,t.value.instance_id).then(()=>{E.push({name:"providersettings"})}).catch(e=>{alert(e)}).finally(()=>{f.value=!1,y.value=!1})},B=async function(a,e){f.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(()=>{f.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",R,[i(C,null,{default:o(()=>{var p;return[m(b(a.$t("settings.setup_provider",[t.value.name||((p=s(l).getProvider(t.value.instance_id))==null?void 0:p.name)])),1)]}),_:1}),i(g,{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(g,{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(g,{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,G)]),_:1})):c("",!0),e[5]||(e[5]=d("br",null,null,-1)),i(h),e[6]||(e[6]=d("br",null,null,-1)),e[7]||(e[7]=d("br",null,null,-1)),"name"in t.value?(r(),v(z,{key:2,modelValue:t.value.name,"onUpdate:modelValue":e[0]||(e[0]=p=>t.value.name=p),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(H,{key:3,modelValue:t.value.enabled,"onUpdate:modelValue":e[1]||(e[1]=p=>t.value.enabled=p),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(h),t.value?(r(),v(N,{key:1,"config-entries":Object.values(t.value.values),disabled:!t.value.enabled,onSubmit:A,onAction:B},null,8,["config-entries","disabled"])):c("",!0)]}),_:1}),i(D,{modelValue:f.value,"onUpdate:modelValue":e[2]||(e[2]=n=>f.value=n),scrim:"true",persistent:"",style:{display:"flex","align-items":"center","justify-content":"center"}},{default:o(()=>[y.value?(r(),v(x,{key:0,style:{"background-color":"white"}},{default:o(()=>[i(C,null,{default:o(()=>e[8]||(e[8]=[m("Authenticating...")])),_:1}),i(g,null,{default:o(()=>e[9]||(e[9]=[m("A new tab/popup should be opened where you can authenticate")])),_:1}),i(q,null,{default:o(()=>[d("a",J,[i(F,null,{default:o(()=>e[10]||(e[10]=[m("Click here if the popup did not open")])),_:1})])]),_:1})]),_:1})):(r(),v(L,{key:1,indeterminate:"",size:"64",color:"primary"}))]),_:1},8,["modelValue"])]))}});export{pe as default};
