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, { useState } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import CTooltipPopoverWrapper from './CTooltipPopoverWrapper';

//component - CoreUI / CTooltip

var CTooltip = function CTooltip(props) {
  var custom = props.custom,
      show = props.show,
      toggle = props.toggle,
      defaultOpen = props.defaultOpen,
      attributes = _objectWithoutProperties(props, ['custom', 'show', 'toggle', 'defaultOpen']);

  var _useState = useState(defaultOpen || false),
      isOpen = _useState[0],
      setIsOpen = _useState[1];

  if (!custom) {
    var userToggle = toggle;
    toggle = function toggle(e) {
      setIsOpen(!isOpen);
      if (userToggle) userToggle(e);
    };
    show = isOpen;
  }

  // render

  var popperClasses = classNames('tooltip', 'show', props.className);

  var classes = classNames('tooltip-inner', props.innerClassName);

  return React.createElement(CTooltipPopoverWrapper, _extends({}, attributes, {
    toggle: toggle,
    show: show,
    className: popperClasses,
    innerClassName: classes
  }));
};

CTooltip.propTypes = process.env.NODE_ENV !== "production" ? _extends({}, CTooltipPopoverWrapper.propTypes, {
  custom: PropTypes.bool,
  //
  innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
  defaultOpen: PropTypes.bool
}) : {};

CTooltip.defaultProps = {
  placement: 'top',
  autohide: true,
  placementPrefix: 'bs-tooltip',
  trigger: 'hover focus'
};

export default CTooltip;