/*
 * Copyright 2016 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import classNames from "classnames";
import * as React from "react";
import { useInteractiveAttributes } from "../../accessibility/useInteractiveAttributes";
import { Classes, DISPLAYNAME_PREFIX, removeNonHTMLProps, Utils, } from "../../common";
import { isReactNodeEmpty } from "../../common/utils";
import { Icon } from "../icon/icon";
import { Text } from "../text/text";
import { TagRemoveButton } from "./tagRemoveButton";
/**
 * Tag component.
 *
 * @see https://blueprintjs.com/docs/#core/components/tag
 */
export const Tag = React.forwardRef((props, ref) => {
    const { children, className, fill = false, icon, intent, interactive, large = false, minimal = false, multiline, onRemove, rightIcon, round = false, tabIndex = 0, htmlTitle, ...htmlProps } = props;
    const isRemovable = Utils.isFunction(onRemove);
    const isInteractive = interactive ?? htmlProps.onClick != null;
    const [active, interactiveProps] = useInteractiveAttributes(isInteractive, props, ref, {
        defaultTabIndex: 0,
        disabledTabIndex: undefined,
    });
    const tagClasses = classNames(Classes.TAG, Classes.intentClass(intent), {
        [Classes.ACTIVE]: active,
        [Classes.FILL]: fill,
        [Classes.INTERACTIVE]: isInteractive,
        [Classes.LARGE]: large,
        [Classes.MINIMAL]: minimal,
        [Classes.ROUND]: round,
    }, className);
    return (React.createElement("span", { ...removeNonHTMLProps(htmlProps), ...interactiveProps, className: tagClasses },
        React.createElement(Icon, { icon: icon }),
        !isReactNodeEmpty(children) && (React.createElement(Text, { className: Classes.FILL, ellipsize: !multiline, tagName: "span", title: htmlTitle }, children)),
        React.createElement(Icon, { icon: rightIcon }),
        isRemovable && React.createElement(TagRemoveButton, { ...props })));
});
Tag.displayName = `${DISPLAYNAME_PREFIX}.Tag`;
//# sourceMappingURL=tag.js.map