import{u as R,a as T,_ as U,p as B}from"./ProviderGeneralForm-DwCmFqXI.js";import{b as S,n as j,s as A,g as v,L as G,m as x,o as i,a,e as w,w as e,l as u,t as n,f as d,c as y,F as L,M as D}from"./index-CTxlYqj4.js";import{g as F,V as $}from"./VAvatar-x_79C0tA.js";import{V as b,c as E,a as N,b as M}from"./VExpansionPanels-DpJzLCB-.js";import{V as g,a as m}from"./VRow-B-csPNw7.js";import"./domains-HueJ9pRR.js";import"./VTextField-CWm47OUI.js";import"./tag-Dx3OexMp.js";import"./VProgressCircular-ubzZW5PC.js";import"./forwardRefs-BSESyuUp.js";import"./ssrBoot-DGgZQEVC.js";import"./VAutocomplete-CfnbXRi6.js";import"./VSelect-tV4GZAtn.js";import"./VMenu-DTm7W1Hp.js";import"./VCheckboxBtn-xrhfoOlo.js";import"./VSelectionControl-Bdgm37Tl.js";import"./VChip-Def9BYoN.js";import"./filter-DaBUD6Rp.js";import"./VForm-CXf-xKYz.js";import"./VSpacer-BcQnH0oL.js";/* empty css              */import"./VSwitch-HiyBjUWI.js";const O={key:0},q={key:0},z={class:"mt-4 d-flex justify-end"},H={__name:"ProviderForm",props:{provider:{type:Object,default:null}},setup(P){const k=P,{$gettext:r}=S(),c=j(),_=A(),V=R(),s=v({domains:[]}),h=v(0),p=v(),f=v();G(()=>k.provider,t=>{t&&(s.value={...t},s.value.domains||(s.value.domains=[]))},{immediate:!0});async function C(){if(p.value!==void 0){const{valid:t}=await p.value.vFormRef.validate();if(!t)return}if(f.value!==void 0){const{valid:t}=await f.value.vFormRef.validate();if(!t)return}try{const t={...s.value};t.domains=[];for(const o of s.value.domains)o.new_domain?t.domains.push({name:o.name,new_domain:o.new_domain.pk||o.new_domain.id}):t.domains.push(o);await B.patchProvider(s.value.id,t).then(()=>{c.displayNotification({msg:r("Provider updated")}),V.getProviders(),_.push({name:"ProvidersList"})})}catch(t){p.value&&p.value.$refs.observer.setErrors(t.response.data),f.value&&f.value.$refs.observer.setErrors(t.response.data)}}return(t,o)=>(i(),x(L,null,[a(M,{modelValue:h.value,"onUpdate:modelValue":o[2]||(o[2]=l=>h.value=l)},{default:e(()=>[a(b,null,{default:e(()=>[a(E,null,{default:e(({open:l})=>[a(g,{"no-gutters":""},{default:e(()=>[a(m,{cols:"4"},{default:e(()=>[u(n(d(r)("General")),1)]),_:1}),a(m,{cols:"8",class:"text-secondary"},{default:e(()=>[a(F,{"leave-absolute":""},{default:e(()=>[l?(i(),x("span",O)):(i(),y(g,{key:1,"no-gutters":"",style:{width:"100%"}},{default:e(()=>[a(m,{cols:"6"},{default:e(()=>[u(n(d(r)("Name:"))+" "+n(s.value.name),1)]),_:1})]),_:1}))]),_:2},1024)]),_:2},1024)]),_:2},1024)]),_:1}),a(N,null,{default:e(()=>[a(T,{ref_key:"generalForm",ref:p,modelValue:s.value,"onUpdate:modelValue":o[0]||(o[0]=l=>s.value=l)},null,8,["modelValue"])]),_:1})]),_:1}),a(b,null,{default:e(()=>[a(E,null,{default:e(({open:l})=>[a(g,{"no-gutters":""},{default:e(()=>[a(m,{cols:"4"},{default:e(()=>[u(n(d(r)("Associated domains")),1)]),_:1}),a(m,{cols:"8",class:"text-secondary"},{default:e(()=>[a(F,{"leave-absolute":""},{default:e(()=>[l?(i(),x("span",q)):(i(),y(g,{key:1,"no-gutters":"",style:{width:"100%"}},{default:e(()=>[s.value.domains.length>0?(i(),y(m,{key:0,cols:"6"},{default:e(()=>[u(n(d(r)("Number of associated domains:"))+" "+n(s.value.domains.length),1)]),_:1})):(i(),y(m,{key:1,cols:"6"},{default:e(()=>[u(n(d(r)("No associated domains")),1)]),_:1}))]),_:1}))]),_:2},1024)]),_:2},1024)]),_:2},1024)]),_:1}),a(N,null,{default:e(()=>[a(U,{ref_key:"associatedForm",ref:f,modelValue:s.value.domains,"onUpdate:modelValue":o[1]||(o[1]=l=>s.value.domains=l)},null,8,["modelValue"])]),_:1})]),_:1})]),_:1},8,["modelValue"]),w("div",z,[a($,{onClick:o[3]||(o[3]=l=>t.$router.go(-1))},{default:e(()=>[u(n(d(r)("Cancel")),1)]),_:1}),a($,{class:"ml-4",color:"primary darken-1",onClick:C},{default:e(()=>[u(n(d(r)("Save")),1)]),_:1})])],64))}},I={class:"text-h4"},ce={__name:"ProviderEditView",setup(P){const{$gettext:k}=S(),r=D(),c=v({});return B.getProvider(r.params.id).then(_=>{c.value=_.data}),(_,V)=>(i(),x("div",null,[w("span",I,n(d(k)("Edit provider")),1),V[0]||(V[0]=w("div",{class:"mt-4"},null,-1)),a(H,{provider:c.value},null,8,["provider"])]))}};export{ce as default};
