"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _reactIntl = require("react-intl");

var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));

var _styles = require("@material-ui/core/styles");

var _MultipleLinesText = _interopRequireDefault(require("../TooltippedElements/MultipleLinesText"));

var _textProps = _interopRequireDefault(require("../../textProps"));

var _propertyValidator = require("../../../../utils/propertyValidator");

var _sharedMessages = _interopRequireDefault(require("../../../../sharedMessages"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var useStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    title: {
      fontSize: theme.typography.fieldLabelSize,
      color: function color(props) {
        return !props.error ? theme.palette.text.hint : theme.palette.error.main;
      },
      fontFamily: theme.typography.fontFamily,
      marginBottom: theme.spacing(1),
      "&:after": {
        content: function content(props) {
          return props.required && '" *"';
        },
        color: theme.palette.error.main
      }
    },
    value: {
      fontSize: theme.typography.fontSize,
      color: theme.palette.grey.dark,
      fontFamily: theme.typography.fontFamily,
      minHeight: theme.spacing(1.8)
    },
    container: {
      width: "100%",
      marginTop: function marginTop(props) {
        return theme.spacing(props.marginTop);
      },
      "& + &": {
        marginTop: theme.spacing(2)
      }
    },
    headerRoot: {
      display: "flex",
      flexDirection: "row",
      alignItems: "center",
      marginBottom: theme.spacing(1)
    },
    headerTextContainer: {
      flexGrow: 0,
      "& > $title": {
        marginBottom: 0
      }
    },
    headerIconContainer: {
      paddingLeft: theme.spacing(0.5),
      display: "flex",
      flexDirection: "column",
      justifyContent: "flex-start"
    }
  };
});

var InformationItemChildren = function InformationItemChildren(_ref) {
  var classes = _ref.classes,
      children = _ref.children,
      showNotAvailable = _ref.showNotAvailable;

  var _useIntl = (0, _reactIntl.useIntl)(),
      formatMessage = _useIntl.formatMessage;

  if ((0, _propertyValidator.isReactComponent)(children)) {
    return children;
  }

  var multipleLinesTextProps = new _textProps.default();
  multipleLinesTextProps.set(_textProps.default.propNames.lineCount, 2);
  multipleLinesTextProps.set(_textProps.default.propNames.classes, classes.value);
  var value = children != null ? children : showNotAvailable ? formatMessage(_sharedMessages.default.notAvailable) : "";
  return /*#__PURE__*/_react.default.createElement(_MultipleLinesText.default, {
    textProps: multipleLinesTextProps,
    children: value
  });
};

__signature__(InformationItemChildren, "useIntl{{ formatMessage }}", function () {
  return [_reactIntl.useIntl];
});

__signature__(InformationItemChildren, "useIntl{{ formatMessage }}", function () {
  return [_reactIntl.useIntl];
});

var InformationItemHeader = function InformationItemHeader(_ref2) {
  var _ref3;

  var classes = _ref2.classes,
      label = _ref2.label,
      headerIcon = _ref2.headerIcon;
  var formattedLabel = typeof label === "object" ? /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, label) : label;
  var headerText = (_ref3 = formattedLabel && /*#__PURE__*/_react.default.createElement(_Typography.default, {
    className: classes.title,
    children: formattedLabel
  })) != null ? _ref3 : null;

  if (headerIcon) {
    return /*#__PURE__*/_react.default.createElement("div", {
      className: classes.headerRoot
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: classes.headerTextContainer
    }, headerText), /*#__PURE__*/_react.default.createElement("div", {
      className: classes.headerIconContainer
    }, headerIcon));
  }

  return headerText;
};

var InformationItem = function InformationItem(_ref4) {
  var label = _ref4.label,
      children = _ref4.children,
      required = _ref4.required,
      error = _ref4.error,
      _ref4$headerIcon = _ref4.headerIcon,
      headerIcon = _ref4$headerIcon === void 0 ? undefined : _ref4$headerIcon,
      _ref4$showNotAvailabl = _ref4.showNotAvailable,
      showNotAvailable = _ref4$showNotAvailabl === void 0 ? false : _ref4$showNotAvailabl,
      _ref4$marginTop = _ref4.marginTop,
      marginTop = _ref4$marginTop === void 0 ? 0 : _ref4$marginTop;
  var classes = useStyles({
    required: required,
    error: error,
    marginTop: marginTop
  });
  return /*#__PURE__*/_react.default.createElement("div", {
    className: classes.container
  }, /*#__PURE__*/_react.default.createElement(InformationItemHeader, {
    classes: classes,
    label: label,
    headerIcon: headerIcon
  }), /*#__PURE__*/_react.default.createElement(InformationItemChildren, {
    classes: classes,
    children: children,
    showNotAvailable: showNotAvailable
  }));
};

__signature__(InformationItem, "useStyles{classes}", function () {
  return [useStyles];
});

__signature__(InformationItem, "useStyles{classes}", function () {
  return [useStyles];
});

var _default = _react.default.memo(InformationItem);

var _default2 = _default;
var _default3 = _default2;
exports.default = _default3;
;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js");
  reactHotLoader.register(InformationItemChildren, "InformationItemChildren", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js");
  reactHotLoader.register(InformationItemHeader, "InformationItemHeader", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js");
  reactHotLoader.register(InformationItem, "InformationItem", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();

;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js");
  reactHotLoader.register(InformationItemChildren, "InformationItemChildren", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js");
  reactHotLoader.register(InformationItemHeader, "InformationItemHeader", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js");
  reactHotLoader.register(InformationItem, "InformationItem", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();