import t from"react";import e from"../../prop-types/index.js";import o from"../../classnames/index.js";import{DropdownContext as r}from"./DropdownContext.js";import{tagPropType as n,omit as i,mapToCssModules as c}from"./utils.js";function l(t){return l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},l(t)}var u=["className","cssModule","divider","tag","header","active","text"];function a(){return a=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(t[r]=o[r])}return t},a.apply(this,arguments)}function s(t,e){if(null==t)return{};var o,r,n=function(t,e){if(null==t)return{};var o,r,n={},i=Object.keys(t);for(r=0;r<i.length;r++)o=i[r],e.indexOf(o)>=0||(n[o]=t[o]);return n}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)o=i[r],e.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(t,o)&&(n[o]=t[o])}return n}function f(t,e){for(var o=0;o<e.length;o++){var r=e[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function p(t,e){return p=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},p(t,e)}function d(t){var e=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(t){return!1}}();return function(){var o,r=y(t);if(e){var n=y(this).constructor;o=Reflect.construct(r,arguments,n)}else o=r.apply(this,arguments);return function(t,e){if(e&&("object"===l(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return b(t)}(this,o)}}function b(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function y(t){return y=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},y(t)}var v={children:e.node,active:e.bool,disabled:e.bool,divider:e.bool,tag:n,header:e.bool,onClick:e.func,className:e.string,cssModule:e.object,toggle:e.bool,text:e.bool},h=function(e){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&p(t,e)}(v,t.Component);var r,n,l,y=d(v);function v(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,v),(e=y.call(this,t)).onClick=e.onClick.bind(b(e)),e.getTabIndex=e.getTabIndex.bind(b(e)),e}return r=v,(n=[{key:"onClick",value:function(t){var e,o=this.props,r=o.disabled,n=o.header,i=o.divider,c=o.text;r||n||i||c?t.preventDefault():(this.props.onClick&&this.props.onClick(t),(null===(e=this.props.toggle)||void 0===e||e)&&this.context.toggle(t))}},{key:"getRole",value:function(){return"listbox"===this.context.menuRole?"option":"menuitem"}},{key:"getTabIndex",value:function(){var t=this.props,e=t.disabled,o=t.header,r=t.divider,n=t.text;return e||o||r||n?"-1":"0"}},{key:"render",value:function(){var e=this.getTabIndex(),r=e>-1?this.getRole():void 0,n=i(this.props,["toggle"]),l=n.className,f=n.cssModule,p=n.divider,d=n.tag,b=void 0===d?"button":d,y=n.header,v=n.active,h=n.text,m=s(n,u),g=c(o(l,{disabled:m.disabled,"dropdown-item":!p&&!y&&!h,active:v,"dropdown-header":y,"dropdown-divider":p,"dropdown-item-text":h}),f);return"button"===b&&(y?b="h6":p?b="div":m.href?b="a":h&&(b="span")),t.createElement(b,a({type:"button"===b&&(m.onClick||this.props.toggle)?"button":void 0},m,{tabIndex:e,role:r,className:g,onClick:this.onClick}))}}])&&f(r.prototype,n),l&&f(r,l),Object.defineProperty(r,"prototype",{writable:!1}),v}();h.propTypes=v,h.contextType=r;var m=h;export{m as default};
//# sourceMappingURL=DropdownItem.js.map
