import { __assign, __read } from "tslib";
import * as React from 'react';
import { usePlatform } from '../../utils/platform';
import { ConfigProvider, ImagePreview } from 'tea-component';
export function ImageInner(_a) {
    var objectFit = _a.objectFit, style = _a.style, className = _a.className, alt = _a.alt, src = _a.src, setIsError = _a.setIsError, events = _a.events, lazyLoad = _a.lazyLoad, maskClosable = _a.maskClosable, imgPreview = _a.imgPreview;
    var platform = usePlatform();
    var _b = __read(React.useState(false), 2), imgShow = _b[0], setImgShow = _b[1];
    var onMaskClick = function () {
        if (maskClosable) {
            setImgShow(false);
        }
    };
    if (platform === 'h5' || !imgPreview) {
        return (React.createElement(React.Fragment, null,
            React.createElement("img", { style: __assign({ objectFit: objectFit }, style), className: className, alt: alt, src: src, onLoad: function (e) {
                    setIsError(false);
                    events.load && events.load({}, { originEvent: e });
                }, onError: function (e) {
                    setIsError(true);
                    events.error && events.error({}, { originEvent: e });
                }, onClick: function () {
                    if (imgPreview) {
                        setImgShow(true);
                    }
                }, loading: lazyLoad ? 'lazy' : undefined }),
            imgShow && (React.createElement("div", { className: "weda-img-mask", onClick: onMaskClick },
                React.createElement("div", { onClick: function () { return setImgShow(false); }, className: "weda-img-modal-close-btn" },
                    React.createElement("i", { className: "weui-icon-clear", style: { color: 'white' } })),
                React.createElement("div", { className: "weda-img-preview", style: {
                        backgroundImage: "url(" + src + ")",
                    } })))));
    }
    else {
        return (React.createElement(ConfigProvider, { classPrefix: "wedatea2td" },
            React.createElement(ImagePreview, { previewSrc: src, lazyLoad: true, maskClosable: maskClosable, className: className, style: __assign(__assign({}, style), { objectFit: objectFit }) }, function (open) { return (React.createElement("img", { style: __assign({ objectFit: objectFit, cursor: 'zoom-in' }, style), className: className, alt: alt, src: src, onLoad: function (e) {
                    setIsError(false);
                    events.load && events.load({}, { originEvent: e });
                }, onError: function (e) {
                    setIsError(true);
                    events.error && events.error({}, { originEvent: e });
                }, loading: lazyLoad ? 'lazy' : undefined, onClick: open })); })));
    }
}
//# sourceMappingURL=image.js.map