import{r as f,c as D,q as E,Z as R,x as s,y as n,z as c,I as N,L as v,C as d,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-DfnFpxGJ.js";import{_ as P}from"./index-BL9wmVIt.js";const F={class:"relative"},J={class:"select-none whitespace-nowrap text-sm font-medium text-gray-700"},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 w=o,g=V,t=f(!1),r=f(null),u=f(null),h=f({}),B=D(()=>{const e=w.options.find(i=>i.value===w.modelValue);return e?e.label:""}),S=async()=>{t.value=!t.value,t.value&&(await I(),y())},m=()=>{t.value=!1},z=e=>{g("update:modelValue",e.value),g("change",e.value),m()},y=()=>{if(!r.value||!t.value)return;const e=r.value.getBoundingClientRect(),i=250,a=window.innerHeight-e.bottom,C=e.top;let p,l;a>=i||a>=C?p=e.bottom+8:p=e.top-i-8,l=e.left;const _=200;l+_>window.innerWidth&&(l=window.innerWidth-_-10),l<10&&(l=10),h.value={top:`${p}px`,left:`${l}px`,minWidth:`${e.width}px`}},x=()=>{t.value&&y()},b=()=>{t.value&&m()},k=e=>{!r.value||!t.value||r.value.contains(e.target)||(u.value&&!u.value.contains(e.target)?m():u.value||m())};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)=>(n(),s("div",F,[c("div",{ref_key:"triggerRef",ref:r,class:d(["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",[t.value&&"border-blue-400 shadow-md"]]),onClick:S},[o.icon?(n(),s("i",{key:0,class:d(["fas",o.icon,"text-sm",o.iconColor])},null,2)):v("",!0),c("span",J,L(B.value||o.placeholder),1),c("i",{class:d(["fas fa-chevron-down ml-auto text-xs text-gray-400 transition-transform duration-200",t.value&&"rotate-180"])},null,2)],2),(n(),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?(n(),s("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",style:$(h.value)},[c("div",M,[(n(!0),s(O,null,q(o.options,a=>(n(),s("div",{key:a.value,class:d(["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":"text-gray-700 hover:bg-gray-50"]]),onClick:C=>z(a)},[a.icon?(n(),s("i",{key:0,class:d(["fas",a.icon,"text-xs"])},null,2)):v("",!0),c("span",null,L(a.label),1),a.value===o.modelValue?(n(),s("i",U)):v("",!0)],10,Q))),128))])],4)):v("",!0)]),_:1})]))]))}},K=P(Z,[["__scopeId","data-v-87609db5"]]);export{K as C};