import{K as D,L as E,v as s,x as n,E as w,B as f,D as u,l as c,s as v,p as m,z as p,X as z,q as F,$ as M,U as T,a7 as U,F as L,y as R,k as $,C as j,r as V,f as B}from"./x-CuOWXDIc.js";import{C as K}from"./chevron-down-pL4huxTV.js";import{S as P}from"./search-ITz7hQUi.js";import{L as X}from"./DateField.vue_vue_type_style_index_0_lang-BFhdkW_K.js";import{C as G}from"./check-D7sgkfv8.js";const H={class:"form-group"},I={key:0,class:"form-group__label"},J={key:0,class:"form-group__required"},Q=["disabled"],W={class:"select__trigger-icons"},Y={key:0,class:"select__dropdown"},Z={key:0,class:"select__search"},ee={class:"input-wrapper"},te={class:"input-wrapper__icon"},le={key:1,class:"select__empty"},ae={key:0,class:"select__empty"},se=["onClick"],oe={key:1,class:"icon-md"},ne={key:1,class:"form-group__error"},ie={key:2,class:"form-group__hint"},pe={__name:"SelectField",props:{modelValue:{type:[String,Number,Array,null],default:null},label:{type:String,default:""},placeholder:{type:String,default:"Выберите..."},hint:{type:String,default:""},error:{type:String,default:""},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},size:{type:String,default:"md"},options:{type:Array,default:()=>[]},optionLabel:{type:String,default:"label"},optionValue:{type:String,default:"value"},multiple:{type:Boolean,default:!1},searchable:{type:Boolean,default:!1},clearable:{type:Boolean,default:!1},loading:{type:Boolean,default:!1}},emits:["update:modelValue","focus","blur"],setup(a,{emit:x}){const e=a,g=x,r=V(!1),d=V(""),_=V(null),b=B(()=>{if(!d.value)return e.options;const t=d.value.toLowerCase();return e.options.filter(l=>{const o=typeof l=="string"?l:l[e.optionLabel];return o==null?void 0:o.toString().toLowerCase().includes(t)})}),k=B(()=>{if(e.multiple)return!Array.isArray(e.modelValue)||!e.modelValue.length?"":e.modelValue.map(l=>{const o=e.options.find(i=>y(i)===l);return o?h(o):l}).join(", ");if(e.modelValue===null||e.modelValue===void 0||e.modelValue==="")return"";const t=e.options.find(l=>y(l)===e.modelValue);return t?h(t):e.modelValue});function h(t){return typeof t=="string"?t:t[e.optionLabel]}function y(t){return typeof t=="string"?t:t[e.optionValue]}function C(t){const l=y(t);return e.multiple?Array.isArray(e.modelValue)&&e.modelValue.includes(l):e.modelValue===l}function A(t){const l=y(t);if(e.multiple){const o=Array.isArray(e.modelValue)?[...e.modelValue]:[],i=o.indexOf(l);i===-1?o.push(l):o.splice(i,1),g("update:modelValue",o)}else g("update:modelValue",l),r.value=!1}function O(t){t.stopPropagation(),g("update:modelValue",e.multiple?[]:null)}function q(){e.disabled||(r.value=!r.value,r.value&&(d.value=""))}function S(t){_.value&&!_.value.contains(t.target)&&(r.value=!1)}return D(()=>document.addEventListener("click",S)),E(()=>document.removeEventListener("click",S)),(t,l)=>{var o;return s(),n("div",H,[a.label?(s(),n("label",I,[w(f(a.label)+" ",1),a.required?(s(),n("span",J,"*")):u("",!0)])):u("",!0),c("div",{ref_key:"wrapperRef",ref:_,class:"select"},[c("button",{type:"button",disabled:a.disabled,class:v(["select__trigger",r.value?"select__trigger--open":"",a.error?"input-error":""]),onClick:q},[c("span",{class:v(k.value?"":"select__placeholder")},f(k.value||a.placeholder),3),c("div",W,[a.clearable&&(a.multiple?(o=a.modelValue)!=null&&o.length:a.modelValue!==null&&a.modelValue!=="")?(s(),n("button",{key:0,type:"button",class:"select__tag-remove",onClick:O},[m(p(z),{class:"icon-xs"})])):u("",!0),m(p(K),{class:v(["icon-md",r.value?"select__chevron--open":""])},null,8,["class"])])],10,Q),m(j,{name:"slide-down"},{default:F(()=>[r.value?(s(),n("div",Y,[a.searchable?(s(),n("div",Z,[c("div",ee,[c("div",te,[m(p(P),{class:"icon-sm"})]),M(c("input",{"onUpdate:modelValue":l[0]||(l[0]=i=>d.value=i),type:"text",class:"input input-sm input--has-icon",placeholder:"Поиск...",onClick:l[1]||(l[1]=T(()=>{},["stop"]))},null,512),[[U,d.value]])])])):u("",!0),a.loading?(s(),n("div",le,[m(p(X),{class:"icon-lg icon-spin"})])):(s(),n(L,{key:2},[b.value.length?u("",!0):(s(),n("div",ae," Нет вариантов ")),(s(!0),n(L,null,R(b.value,(i,N)=>(s(),n("div",{key:N,class:v(["select__option",C(i)?"select__option--selected":"",i.disabled?"select__option--disabled":""]),onClick:re=>!i.disabled&&A(i)},[C(i)?(s(),$(p(G),{key:0,class:"icon-md"})):(s(),n("span",oe)),w(" "+f(h(i)),1)],10,se))),128))],64))])):u("",!0)]),_:1})],512),a.error?(s(),n("p",ne,f(a.error),1)):a.hint?(s(),n("p",ie,f(a.hint),1)):u("",!0)])}}};export{pe as _};
