import e from"react";import t from"../../prop-types/index.js";import r from"../../classnames/index.js";import{Reference as o}from"../../react-popper/lib/esm/Reference.js";import{DropdownContext as n}from"./DropdownContext.js";import{tagPropType as i,mapToCssModules as c}from"./utils.js";import a from"./Button.js";function l(e){return l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},l(e)}var s=["className","color","cssModule","caret","split","nav","tag","innerRef"];function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},p.apply(this,arguments)}function u(e,t){if(null==e)return{};var r,o,n=function(e,t){if(null==e)return{};var r,o,n={},i=Object.keys(e);for(o=0;o<i.length;o++)r=i[o],t.indexOf(r)>=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)r=i[o],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function f(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function y(e,t){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},y(e,t)}function b(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,o=h(e);if(t){var n=h(this).constructor;r=Reflect.construct(o,arguments,n)}else r=o.apply(this,arguments);return function(e,t){if(t&&("object"===l(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return d(e)}(this,r)}}function d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},h(e)}var m={caret:t.bool,color:t.string,children:t.node,className:t.string,cssModule:t.object,disabled:t.bool,onClick:t.func,"aria-haspopup":t.bool,split:t.bool,tag:i,nav:t.bool,innerRef:t.oneOfType([t.object,t.string,t.func])},v=function(t){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&y(e,t)}(m,e.Component);var n,i,l,h=b(m);function m(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,m),(t=h.call(this,e)).onClick=t.onClick.bind(d(t)),t}return n=m,(i=[{key:"onClick",value:function(e){this.props.disabled||this.context.disabled?e.preventDefault():(this.props.nav&&!this.props.tag&&e.preventDefault(),this.props.onClick&&this.props.onClick(e),this.context.toggle(e))}},{key:"getRole",value:function(){return this.context.menuRole||this.props["aria-haspopup"]}},{key:"render",value:function(){var t,n=this,i=this.props,l=i.className,f=i.color,y=i.cssModule,b=i.caret,d=i.split,h=i.nav,m=i.tag,v=i.innerRef,g=u(i,s),O=g["aria-label"]||"Toggle Dropdown",j=c(r(l,{"dropdown-toggle":b||d,"dropdown-toggle-split":d,"nav-link":h}),y),w=void 0!==g.children?g.children:e.createElement("span",{className:"visually-hidden"},O);return h&&!m?(t="a",g.href="#"):m?t=m:(t=a,g.color=f,g.cssModule=y),this.context.inNavbar?e.createElement(t,p({},g,{className:j,onClick:this.onClick,ref:this.context.onToggleRef,"aria-expanded":this.context.isOpen,"aria-haspopup":this.getRole(),children:w})):e.createElement(o,{innerRef:v},(function(r){var o,i,c,a=r.ref;return e.createElement(t,p({},g,(c=function(e){a(e);var t=n.context.onToggleRef;t&&t(e)},(i="string"==typeof t?"ref":"innerRef")in(o={})?Object.defineProperty(o,i,{value:c,enumerable:!0,configurable:!0,writable:!0}):o[i]=c,o),{className:j,onClick:n.onClick,"aria-expanded":n.context.isOpen,"aria-haspopup":n.getRole(),children:w}))}))}}])&&f(n.prototype,i),l&&f(n,l),Object.defineProperty(n,"prototype",{writable:!1}),m}();v.propTypes=m,v.defaultProps={color:"secondary","aria-haspopup":!0},v.contextType=n;var g=v;export{g as default};
//# sourceMappingURL=DropdownToggle.js.map
