/**
 * 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 Transfer = require('./Transfer.js');
var React = require('react');
var ResultBox = require('./ResultBox.js');
var icons = require('./icons.js');
var PickerContainer = require('./PickerContainer.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 TransferPicker = /** @class */ (function (_super) {
    tslib.__extends(TransferPicker, _super);
    function TransferPicker() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            tempValue: null
        };
        _this.optionModified = false;
        return _this;
    }
    TransferPicker.prototype.handleConfirm = function (value) {
        var _a, _b;
        this.setState({
            tempValue: null
        });
        (_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;
        this.setState({
            tempValue: null
        });
        (_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, onItemClick = _a.onItemClick, size = _a.size, borderMode = _a.borderMode, _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 = tslib.__rest(_a, ["classnames", "value", "translate", "disabled", "className", "onChange", "onItemClick", "size", "borderMode", "labelField", "mobileUI", "popOverContainer", "maxTagCount", "overflowTagPopover", "placeholder"]);
        var tp = {
            value: this.state.tempValue || value,
            onChange: function (value) {
                _this.setState({
                    tempValue: value
                });
            }
        };
        return (_J$X_(PickerContainer["default"], { title: __('Select.placeholder'), onFocus: this.onFocus, onClose: this.onBlur, mobileUI: mobileUI, popOverContainer: popOverContainer, bodyRender: function (_a) {
                _a.onClose; var value = _a.value; _a.onChange; var setState = _a.setState, states = tslib.__rest(_a, ["onClose", "value", "onChange", "setState"]);
                return (_J$X_(Transfer["default"], tslib.__assign({ mobileUI: mobileUI }, rest, states, { value: value, labelField: labelField, onChange: function (value, optionModified) {
                        if (optionModified) {
                            var options = amisCore.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 {
                            tp.onChange(value);
                        }
                    } })));
            }, value: tp.value, onConfirm: this.handleConfirm, size: size }, function (_a) {
            var onClick = _a.onClick, isOpened = _a.isOpened;
            return (_J$X_(ResultBox["default"], { className: cx('TransferPicker', className, isOpened ? 'is-active' : ''), allowInput: false, result: value, onItemClick: onItemClick, onResultChange: onChange, onResultClick: onClick, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : __('Select.placeholder'), disabled: disabled, borderMode: borderMode, itemRender: function (option) { return (_J$X_("span", null, (option && option[labelField]) || 'undefined')); }, mobileUI: mobileUI, maxTagCount: maxTagCount, overflowTagPopover: overflowTagPopover }, !mobileUI ? (_J$X_("span", { className: cx('TransferPicker-icon') },
                _J$X_(icons.Icon, { icon: "pencil", className: "icon" }))) : null));
        }));
    };
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], TransferPicker.prototype, "handleConfirm", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], TransferPicker.prototype, "onFocus", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], TransferPicker.prototype, "onBlur", null);
    return TransferPicker;
}(React__default["default"].Component));
var TransferPicker$1 = amisCore.themeable(amisCore.localeable(amisCore.uncontrollable(TransferPicker, {
    value: 'onChange'
})));

exports.TransferPicker = TransferPicker;
exports["default"] = TransferPicker$1;
