import{ay as S,J as b,i as $,a3 as j,aP as s,bb as H,a4 as L,L as x,az as m,aA as l,aB as p,aI as h,o as r,aD as o,aG as d,E as c,aV as U,aN as y,c0 as k,aS as V,bg as O,bh as _,bi as z,bV as D,M as G,b8 as J,bx as R,bN as M,aE as q,_ as F}from"./index-B4UF4wLI.js";import{E as K}from"./EditConfig-JmZdV3ab.js";import{n as Q}from"./index.browser-OxPLOBIU.js";import"./VAlert-4-piUH1o.js";import"./VCheckbox-D8f2Z6se.js";import"./VCheckboxBtn-CzJltldW.js";import"./VSelectionControl-D7cbOkhF.js";import"./VSlider-6ci0gEBm.js";import"./VSelect-k6Sczint.js";import"./VVirtualScroll-B4qViT6U.js";import"./VForm-DAq47WE0.js";import"./VSwitch-PcL2mz3l.js";import"./VExpansionPanels-D1YYtrDw.js";import"./VDialog-BIfmHFFw.js";const W={class:"edit-provider"},X={key:0},Y={class:"header-content"},Z={class:"header-icon"},ee={class:"header-info"},ae={class:"header-title"},te={class:"header-description"},ne=["innerHTML"],se=["innerHTML"],oe={id:"auth",href:"",target:"_blank"},ie=S({__name:"EditProvider",props:{instanceId:{}},setup(w){const C=q(),e=b(),g=Q(11),u=b(!1),v=b(!1),E=w,A=t=>!t.hidden,T=$(()=>e.value?Object.values(e.value.values).filter(t=>A(t)):[]);j(()=>{const t=s.subscribe(H.AUTH_SESSION,a=>{if(a.object_id!==g)return;const n=a.data;v.value=!0,window.setTimeout(()=>{const i=document.getElementById("auth");i.setAttribute("href",n),i.click()},100)});L(t)}),x(()=>E.instanceId,async t=>{t&&(e.value=await s.getProviderConfig(t))},{immediate:!0});const B=async function(t){u.value=!0,t.enabled=e.value.enabled,t.name=e.value.name||null,s.saveProviderConfig(e.value.domain,t,e.value.instance_id).then(()=>{C.push({name:"providersettings"})}).catch(a=>{alert(a)}).finally(()=>{u.value=!1,v.value=!1})},I=async function(t,a){u.value=!0;for(const n of Object.values(e.value.values))n.value!==void 0&&a[n.key]==null&&(a[n.key]=n.value);a.session_id=g,s.getProviderConfigEntries(e.value.domain,e.value.instance_id,t,a).then(n=>{e.value.values={};for(const i of n)e.value.values[i.key]=i}).catch(n=>{alert(n)}).finally(()=>{u.value=!1,v.value=!1})},N=function(t){const a=[],{t:n}=M();for(const i of t)if(i.includes("@")){let f=i.replace("@","");f=="music-assistant"&&(f="the Music Assistant team"),a.push(`[${f}](https://github.com/${i.replace("@","")})`)}else a.push(i);return`**${n("settings.provider_codeowners")}**: `+a.join(" / ")},P=function(t){const{t:a}=M();return`**${a("settings.provider_credits")}**: `+t.join(" / ")};return(t,a)=>(l(),m("section",W,[e.value&&o(s).providerManifests[e.value.domain]?(l(),m("div",X,[r(V,{class:"header-card mb-4",elevation:"0"},{default:d(()=>[c("div",Y,[c("div",Z,[r(U,{domain:e.value.domain,size:48},null,8,["domain"])]),c("div",ee,[c("h2",ae,y(o(s).providerManifests[e.value.domain].name),1),c("p",te,y(o(s).providerManifests[e.value.domain].description),1),o(s).providerManifests[e.value.domain].codeowners.length?(l(),m("div",{key:0,class:"header-authors",innerHTML:o(k)(N(o(s).providerManifests[e.value.domain].codeowners))},null,8,ne)):p("",!0),o(s).providerManifests[e.value.domain].credits.length?(l(),m("div",{key:1,class:"header-authors",innerHTML:o(k)(P(o(s).providerManifests[e.value.domain].credits))},null,8,se)):p("",!0)])])]),_:1})])):p("",!0),e.value?(l(),h(K,{key:1,"config-entries":T.value,disabled:!e.value.enabled,"name-value":e.value.name??null,"name-placeholder":o(s).getProvider(e.value.instance_id)?.name,"name-label":t.$t("settings.provider_name"),"enabled-value":e.value.enabled,"enabled-label":t.$t("settings.enable_provider"),"enabled-disabled":!o(s).providerManifests[e.value.domain]?.allow_disable,"onUpdate:nameValue":a[0]||(a[0]=n=>e.value.name=n??void 0),"onUpdate:enabledValue":a[1]||(a[1]=n=>e.value.enabled=n),onSubmit:B,onAction:I},null,8,["config-entries","disabled","name-value","name-placeholder","name-label","enabled-value","enabled-label","enabled-disabled"])):p("",!0),r(R,{modelValue:u.value,"onUpdate:modelValue":a[2]||(a[2]=n=>u.value=n),scrim:"true",persistent:"",style:{display:"flex","align-items":"center","justify-content":"center"}},{default:d(()=>[v.value?(l(),h(V,{key:0,style:{"background-color":"white"}},{default:d(()=>[r(O,null,{default:d(()=>[...a[3]||(a[3]=[_("Authenticating...",-1)])]),_:1}),r(z,null,{default:d(()=>[...a[4]||(a[4]=[_("A new tab/popup should be opened where you can authenticate",-1)])]),_:1}),r(D,null,{default:d(()=>[c("a",oe,[r(G,null,{default:d(()=>[...a[5]||(a[5]=[_("Click here if the popup did not open",-1)])]),_:1})])]),_:1})]),_:1})):(l(),h(J,{key:1,indeterminate:"",size:"64",color:"primary"}))]),_:1},8,["modelValue"])]))}}),ke=F(ie,[["__scopeId","data-v-cd50dd9f"]]);export{ke as default};
