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

'use strict';

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

var tslib = require('tslib');
var React = require('react');
var merge = require('lodash/merge');
var amisCore = require('amis-core');
var amisUi = require('amis-ui');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var merge__default = /*#__PURE__*/_interopDefaultLegacy(merge);

var Container = /** @class */ (function (_super) {
    tslib.__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__default["default"].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 = amisCore.isPureVariable(draggable)
            ? amisCore.resolveVariableAndFilter(draggable, data, '| raw')
            : draggable;
        var finalDraggableConfig = merge__default["default"](Container.defaultProps.draggableConfig, amisCore.isPureVariable(draggableConfig)
            ? amisCore.resolveVariableAndFilter(draggableConfig, data, '| raw')
            : draggableConfig);
        var Component = wrapperComponent || 'div';
        var contentDom = (React__default["default"].createElement(Component, { className: cx('Container', size && size !== 'none' ? "Container--".concat(size) : '', className), style: amisCore.buildStyle(style, data) }, this.renderBody()));
        return finalDraggable ? (React__default["default"].createElement(amisUi.DndContainer, tslib.__assign({}, finalDraggableConfig, { draggable: true }), contentDom)) : (contentDom);
    };
    Container.propsList = ['body', 'className'];
    Container.defaultProps = {
        className: '',
        draggableConfig: {
            axis: 'both',
            scale: 1,
            enableUserSelect: false
        }
    };
    return Container;
}(React__default["default"].Component));
/** @class */ ((function (_super) {
    tslib.__extends(ContainerRenderer, _super);
    function ContainerRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ContainerRenderer = tslib.__decorate([
        amisCore.Renderer({
            type: 'container'
        })
    ], ContainerRenderer);
    return ContainerRenderer;
})(Container));

exports["default"] = Container;
