import { rpx2vw4style as __rpx2vw__ } from "babel-runtime-jsx-style-transform";

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import classNames from 'classnames';
import React, { createElement, forwardRef } from "react";
import { Text } from "@alifd/meet-react-component-one";
import { isFunction } from '../utils';
import View from '../view';
import BaseSelect from './base-select';
import { getPreviewValue } from './util';

var Select = function Select(props, ref) {
  var isPreview = props.isPreview,
      previewClassNameProp = props.previewClassName,
      previewStyle = props.previewStyle,
      renderPreview = props.renderPreview,
      _props$prefix = props.prefix,
      prefix = _props$prefix === void 0 ? 'mt-' : _props$prefix,
      _props$size = props.size,
      size = _props$size === void 0 ? 'medium' : _props$size;
  var values = getPreviewValue(props);
  var previewClassName = classNames(previewClassNameProp, "".concat(prefix, "form-item-input--preview-").concat(size));

  if (isPreview) {
    if (isFunction(renderPreview)) {
      return /*#__PURE__*/React.createElement(View, {
        className: previewClassName,
        style: __rpx2vw__(previewStyle)
      }, renderPreview(values, props));
    }

    var directRenderVal = '';

    if (Array.isArray(values)) {
      directRenderVal = values.map(function (v) {
        return v.label;
      }).join(',');
    } else if (values && values.label) {
      directRenderVal = values.label;
    }

    return /*#__PURE__*/React.createElement(Text, {
      className: previewClassName,
      style: __rpx2vw__(previewStyle)
    }, directRenderVal);
  }

  return /*#__PURE__*/React.createElement(BaseSelect, _extends({}, props, {
    ref: ref
  }));
};

export default /*#__PURE__*/forwardRef(Select);