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

import { __extends, __rest, __assign, __decorate, __metadata } from 'tslib';
import { mapTree, autobind, themeable, localeable, uncontrollable } from 'amis-core';
import React__default from 'react';
import ResultBox from './ResultBox.js';
import { Icon } from './icons.js';
import PickerContainer from './PickerContainer.js';
import TabsTransfer from './TabsTransfer.js';

var TransferPicker = /** @class */ (function (_super) {
    __extends(TransferPicker, _super);
    function TransferPicker() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.optionModified = false;
        return _this;
    }
    TransferPicker.prototype.handleConfirm = function (value) {
        var _a, _b;
        (_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, value, this.optionModified);
        this.optionModified = false;
    };
    TransferPicker.prototype.onFocus = function () {
        var _a, _b;
        (_b = (_a = this.props).onFocus) === null || _b === void 0 ? void 0 : _b.call(_a);
    };
    TransferPicker.prototype.onBlur = function () {
        var _a, _b;
        (_b = (_a = this.props).onBlur) === null || _b === void 0 ? void 0 : _b.call(_a);
    };
    TransferPicker.prototype.render = function () {
        var _this = this;
        var _a = this.props, cx = _a.classnames, value = _a.value, __ = _a.translate, disabled = _a.disabled, className = _a.className, onChange = _a.onChange, size = _a.size, _b = _a.labelField, labelField = _b === void 0 ? 'label' : _b, mobileUI = _a.mobileUI, popOverContainer = _a.popOverContainer, maxTagCount = _a.maxTagCount, overflowTagPopover = _a.overflowTagPopover, placeholder = _a.placeholder, rest = __rest(_a, ["classnames", "value", "translate", "disabled", "className", "onChange", "size", "labelField", "mobileUI", "popOverContainer", "maxTagCount", "overflowTagPopover", "placeholder"]);
        return (React__default.createElement(PickerContainer, { title: __('Select.placeholder'), mobileUI: mobileUI, popOverContainer: popOverContainer, onFocus: this.onFocus, onClose: this.onBlur, bodyRender: function (_a) {
                _a.onClose; var value = _a.value, onChange = _a.onChange, setState = _a.setState, states = __rest(_a, ["onClose", "value", "onChange", "setState"]);
                return (React__default.createElement(TabsTransfer, __assign({}, rest, states, { value: value, mobileUI: mobileUI, onChange: function (value, optionModified) {
                        if (optionModified) {
                            var options = mapTree(rest.options, function (item) {
                                return (value.find(function (a) { return a.value === item.value; }) || item);
                            });
                            _this.optionModified = true;
                            setState({ options: options, value: value });
                        }
                        else {
                            onChange(value);
                        }
                    }, labelField: labelField })));
            }, value: value, onConfirm: this.handleConfirm, size: size }, function (_a) {
            var onClick = _a.onClick, isOpened = _a.isOpened;
            return (React__default.createElement(ResultBox, { className: cx('TransferPicker', className, isOpened ? 'is-active' : ''), allowInput: false, result: value, onResultChange: onChange, onResultClick: onClick, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : __('Select.placeholder'), disabled: disabled, itemRender: function (option) { return (React__default.createElement("span", null, (option && option[labelField]) || 'undefiend')); }, mobileUI: mobileUI, maxTagCount: maxTagCount, overflowTagPopover: overflowTagPopover }, !mobileUI ? (React__default.createElement("span", { className: cx('TransferPicker-icon') },
                React__default.createElement(Icon, { icon: "pencil", className: "icon" }))) : null));
        }));
    };
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], TransferPicker.prototype, "handleConfirm", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], TransferPicker.prototype, "onFocus", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], TransferPicker.prototype, "onBlur", null);
    return TransferPicker;
}(React__default.Component));
var TabsTransferPicker = themeable(localeable(uncontrollable(TransferPicker, {
    value: 'onChange'
})));

export { TransferPicker, TabsTransferPicker as default };
