import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo } from 'react';
import { styled, useStyleConfig, vui } from '../core';
import { cs, filterUndefined, isReactText, isString } from '../utils';
import { TagProvider } from './context';
import TagButton from './tagButton';
import TagIcon from './tagIcon';
import TagText from './tagText';
export const TagBase = styled.spanBox `
  align-items: center;
  border-radius: xl;
  display: inline-flex;
  font-weight: medium;
  justify-content: center;
  line-height: normal;
  max-width: 100%;
  position: relative;
  transition-duration: fast;
  width: fit-content;

  &:focus {
    border-color: transparent;
    outline: none;
  }

  &[aria-disabled='true'] {
    opacity: 0.5;
    cursor: not-allowed;
    user-select: none;
  }
`;
/**
 * Displays text, icons or custom content. Can be made interactive or a link.
 * Exposes some props to the children via context.
 */
export const Tag = vui((props, ref) => {
    const { casing, children, className, disabled, icon, iconLeft, iconRight, isFullWidth, isInteractive = props.onClick !== undefined && props.onDelete === undefined, isRound, isTruncated = true, itemLeft, itemRight, onClick, onDelete, size = 'md', text, variant = 'subtleBlue', weight, ...rest } = props;
    const styles = useStyleConfig('Tag', props);
    const { activeBg, h, hoverBg, spaceX: spaceXBase = 0, ...tagStyles } = styles.container;
    const context = useMemo(() => filterUndefined({ disabled, size, variant }), [disabled, size, variant]);
    const spaceX = spaceXBase / 8;
    let spaceXText = (spaceXBase + 4) / 8;
    if (size === 'xs') {
        spaceXText = spaceXBase / 8;
    }
    const pl = icon || itemLeft || iconLeft ? spaceX : spaceXText;
    const pr = icon || itemRight || iconRight ? spaceX : spaceXText;
    const interactiveProps = !disabled && isInteractive
        ? {
            cursor: 'pointer',
            hoverBg,
            activeBg,
            tabIndex: 0,
            userSelect: 'none',
        }
        : {};
    const aliasedProps = filterUndefined({
        borderRadius: isRound ? h / 2 : undefined,
        'aria-disabled': disabled,
        fontWeight: weight,
        textTransform: casing,
        w: isFullWidth ? '100%' : undefined,
    });
    return (_jsx(TagProvider, { value: context, children: _jsxs(TagBase, { className: cs('vui-tag', className), focusRing: 2, h: h, isTruncated: isTruncated, onClick: !disabled ? onClick : undefined, pl: pl, pr: pr, ref: ref, ...tagStyles, ...interactiveProps, ...aliasedProps, ...rest, children: [isString(icon) ? _jsx(TagIcon, { name: icon }) : icon, !icon && (_jsxs(_Fragment, { children: [itemLeft, isString(iconLeft) ? _jsx(TagIcon, { mr: spaceX, name: iconLeft }) : iconLeft, children ?? (isReactText(text) ? _jsx(TagText, { isTruncated, text }) : text), isString(iconRight) ? _jsx(TagIcon, { ml: spaceX, name: iconRight }) : iconRight, onDelete ? (_jsx(TagButton, { "aria-label": "delete", disabled: disabled, isRound: isRound, ml: spaceX, onClick: e => onDelete?.(e) })) : (itemRight)] }))] }) }));
});
Tag.Button = TagButton;
Tag.Icon = TagIcon;
Tag.Text = TagText;
Tag.displayName = 'Tag';
export default Tag;
//# sourceMappingURL=tag.js.map