"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FInputAddon = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactstrap = require("reactstrap");
var _FInputFeedback = _interopRequireDefault(require("./FInputFeedback"));
var _FIcon = _interopRequireDefault(require("../../commons/icons/FIcon.cjs"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var FInputAddon = props => {
  var {
    name,
    value,
    label,
    description,
    feedback,
    icon,
    valid,
    children,
    inline,
    formClassName,
    showValidity,
    keepHeight,
    formGroupStyle,
    inputGroupStyle,
    middleElement,
    bsSize
  } = props;
  var originalValue = (0, _react.useRef)(value);
  var [loaded, setLoaded] = (0, _react.useState)(false);
  (0, _react.useEffect)(() => {
    setLoaded(true);
  }, []);
  var hasChanged = loaded && value != originalValue.current;
  return /*#__PURE__*/_react.default.createElement(_reactstrap.FormGroup, {
    className: "formiga-reactstrap-form-group ".concat(hasChanged ? 'is-unsaved' : '', " ").concat(inline === true ? 'inline' : '', " ").concat(formClassName || ''),
    style: formGroupStyle
  }, label != undefined || description != undefined ? /*#__PURE__*/_react.default.createElement("div", {
    className: "formiga-reactstrap-label-container"
  }, label != undefined ? /*#__PURE__*/_react.default.createElement(_reactstrap.Label, {
    for: name,
    className: "formiga-reactstrap-label"
  }, label) : null, description != undefined ? /*#__PURE__*/_react.default.createElement("div", {
    className: "formiga-reactstrap-description"
  }, description) : null) : null, /*#__PURE__*/_react.default.createElement(_reactstrap.InputGroup, {
    style: inputGroupStyle,
    size: bsSize,
    className: bsSize ? "input-group-".concat(bsSize) : ''
  }, icon === false ? null : /*#__PURE__*/_react.default.createElement("span", {
    className: "input-group-prepend"
  }, /*#__PURE__*/_react.default.createElement(_reactstrap.InputGroupText, {
    className: "input-group-addon"
  }, icon == undefined ? '' : /*#__PURE__*/_react.default.createElement(_FIcon.default, {
    icon: icon
  }))), children), middleElement != undefined ? middleElement : null, (keepHeight === true || feedback != undefined) && showValidity >= 2 ? /*#__PURE__*/_react.default.createElement(_FInputFeedback.default, {
    valid: valid,
    feedback: feedback,
    keepHeight: keepHeight
  }) : null);
};
exports.FInputAddon = FInputAddon;