"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.StyledTypography = void 0;
exports.ValueDisplay = ValueDisplay;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _ = require("../../..");
var _Select = require("../Select.styles");
var _2 = require("..");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function renderValue(selectedOptions) {
  var _selectedOptions$labe;
  if (Array.isArray(selectedOptions)) {
    return _react.default.createElement(_react.default.Fragment, null, selectedOptions.map(function (o) {
      return o.label;
    }).join(', '));
  }
  return (_selectedOptions$labe = selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) !== null && _selectedOptions$labe !== void 0 ? _selectedOptions$labe : '';
}
function getSelectedOptionsLabel(getOptionMetadata, value) {
  var selectedOptionsMetadata = null;
  if (value) {
    if (Array.isArray(value)) {
      selectedOptionsMetadata = value.map(function (v) {
        return getOptionMetadata(v);
      }).filter(function (o) {
        return o !== undefined;
      });
    } else {
      selectedOptionsMetadata = getOptionMetadata(value);
    }
  }
  return selectedOptionsMetadata ? renderValue(selectedOptionsMetadata) : null;
}
var StyledTypography = exports.StyledTypography = (0, _styledComponents.default)(_.Typography).withConfig({
  displayName: "ValueDisplay__StyledTypography",
  componentId: "sc-1e53f4y-0"
})(["display:inline-block;margin-right:", "px;color:inherit;", ""], function (_ref) {
  var theme = _ref.theme;
  return theme.spacing.unit(2);
}, _Select.ellipsis);
function ValueDisplay(_ref2) {
  var placeholder = _ref2.placeholder;
  var _useSelect = (0, _2.useSelect)(),
    value = _useSelect.value,
    getOptionMetadata = _useSelect.getOptionMetadata;
  var selectedOptionsLabel = value ? getSelectedOptionsLabel(getOptionMetadata, value) : null;
  return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(StyledTypography, {
    type: "secondary"
  }, selectedOptionsLabel || placeholder));
}