import _isEmpty from "lodash/fp/isEmpty";
import _keys from "lodash/fp/keys";
import _isNil from "lodash/fp/isNil";
import _noop from "lodash/fp/noop";
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { NovaSolidStatusCheckCircle2 as CheckIcon, NovaSolidStatusClose as ErrorIcon, NovaCompositionCoorpacademyInformationIcon as InfoIcon } from '@coorpacademy/nova-icons';
import classnames from 'classnames';
import getClassState from '../../util/get-class-state';
import style from './style.css';
const themeStyle = {
  setup: style.setup,
  coorpmanager: style.coorpmanager,
  cockpit: style.cockpit,
  default: style.defaultStyle
};
const InputText = props => {
  const {
    autoFocus = false,
    placeholder = '',
    value,
    type = 'text',
    hint,
    defaultValue,
    onChange = _noop,
    error,
    valid,
    theme = 'default',
    description,
    disabled,
    modified = false,
    title: propsTitle,
    'data-name': dataName = 'input-text',
    'aria-label': ariaLabel = 'Input Text',
    inputColor = false
  } = props;
  const isCMTheme = theme === 'coorpmanager';
  const handleChange = useMemo(() => e => onChange(e.target.value), [onChange]);
  const mainClass = themeStyle[theme];
  const className = getClassState(style.defaultStyle, style.modified, style.error, modified, error);
  const descriptionView = description && theme !== 'coorpmanager' ? /*#__PURE__*/React.createElement("div", {
    className: style.description
  }, description) : null;
  const toolTipView = description && theme === 'coorpmanager' ? /*#__PURE__*/React.createElement("div", {
    className: style.infoIconWrapper
  }, /*#__PURE__*/React.createElement(InfoIcon, {
    className: style.infoIcon
  }), /*#__PURE__*/React.createElement("div", {
    className: style.descriptionLabel
  }, description)) : null;
  const hintView = theme === 'coorpmanager' ? /*#__PURE__*/React.createElement("div", {
    className: style.hint
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: error || hint
    }
  }) : null;
  const errorIconView = isCMTheme && error ? /*#__PURE__*/React.createElement(ErrorIcon, {
    className: style.leftIcon
  }) : null;
  const validIconView = isCMTheme && valid ? /*#__PURE__*/React.createElement(CheckIcon, {
    className: style.leftIcon
  }) : null;
  return /*#__PURE__*/React.createElement("div", {
    className: classnames(mainClass, className, disabled && style.disabled, _isNil(propsTitle) && style.isNoTitle)
  }, /*#__PURE__*/React.createElement("label", null, /*#__PURE__*/React.createElement("span", {
    className: classnames(style.title, _isEmpty(value) && style.noValue)
  }, propsTitle, toolTipView), /*#__PURE__*/React.createElement("input", {
    autoFocus: autoFocus,
    type: type,
    name: propsTitle,
    className: style.input,
    placeholder: placeholder,
    defaultValue: defaultValue,
    autoComplete: 'off',
    value: value,
    onInput: handleChange,
    disabled: disabled,
    onChange: _noop,
    "data-name": dataName,
    "aria-label": ariaLabel
  }), inputColor && !error && value ? /*#__PURE__*/React.createElement("span", {
    className: style.preview,
    style: {
      backgroundColor: value
    }
  }) : null, errorIconView, validIconView, hintView), descriptionView);
};
InputText.propTypes = process.env.NODE_ENV !== "production" ? {
  autoFocus: PropTypes.bool,
  title: PropTypes.string,
  placeholder: PropTypes.string,
  defaultValue: PropTypes.string,
  theme: PropTypes.oneOf(_keys(themeStyle)),
  disabled: PropTypes.bool,
  value: PropTypes.string,
  hint: PropTypes.string,
  error: PropTypes.string,
  onChange: PropTypes.func,
  description: PropTypes.string,
  modified: PropTypes.bool,
  type: PropTypes.string,
  valid: PropTypes.bool,
  'aria-label': PropTypes.string,
  'data-name': PropTypes.string,
  inputColor: PropTypes.bool
} : {};
export default InputText;
//# sourceMappingURL=index.js.map