'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

require('./style.css');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var Tabs = function Tabs(_ref) {
  var handleClick = _ref.handleClick,
      tabs = _ref.tabs,
      selectedTab = _ref.selectedTab;

  var isClickFunction = typeof handleClick === 'function';
  var handleAllClick = function handleAllClick(e) {
    var selTab = e.target;
    if (selTab && selTab.scrollIntoView) {
      selTab.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
    }
    // invokes custom function if passed in the component
    if (isClickFunction) {
      handleClick(selTab.name);
    }
  };
  return _react2.default.createElement(
    'div',
    { className: 'ma__search--tabs' },
    _react2.default.createElement(
      'div',
      { className: 'main-content--two' },
      _react2.default.createElement(
        'div',
        { className: 'ma__tabs' },
        tabs.map(function (tab) {
          var value = tab.value,
              label = tab.label,
              ariaLabel = tab.ariaLabel,
              href = tab.href;

          var isSelected = selectedTab === value ? 'is-selected' : '';
          if (isClickFunction) {
            return _react2.default.createElement(
              'button',
              {
                key: 'tab_' + value,
                className: 'ma__tabs-item ' + isSelected,
                name: value,
                onClick: function onClick(e) {
                  return handleAllClick(e);
                },
                'aria-label': ariaLabel || value
              },
              label
            );
          }
          return _react2.default.createElement(
            'a',
            {
              key: 'tab_' + value,
              href: href,
              className: 'ma__tabs-item ' + isSelected
            },
            label
          );
        })
      )
    )
  );
};
// eslint-disable-next-line import/no-unresolved


Tabs.propTypes = process.env.NODE_ENV !== "production" ? {
  /* handleClick is a custom callback function that returns the selected tab value.
   * If handleClick is passed in as a function, the tabs will be rendered as buttons, otherwise will be rendered anchor links.
  */
  handleClick: _propTypes2.default.func,
  /* default tab value rendered as selected */
  selectedTab: _propTypes2.default.string,
  tabs: _propTypes2.default.arrayOf(_propTypes2.default.shape({
    /* href is used as anchor link href for the tab if the handleClick is not passed as a function */
    value: _propTypes2.default.string.isRequired,
    /* text rendered for the tab */
    label: _propTypes2.default.string.isRequired,
    /* href is used as anchor link href for the tab if the handleClick is not passed as a function */
    href: _propTypes2.default.string,
    /* arial-label for the tab button if the handleClick is passed as a function */
    ariaLabel: _propTypes2.default.string
  }))
} : {};

exports.default = Tabs;
module.exports = exports['default'];