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

import { __extends, __assign, __decorate, __metadata } from 'tslib';
import { autobind, themeable, localeable, uncontrollable } from 'amis-core';
import { Transfer } from './Transfer.js';
import React__default from 'react';
import ResultBox from './ResultBox.js';
import { Icon } from './icons.js';
import InputBox from './InputBox.js';
import { PopOverContainer } from './PopOverContainer.js';

var TransferDropDown = /** @class */ (function (_super) {
    __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 (React__default.createElement(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 (React__default.createElement("div", { className: cx('TransferDropDown-content', {
                        'is-mobile': mobileUI
                    }) },
                    onSearch ? (React__default.createElement("div", { className: cx('Transfer-search') },
                        React__default.createElement(InputBox, { value: inputValue, onChange: _this.handleSearch, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : __('Transfer.searchKeyword'), clearable: false, onKeyDown: _this.handleSearchKeyDown, mobileUI: mobileUI }, searchResult !== null ? (React__default.createElement("a", { onClick: _this.handleSeachCancel },
                            React__default.createElement(Icon, { icon: "close", className: "icon" }))) : (React__default.createElement(Icon, { icon: "search", className: "icon" }))))) : null,
                    searchResult !== null
                        ? _this.renderSearchResult(__assign(__assign({}, _this.props), { value: _this.state.tempValue, onChange: function (value) { return _this.handleChange(value, onClose); }, multiple: multiple }))
                        : _this.renderOptions(__assign(__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 (React__default.createElement(ResultBox, { 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 }));
        }));
    };
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], TransferDropDown.prototype, "handleAfterPopoverHide", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object, Function]),
        __metadata("design:returntype", void 0)
    ], TransferDropDown.prototype, "handleChange", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], TransferDropDown.prototype, "onConfirm", null);
    return TransferDropDown;
}(Transfer));
var TransferDropDown$1 = themeable(localeable(uncontrollable(TransferDropDown, {
    value: 'onChange'
})));

export { TransferDropDown, TransferDropDown$1 as default };
