"use strict";

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

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

var _clsx = _interopRequireDefault(require("clsx"));

var _icons = require("@react-vant/icons");

var _utils = require("../utils");

var _ConfigProviderContext = _interopRequireDefault(require("../config-provider/ConfigProviderContext"));

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 Cell = function Cell(props) {
  var _useContext = (0, _react.useContext)(_ConfigProviderContext.default),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('cell', prefixCls),
      bem = _createNamespace[0];

  var renderLabel = function renderLabel() {
    var showLabel = (0, _utils.isDef)(props.label);

    if (showLabel) {
      return /*#__PURE__*/_react.default.createElement("div", {
        className: (0, _clsx.default)(bem('label'), props.labelClass)
      }, props.label);
    }

    return null;
  };

  var renderTitle = function renderTitle() {
    if ((0, _utils.isDef)(props.title)) {
      return /*#__PURE__*/_react.default.createElement("div", {
        className: (0, _clsx.default)(bem('title'), props.titleClass),
        style: props.titleStyle
      }, props.title, renderLabel());
    }

    return null;
  };

  var renderValue = function renderValue() {
    var hasTitle = (0, _utils.isDef)(props.title);
    var hasValue = props.children || (0, _utils.isDef)(props.value);

    if (hasValue) {
      return /*#__PURE__*/_react.default.createElement("div", {
        className: (0, _clsx.default)(bem('value', {
          alone: !hasTitle
        }), props.valueClass)
      }, props.children ? props.children : /*#__PURE__*/_react.default.createElement("span", null, props.value));
    }

    return null;
  };

  var renderLeftIcon = function renderLeftIcon() {
    if (props.icon) {
      return /*#__PURE__*/_react.default.cloneElement(props.icon, {
        className: (0, _clsx.default)(bem('left-icon'))
      });
    }

    return null;
  };

  var renderRightIcon = function renderRightIcon() {
    if (props.rightIcon) {
      return props.rightIcon;
    }

    if (props.isLink) {
      var _className = (0, _clsx.default)(bem('right-icon'));

      if (props.arrowDirection === 'left') return /*#__PURE__*/_react.default.createElement(_icons.ArrowLeft, {
        className: _className
      });
      if (props.arrowDirection === 'up') return /*#__PURE__*/_react.default.createElement(_icons.ArrowUp, {
        className: _className
      });
      if (props.arrowDirection === 'down') return /*#__PURE__*/_react.default.createElement(_icons.ArrowDown, {
        className: _className
      });
      return /*#__PURE__*/_react.default.createElement(_icons.Arrow, {
        className: _className
      });
    }

    return null;
  };

  var className = props.className,
      style = props.style,
      size = props.size,
      center = props.center,
      _props$border = props.border,
      border = _props$border === void 0 ? true : _props$border,
      isLink = props.isLink,
      required = props.required,
      onClick = props.onClick;
  var clickable = isLink || props.clickable;
  var classes = {
    center: center,
    required: required,
    clickable: clickable,
    borderless: !border
  };

  if (size) {
    classes[size] = !!size;
  }

  return /*#__PURE__*/_react.default.createElement("div", {
    style: style,
    className: (0, _clsx.default)(bem(classes), className),
    role: clickable ? 'button' : undefined,
    onClick: onClick
  }, renderLeftIcon(), renderTitle(), renderValue(), renderRightIcon(), props.extra);
};

var _default = Cell;
exports.default = _default;