function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, 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; }

import React from "react";
import PropTypes from "prop-types";
import { VictoryAxis, VictoryBar, VictoryChart, VictoryLabel, VictoryPortal, VictoryTooltip } from "victory";
import { ThemeProvider } from "emotion-theming";
import { VictoryTheme } from "../_Themes/index";
import ChartContainer from "../ChartContainer";
import DataChecker from "../utils/DataChecker";
import civicFormat from "../utils/civicFormat";
import { chartEvents, getDefaultDomain } from "../utils/chartHelpers";

var BarChart = function BarChart(_ref) {
  var data = _ref.data,
      dataKey = _ref.dataKey,
      dataValue = _ref.dataValue,
      domain = _ref.domain,
      title = _ref.title,
      subtitle = _ref.subtitle,
      xLabel = _ref.xLabel,
      yLabel = _ref.yLabel,
      xNumberFormatter = _ref.xNumberFormatter,
      yNumberFormatter = _ref.yNumberFormatter,
      barWidth = _ref.barWidth,
      loading = _ref.loading,
      error = _ref.error,
      theme = _ref.theme;
  var safeData = data && data.length ? data : [{}];
  var chartDomain = domain || getDefaultDomain(safeData, dataKey, dataValue);
  return React.createElement(ThemeProvider, {
    theme: theme
  }, React.createElement(ChartContainer, {
    title: title,
    subtitle: subtitle,
    loading: loading,
    error: error
  }, React.createElement(DataChecker, {
    dataAccessors: {
      dataKey: dataKey,
      dataValue: dataValue
    },
    data: safeData
  }, React.createElement(VictoryChart, {
    padding: {
      left: 90,
      right: 50,
      bottom: 50,
      top: 50
    },
    domainPadding: {
      x: [40, 40],
      y: [0, 0]
    },
    domain: chartDomain,
    theme: theme
  }, React.createElement(VictoryAxis, {
    tickFormat: xNumberFormatter,
    style: {
      grid: {
        stroke: "none"
      }
    },
    title: "X Axis"
  }), React.createElement(VictoryAxis, {
    dependentAxis: true,
    tickFormat: yNumberFormatter,
    title: "Y Axis"
  }), React.createElement(VictoryPortal, null, React.createElement(VictoryLabel, {
    style: _objectSpread({}, theme.axisLabel.style),
    text: yLabel,
    textAnchor: "middle",
    title: "Y Axis Label",
    verticalAnchor: "end",
    x: 85,
    y: 45
  })), React.createElement(VictoryPortal, null, React.createElement(VictoryLabel, {
    style: _objectSpread({}, theme.axisLabel.style),
    text: xLabel,
    textAnchor: "end",
    title: "X Axis Label",
    verticalAnchor: "end",
    x: 600,
    y: 295
  })), React.createElement(VictoryBar, {
    alignment: "middle",
    labelComponent: React.createElement(VictoryTooltip, {
      x: 325,
      y: 0,
      orientation: "bottom",
      pointerLength: 0,
      cornerRadius: 0,
      theme: theme
    }),
    data: safeData.map(function (d) {
      return {
        dataKey: d[dataKey],
        dataValue: d[dataValue],
        label: "".concat(xLabel, ": ").concat(xNumberFormatter(d[dataKey]), " \u2022 ").concat(yLabel, ": ").concat(yNumberFormatter(d[dataValue]))
      };
    }),
    events: chartEvents(theme),
    x: "dataKey",
    y: "dataValue",
    title: "Bar Chart",
    style: {
      data: {
        width: barWidth
      }
    },
    animate: true
  })))));
};

BarChart.propTypes = {
  data: PropTypes.arrayOf(PropTypes.shape({})),
  loading: PropTypes.bool,
  error: PropTypes.string,
  dataKey: PropTypes.string,
  dataValue: PropTypes.string,
  domain: PropTypes.shape({
    x: PropTypes.arrayOf(PropTypes.number),
    y: PropTypes.arrayOf(PropTypes.number)
  }),
  title: PropTypes.string,
  subtitle: PropTypes.string,
  xLabel: PropTypes.string,
  yLabel: PropTypes.string,
  xNumberFormatter: PropTypes.func,
  yNumberFormatter: PropTypes.func,
  barWidth: PropTypes.number,
  theme: PropTypes.shape({})
};
BarChart.defaultProps = {
  data: null,
  dataKey: "x",
  dataValue: "y",
  domain: null,
  title: null,
  subtitle: null,
  xLabel: "X",
  yLabel: "Y",
  xNumberFormatter: civicFormat.year,
  yNumberFormatter: civicFormat.numeric,
  barWidth: null,
  theme: VictoryTheme
};
export default BarChart;