import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import React__default, { useState } from 'react';
import { TextField, InputAdornment } from '@mui/material';
import Label from '../../labels/Label/index.js';
import RequiredLabel from '../../labels/RequiredLabel/index.js';
import InputFieldErrorIcon from '../../Icons/InputFieldErrorIcon/index.js';
import InputFieldSuccessIcon from '../../Icons/InputFieldSuccessIcon/index.js';
import InputFieldHiddenIcon from '../../Icons/InputFieldHiddenIcon/index.js';
import InputFieldUnhiddenIcon from '../../Icons/InputFieldUnhiddenIcon/index.js';
import theme from '../../../Globals/theme.js';
import { ThemeProvider } from 'styled-components';
import globalStyle from '../../../Globals/global-styles.js';
import { InputFieldContainer } from './style.js';

var _excluded = ["fieldname", "inputerror", "hasLabel", "hasInputAdorment", "hasRequiredLabel", "info", "isInfo", "infoPlace", "isRequired"];

var RequiredInputField = function RequiredInputField(props) {
  var fieldname = props.fieldname,
      inputerror = props.inputerror,
      _props$hasLabel = props.hasLabel,
      hasLabel = _props$hasLabel === void 0 ? false : _props$hasLabel,
      _props$hasInputAdorme = props.hasInputAdorment,
      hasInputAdorment = _props$hasInputAdorme === void 0 ? true : _props$hasInputAdorme,
      _props$hasRequiredLab = props.hasRequiredLabel,
      hasRequiredLabel = _props$hasRequiredLab === void 0 ? true : _props$hasRequiredLab,
      info = props.info,
      isInfo = props.isInfo,
      infoPlace = props.infoPlace,
      isRequired = props.isRequired,
      rest = _objectWithoutProperties(props, _excluded);

  var _useState = useState(false),
      _useState2 = _slicedToArray(_useState, 2),
      show = _useState2[0],
      setShow = _useState2[1];

  var _useState3 = useState(props.type),
      _useState4 = _slicedToArray(_useState3, 2),
      inputType = _useState4[0],
      setInputType = _useState4[1];

  var getClassname = function getClassname() {
    if (inputerror === "error") {
      var errorIcon = "";

      if (props.type === "password") {
        if (show) {
          errorIcon = /*#__PURE__*/React__default.createElement(InputFieldUnhiddenIcon, null);
        } else if (!show) {
          errorIcon = /*#__PURE__*/React__default.createElement(InputFieldHiddenIcon, null);
        }
      } else {
        errorIcon = /*#__PURE__*/React__default.createElement(InputFieldErrorIcon, null);
      }

      return {
        class: "InputError",
        icon: errorIcon
      };
    } else if (inputerror === "success") {
      var successIcon = "";

      if (props.type === "password") {
        if (show) {
          successIcon = /*#__PURE__*/React__default.createElement(InputFieldUnhiddenIcon, null);
        } else if (!show) {
          successIcon = /*#__PURE__*/React__default.createElement(InputFieldHiddenIcon, null);
        }
      } else {
        successIcon = /*#__PURE__*/React__default.createElement(InputFieldSuccessIcon, null);
      }

      return {
        class: "InputSuccess",
        icon: successIcon
      };
    } else if (props.type === "password" && show) {
      return {
        class: "",
        icon: /*#__PURE__*/React__default.createElement(InputFieldUnhiddenIcon, null)
      };
    } else if (props.type === "password" && !show) {
      return {
        class: "",
        icon: /*#__PURE__*/React__default.createElement(InputFieldHiddenIcon, null)
      };
    } else {
      return {
        class: "",
        icon: ""
      };
    }
  };

  var getInputClassAndIcon = getClassname();
  return /*#__PURE__*/React__default.createElement(ThemeProvider, {
    theme: theme
  }, /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(globalStyle, null), /*#__PURE__*/React__default.createElement(InputFieldContainer, {
    className: getInputClassAndIcon && getInputClassAndIcon.class
  }, hasLabel && /*#__PURE__*/React__default.createElement(Label, {
    label: fieldname
  }), hasRequiredLabel && /*#__PURE__*/React__default.createElement(RequiredLabel, {
    label: fieldname,
    info: info,
    isInfo: isInfo,
    infoPlace: infoPlace,
    isRequired: isRequired
  }), /*#__PURE__*/React__default.createElement(TextField, _extends({}, rest, {
    autoComplete: "off",
    type: inputType,
    InputProps: {
      endAdornment: hasInputAdorment && /*#__PURE__*/React__default.createElement(InputAdornment, {
        position: "end",
        onClick: function onClick() {
          if (props.type === "password") {
            if (show) setInputType("password");else setInputType("text");
            setShow(!show);
          }
        }
      }, getInputClassAndIcon && getInputClassAndIcon.icon)
    }
  })))));
};

export { RequiredInputField as default };
//# sourceMappingURL=index.js.map
