import{r as m,c as D,q as E,Z as R,x as n,y as r,z as d,I as N,L as v,C as c,P as L,R as T,J as W,B as $,Q as O,ac as q,T as A,a5 as H,D as I}from"./vue-vendor-Bsazo-x0.js";import{_ as P}from"./index-DNRbUlyV.js";const F={class:"relative"},J={class:"select-none whitespace-nowrap text-sm font-medium text-gray-700 dark:text-gray-200"},M={class:"max-h-60 overflow-y-auto py-1"},Q=["onClick"],U={key:1,class:"fas fa-check ml-auto pl-3 text-xs text-blue-600"},Z={__name:"CustomDropdown",props:{modelValue:{type:[String,Number],default:""},options:{type:Array,required:!0},placeholder:{type:String,default:"请选择"},icon:{type:String,default:""},iconColor:{type:String,default:"text-gray-500"}},emits:["update:modelValue","change"],setup(o,{emit:V}){const p=o,y=V,t=m(!1),l=m(null),u=m(null),w=m({}),B=D(()=>{const e=p.options.find(i=>i.value===p.modelValue);return e?e.label:""}),S=async()=>{t.value=!t.value,t.value&&(await I(),h())},f=()=>{t.value=!1},z=e=>{y("update:modelValue",e.value),y("change",e.value),f()},h=()=>{if(!l.value||!t.value)return;const e=l.value.getBoundingClientRect(),i=250,a=window.innerHeight-e.bottom,C=e.top;let g,s;a>=i||a>=C?g=e.bottom+8:g=e.top-i-8,s=e.left;const _=200;s+_>window.innerWidth&&(s=window.innerWidth-_-10),s<10&&(s=10),w.value={top:`${g}px`,left:`${s}px`,minWidth:`${e.width}px`}},x=()=>{t.value&&h()},b=()=>{t.value&&f()},k=e=>{!l.value||!t.value||l.value.contains(e.target)||(u.value&&!u.value.contains(e.target)?f():u.value||f())};return E(()=>{window.addEventListener("scroll",x,!0),window.addEventListener("resize",b),document.addEventListener("click",k)}),R(()=>{window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",b),document.removeEventListener("click",k)}),(e,i)=>(r(),n("div",F,[d("div",{ref_key:"triggerRef",ref:l,class:c(["relative flex cursor-pointer items-center gap-2 rounded-lg border border-gray-200 bg-white px-3 py-2 shadow-sm transition-all duration-200 hover:shadow-md dark:border-gray-600 dark:bg-gray-800",[t.value&&"border-blue-400 shadow-md"]]),onClick:S},[o.icon?(r(),n("i",{key:0,class:c(["fas",o.icon,"text-sm",o.iconColor])},null,2)):v("",!0),d("span",J,L(B.value||o.placeholder),1),d("i",{class:c(["fas fa-chevron-down ml-auto text-xs text-gray-400 transition-transform duration-200 dark:text-gray-500",t.value&&"rotate-180"])},null,2)],2),(r(),N(H,{to:"body"},[T(A,{"enter-active-class":"transition duration-200 ease-out","enter-from-class":"transform scale-95 opacity-0","enter-to-class":"transform scale-100 opacity-100","leave-active-class":"transition duration-150 ease-in","leave-from-class":"transform scale-100 opacity-100","leave-to-class":"transform scale-95 opacity-0"},{default:W(()=>[t.value?(r(),n("div",{key:0,ref_key:"dropdownRef",ref:u,class:"fixed z-[9999] min-w-max overflow-hidden rounded-lg border border-gray-200 bg-white shadow-lg dark:border-gray-600 dark:bg-gray-800",style:$(w.value)},[d("div",M,[(r(!0),n(O,null,q(o.options,a=>(r(),n("div",{key:a.value,class:c(["flex cursor-pointer items-center gap-2 whitespace-nowrap px-3 py-2 text-sm transition-colors duration-150",[a.value===o.modelValue?"bg-blue-50 font-medium text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":"text-gray-700 hover:bg-gray-50 dark:text-gray-300 dark:hover:bg-gray-700"]]),onClick:C=>z(a)},[a.icon?(r(),n("i",{key:0,class:c(["fas",a.icon,"text-xs"])},null,2)):v("",!0),d("span",null,L(a.label),1),a.value===o.modelValue?(r(),n("i",U)):v("",!0)],10,Q))),128))])],4)):v("",!0)]),_:1})]))]))}},K=P(Z,[["__scopeId","data-v-ffee8773"]]);export{K as C};
