import { jsx } from 'react/jsx-runtime';
import { A as Avatar } from './Avatar-DX96Mxe7.js';
import { I as Icon } from './Icon-B4uCvMU9.js';
import { S as SelectTriggerBase, d as defaultItemToString, a as defaultItemToKey } from './SelectTriggerBase-lYieONTb.js';
import { u as useLayoutPropsUtil } from './useLayoutPropsUtil-DjqeAJZ9.js';
import { c as childrenToString } from './childrenToString-Bz9MqbHb.js';
import { useTrackingId } from './useTrackingId.js';

const SelectTrigger = function(props) {
  const { layoutStyles, componentProps } = useLayoutPropsUtil(props);
  const {
    className,
    style,
    label,
    size,
    error,
    hint,
    description,
    required,
    moreInfo,
    prefix: prefixProp,
    suffix,
    maxRows,
    selectedItemProps = () => ({}),
    id,
    placeholder,
    disabled: isDisabled,
    readOnly: isReadOnly,
    onClick,
    multiple,
    onChange,
    disableClearSelection,
    itemToString: itemToStringProp,
    itemToKey: itemToKeyProp,
    selectedItem = null,
    selectedItems = [],
    ...rest
  } = componentProps;
  const itemToString = itemToStringProp ?? defaultItemToString;
  const itemToKey = itemToKeyProp ?? defaultItemToKey;
  function removeSelectedItem(item) {
    if (multiple) {
      onChange?.(
        selectedItems.filter(
          (selectedItem2) => itemToKey(selectedItem2) !== itemToKey(item)
        )
      );
    } else if (itemToKey(selectedItem) === itemToKey(item)) {
      onChange?.(null);
    }
  }
  function reset() {
    if (multiple) {
      onChange?.([]);
    } else {
      onChange?.(null);
    }
  }
  const noClearButton = isDisabled || isReadOnly || disableClearSelection;
  const styleCombined = {
    ...style,
    ...layoutStyles
  };
  const { aiMark, ...labelPropsWithoutAiMark } = props.labelProps || {};
  const data = {
    label: childrenToString(props.label),
    size: props.size,
    required: props.required,
    moreInfo: props.moreInfo,
    description: childrenToString(props.description),
    hint: props.hint,
    labelProps: labelPropsWithoutAiMark
  };
  const trackingId = useTrackingId({
    name: "ComboboxSearchField",
    data,
    hasOverride: !!props["data-tracking-id"]
  });
  const prefix = prefixProp == null || typeof prefixProp === "string" ? prefixProp : "icon" in prefixProp ? /* @__PURE__ */ jsx(Icon, { ...prefixProp.icon }) : "avatar" in prefixProp ? /* @__PURE__ */ jsx(
    Avatar,
    {
      ...prefixProp.avatar,
      size: props.size === "small" ? "small" : "medium"
    }
  ) : prefixProp;
  return /* @__PURE__ */ jsx(
    SelectTriggerBase,
    {
      "data-anv": "select-trigger",
      "data-tracking-id": trackingId,
      className,
      style: styleCombined,
      label,
      size,
      error,
      hint,
      description,
      labelProps: {
        aiMark,
        moreInfo,
        required
      },
      prefix,
      suffix,
      maxRows,
      selectedItemProps,
      id,
      placeholder,
      disabled: isDisabled,
      readOnly: isReadOnly,
      itemToString,
      removeSelectedItem,
      disableClearSelection: noClearButton,
      selectedItem,
      selectedItems,
      onClearButtonClick: reset,
      inputWrapperProps: { onClick },
      inputProps: rest
    }
  );
};

export { SelectTrigger as S };
//# sourceMappingURL=SelectTrigger-APxYfL3V.js.map
