import{d as P,ak as S,r as V,o as T,b as l,a7 as j,a as $,K as I,c as r,h as w,f as i,w as o,u as s,W as m,t as b,g as d,e as v,j as c}from"./index-CLKg64ON.js";import{V as N,E as U}from"./EditConfig-CkB1xNeb.js";import{n as O}from"./index.browser-DP16PUbO.js";import{b as z,V as C,a as g}from"./VCardText-BAUfdzDA.js";import{c as D}from"./VMenu-CLSWQG_U.js";import{V as h}from"./VList-BvG6-yh2.js";import{V as x}from"./VTextField-C1QkMZRy.js";import{a as F,V as H}from"./VCard-BaRPabiE.js";import{s as K,z as L}from"./VListItem-B_TSjQ1y.js";import"./VExpansionPanels-BBVj4yuE.js";import"./VCheckboxBtn-DXJHHMHd.js";import"./VAlert-CCGDAWu2.js";import"./VForm-Cft_KNdc.js";import"./VVirtualScroll-DKBgr9yN.js";import"./VSpacer-CqqJVVs3.js";/* empty css              */import"./VDialog-BpGrcp5y.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";const R={key:0},W=["href"],q={id:"auth",href:"",target:"_blank"},ve=P({__name:"EditProvider",props:{instanceId:{}},setup(_){const E=S(),a=V(),k=O(11),f=V(!1),y=V(!1),M=_;T(()=>{const t=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)});$(t)}),I(()=>M.instanceId,async t=>{t&&(a.value=await l.getProviderConfig(t))},{immediate:!0});const A=async function(t){f.value=!0,t.enabled=a.value.enabled,t.name=a.value.name||null,l.saveProviderConfig(a.value.domain,t,a.value.instance_id).then(()=>{E.push({name:"providersettings"})}).catch(e=>{alert(e)}).finally(()=>{f.value=!1,y.value=!1})},B=async function(t,e){f.value=!0;for(const n of Object.values(a.value.values))n.value!==void 0&&e[n.key]==null&&(e[n.key]=n.value);e.session_id=k,l.getProviderConfigEntries(a.value.domain,a.value.instance_id,t,e).then(n=>{a.value.values={};for(const u of n)a.value.values[u.key]=u}).catch(n=>{alert(n)}).finally(()=>{f.value=!1,y.value=!1})};return(t,e)=>(r(),w("section",null,[i(z,null,{default:o(()=>{var n,u;return[a.value&&s(l).providerManifests[a.value.domain]?(r(),w("div",R,[i(C,null,{default:o(()=>{var p;return[m(b(t.$t("settings.setup_provider",[a.value.name||((p=s(l).getProvider(a.value.instance_id))==null?void 0:p.name)])),1)]}),_:1}),i(g,{style:{"white-space":"normal"}},{default:o(()=>[m(b(s(l).providerManifests[a.value.domain].description),1)]),_:1}),e[4]||(e[4]=d("br",null,null,-1)),s(l).providerManifests[a.value.domain].codeowners.length?(r(),v(g,{key:0},{default:o(()=>[d("b",null,b(t.$t("settings.codeowners"))+": ",1),m(b(s(l).providerManifests[a.value.domain].codeowners.join(" / ")),1)]),_:1})):c("",!0),s(l).providerManifests[a.value.domain].documentation?(r(),v(g,{key:1},{default:o(()=>[d("b",null,b(t.$t("settings.need_help_setup_provider")),1),e[3]||(e[3]=m("  ")),d("a",{href:s(l).providerManifests[a.value.domain].documentation,target:"_blank"},b(t.$t("settings.check_docs")),9,W)]),_: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 a.value?(r(),v(x,{key:2,modelValue:a.value.name,"onUpdate:modelValue":e[0]||(e[0]=p=>a.value.name=p),placeholder:(n=s(l).getProvider(a.value.instance_id))==null?void 0:n.name,label:t.$t("settings.provider_name"),variant:"outlined",clearable:""},null,8,["modelValue","placeholder","label"])):c("",!0),"enabled"in a.value?(r(),v(N,{key:3,modelValue:a.value.enabled,"onUpdate:modelValue":e[1]||(e[1]=p=>a.value.enabled=p),label:t.$t("settings.enable_provider"),color:"primary",disabled:!((u=s(l).providerManifests[a.value.domain])!=null&&u.allow_disable)},null,8,["modelValue","label","disabled"])):c("",!0)])):c("",!0),i(h),a.value?(r(),v(U,{key:1,"config-entries":Object.values(a.value.values),disabled:!a.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(H,{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(F,null,{default:o(()=>[d("a",q,[i(K,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{ve as default};
