import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2, extends as _extends } from '../../../../_virtual/_rollupPluginBabelHelpers.js';
import React__default, { forwardRef, useCallback, useMemo } from 'react';
import { cx } from '../../../../utils/index.js';
import { classes } from '../../Dropdown.tokens.js';
import { getValidComponent } from '../../utils/index.js';
import { base as base$1 } from './variations/_view/base.js';
import { base as base$2 } from './variations/_size/base.js';
import { StyledContentLeft, StyledText, StyledContentRight, base } from './DropdownItem.styles.js';
import { safeUseId } from '../../../../utils/react.js';

var _excluded = ["id", "className", "children", "text", "isSelected", "name", "checked", "value", "role", "view", "size", "disabled", "contentLeft", "contentRight", "onSelect", "onClick", "onChange"];
/**
 * Элемент выпадающего списка
 */
var dropdownItemOldRoot = function dropdownItemOldRoot(Root) {
  return /*#__PURE__*/forwardRef(function (_ref, outerRootRef) {
    var id = _ref.id,
      className = _ref.className,
      children = _ref.children,
      text = _ref.text,
      isSelected = _ref.isSelected,
      name = _ref.name,
      checked = _ref.checked,
      value = _ref.value,
      role = _ref.role,
      view = _ref.view,
      size = _ref.size,
      disabled = _ref.disabled,
      ContentLeftComponent = _ref.contentLeft,
      ContentRightComponent = _ref.contentRight,
      onSelect = _ref.onSelect,
      onClick = _ref.onClick,
      onChange = _ref.onChange,
      rest = _objectWithoutProperties(_ref, _excluded);
    var uniqId = safeUseId();
    var innerId = id || uniqId;
    var withDropdownItemIsSelected = checked || isSelected ? classes.dropdownItemIsSelected : undefined;
    var withDropdownItemIsDisabled = disabled ? classes.dropdownItemIsDisabled : undefined;
    var handleOnClick = useCallback(function (event) {
      if (disabled) {
        return;
      }
      onClick === null || onClick === void 0 || onClick(event);
      if (onSelect && !ContentLeftComponent) {
        onSelect(value, text);
      }
    }, [onSelect, disabled]);
    var handleOnChange = useCallback(function (event) {
      if (disabled) {
        return;
      }
      onChange === null || onChange === void 0 || onChange(event);
      if (onSelect && ContentLeftComponent) {
        onSelect(value, text);
      }
    }, [onSelect, disabled]);
    var contentProps = _objectSpread2({
      name: name,
      value: value,
      checked: checked || isSelected,
      disabled: disabled,
      tabIndex: 0
    }, !disabled && {
      onChange: handleOnChange
    });
    var ContentLeft = useMemo(function () {
      return getValidComponent(ContentLeftComponent, contentProps);
    }, [ContentRightComponent, contentProps]);
    var ContentRight = useMemo(function () {
      return getValidComponent(ContentRightComponent, contentProps);
    }, [ContentRightComponent, contentProps]);
    return /*#__PURE__*/React__default.createElement(Root, _extends({
      className: cx(withDropdownItemIsSelected, withDropdownItemIsDisabled, className),
      view: view,
      size: size,
      id: innerId,
      isSelected: isSelected,
      role: role,
      ref: outerRootRef,
      tabIndex: 0,
      "aria-disabled": disabled,
      onClick: handleOnClick,
      "data-value": value
    }, rest), text ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(StyledContentLeft, null, ContentLeftComponent && ContentLeft), /*#__PURE__*/React__default.createElement(StyledText, null, text), /*#__PURE__*/React__default.createElement(StyledContentRight, null, ContentRightComponent && ContentRight)) : children);
  });
};
var dropdownItemOldConfig = {
  name: 'DropdownItem',
  tag: 'div',
  layout: dropdownItemOldRoot,
  base: base,
  variations: {
    view: {
      css: base$1
    },
    size: {
      css: base$2
    }
  },
  defaults: {
    view: 'primary',
    size: 'm'
  }
};

export { dropdownItemOldConfig, dropdownItemOldRoot };
//# sourceMappingURL=DropdownItemOld.js.map
