"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

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

var _one = require("remax/one");

var _indexModule = _interopRequireDefault(require("./styles/index.module.less"));

var _classnames = _interopRequireDefault(require("classnames"));

var _icon = _interopRequireDefault(require("../icon"));

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; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var Cell = function Cell(props) {
  var label = props.label,
      style = props.style,
      labelWidth = props.labelWidth,
      labelStyle = props.labelStyle,
      valueStyle = props.valueStyle,
      _props$labelJustify = props.labelJustify,
      labelJustify = _props$labelJustify === void 0 ? 'left' : _props$labelJustify,
      _props$valueJustify = props.valueJustify,
      valueJustify = _props$valueJustify === void 0 ? 'right' : _props$valueJustify,
      children = props.children,
      description = props.description,
      verticality = props.verticality,
      arrow = props.arrow,
      after = props.after,
      required = props.required,
      onTap = props.onTap;

  if (verticality) {
    return /*#__PURE__*/_react.default.createElement(_one.View, {
      className: _indexModule.default.cell,
      style: _objectSpread({
        margin: 0
      }, style),
      onTap: onTap
    }, /*#__PURE__*/_react.default.createElement(_one.View, {
      className: _indexModule.default.verticality
    }, label ? /*#__PURE__*/_react.default.createElement(_one.View, {
      className: _indexModule.default.verticality_label,
      style: labelStyle
    }, required ? /*#__PURE__*/_react.default.createElement(_one.View, {
      className: _indexModule.default.required
    }, "*") : null, label) : null, /*#__PURE__*/_react.default.createElement(_one.View, {
      className: _indexModule.default.verticality_value,
      style: valueStyle
    }, children)));
  }

  var after_model = (0, _react.useMemo)(function () {
    return after ? /*#__PURE__*/_react.default.createElement(_one.View, {
      className: _indexModule.default.after
    }, after) : null;
  }, [after]);
  var after_arrow = (0, _react.useMemo)(function () {
    return arrow ? /*#__PURE__*/_react.default.createElement(_one.View, {
      className: _indexModule.default.after
    }, /*#__PURE__*/_react.default.createElement(_icon.default, {
      name: "right",
      color: "#aaa",
      size: '24px'
    })) : null;
  }, [arrow]);
  return /*#__PURE__*/_react.default.createElement(_one.View, {
    className: (0, _classnames.default)(_indexModule.default.cell),
    style: style,
    onTap: onTap
  }, /*#__PURE__*/_react.default.createElement(_one.View, {
    className: (0, _classnames.default)(_indexModule.default.container)
  }, /*#__PURE__*/_react.default.createElement(_one.View, {
    className: (0, _classnames.default)(_indexModule.default.left)
  }, /*#__PURE__*/_react.default.createElement(_one.View, {
    className: _indexModule.default.label,
    style: _objectSpread({
      minWidth: labelWidth,
      justifyContent: labelJustify === 'right' ? 'flex-end' : labelJustify === 'justify' ? 'space-between' : 'flex-start'
    }, labelStyle)
  }, required ? /*#__PURE__*/_react.default.createElement(_one.View, {
    className: _indexModule.default.required
  }, "*") : null, label ? /*#__PURE__*/_react.default.createElement(_one.View, {
    className: _indexModule.default.value,
    style: labelStyle
  }, /*#__PURE__*/_react.default.createElement(_one.View, null, label), description ? /*#__PURE__*/_react.default.createElement(_one.View, {
    className: _indexModule.default.description
  }, description) : null) : null)), /*#__PURE__*/_react.default.createElement(_one.View, {
    className: _indexModule.default.right,
    style: {
      justifyContent: valueJustify === 'right' ? 'flex-end' : valueJustify === 'justify' ? 'space-between' : 'flex-start'
    }
  }, /*#__PURE__*/_react.default.createElement(_one.View, {
    className: (0, _classnames.default)(_indexModule.default.value),
    style: _objectSpread({}, valueStyle)
  }, children), after_model, after_arrow)));
};

var _default = Cell;
exports.default = _default;