/**
 * amis v3.1.0
 * Copyright 2018-2023 baidu
 */

import { __extends, __assign, __decorate } from 'tslib';
import React from 'react';
import merge from 'lodash/merge';
import { isPureVariable, resolveVariableAndFilter, buildStyle, Renderer } from 'amis-core';
import { DndContainer } from 'amis-ui';

var Container = /** @class */ (function (_super) {
    __extends(Container, _super);
    function Container() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Container.prototype.renderBody = function () {
        var _a = this.props, children = _a.children, body = _a.body, render = _a.render, cx = _a.classnames, bodyClassName = _a.bodyClassName, disabled = _a.disabled, wrapperBody = _a.wrapperBody;
        var isWrapperBody = wrapperBody !== null && wrapperBody !== void 0 ? wrapperBody : true;
        var containerBody = children
            ? typeof children === 'function'
                ? children(this.props)
                : children
            : body
                ? render('body', body, { disabled: disabled })
                : null;
        if (isWrapperBody) {
            return (React.createElement("div", { className: cx('Container-body', bodyClassName) }, containerBody));
        }
        else {
            return containerBody;
        }
    };
    Container.prototype.render = function () {
        var _a = this.props, className = _a.className, wrapperComponent = _a.wrapperComponent, size = _a.size, cx = _a.classnames, style = _a.style, data = _a.data, draggable = _a.draggable, draggableConfig = _a.draggableConfig;
        var finalDraggable = isPureVariable(draggable)
            ? resolveVariableAndFilter(draggable, data, '| raw')
            : draggable;
        var finalDraggableConfig = merge(Container.defaultProps.draggableConfig, isPureVariable(draggableConfig)
            ? resolveVariableAndFilter(draggableConfig, data, '| raw')
            : draggableConfig);
        var Component = wrapperComponent || 'div';
        var contentDom = (React.createElement(Component, { className: cx('Container', size && size !== 'none' ? "Container--".concat(size) : '', className), style: buildStyle(style, data) }, this.renderBody()));
        return finalDraggable ? (React.createElement(DndContainer, __assign({}, finalDraggableConfig, { draggable: true }), contentDom)) : (contentDom);
    };
    Container.propsList = ['body', 'className'];
    Container.defaultProps = {
        className: '',
        draggableConfig: {
            axis: 'both',
            scale: 1,
            enableUserSelect: false
        }
    };
    return Container;
}(React.Component));
/** @class */ ((function (_super) {
    __extends(ContainerRenderer, _super);
    function ContainerRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ContainerRenderer = __decorate([
        Renderer({
            type: 'container'
        })
    ], ContainerRenderer);
    return ContainerRenderer;
})(Container));

export { Container as default };
