"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = (0, tslib_1.__importStar)(require("react"));
var react_1 = require("react");
var classnames_1 = (0, tslib_1.__importDefault)(require("../../utils/classnames"));
require("./index.css");
var image_1 = require("./image");
function Image(_a) {
    var _b;
    var 
    // 系统属性
    className = _a.className, _c = _a.events, events = _c === void 0 ? {} : _c, style = _a.style, 
    // 组件属性
    src = _a.src, alt = _a.alt, mode = _a.mode, lazyLoad = _a.lazyLoad, imgPreview = _a.imgPreview, maskClosable = _a.maskClosable, fit = _a.fit;
    var _d = (0, tslib_1.__read)((0, react_1.useState)(false), 2), isError = _d[0], setIsError = _d[1];
    var cls = (0, classnames_1.default)((_b = {
            'weda-ui': true,
            'weda-image': true,
            'weda-image-error': isError
        },
        _b[className] = className,
        _b));
    var objectFit = fit || getObjectFitByWxImageMode(mode);
    var _e = (0, tslib_1.__read)((0, react_1.useState)(/^cloud:\/\//.test(src) ? undefined : src), 2), realSrc = _e[0], setRealSrc = _e[1];
    (0, react_1.useEffect)(function () {
        if (/^cloud:\/\//.test(src)) {
            window.app.cloud
                .getTempFileURL(src)
                .then(function (res) {
                setRealSrc(res || '');
            })
                .catch(function () {
                setRealSrc('');
            });
        }
        else {
            setRealSrc(src);
        }
    }, [src]);
    return src === realSrc || (realSrc !== undefined && src !== realSrc) ? (React.createElement(image_1.ImageInner, { objectFit: objectFit, style: style, className: cls, alt: alt, src: realSrc, setIsError: setIsError, events: events, lazyLoad: lazyLoad, imgPreview: imgPreview, maskClosable: maskClosable })) : null;
}
exports.default = Image;
function getObjectFitByWxImageMode(mode) {
    var array = [
        {
            mode: 'scaleToFill',
            h5: 'fill',
        },
        {
            mode: 'aspectFit',
            h5: 'contain',
        },
        {
            mode: 'aspectFill',
            h5: 'cover',
        },
        {
            mode: 'widthFix',
            h5: 'cover',
        },
        {
            mode: 'heightFix',
            h5: 'contain',
        },
    ];
    var item = array.find(function (item) { return item.mode === mode; });
    return item === null || item === void 0 ? void 0 : item.h5;
}
//# sourceMappingURL=index.js.map