/**
 * amis-ui v6.12.0-beta.0
 * Copyright 2018-2025 fex
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var tslib = require('tslib');
var amisCore = require('amis-core');
var React = require('react');
var icons = require('../icons.js');
var Group = require('./Group.js');
var Item = require('./Item.js');
var Picker = require('../formula/Picker.js');
var Button = require('../Button.js');
var TooltipWrapper = require('../TooltipWrapper.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
var CBGroupOrItem = /** @class */ (function (_super) {
    tslib.__extends(CBGroupOrItem, _super);
    function CBGroupOrItem() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            hover: false
        };
        return _this;
    }
    CBGroupOrItem.prototype.handleItemChange = function (value) {
        this.props.onChange(value, this.props.index);
    };
    CBGroupOrItem.prototype.handleItemRemove = function () {
        var _a, _b;
        (_b = (_a = this.props).onRemove) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.index);
    };
    CBGroupOrItem.prototype.handlerHoverIn = function (e) {
        if (this.props.mobileUI) {
            return;
        }
        e.stopPropagation();
        this.setState({
            hover: true
        });
    };
    CBGroupOrItem.prototype.handlerHoverOut = function (e) {
        this.setState({
            hover: false
        });
    };
    CBGroupOrItem.prototype.handleIfChange = function (condition) {
        var value = tslib.__assign(tslib.__assign({}, this.props.value), { if: condition });
        this.props.onChange(value, this.props.index);
    };
    CBGroupOrItem.prototype.render = function () {
        var _a = this.props, builderMode = _a.builderMode, cx = _a.classnames, fieldClassName = _a.fieldClassName, value = _a.value, config = _a.config, fields = _a.fields, funcs = _a.funcs, draggable = _a.draggable, data = _a.data, disabled = _a.disabled, searchable = _a.searchable, onDragStart = _a.onDragStart, formula = _a.formula, popOverContainer = _a.popOverContainer, selectMode = _a.selectMode, renderEtrValue = _a.renderEtrValue, isCollapsed = _a.isCollapsed, depth = _a.depth, isAddBtnVisibleOn = _a.isAddBtnVisibleOn, isAddGroupBtnVisibleOn = _a.isAddGroupBtnVisibleOn, showIf = _a.showIf, formulaForIf = _a.formulaForIf, testIdBuilder = _a.testIdBuilder, mobileUI = _a.mobileUI;
        return (_J$X_("div", { className: cx("CBGroupOrItem".concat(builderMode === 'simple' ? '-simple' : ''), { 'is-mobile': mobileUI }), "data-id": value === null || value === void 0 ? void 0 : value.id },
            _J$X_("div", { className: cx('CBGroupOrItem-body') }, (value === null || value === void 0 ? void 0 : value.conjunction) ? (_J$X_("div", { className: cx('CBGroupOrItem-body-group', {
                    'is-hover': this.state.hover || mobileUI
                }), onMouseOver: this.handlerHoverIn, onMouseOut: this.handlerHoverOut },
                draggable && !disabled ? (_J$X_("a", { draggable: true, onDragStart: onDragStart, className: cx('CBGroupOrItem-dragbar') },
                    _J$X_(icons.Icon, { icon: "drag-bar", className: "icon" }))) : null,
                _J$X_(Group["default"], { isCollapsed: isCollapsed, draggable: draggable, disabled: disabled, searchable: searchable, selectMode: selectMode, onDragStart: onDragStart, config: config, fields: fields, formula: formula, value: value, onChange: this.handleItemChange, fieldClassName: fieldClassName, funcs: funcs, removeable: true, onRemove: this.handleItemRemove, data: data, renderEtrValue: renderEtrValue, depth: depth + 1, isAddBtnVisibleOn: isAddBtnVisibleOn, isAddGroupBtnVisibleOn: isAddGroupBtnVisibleOn, showIf: showIf, formulaForIf: formulaForIf, testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild("sub-".concat(depth)) }))) : (_J$X_("div", { className: cx('CBGroupOrItem-body-item') },
                draggable && !disabled ? (_J$X_("a", { draggable: true, onDragStart: onDragStart, className: cx('CBGroupOrItem-dragbar') },
                    _J$X_(icons.Icon, { icon: "drag-bar", className: "icon" }))) : null,
                _J$X_(Item["default"], { disabled: disabled, searchable: searchable, config: config, fields: fields, value: value, onChange: this.handleItemChange, fieldClassName: fieldClassName, funcs: funcs, data: data, formula: formula, popOverContainer: popOverContainer, renderEtrValue: renderEtrValue, selectMode: selectMode, testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild("cItem") }),
                showIf ? (_J$X_(Picker["default"], tslib.__assign({}, formulaForIf, { evalMode: true, mixedMode: false, header: "\u8BBE\u7F6E\u6761\u4EF6", value: (value === null || value === void 0 ? void 0 : value.if) || '', onChange: this.handleIfChange }), function (_a) {
                    var onClick = _a.onClick;
                    return (_J$X_(TooltipWrapper["default"], { tooltip: '配置启动条件，当前规则只有在此条件成立时才会生效', tooltipTheme: "dark", container: popOverContainer },
                        _J$X_("a", { className: cx('CBIf', (value === null || value === void 0 ? void 0 : value.if) ? 'is-active' : ''), onClick: onClick },
                            _J$X_(icons.Icon, { icon: "if", className: "icon" }))));
                })) : null,
                _J$X_(Button["default"], { className: cx('CBDelete'), onClick: this.handleItemRemove, disabled: disabled, level: "link", testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild("delete") },
                    _J$X_(icons.Icon, { icon: "remove", className: "icon" })))))));
    };
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], CBGroupOrItem.prototype, "handleItemChange", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], CBGroupOrItem.prototype, "handleItemRemove", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], CBGroupOrItem.prototype, "handlerHoverIn", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], CBGroupOrItem.prototype, "handlerHoverOut", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [String]),
        tslib.__metadata("design:returntype", void 0)
    ], CBGroupOrItem.prototype, "handleIfChange", null);
    return CBGroupOrItem;
}(React__default["default"].Component));
var GroupOrItem = amisCore.themeable(CBGroupOrItem);

exports.CBGroupOrItem = CBGroupOrItem;
exports["default"] = GroupOrItem;
