/*!
 * KoliBri - The accessible HTML-Standard
 */
import{h}from"./index-C_yiBYg2.js";import{_ as __rest}from"./tslib.es6-CxX45GIN.js";import{d as KolButtonWcTag}from"./component-names-C3fyby67.js";import{K as KolIconFc}from"./Icon-FTWc_xI9.js";import{c as clsx}from"./clsx-eK3rPvPS.js";import{w as watchValidator}from"./common-Dd0zJQbD.js";import{c as checkHasMsg,I as InputController}from"./FormFieldStateWrapper-Cj4-CJCr.js";import{i as isString}from"./InternalUnderlinedBadgeText-BeTCgMOl.js";import{i as isObject}from"./isObject-DvSELytj.js";import{v as validateIcons}from"./icons-DNTuScEN.js";const InputAdornment=(t,n)=>{var{position:o="start",class:s}=t,e=__rest(t,["position","class"]);const r="kol-input-container__adornment",i=`${r}--${o}`;return h("div",Object.assign({class:clsx(r,i,s)},e),n)};function hasItems(t){return!!t&&(Array.isArray(t)?t.length>0:Boolean(t))}const Container=(t,n)=>{var{class:o}=t,s=__rest(t,["class"]);return h("div",Object.assign({class:clsx("kol-input-container__container",o)},s),n)},KolInputContainerFc=(t,n)=>{const{class:o,startAdornment:s,endAdornment:e,disabled:r,msg:i,touched:a,containerProps:c,startAdornmentProps:l,endAdornmentProps:u}=t,d=__rest(t,["class","startAdornment","endAdornment","disabled","msg","touched","containerProps","startAdornmentProps","endAdornmentProps"]),m=checkHasMsg(i,a),p="string"==typeof i?"error":null==i?void 0:i._type,b={"kol-input-container--disabled":r,[`kol-input-container--${p||"error"}`]:m},g=Object.assign({class:clsx("kol-input-container",b,o)},d);return hasItems(s)||hasItems(e)?h("div",Object.assign({},g),h(InputAdornment,Object.assign({},l,{position:"start"}),s),h(Container,Object.assign({},c),n),h(InputAdornment,Object.assign({},u,{position:"end"}),e)):h("div",Object.assign({},g),h(Container,Object.assign({},c),n))},KolButtonFc=t=>{const{label:n,icons:o,hideLabel:s,disabled:e,onClick:r}=t,i=__rest(t,["label","icons","hideLabel","disabled","onClick"]);return h(KolButtonWcTag,Object.assign({_label:n,_disabled:e,_icons:o,_hideLabel:s,_on:{onClick:r}},i))},KolIconButtonFc=t=>{const{componentName:n="button",label:o,icon:s,onClick:e}=t,r=__rest(t,["componentName","label","icon","onClick"]);return h("button"===n?KolButtonFc:KolIconFc,Object.assign({label:o||"",hideLabel:!0,icons:`${s}`,onClick:e},r))};function getInputContainerProps(t){let n,o;return"_icons"in t&&(n=t._icons),"_smartButton"in t&&(o=t._smartButton),{icons:n,smartButton:o,disabled:t._disabled,msg:t._msg,touched:t._touched}}const InputContainerStateWrapperFc=({state:t,endAdornment:n},o)=>{const{icons:s,smartButton:e,disabled:r,msg:i,touched:a}=getInputContainerProps(t);let c=null==s?void 0:s.left;isString(c)&&(c={icon:c});let l=null==s?void 0:s.right;isString(l)&&(l={icon:l});const u=[],d=[];return n&&(Array.isArray(n)?d.push(...n):d.push(n)),c&&u.push(h(KolIconButtonFc,Object.assign({componentName:"icon",class:"kol-input-container__icon"},isObject(c)?c:{}))),isObject(e)&&d.push(h(KolIconButtonFc,Object.assign({componentName:"button",class:"kol-input-container__smart-button"},e,{hideLabel:!0,disabled:r}))),l&&d.push(h(KolIconButtonFc,Object.assign({componentName:"icon",class:"kol-input-container__icon"},isObject(l)?l:{}))),h(KolInputContainerFc,{disabled:r,msg:i,touched:a,startAdornment:u,endAdornment:d},o)};class InputIconController extends InputController{constructor(t,n,o){super(t,n,o),this.numberStringRegex=/^\d+(\.\d+)?$/,this.parseToNumber=t=>"number"==typeof t?isNaN(t)?null:t:this.isNumberString(t)?parseFloat(t):null,this.validateNumber=(t,n)=>watchValidator(this.component,t,t=>null==t||"number"==typeof t||"string"==typeof t&&this.numberStringRegex.test(t),new Set(["number","NumberString"]),n,{hooks:{beforePatch:(n,o)=>{(null==o?void 0:o.has(t))&&(null==o||o.set(t,this.parseToNumber(n)))}}}),this.component=t}validateIcons(t){validateIcons(this.component,t)}isNumberString(t){return"string"==typeof t&&this.numberStringRegex.test(t)}componentWillLoad(){super.componentWillLoad(),this.validateIcons(this.component._icons)}}export{InputIconController as I,KolIconButtonFc as K,InputContainerStateWrapperFc as a};