"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _form = require("../../form");
var _tagSelect = _interopRequireDefault(require("../../tag-select"));
var _view = _interopRequireDefault(require("../../view"));
var _tag = _interopRequireDefault(require("../../tag"));
var _hooks = require("../../utils/hooks");
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 SelectValue = function (props) {
  var _classNames, _classNames2;
  var items = props.items,
    prefix = props.prefix,
    displayType = props.displayType,
    sizeProp = props.size,
    disabled = props.disabled,
    type = props.type;
  var _useContext = (0, _react.useContext)(_form.ItemContext),
    isInsideForm = _useContext.isInsideForm,
    labelAlign = _useContext.labelAlign,
    contextSize = _useContext.size;
  var clsPrefix = prefix + "select";
  var isInverse = type === 'inverse';
  var size = sizeProp || (isInsideForm ? contextSize : 'medium');
  var ref = (0, _react.useRef)((0, _hooks.guid)('select-val-'));
  switch (displayType) {
    case 'tag':
      return /*#__PURE__*/(0, _react.createElement)(_tagSelect.default, {
        disabled: disabled,
        isPreview: true,
        inlineMode: displayType === 'tag' && isInsideForm && labelAlign === 'inset',
        prefix: prefix,
        size: size,
        dataSource: items
      });
    case 'tag-value':
      return /*#__PURE__*/(0, _react.createElement)(_view.default, {
        className: (0, _classnames.default)(clsPrefix + "-tag-value", (_classNames = {}, _classNames[clsPrefix + "-value--inverse"] = isInverse, _classNames[clsPrefix + "-value--disabled"] = disabled, _classNames[clsPrefix + "-value--inverse-disabled"] = disabled && isInverse, _classNames))
      }, items.map(function (val) {
        return /*#__PURE__*/(0, _react.createElement)(_tag.default, {
          key: ref.current + "-" + val,
          className: clsPrefix + "-tag-item",
          type: "primary",
          size: size
        }, "" + val);
      }));
    default:
      return /*#__PURE__*/(0, _react.createElement)(_view.default, {
        className: (0, _classnames.default)((_classNames2 = {}, _classNames2[clsPrefix + "-value--inverse"] = isInverse, _classNames2[clsPrefix + "-value--disabled"] = disabled, _classNames2[clsPrefix + "-value--inverse-disabled"] = disabled && isInverse, _classNames2))
      }, items.join(','));
  }
};
var _default = SelectValue;
exports.default = _default;