import{u as e,N as a}from"./index-DoBLtCBk.js";import{d as l,r as t,w as u,o as s,c as d,v as o,q as n,$ as v,n as p,B as r,i}from"./main-DKqTMGci.js";import{b as y}from"./useStore-BxWZ-2Xk.js";import{S as f}from"./index-K1QYmvkf.js";import{N as c}from"./text-CBxeXF61.js";import{N as m}from"./Flex-CfuRT3n6.js";const b=l({name:"DnsProviderSelect",props:{type:{type:String,default:""},path:{type:String,default:""},value:{type:String,default:""},valueType:{type:String,default:"value"},isAddMode:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},customClass:{type:String,default:""}},emits:["update:value"],setup(l,{emit:b}){const{handleError:_}=e(),{fetchDnsProvider:g,dnsProvider:x}=y(),h=t({label:"",value:"",type:""}),j=t([]),S=t(!1),w=t(""),C=()=>{window.open("/auth-api-manage","_blank")},T=({option:e})=>d("div",{class:"flex items-center"},[e.label?k(e):d(c,{class:"text-[#aaa]"},{default:()=>["dns"===l.type?v("t_0_1747019621052",[]):v("t_0_1746858920894")]})]),k=e=>d(m,null,{default:()=>[d(f,{icon:`resources-${e.type}`,size:"2rem"},null),d(c,null,{default:()=>[e.label]})]}),A=async()=>{var e,a,l;const t=x.value.find((e=>e.value===h.value.value));t&&(h.value={label:t.label,value:t.value,type:t.type}),x.value.length>0&&""===h.value.value&&(h.value={label:(null==(e=x.value[0])?void 0:e.label)||"",value:(null==(a=x.value[0])?void 0:a.value)||"",type:(null==(l=x.value[0])?void 0:l.type)||""}),b("update:value",h.value)},B=e=>{h.value.value=e,A()},D=async(e="")=>{S.value=!0,w.value="";try{await g(e)}catch(a){w.value="string"==typeof a?a:v("t_0_1746760933542"),_(a)}finally{S.value=!1}},L=(e,a)=>a.label.toLowerCase().includes(e.toLowerCase());return u((()=>x.value),(e=>{j.value=e.map((e=>({label:e.label,value:"value"===l.valueType?e.value:e.type,type:"value"===l.valueType?e.type:e.value})))||[],A()})),u((()=>l.value),(()=>{B(l.value)}),{immediate:!0}),s((()=>{D(l.type)})),()=>{let e;return d(a,{show:S.value},{default:()=>[d(o,{cols:24,class:l.customClass},{default:()=>[d(n,{span:l.isAddMode?13:24,label:"dns"===l.type?v("t_3_1745735765112"):v("t_0_1746754500246"),path:l.path},{default:()=>[d(p,{class:"flex-1 w-full",options:j.value,renderLabel:k,renderTag:T,filterable:!0,filter:L,placeholder:"dns"===l.type?v("t_3_1745490735059"):v("t_0_1746858920894"),value:h.value.value,"onUpdate:value":e=>h.value.value=e,onUpdateValue:B,disabled:l.disabled},{empty:()=>d("span",{class:"text-[1.4rem]"},[w.value||("dns"===l.type?v("t_1_1746858922914"):v("t_2_1746858923964"))])})]}),l.isAddMode&&d(n,{span:11},{default:()=>{return[d(r,{class:"mx-[8px]",onClick:C,disabled:l.disabled},{default:()=>["dns"===l.type?v("t_1_1746004861166"):v("t_3_1746858920060")]}),d(r,{onClick:()=>D(l.type),loading:S.value,disabled:l.disabled},(a=e=v("t_0_1746497662220"),"function"==typeof a||"[object Object]"===Object.prototype.toString.call(a)&&!i(a)?e:{default:()=>[e]}))];var a}})]})]})}}});export{b as D};
