import{d as L,i as _,E as S,j as M,c as n,a as t,y as f,t as m,w as j,e as v,f as x,z as E,v as z,F as D,m as F,r as d,s as w,G as N,o as u}from"./index-BaNRFt4f.js";const R=["disabled"],T={class:"flex items-center gap-1 shrink-0 ml-2"},U={class:"absolute z-50 mt-1 w-full bg-white border border-gray-200 rounded-md shadow-lg"},q={class:"p-2 border-b border-gray-100"},G={class:"max-h-48 overflow-y-auto py-1"},O={key:0,class:"px-3 py-2 text-sm text-gray-400 text-center"},$=["onClick"],A={key:0,class:"text-xs text-gray-400"},J=L({__name:"SearchableSelect",props:{modelValue:{},options:{},placeholder:{default:"Seleccionar..."},disabled:{type:Boolean,default:!1},allowClear:{type:Boolean,default:!0}},emits:["update:modelValue"],setup(r,{emit:h}){const i=r,b=h,a=d(!1),l=d(""),c=d(null),p=d(null),k=w(()=>i.options.find(e=>e.value===i.modelValue)?.label??""),y=w(()=>{if(!l.value)return i.options;const o=l.value.toLowerCase();return i.options.filter(e=>e.label.toLowerCase().includes(o)||e.sublabel&&e.sublabel.toLowerCase().includes(o))});function C(){i.disabled||(a.value=!a.value,a.value&&(l.value="",N(()=>p.value?.focus())))}function V(o){b("update:modelValue",o.value),a.value=!1,l.value=""}function B(){b("update:modelValue",""),a.value=!1,l.value=""}function g(o){c.value&&!c.value.contains(o.target)&&(a.value=!1,l.value="")}return _(()=>document.addEventListener("mousedown",g)),S(()=>document.removeEventListener("mousedown",g)),M(()=>i.modelValue,()=>{l.value=""}),(o,e)=>(u(),n("div",{ref_key:"container",ref:c,class:"relative"},[t("button",{type:"button",onClick:C,disabled:r.disabled,class:"w-full flex items-center justify-between px-3 py-2 text-sm border rounded-md transition text-left border-gray-300 bg-white focus:outline-none focus:ring-1 focus:ring-primary-500 focus:border-primary-500 disabled:bg-gray-50 disabled:text-gray-400 disabled:cursor-not-allowed"},[t("span",{class:f([r.modelValue?"text-gray-900":"text-gray-400","truncate"])},m(k.value||r.placeholder),3),t("span",T,[r.allowClear&&r.modelValue?(u(),n("svg",{key:0,onClick:j(B,["stop"]),class:"w-4 h-4 text-gray-400 hover:text-gray-600",fill:"none",stroke:"currentColor","stroke-width":"2",viewBox:"0 0 24 24"},[...e[1]||(e[1]=[t("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M6 18 18 6M6 6l12 12"},null,-1)])])):v("",!0),(u(),n("svg",{class:f(["w-4 h-4 text-gray-400 transition-transform",{"rotate-180":a.value}]),fill:"none",stroke:"currentColor","stroke-width":"2",viewBox:"0 0 24 24"},[...e[2]||(e[2]=[t("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"m19.5 8.25-7.5 7.5-7.5-7.5"},null,-1)])],2))])],8,R),x(t("div",U,[t("div",q,[x(t("input",{ref_key:"inputRef",ref:p,"onUpdate:modelValue":e[0]||(e[0]=s=>l.value=s),type:"text",placeholder:"Buscar...",class:"w-full px-2.5 py-1.5 text-sm border border-gray-200 rounded focus:outline-none focus:ring-1 focus:ring-primary-500 focus:border-primary-500"},null,512),[[z,l.value]])]),t("ul",G,[y.value.length===0?(u(),n("li",O," Sin resultados ")):v("",!0),(u(!0),n(D,null,F(y.value,s=>(u(),n("li",{key:s.value,onClick:H=>V(s),class:f(["px-3 py-1.5 text-sm cursor-pointer transition",s.value===r.modelValue?"bg-primary-50 text-primary-700 font-medium":"text-gray-700 hover:bg-gray-50"])},[t("div",null,m(s.label),1),s.sublabel?(u(),n("div",A,m(s.sublabel),1)):v("",!0)],10,$))),128))])],512),[[E,a.value]])],512))}});export{J as _};
