var _excluded = ["dataSource", "columns", "bodyStyle", "bodyCls", "rowStyle", "rowCls", "headerStyle", "headerCls", "itemStyle", "itemCls", "className", "noDataStyle", "noDataCls", "loading", "doubleColor", "shadow", "align"];

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

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import React from 'react';
import { View } from 'remax/one';
import styles from './styles/index.module.less';
import { useConfig } from '../config-provider';
import NoData from '../no-data';
import Loading from '../loading';
import Shadow from '../shadow';
import NeedWrap from '../need-wrap';
import classNames from 'classnames';

var convert = require('color-convert');

export default (function (_ref) {
  var dataSource = _ref.dataSource,
      columns = _ref.columns,
      bodyStyle = _ref.bodyStyle,
      bodyCls = _ref.bodyCls,
      rowStyle = _ref.rowStyle,
      rowCls = _ref.rowCls,
      headerStyle = _ref.headerStyle,
      headerCls = _ref.headerCls,
      itemStyle = _ref.itemStyle,
      itemCls = _ref.itemCls,
      className = _ref.className,
      noDataStyle = _ref.noDataStyle,
      noDataCls = _ref.noDataCls,
      loading = _ref.loading,
      doubleColor = _ref.doubleColor,
      shadow = _ref.shadow,
      align = _ref.align,
      props = _objectWithoutProperties(_ref, _excluded);

  var _useConfig = useConfig(),
      brandPrimary = _useConfig.brandPrimary;

  var isBetween = align === 'between';

  var getJustify = function getJustify(i) {
    return isBetween ? i === 0 ? 'flex-start' : i === ((columns === null || columns === void 0 ? void 0 : columns.length) || 0) - 1 ? 'flex-end' : undefined : undefined;
  };

  return /*#__PURE__*/React.createElement(NeedWrap, {
    wrap: Shadow,
    need: shadow !== false,
    wrapProps: shadow
  }, /*#__PURE__*/React.createElement(View, _objectSpread({
    className: classNames(styles.table, className)
  }, props), /*#__PURE__*/React.createElement(View, {
    className: classNames(styles.header, headerCls)
  }, columns === null || columns === void 0 ? void 0 : columns.map(function (_ref2, i) {
    var title = _ref2.title;
    return /*#__PURE__*/React.createElement(View, {
      key: i,
      className: classNames(styles.item, itemCls),
      style: {
        justifyContent: getJustify(i)
      }
    }, title);
  })), /*#__PURE__*/React.createElement(View, {
    className: classNames(styles.body, bodyCls),
    style: bodyStyle
  }, loading ? /*#__PURE__*/React.createElement(Loading, {
    type: 'inline'
  }) : /*#__PURE__*/React.createElement(React.Fragment, null, !(dataSource === null || dataSource === void 0 ? void 0 : dataSource.length) && /*#__PURE__*/React.createElement(NoData, {
    style: noDataStyle,
    className: noDataCls
  }), dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (item, i) {
    return /*#__PURE__*/React.createElement(View, {
      key: i,
      className: classNames(styles.row, rowCls),
      style: _objectSpread(_objectSpread({}, rowStyle), i % 2 ? {
        backgroundColor: doubleColor || "rgba(".concat(convert.hex.rgb(brandPrimary).join(','), ", 0.1)")
      } : undefined)
    }, columns === null || columns === void 0 ? void 0 : columns.map(function (_ref3, i) {
      var dataIndex = _ref3.dataIndex,
          _ref3$render = _ref3.render,
          render = _ref3$render === void 0 ? function (v) {
        return v;
      } : _ref3$render;
      return /*#__PURE__*/React.createElement(View, {
        style: _objectSpread({
          justifyContent: getJustify(i)
        }, itemStyle),
        className: classNames(styles.item, itemCls),
        key: i
      }, render(item[dataIndex], item, i));
    }));
  })))));
});