import{a as M,b as D,c as z,d as F,_ as I}from"./CNprkc5i.js";import{e as K,Z as O,$ as P,a5 as T,i as W,x as u,h as j,B as E,c,o as n,a as U,m as x,C as _,b as m,w as i,n as s,I as h,W as B,t as p,F as Z,y as q,d as G,a6 as H}from"./BoB2h2qv.js";import{_ as J}from"./_43AjLD4.js";import{u as Q}from"./DiDp2S6K.js";import{u as R}from"./DwWsztjp.js";const X={key:0},Y={key:1,class:"px-2 py-3 text-sm text-muted-foreground"},ee={key:0,class:"text-xs text-muted-foreground"},ae=K({inheritAttrs:!1,__name:"bucket-selector",props:O({options:{default:void 0},label:{default:void 0},placeholder:{default:"Please select bucket"},disabled:{type:Boolean,default:!1},description:{default:void 0},layout:{default:"inline"},class:{default:void 0},selectorClass:{default:void 0},loading:{type:Boolean,default:!1},emptyMessage:{default:void 0},autoLoad:{type:Boolean,default:!0},cacheKey:{default:"bucket-selector-buckets"}},{modelValue:{default:null},modelModifiers:{}}),emits:["update:modelValue"],async setup(b){let d,g;const o=P(b,"modelValue"),e=b,C=T(),{t:V}=W(),v=u(()=>!e.options&&e.autoLoad),N=u(()=>e.label||V("Bucket")),{listBuckets:$}=Q({}),{data:S,pending:w}=([d,g]=j(async()=>R(e.cacheKey,async()=>v.value?((await $()).Buckets??[]).filter(t=>!!t?.Name).sort((t,r)=>(t.Name??"").localeCompare(r.Name??"")):[],{default:()=>[],server:!1})),d=await d,g(),d),f=u(()=>e.options?e.options:(S.value??[]).reduce((a,t)=>{const r=t.Name??"";return r&&a.push({label:r,value:r}),a},[]));E(()=>f.value,l=>{if(v.value&&l.length>0&&o.value===null){const a=l[0];a?.value&&(o.value=String(a.value))}},{immediate:!0});const y=u(()=>e.loading||v.value&&w.value),k=u(()=>{if(!o.value)return"";const l=f.value.find(a=>String(a.value)===String(o.value));return l?`${N.value}: ${l.label}`:String(o.value)}),L=u(()=>e.layout==="inline"?"flex items-center gap-3":"flex flex-col gap-2"),A=u(()=>e.layout==="inline"?"flex flex-col gap-1 min-w-[220px]":"flex flex-col gap-1");return(l,a)=>(n(),c("div",H(s(C),{class:s(B)(L.value,e.class)}),[U("div",{class:h(A.value)},[m(s(I),{modelValue:o.value,"onUpdate:modelValue":a[0]||(a[0]=t=>o.value=t),disabled:e.disabled||y.value},{default:i(()=>[m(s(M),{class:h(s(B)("min-w-[200px]",e.selectorClass))},{default:i(()=>[m(s(D),{placeholder:e.placeholder},{default:i(()=>[k.value?(n(),c("span",X,p(k.value),1)):_("",!0)]),_:1},8,["placeholder"])]),_:1},8,["class"]),m(s(z),null,{default:i(()=>[f.value.length?(n(!0),c(Z,{key:0},q(f.value,t=>(n(),x(s(F),{key:String(t.value),value:String(t.value),disabled:t.disabled},{default:i(()=>[G(p(t.label),1)]),_:2},1032,["value","disabled"]))),128)):(n(),c("div",Y,p(e.emptyMessage||"No options available"),1))]),_:1})]),_:1},8,["modelValue","disabled"]),e.description?(n(),c("p",ee,p(e.description),1)):_("",!0)],2),y.value&&e.layout==="inline"?(n(),x(s(J),{key:0,class:"size-4 text-muted-foreground"})):_("",!0)],16))}}),ne=Object.assign(ae,{__name:"BucketSelector"});export{ne as _};
