'use strict';

exports.__esModule = true;

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; };

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _CDropdownCustom = require('./CDropdownCustom');

var _CDropdownCustom2 = _interopRequireDefault(_CDropdownCustom);

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

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; }

//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 = (0, _react.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 _react2.default.createElement(_CDropdownCustom2.default, _extends({}, attributes, { show: show, toggle: toggle }));
};

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

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