"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tag = exports.TagBase = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const core_1 = require("../core");
const utils_1 = require("../utils");
const context_1 = require("./context");
const tagButton_1 = __importDefault(require("./tagButton"));
const tagIcon_1 = __importDefault(require("./tagIcon"));
const tagText_1 = __importDefault(require("./tagText"));
exports.TagBase = core_1.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.
 */
exports.Tag = (0, core_1.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 } = props, rest = __rest(props, ["casing", "children", "className", "disabled", "icon", "iconLeft", "iconRight", "isFullWidth", "isInteractive", "isRound", "isTruncated", "itemLeft", "itemRight", "onClick", "onDelete", "size", "text", "variant", "weight"]);
    const styles = (0, core_1.useStyleConfig)('Tag', props);
    const _a = styles.container, { activeBg, h, hoverBg, spaceX: spaceXBase = 0 } = _a, tagStyles = __rest(_a, ["activeBg", "h", "hoverBg", "spaceX"]);
    const context = (0, react_1.useMemo)(() => (0, utils_1.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 = (0, utils_1.filterUndefined)({
        borderRadius: isRound ? h / 2 : undefined,
        'aria-disabled': disabled,
        fontWeight: weight,
        textTransform: casing,
        w: isFullWidth ? '100%' : undefined,
    });
    return ((0, jsx_runtime_1.jsx)(context_1.TagProvider, { value: context, children: (0, jsx_runtime_1.jsxs)(exports.TagBase, Object.assign({ className: (0, utils_1.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: [(0, utils_1.isString)(icon) ? (0, jsx_runtime_1.jsx)(tagIcon_1.default, { name: icon }) : icon, !icon && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [itemLeft, (0, utils_1.isString)(iconLeft) ? (0, jsx_runtime_1.jsx)(tagIcon_1.default, { mr: spaceX, name: iconLeft }) : iconLeft, children !== null && children !== void 0 ? children : ((0, utils_1.isReactText)(text) ? (0, jsx_runtime_1.jsx)(tagText_1.default, { isTruncated, text }) : text), (0, utils_1.isString)(iconRight) ? (0, jsx_runtime_1.jsx)(tagIcon_1.default, { ml: spaceX, name: iconRight }) : iconRight, onDelete ? ((0, jsx_runtime_1.jsx)(tagButton_1.default, { "aria-label": "delete", disabled: disabled, isRound: isRound, ml: spaceX, onClick: e => onDelete === null || onDelete === void 0 ? void 0 : onDelete(e) })) : (itemRight)] }))] })) }));
});
exports.Tag.Button = tagButton_1.default;
exports.Tag.Icon = tagIcon_1.default;
exports.Tag.Text = tagText_1.default;
exports.Tag.displayName = 'Tag';
exports.default = exports.Tag;
//# sourceMappingURL=tag.js.map