import o,{useRef as e,useEffect as n,useCallback as t,useMemo as l}from"react";import i from"classnames";import r from"../../../Icon/Icon.js";import c from"../../../Tooltip/Tooltip.js";import s from"../../../../hooks/useIsOverflowing.js";import{keyCodes as a}from"../../../../constants/keyCodes.js";import{getOptionId as u}from"../../helpers.js";import"./ComboboxOption.scss.js";var f=function f(p){var m=p.index,d=p.option,v=p.isActive,h=p.visualFocus,E=p.scrollRef,b=p.scrollOffset,y=p.onOptionClick,T=p.onOptionLeave,g=p.onOptionHover,I=p.optionLineHeight,R=p.shouldScrollWhenActive,k=p.optionRenderer,C=p.forceUndoScrollNullCheck,N=void 0!==C&&C,O=d.id,S=d.leftIcon,j=d.rightIcon,A=d.leftIconType,F=d.rightIconType,L=d.label,w=d.iconSize,x=void 0===w?16:w,D=d.disabled,z=d.selected,H=d.ariaLabel,M=d.belongToCategory,P=void 0!==M&&M,U=d.tooltipContent,V=e(null),W=e(),K=s({ref:W});n((function(){var o,e,n=V.current;h&&n&&R&&(null!=E&&E.current&&n?E.current.scrollTop=n.offsetTop-b:N?null==n||null===(o=n.scrollIntoView)||void 0===o||o.call(n,{behaviour:"smooth"}):null===(e=n.scrollIntoView)||void 0===e||e.call(n,{behaviour:"smooth"}))}),[V,h,R,N,E,b,P]);var _=function(e,n,t){return n===f.iconTypes.RENDERER?e("option-icon ".concat(t)):o.createElement(r,{className:i("option-icon",t),iconType:r.type.ICON_FONT,clickable:!1,icon:e,iconSize:x,ignoreFocusStyle:!0})},q=t((function(o){y(o,m,d,!0)}),[m,d,y]),B=t((function(o){D||T(o,m,d,!0)}),[m,d,T,D]),G=t((function(o){D||g(o,m,d,!0)}),[m,d,g,D]),J=t((function(o){o.key!==a.ENTER&&o.key!==a.SPACE||y(o,m,d,!1)}),[y,m,d]);U||(U=K?L:null);var Q=l((function(){return k&&k(d)}),[k,d]),X=o.createElement(o.Fragment,null,S&&_(S,A,"left"),o.createElement("div",{ref:W,className:"option-label"},L),j&&_(j,F,"right"));return o.createElement(c,{content:U},o.createElement("div",{ref:V,key:O||L,"aria-level":P?2:1,"aria-selected":v,"aria-label":H||L,id:u(O,m),onMouseEnter:G,onClick:q,onKeyDown:J,onMouseLeave:B,className:i("combobox-option",{disabled:D,selected:z,active:v,"active-outline":h,first:0===m}),style:{height:I}},Q||X))};f.iconTypes={DEFAULT:"default",RENDERER:"renderer"},f.defaultProps={shouldScrollWhenActive:!0,optionRenderer:null,scrollOffset:100};var p=f;export{p as default};
