"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Context_1 = require("../../Context");
const getComponent_1 = require("../../getComponent");
const react_1 = tslib_1.__importDefault(require("react"));
// tslint:disable: jsdoc-format
/**
 * # 🖼 BlueBaseImage
 *
 * A drop in replacement for React Native's Image component.
 * Adds ability to display image stored in BlueBase Asset Registry.
 *
 * ## Usage
 * ```jsx
<BlueBaseImage resolve="Logo" />
<BlueBaseImage resolve={['LogoSquare', 'Logo']} />
```
 */
class BlueBaseImage extends react_1.default.PureComponent {
    render() {
        const _a = this.props, { resolve, source: _source } = _a, rest = tslib_1.__rest(_a, ["resolve", "source"]);
        const BB = this.context;
        let Asset;
        if (typeof _source === 'string') {
            Asset = BB.Assets.resolve(_source);
        }
        else if (Array.isArray(_source)) {
            const keys = _source.filter(s => typeof s === 'string');
            if (keys.length > 0) {
                Asset = BB.Assets.resolve(...keys);
            }
        }
        else if (resolve) {
            BB.Logger.warn('resolve prop in BlueBaseImage is deprecated. Use "source" instead');
            Asset = Array.isArray(resolve)
                ? BB.Assets.resolve(...resolve)
                : BB.Assets.get(resolve);
        }
        const source = Asset ? Asset.value : _source;
        return react_1.default.createElement(getComponent_1.Image, Object.assign({}, rest, { source }));
    }
}
BlueBaseImage.contextType = Context_1.BlueBaseContext;
BlueBaseImage.defaultProps = {
    args: {}
};
exports.BlueBaseImage = BlueBaseImage;
