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

import { __extends, __assign } from 'tslib';
import React__default from 'react';
import { findDOMNode } from 'react-dom';
import { Overlay, PopOver, themeable, localeable } from 'amis-core';

/**
 * @file table/HeadCellDropDown
 * @author fex
 */
var HeadCellDropDown = /** @class */ (function (_super) {
    __extends(HeadCellDropDown, _super);
    function HeadCellDropDown(props) {
        var _this = _super.call(this, props) || this;
        _this.state = {
            isOpened: false
        };
        _this.openLayer = _this.openLayer.bind(_this);
        _this.closeLayer = _this.closeLayer.bind(_this);
        return _this;
    }
    HeadCellDropDown.prototype.render = function () {
        var _this = this;
        var isOpened = this.state.isOpened;
        var _a = this.props, popOverContainer = _a.popOverContainer, active = _a.active, className = _a.className, layerClassName = _a.layerClassName, filterIcon = _a.filterIcon, filterDropdown = _a.filterDropdown, cx = _a.classnames, ns = _a.classPrefix;
        return (React__default.createElement("span", { className: cx(className, active ? 'is-active' : '') },
            React__default.createElement("span", { onClick: this.openLayer }, filterIcon && typeof filterIcon === 'function'
                ? filterIcon(active)
                : filterIcon || null),
            isOpened ? (React__default.createElement(Overlay, { container: popOverContainer || (function () { return findDOMNode(_this); }), placement: "left-bottom-left-top right-bottom-right-top", target: popOverContainer ? function () { return findDOMNode(_this).parentNode; } : null, show: true },
                React__default.createElement(PopOver, { classPrefix: ns, onHide: this.closeLayer, className: cx(layerClassName), overlay: true }, filterDropdown && typeof filterDropdown === 'function'
                    ? filterDropdown(__assign(__assign({}, this.props), { confirm: function (payload) {
                            if (!(payload && payload.closeDropdown === false)) {
                                _this.closeLayer();
                            }
                        } }))
                    : React__default.isValidElement(filterDropdown)
                        ? filterDropdown
                        : null))) : null));
    };
    HeadCellDropDown.prototype.openLayer = function () {
        this.setState({ isOpened: true });
    };
    HeadCellDropDown.prototype.closeLayer = function () {
        this.setState({ isOpened: false });
    };
    return HeadCellDropDown;
}(React__default.PureComponent));
var HeadCellDropDown$1 = themeable(localeable(HeadCellDropDown));

export { HeadCellDropDown, HeadCellDropDown$1 as default };
