/**
 * amis-ui v6.14.0-beta.1
 * Copyright 2018-2025 fex
 */

import { __extends, __assign, __decorate, __metadata } from 'tslib';
import React__default from 'react';
import { autobind, noop, themeable } from 'amis-core';
import { Icon } from './icons.js';

/**
 * @file Tag
 */
var PRESET_COLOR = [
    'inactive',
    'active',
    'success',
    'processing',
    'error',
    'warning'
];
var Tag = /** @class */ (function (_super) {
    __extends(Tag, _super);
    function Tag() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Tag.prototype.renderCloseIcon = function () {
        var _a = this.props, closeIcon = _a.closeIcon, cx = _a.classnames, closable = _a.closable;
        if (!closable) {
            return null;
        }
        var icon = React__default.createElement(Icon, { cx: cx, icon: closeIcon || 'close', className: "icon" });
        return (React__default.createElement("span", { className: cx("Tag--close"), onClick: this.handleClose }, icon));
    };
    Tag.prototype.handleClose = function (e) {
        var onClose = this.props.onClose;
        e.stopPropagation();
        onClose === null || onClose === void 0 ? void 0 : onClose(e);
    };
    Tag.prototype.handleClick = function (e) {
        var onClick = this.props.onClick;
        onClick === null || onClick === void 0 ? void 0 : onClick(e);
    };
    Tag.prototype.handleMouseEnter = function (e) {
        var onMouseEnter = this.props.onMouseEnter;
        onMouseEnter === null || onMouseEnter === void 0 ? void 0 : onMouseEnter(e);
    };
    Tag.prototype.handleMouseLeave = function (e) {
        var onMouseLeave = this.props.onMouseLeave;
        onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave(e);
    };
    Tag.prototype.render = function () {
        var _a;
        var _b = this.props, children = _b.children, cx = _b.classnames, className = _b.className, displayMode = _b.displayMode, disabled = _b.disabled, color = _b.color, icon = _b.icon, style = _b.style, label = _b.label, dataIndex = _b.dataIndex;
        var isPresetColor = color && PRESET_COLOR.indexOf(color) !== -1;
        var customColor = color && !isPresetColor ? color : undefined;
        var tagStyle = __assign({ backgroundColor: displayMode === 'normal' ? customColor : undefined, borderColor: displayMode === 'rounded' ? customColor : undefined, color: displayMode === 'rounded' ? customColor : undefined }, style);
        var prevIcon;
        if (displayMode === 'status') {
            var iconItem = void 0;
            if (icon) {
                iconItem = React__default.createElement(Icon, { icon: icon, className: "icon" });
            }
            if (!iconItem) {
                iconItem = (React__default.createElement(Icon, { icon: "dot", className: cx('icon', 'Tag-default-icon') }));
            }
            var prevIconStyle = customColor ? { style: { color: customColor } } : {};
            prevIcon = (React__default.createElement("span", __assign({ className: cx('Tag--prev') }, prevIconStyle), iconItem));
        }
        return (React__default.createElement("span", { className: cx('Tag', "Tag--".concat(displayMode), className, (_a = {},
                _a["Tag--".concat(displayMode, "--").concat(color)] = isPresetColor,
                _a["Tag--".concat(displayMode, "--hasColor")] = color,
                _a["Tag--disabled"] = disabled,
                _a)), style: tagStyle, onClick: this.handleClick, onMouseEnter: this.handleMouseEnter, onMouseLeave: this.handleMouseLeave, "data-index": dataIndex },
            React__default.createElement("span", { className: cx('Tag-text'), title: typeof label === 'string' ? label : undefined },
                prevIcon,
                label || children),
            this.renderCloseIcon()));
    };
    Tag.defaultProps = {
        displayMode: 'normal'
    };
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], Tag.prototype, "handleClose", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], Tag.prototype, "handleClick", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], Tag.prototype, "handleMouseEnter", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], Tag.prototype, "handleMouseLeave", null);
    return Tag;
}(React__default.Component));
var CheckableTagComp = /** @class */ (function (_super) {
    __extends(CheckableTagComp, _super);
    function CheckableTagComp() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    CheckableTagComp.prototype.handleClick = function (e) {
        var _a = this.props, onChange = _a.onChange, onClick = _a.onClick, checked = _a.checked;
        onChange === null || onChange === void 0 ? void 0 : onChange(!checked);
        onClick === null || onClick === void 0 ? void 0 : onClick(e);
    };
    CheckableTagComp.prototype.render = function () {
        var _a = this.props, cx = _a.classnames, className = _a.className, disabled = _a.disabled, label = _a.label, children = _a.children, checked = _a.checked, _b = _a.style, style = _b === void 0 ? {} : _b, dataIndex = _a.dataIndex;
        return (React__default.createElement("span", { className: cx(className, 'Tag', 'Tag--checkable', {
                'Tag--checkable--checked': checked,
                'Tag--checkable--disabled': disabled
            }), onClick: disabled ? noop : this.handleClick, style: style, title: typeof label === 'string' ? label : undefined, "data-index": dataIndex }, label || children));
    };
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], CheckableTagComp.prototype, "handleClick", null);
    return CheckableTagComp;
}(React__default.Component));
themeable(CheckableTagComp);
var Tag$1 = themeable(Tag);

export { Tag, Tag$1 as default };
