/*!
 * KoliBri - The accessible HTML-Standard
 */
import{I as InputController}from"./getRenderStates.js";import{i as isIcon}from"./icons.js";import{o as objectObjectHandler,p as parseJson,w as watchValidator}from"./prop.validators.js";import{i as isString}from"./common.js";import{h}from"@stencil/core/internal/client";import{i as isString$1}from"./InternalUnderlinedBadgeText.js";import{_ as __rest}from"./tslib.es6.js";import{a as KolButtonWcTag}from"./component-names.js";import{K as KolIconFc}from"./Icon.js";import{i as isObject}from"./isObject.js";import{c as clsx}from"./clsx.js";import{a as checkHasError,c as convertMsgToInternMsg}from"./FormFieldMsg.js";const InputAdornment=(t,n)=>{var{position:o="start",class:e}=t,s=__rest(t,["position","class"]);const r="kol-input-container__adornment",i=`${r}--${o}`;return h("div",Object.assign({class:clsx(r,i,e)},s),n)},InputAdornment$1=InputAdornment;function hasItems(t){return!!t&&(Array.isArray(t)?t.length>0:Boolean(t))}const Container=(t,n)=>{var{class:o}=t,e=__rest(t,["class"]);return h("div",Object.assign({class:clsx("kol-input-container__container",o)},e),n)},KolInputContainerFc=(t,n)=>{const{class:o,startAdornment:e,endAdornment:s,disabled:r,msg:i,touched:c,containerProps:a,startAdornmentProps:l,endAdornmentProps:d}=t,p=__rest(t,["class","startAdornment","endAdornment","disabled","msg","touched","containerProps","startAdornmentProps","endAdornmentProps"]),m=checkHasError(i,c),u={"kol-input-container--disabled":r,[`kol-input-container--${(null==i?void 0:i.type)||"error"}`]:m},b=Object.assign({class:clsx("kol-input-container",u,o)},p);return hasItems(e)||hasItems(s)?h("div",Object.assign({},b),h(InputAdornment$1,Object.assign({},l,{position:"start"}),e),h(Container,Object.assign({},a),n),h(InputAdornment$1,Object.assign({},d,{position:"end"}),s)):h("div",Object.assign({},b),h(Container,Object.assign({},a),n))},KolInputContainerFc$1=KolInputContainerFc,beforePatchIcons=(t,n)=>{const o=t;"object"==typeof o&&null!==o&&(isString(o.right,1)&&(o.right={icon:o.right}),isString(o.left,1)&&(o.left={icon:o.left}),n.set("_icons",o))};class InputIconController extends InputController{constructor(t,n,o){super(t,n,o),this.component=t}validateIcons(t){objectObjectHandler(t,(()=>{try{t=parseJson(t)}catch(t){}watchValidator(this.component,"_icons",(t=>"object"==typeof t&&null!==t&&(isString(t.left,1)||isIcon(t.left)||isString(t.right,1)||isIcon(t.right))),new Set(["KoliBriHorizontalIcon"]),t,{hooks:{beforePatch:beforePatchIcons},required:!0})}))}componentWillLoad(){super.componentWillLoad(),this.validateIcons(this.component._icons)}}const KolButtonFc=t=>{const{label:n,icons:o,hideLabel:e,disabled:s,onClick:r}=t,i=__rest(t,["label","icons","hideLabel","disabled","onClick"]);return h(KolButtonWcTag,Object.assign({tabindex:0,_label:n,_disabled:s,_icons:o,_hideLabel:e,_on:{onClick:r}},i))},KolButtonFc$1=KolButtonFc,KolIconButtonFc=t=>{const{componentName:n="button",label:o,icon:e,onClick:s}=t,r=__rest(t,["componentName","label","icon","onClick"]);return h("button"===n?KolButtonFc$1:KolIconFc,Object.assign({label:o||"",hideLabel:!0,icons:`codicon codicon-${e}`,onClick:s},r))},KolIconButtonFc$1=KolIconButtonFc;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:convertMsgToInternMsg(t._msg),touched:t._touched}}const InputContainerStateWrapperFc=({state:t,endAdornment:n},o)=>{const{icons:e,smartButton:s,disabled:r,msg:i,touched:c}=getInputContainerProps(t);let a=null==e?void 0:e.left;isString$1(a)&&(a={icon:a});let l=null==e?void 0:e.right;isString$1(l)&&(l={icon:l});const d=[],p=[];return n&&(Array.isArray(n)?p.push(...n):p.push(n)),a&&d.push(h(KolIconButtonFc$1,Object.assign({componentName:"icon"},isObject(a)?a:{}))),isObject(s)&&p.push(h(KolIconButtonFc$1,Object.assign({componentName:"button"},s,{hideLabel:!0,disabled:r}))),l&&p.push(h(KolIconButtonFc$1,Object.assign({componentName:"icon"},isObject(l)?l:{}))),h(KolInputContainerFc$1,{disabled:r,msg:i,touched:c,startAdornment:d,endAdornment:p},o)},KolInputContainerStateWrapperFc=InputContainerStateWrapperFc;export{InputIconController as I,KolInputContainerStateWrapperFc as K,KolIconButtonFc$1 as a};