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 CDropdownCustom from './CDropdownCustom';

//component - CoreUI / CDropdown

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

  //custom

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

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

  //render

  return React.createElement(CDropdownCustom, _extends({}, attributes, { show: show, toggle: toggle }));
};

CDropdown.propTypes = process.env.NODE_ENV !== "production" ? _extends({}, CDropdownCustom.propTypes, {
  custom: PropTypes.bool,
  //
  defaultOpen: PropTypes.bool
}) : {};

export default CDropdown;