"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

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

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

var _lodash = require("lodash");

var _next = require("@alifd/next");

var _title = _interopRequireDefault(require("../title"));

var _carouselTable = _interopRequireDefault(require("../carousel-table"));

var _context = _interopRequireDefault(require("../context"));

var _Utils = require("../Utils");

var _excluded = ["className", "sliderOptions", "direction", "labelOptions", "barOptions", "valueOptions"];

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

/**
 * 条形占比统计图
 * @param props IProps
 */
var BarChart = function BarChart(props) {
  var _useContext = (0, _react.useContext)(_context["default"]),
      _cssPrefix = _useContext._cssPrefix;

  var className = props.className,
      _props$sliderOptions = props.sliderOptions,
      sliderOptions = _props$sliderOptions === void 0 ? {} : _props$sliderOptions,
      _props$direction = props.direction,
      direction = _props$direction === void 0 ? 'ver' : _props$direction,
      _props$labelOptions = props.labelOptions,
      labelOptions = _props$labelOptions === void 0 ? {} : _props$labelOptions,
      barOptions = props.barOptions,
      _props$valueOptions = props.valueOptions,
      valueOptions = _props$valueOptions === void 0 ? {} : _props$valueOptions,
      others = (0, _objectWithoutPropertiesLoose2["default"])(props, _excluded);
  return /*#__PURE__*/_react["default"].createElement(_carouselTable["default"], (0, _extends2["default"])({
    className: (0, _classnames["default"])(_cssPrefix + "bar-chart-wrapper", className),
    sliderOptions: (0, _extends2["default"])({
      slidesToShow: (0, _lodash.get)(sliderOptions, 'slidesToShow', 5)
    }, sliderOptions)
  }, others, {
    headerOptions: {
      universalStyle: {
        height: 0
      }
    },
    rowOptions: {
      oddBackgroundColor: 'transparent',
      evenBackgroundColor: 'transparent'
    },
    column: [{
      key: 'value',
      widthRate: 100,
      align: 'left',
      cell: function cell(val, i, record) {
        return direction === 'hoz' ? /*#__PURE__*/_react["default"].createElement("div", {
          style: {
            width: '100%',
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'space-between'
          }
        }, /*#__PURE__*/_react["default"].createElement(_title["default"], (0, _extends2["default"])({
          universalStyle: {
            width: (0, _lodash.get)(labelOptions, 'widthRate', 30) + "%"
          },
          align: "left"
        }, labelOptions), record.label), /*#__PURE__*/_react["default"].createElement(_next.Progress, {
          style: {
            width: (0, _lodash.get)(barOptions, 'widthRate', 60) + "%"
          },
          color: (0, _lodash.get)(barOptions, 'color', 'var(--color-brand1-6)'),
          backgroundColor: (0, _lodash.get)(barOptions, 'backgroundColor'),
          size: "medium",
          shape: "line",
          percent: record.rate,
          textRender: function textRender() {
            return '';
          }
        }), /*#__PURE__*/_react["default"].createElement(_title["default"], (0, _extends2["default"])({
          className: _cssPrefix + "data",
          universalStyle: {
            width: (0, _lodash.get)(valueOptions, 'widthRate', 10) + "%"
          },
          align: "right"
        }, valueOptions), (0, _Utils.NWC)(record.value))) : /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
          style: {
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'space-between'
          }
        }, /*#__PURE__*/_react["default"].createElement(_title["default"], (0, _extends2["default"])({
          universalStyle: {
            width: (0, _lodash.get)(labelOptions, 'widthRate', 50) + "%"
          },
          align: "left"
        }, labelOptions), record.label), /*#__PURE__*/_react["default"].createElement(_title["default"], (0, _extends2["default"])({
          className: _cssPrefix + "data",
          universalStyle: {
            width: (0, _lodash.get)(valueOptions, 'widthRate', 50) + "%"
          },
          align: "right"
        }, valueOptions), (0, _Utils.NWC)(record.value))), /*#__PURE__*/_react["default"].createElement(_next.Progress, {
          style: {
            width: (0, _lodash.get)(barOptions, 'widthRate', 100) + "%"
          },
          color: (0, _lodash.get)(barOptions, 'color', 'var(--color-brand1-6)'),
          backgroundColor: (0, _lodash.get)(barOptions, 'backgroundColor'),
          size: "medium",
          shape: "line",
          percent: record.rate,
          textRender: function textRender() {
            return '';
          }
        }));
      }
    }]
  }));
};

var _default = BarChart;
exports["default"] = _default;