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