import{_ as g}from"./InputModelBase-CeuTljlj.js";import{_ as v,$ as m,o as n,a as d,e as o,n as u,t as c,F as f,j as p,b as S,z as y,R as q,d as h,r as _,f as k,g as I}from"./_plugin-vue_export-helper-DfQgE-tC.js";const C={name:"FormSelectHandler",extends:g,props:{options:{type:[Array,Object],required:!0},default:{required:!1,default:null},placeholder:{type:String,required:!1,default:null},multiselect:{type:Boolean,required:!1,default:!1},required:{type:Boolean,required:!1,default:!1},disabled:{type:Boolean,required:!1,default:!1},error:{type:Boolean,required:!1,default:!1},tabindex:{type:Number,required:!1,default:0},fixedItemsHeight:{type:Number,default:0}},emits:["change","close","invalid"],data(){return{selected:this.default?this.default:"",open:!1,multiselected:[]}},created(){this.selected===void 0&&(this.selected="",console.warn("Ein Formfield hat einen Defaultwert("+this.default+") bekommen ohne das dieser in den Options zur Verfügung steht.["+this.options.toString()+"]"))},mounted(){m(document).on("click",this.clickout)},unmounted(){m(document).off("click",this.clickout)},methods:{onOpenState(e){this.disabled||(this.open=e,e||this.$emit("close"))},onSelect(e,t){this.multiselect?(this.multiselected.includes(e)?this.multiselected=this.multiselected.filter(s=>s!==e):e!==void 0&&this.multiselected.push(e),this.selected=this.multiselected.toString(),this.$emit("change",this.multiselected,t)):(e!==void 0&&(this.selected=e),this.$emit("change",this.selected,t),this.onOpenState(!1))},isSelected(e){return this.multiselect?this.multiselected.includes(e):this.selected===e},clickout(e){this.$el.contains(e.target)||this.open&&this.onOpenState(!1)}},computed:{getOptions(){if(Array.isArray(this.options)){let e={};for(const t of this.options)e[t]=t;return e}return this.options},getSelected(){return this.multiselect?this.multiselected.length===0?!1:this.multiselected.length===1?this.getOptions[this.multiselected.toString()]:this.placeholder+" ("+this.multiselected.length+" ausgewählt)":this.selected.length===0?!1:this.getOptions[this.selected]}},watch:{default(e){if(!(e===void 0||e===!1)){if(this.multiselect){if(this.multiselected===e)return;e.constructor.name==="Array"?this.multiselected=e:e===""?this.multiselected=[]:this.multiselected=[e]}else{if(this.selected===e)return;this.selected=e}this.onSelect(void 0,!1)}}}},O=["tabindex"],H=["onClick"],B=["name","required"],N=o("option",{value:""},null,-1),x=["value"];function A(e,t,s,b,r,l){return n(),d("div",{class:"ainput-dropdown",tabindex:s.tabindex},[o("div",{class:u(["ainput-dropdown-selected",{disabled:s.disabled,open:r.open,error:s.error}]),onClick:t[0]||(t[0]=i=>l.onOpenState(!r.open))},[o("p",{class:u({placeholder:!l.getSelected,smaller:r.multiselected.length>1})},c(l.getSelected||s.placeholder),3)],2),o("div",{class:u(["ainput-dropdown-items",{selectHide:!r.open,fixedItemHeight:s.fixedItemsHeight!==0}]),style:S({height:s.fixedItemsHeight===0?!1:s.fixedItemsHeight+"px"})},[(n(!0),d(f,null,p(l.getOptions,(i,a)=>(n(),d("div",{key:a,class:u({chosen:l.isSelected(a)}),onClick:M=>l.onSelect(a,!0)},[o("span",null,c(i),1)],10,H))),128))],6),r.open?y((n(),d("select",{key:0,name:e.model.uniqueid,required:s.required,style:{"pointer-events":"none",opacity:"0",height:"0"},"onUpdate:modelValue":t[1]||(t[1]=i=>r.selected=i),onInvalid:t[2]||(t[2]=i=>e.$emit("invalid"))},[N,(n(!0),d(f,null,p(l.getOptions,(i,a)=>(n(),d("option",{value:a,key:a},c(i),9,x))),128))],40,B)),[[q,r.selected]]):h("",!0)],8,O)}const F=v(C,[["render",A]]),z={name:"InputSelect",components:{FormSelectHandler:F},extends:g,props:{options:{type:[Array,Object],default:()=>[]},fixedItemsHeight:{type:Number,default:0}},emits:["change"],methods:{onChange(e,t){this.model.value=e,this.$emit("change",e,t)}}},j={class:"ainput-label"},D={key:0,class:"ainput-stern"},E={key:0,class:"ainput-errormessage"};function L(e,t,s,b,r,l){const i=_("form-select-handler");return n(),d("div",{class:u(["ainput",{error:!e.model.valid,disabled:e.model.disabled}])},[o("label",null,[o("span",j,[k(c(e.model.label)+" ",1),e.model.required?(n(),d("span",D,"*")):h("",!0)]),I(i,{options:s.options,placeholder:e.model.placeholder,default:e.model.value,disabled:e.model.disabled,error:!e.model.valid,required:e.model.required,"fixed-items-height":s.fixedItemsHeight,class:"select",onChange:l.onChange,onInvalid:e.onInvalid,onClose:e.validate},null,8,["options","placeholder","default","disabled","error","required","fixed-items-height","onChange","onInvalid","onClose"])]),e.model.valid?h("",!0):(n(),d("p",E,c(e.model.message),1))],2)}const w=v(z,[["render",L]]);export{w as I};