"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importDefault(require("react"));
var factory_1 = require("../factory");
var tpl_builtin_1 = require("../utils/tpl-builtin");
var Image_1 = tslib_1.__importDefault(require("./Image"));
var ImagesField = /** @class */ (function (_super) {
    tslib_1.__extends(ImagesField, _super);
    function ImagesField() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ImagesField.prototype.render = function () {
        var _a = this.props, className = _a.className, defaultImage = _a.defaultImage, thumbMode = _a.thumbMode, thumbRatio = _a.thumbRatio, data = _a.data, name = _a.name, value = _a.value, placeholder = _a.placeholder, cx = _a.classnames, source = _a.source, delimiter = _a.delimiter;
        var list;
        if (typeof source === 'string' && tpl_builtin_1.isPureVariable(source)) {
            list = tpl_builtin_1.resolveVariable(source, data) || undefined;
        }
        else if (Array.isArray(value)) {
            list = value;
        }
        else if (name && data[name]) {
            list = data[name];
        }
        if (typeof list === 'string') {
            list = list.split(delimiter);
        }
        else if (list && !Array.isArray(list)) {
            list = [list];
        }
        return (react_1.default.createElement("div", { className: cx('ImagesField', className) }, Array.isArray(list) ? (react_1.default.createElement("div", { className: cx('Images') }, list.map(function (item, index) { return (react_1.default.createElement(Image_1.default, { className: cx('Images-item'), key: index, src: (item && item.image) || item, title: item && item.title, description: item && item.description, thumbMode: thumbMode, thumbRatio: thumbRatio })); }))) : defaultImage ? (react_1.default.createElement(Image_1.default, { className: cx('Images-item'), src: defaultImage, thumbMode: thumbMode, thumbRatio: thumbRatio })) : (placeholder)));
    };
    ImagesField.defaultProps = {
        className: '',
        delimiter: ',',
        defaultImage: 'https://fex.bdstatic.com/n/static/amis/renderers/crud/field/placeholder_cfad9b1.png',
        placehoder: '-',
        thumbMode: 'contain',
        thumbRatio: '1-1'
    };
    return ImagesField;
}(react_1.default.Component));
exports.ImagesField = ImagesField;
var ImagesFieldRenderer = /** @class */ (function (_super) {
    tslib_1.__extends(ImagesFieldRenderer, _super);
    function ImagesFieldRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ImagesFieldRenderer = tslib_1.__decorate([
        factory_1.Renderer({
            test: /(^|\/)images$/
        })
    ], ImagesFieldRenderer);
    return ImagesFieldRenderer;
}(ImagesField));
exports.ImagesFieldRenderer = ImagesFieldRenderer;
//# sourceMappingURL=./renderers/Images.js.map
