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

//component - CoreUI / CPopover

var CPopover = function CPopover(props) {
  var custom = props.custom,
      toggle = props.toggle,
      show = props.show,
      defaultOpen = props.defaultOpen,
      attributes = _objectWithoutProperties(props, ['custom', 'toggle', 'show', '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('popover', 'show', props.className);

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

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

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

CPopover.defaultProps = {
  placement: 'right',
  placementPrefix: 'bs-popover',
  trigger: 'click'
};

export default CPopover;