"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Tag", {
    enumerable: true,
    get: function() {
        return Tag;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
var _define_property = require("@swc/helpers/_/_define_property");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _components = require("@tarojs/components");
var _iconsreacttaro = require("@nutui/icons-react-taro");
var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames"));
var _typings = require("../../utils/typings");
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    type: 'default',
    background: '',
    color: '',
    plain: false,
    round: false,
    mark: false,
    closeable: false,
    closeIcon: null,
    onClose: function onClose(e) {},
    onClick: function onClick(e) {}
});
var Tag = function Tag(props) {
    var _$_object_spread = (0, _object_spread._)({}, defaultProps, props), className = _$_object_spread.className, style = _$_object_spread.style, background = _$_object_spread.background, plain = _$_object_spread.plain, type = _$_object_spread.type, round = _$_object_spread.round, children = _$_object_spread.children, mark = _$_object_spread.mark, closeable = _$_object_spread.closeable, closeIcon = _$_object_spread.closeIcon, color = _$_object_spread.color, onClick = _$_object_spread.onClick, onClose = _$_object_spread.onClose;
    var _useState = (0, _sliced_to_array._)((0, _react.useState)(true), 2), visible = _useState[0], setVisible = _useState[1];
    var classPrefix = 'nut-tag';
    var _obj;
    var classes = (0, _classnames.default)((_obj = {}, (0, _define_property._)(_obj, classPrefix, true), (0, _define_property._)(_obj, "".concat(classPrefix, "-").concat(type), type), (0, _define_property._)(_obj, "".concat(classPrefix, "-plain"), plain), (0, _define_property._)(_obj, "".concat(classPrefix, "-round"), round), (0, _define_property._)(_obj, "".concat(classPrefix, "-mark"), mark), (0, _define_property._)(_obj, "".concat(classPrefix, "-close"), closeable), (0, _define_property._)(_obj, "".concat(className), className), _obj));
    var handleClick = function handleClick(e) {
        onClick && onClick(e);
    };
    // 综合考虑 color、background、plain 组合使用时的效果
    var getStyle = function getStyle() {
        var style = {};
        // 标签背景与边框颜色
        if (plain) {
            style.borderColor = background;
        } else if (background) {
            style.backgroundColor = background;
        }
        return style;
    };
    var getTextStyle = function getTextStyle() {
        var style = {};
        // 标签内字体颜色
        if (color) {
            style.color = color;
        } else if (background && plain) {
            style.color = background;
        }
        return style;
    };
    var textClasses = (0, _classnames.default)("".concat(classPrefix, "-text"), (0, _define_property._)({}, "".concat(classPrefix, "-text-plain"), plain));
    return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, closeable ? visible && /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: classes,
        style: (0, _object_spread._)({}, style, getStyle()),
        onClick: function onClick(e) {
            return handleClick(e);
        }
    }, children && /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: textClasses,
        style: getTextStyle()
    }, children), closeIcon ? /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: "".concat(classPrefix, "-custom-icon"),
        onClick: function onClick(e) {
            setVisible(false);
            onClose && onClose(e);
        }
    }, closeIcon) : /*#__PURE__*/ _react.default.createElement(_iconsreacttaro.Close, {
        className: "".concat(classPrefix, "-close-icon"),
        onClick: function onClick(e) {
            setVisible(false);
            onClose && onClose(e);
        }
    })) : /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: classes,
        style: (0, _object_spread._)({}, style, getStyle()),
        onClick: function onClick(e) {
            return handleClick(e);
        }
    }, children && /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: textClasses,
        style: getTextStyle()
    }, children)));
};
Tag.displayName = 'NutTag';
