/**
 * amis-ui v6.12.0-beta.0
 * Copyright 2018-2025 fex
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var tslib = require('tslib');
var React = require('react');
var ReactDOM = require('react-dom');
var amisCore = require('amis-core');

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 HeadCellDropDown = /** @class */ (function (_super) {
    tslib.__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 (_J$X_("span", { className: cx(className, active ? 'is-active' : '') },
            _J$X_("span", { onClick: this.openLayer }, filterIcon && typeof filterIcon === 'function'
                ? filterIcon(active)
                : filterIcon || null),
            isOpened ? (_J$X_(amisCore.Overlay, { container: popOverContainer || (function () { return ReactDOM.findDOMNode(_this); }), placement: "left-bottom-left-top right-bottom-right-top", target: popOverContainer ? function () { return ReactDOM.findDOMNode(_this).parentNode; } : null, show: true },
                _J$X_(amisCore.PopOver, { classPrefix: ns, onHide: this.closeLayer, className: cx(layerClassName), overlay: true }, filterDropdown && typeof filterDropdown === 'function'
                    ? filterDropdown(tslib.__assign(tslib.__assign({}, this.props), { confirm: function (payload) {
                            if (!(payload && payload.closeDropdown === false)) {
                                _this.closeLayer();
                            }
                        } }))
                    : React__default["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["default"].PureComponent));
var HeadCellDropDown$1 = amisCore.themeable(amisCore.localeable(HeadCellDropDown));

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