var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { tagPropType, mapToCssModules } from './Shared/helper.js';
//import {Context} from './CDropdownCustom';

//component - CoreUI / CToggler

var CToggler = function CToggler(props) {
  var Tag = props.tag,
      children = props.children,
      className = props.className,
      cssModule = props.cssModule,
      custom = props.custom,
      innerRef = props.innerRef,
      toggle = props.toggle,
      inHeader = props.inHeader,
      inNavbar = props.inNavbar,
      attributes = _objectWithoutProperties(props, ['tag', 'children', 'className', 'cssModule', 'custom', 'innerRef', 'toggle', 'inHeader', 'inNavbar']);

  //const context = useContext(Context);

  //events


  var onClick = function onClick(e) {
    e.preventDefault();
    //if (context.toggle)
    //  context.toggle();
    if (toggle) toggle(e);
  };

  //render

  var togglerType = inNavbar ? 'c-navbar' : inHeader ? 'c-header' : null;

  var classes = mapToCssModules(classNames(className, togglerType ? togglerType + '-toggler' : null), cssModule);

  if (!custom) {
    var classesTrigger = mapToCssModules(classNames(togglerType ? togglerType + '-toggler-icon' : null), cssModule);
    return React.createElement(
      Tag,
      _extends({}, attributes, { className: classes, onClick: onClick }),
      React.createElement('span', { className: classesTrigger })
    );
  }

  return React.createElement(
    Tag,
    _extends({}, attributes, { className: classes, onClick: onClick, ref: innerRef }),
    children
  );
};

CToggler.propTypes = process.env.NODE_ENV !== "production" ? {
  tag: tagPropType,
  className: PropTypes.string,
  cssModule: PropTypes.object,
  custom: PropTypes.bool,
  //
  innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string, PropTypes.object]),
  inHeader: PropTypes.bool,
  inNavbar: PropTypes.bool,
  type: PropTypes.string,
  toggle: PropTypes.func
} : {};

CToggler.defaultProps = {
  tag: 'button',
  type: 'button'
};

export default CToggler;