import * as React from 'react';
import isPlainObject from 'lodash/isPlainObject';
import { CnImageViewer } from '@cainiaofe/cn-ui';
import { renderLine } from './utils/text-render';
export function createImageTextFormat() {
    return () => {
        return {
            align: 'left',
            cell(val) {
                const previewImg = (url) => {
                    CnImageViewer.open({ src: url });
                };
                if (isPlainObject(val)) {
                    const { url = '', title = '', content = '' } = val;
                    return (React.createElement("div", { className: 'cn-table-cell-format-image-text' },
                        React.createElement("img", { className: 'ctfit-img', src: url, onClick: () => {
                                previewImg(url);
                            } }),
                        React.createElement("div", { className: "ctfit-right" },
                            React.createElement("div", { className: "ctfit-title" }, renderLine(title)),
                            React.createElement("div", { className: "ctfit-content" }, renderLine(content, 2)))));
                }
                else if (typeof val === 'string') {
                    return (React.createElement("img", { className: 'ctfit-img', src: val, onClick: () => {
                            previewImg(val);
                        } }));
                }
                else {
                    return '';
                }
            },
        };
    };
}
