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

import { __extends, __assign, __decorate } from 'tslib';
import React from 'react';
import { getPropValue, resolveVariableAndFilter, isObject, createObject, Renderer } from 'amis-core';

var Each = /** @class */ (function (_super) {
    __extends(Each, _super);
    function Each() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Each.prototype.render = function () {
        var _a = this.props, data = _a.data, name = _a.name, className = _a.className, style = _a.style, render = _a.render, items = _a.items, placeholder = _a.placeholder, cx = _a.classnames, __ = _a.translate;
        var value = getPropValue(this.props, function (props) {
            return props.source && !props.name
                ? resolveVariableAndFilter(props.source, props.data, '| raw')
                : undefined;
        });
        var arr = isObject(value)
            ? Object.keys(value).map(function (key) { return ({
                key: key,
                value: value[key]
            }); })
            : Array.isArray(value)
                ? value
                : [];
        return (React.createElement("div", { className: cx('Each', className), style: style }, Array.isArray(arr) && arr.length && items ? (arr.map(function (item, index) {
            var _a;
            return render("item/".concat(index), items, {
                data: createObject(data, isObject(item)
                    ? __assign({ index: index }, item) : (_a = {}, _a[name] = item, _a.item = item, _a.index = index, _a)),
                key: index
            });
        })) : (React.createElement("div", { className: cx('Each-placeholder') }, render('placeholder', __(placeholder))))));
    };
    Each.propsList = ['name', 'items', 'value'];
    Each.defaultProps = {
        className: '',
        placeholder: 'placeholder.noData'
    };
    return Each;
}(React.Component));
/** @class */ ((function (_super) {
    __extends(EachRenderer, _super);
    function EachRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    EachRenderer = __decorate([
        Renderer({
            type: 'each'
        })
    ], EachRenderer);
    return EachRenderer;
})(Each));

export { Each as default };
