'use client';
import React from 'react';
import Icon from '@rsuite/icons/Icon';
import InputGroup from "../../InputGroup/index.js";
import CloseButton from "../CloseButton/index.js";
import Loader from "../../Loader/index.js";
import { useStyles, useCustom } from "../hooks/index.js";
const PickerIndicator = ({
  loading,
  caretAs,
  onClose,
  showCleanButton,
  as: Component = InputGroup.Addon,
  disabled,
  size
}) => {
  const {
    getLocale
  } = useCustom();
  const {
    clear
  } = getLocale('common');
  const {
    prefix
  } = useStyles('picker');
  const addon = () => {
    if (loading) {
      return /*#__PURE__*/React.createElement(Loader, {
        className: prefix('loader'),
        "data-testid": "spinner",
        size: size === 'xs' ? 'xs' : 'sm'
      });
    }
    const caret = caretAs && /*#__PURE__*/React.createElement(Icon, {
      as: caretAs,
      className: prefix('caret-icon'),
      "data-testid": "caret"
    });
    const cleanButton = showCleanButton && !disabled && /*#__PURE__*/React.createElement(CloseButton, {
      className: prefix('clean'),
      tabIndex: -1,
      locale: {
        closeLabel: clear
      },
      onClick: onClose
    });
    if (caret && cleanButton) {
      return /*#__PURE__*/React.createElement(React.Fragment, null, caret, cleanButton);
    }
    return cleanButton || caret || null;
  };
  const props = Component === InputGroup.Addon ? {
    disabled
  } : undefined;
  return /*#__PURE__*/React.createElement(Component, props, addon());
};
export default PickerIndicator;