/**
 * amis-ui v6.14.0-beta.1
 * 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');
require('react');
var ResultBox = require('./ResultBox.js');
var icons = require('./icons.js');
var InputBox = require('./InputBox.js');
var PopOverContainer = require('./PopOverContainer.js');

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
var TransferDropDown = /** @class */ (function (_super) {
    tslib.__extends(TransferDropDown, _super);
    function TransferDropDown(props) {
        var _this = _super.call(this, props) || this;
        _this.state = {
            tempValue: props.value,
            inputValue: '',
            searchResult: null,
            isTreeDeferLoad: false,
            resultSelectMode: 'list'
        };
        return _this;
    }
    TransferDropDown.prototype.componentDidUpdate = function (prevProps) {
        if (this.props.value !== prevProps.value) {
            this.setState({
                tempValue: this.props.value
            });
        }
    };
    TransferDropDown.prototype.handleAfterPopoverHide = function () {
        this.setState({ inputValue: '', searchResult: null });
    };
    TransferDropDown.prototype.handleChange = function (value, onClose) {
        var _a = this.props, multiple = _a.multiple, onChange = _a.onChange, mobileUI = _a.mobileUI;
        if (mobileUI) {
            this.setState({ tempValue: value });
        }
        else {
            onChange === null || onChange === void 0 ? void 0 : onChange(value);
            if (!multiple) {
                onClose();
            }
        }
    };
    TransferDropDown.prototype.onConfirm = function () {
        var onChange = this.props.onChange;
        onChange === null || onChange === void 0 ? void 0 : onChange(this.state.tempValue);
    };
    TransferDropDown.prototype.render = function () {
        var _this = this;
        var _a = this.props, cx = _a.classnames, value = _a.value, itemRender = _a.itemRender, __ = _a.translate, disabled = _a.disabled, clearable = _a.clearable, className = _a.className, onChange = _a.onChange, onSearch = _a.onSearch, multiple = _a.multiple, borderMode = _a.borderMode, mobileUI = _a.mobileUI, popOverContainer = _a.popOverContainer, placeholder = _a.placeholder, maxTagCount = _a.maxTagCount, overflowTagPopover = _a.overflowTagPopover; _a.itemHeight; _a.virtualThreshold; var showInvalidMatch = _a.showInvalidMatch, overlay = _a.overlay;
        var _b = this.state, inputValue = _b.inputValue, searchResult = _b.searchResult;
        return (_J$X_(PopOverContainer.PopOverContainer, { onAfterHide: this.handleAfterPopoverHide, mobileUI: mobileUI, popOverContainer: popOverContainer, overlayWidth: overlay && (overlay === null || overlay === void 0 ? void 0 : overlay.width), align: overlay && (overlay === null || overlay === void 0 ? void 0 : overlay.align), popOverClassName: cx('TransferDropDown-popover'), showConfirm: true, onConfirm: this.onConfirm, popOverRender: function (_a) {
                var onClose = _a.onClose;
                return (_J$X_("div", { className: cx('TransferDropDown-content', {
                        'is-mobile': mobileUI
                    }) },
                    onSearch ? (_J$X_("div", { className: cx('Transfer-search') },
                        _J$X_(InputBox["default"], { value: inputValue, onChange: _this.handleSearch, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : __('Transfer.searchKeyword'), clearable: false, onKeyDown: _this.handleSearchKeyDown, mobileUI: mobileUI }, searchResult !== null ? (_J$X_("a", { onClick: _this.handleSeachCancel },
                            _J$X_(icons.Icon, { icon: "close", className: "icon" }))) : (_J$X_(icons.Icon, { icon: "search", className: "icon" }))))) : null,
                    searchResult !== null
                        ? _this.renderSearchResult(tslib.__assign(tslib.__assign({}, _this.props), { value: _this.state.tempValue, onChange: function (value) { return _this.handleChange(value, onClose); }, multiple: multiple }))
                        : _this.renderOptions(tslib.__assign(tslib.__assign({}, _this.props), { value: _this.state.tempValue, onChange: function (value) { return _this.handleChange(value, onClose); }, multiple: multiple }))));
            } }, function (_a) {
            var onClick = _a.onClick, isOpened = _a.isOpened, ref = _a.ref;
            return (_J$X_(ResultBox["default"], { className: cx('TransferDropDown', className, isOpened ? 'is-opened' : ''), borderMode: borderMode, allowInput: false, result: multiple ? value : (value === null || value === void 0 ? void 0 : value[0]) ? value === null || value === void 0 ? void 0 : value[0] : null, onResultChange: onChange, onResultClick: onClick, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : __('Select.placeholder'), disabled: disabled, clearable: clearable, maxTagCount: maxTagCount, overflowTagPopover: overflowTagPopover, popOverContainer: popOverContainer, ref: ref, itemRender: itemRender, mobileUI: mobileUI, hasDropDownArrow: !mobileUI, showInvalidMatch: showInvalidMatch }));
        }));
    };
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], TransferDropDown.prototype, "handleAfterPopoverHide", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object, Function]),
        tslib.__metadata("design:returntype", void 0)
    ], TransferDropDown.prototype, "handleChange", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], TransferDropDown.prototype, "onConfirm", null);
    return TransferDropDown;
}(Transfer.Transfer));
var TransferDropDown$1 = amisCore.themeable(amisCore.localeable(amisCore.uncontrollable(TransferDropDown, {
    value: 'onChange'
})));

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