import $i18n from '../../../../../../../../locales/i18n.js';
import * as React from 'react';
import isPlainObject from 'lodash/isPlainObject';
import isNil from 'lodash/isNil';
import { CnTooltip } from '@cainiaofe/cn-ui';
import { getUserAvatarUrl } from '../constants';
import { renderValueHandleEmpty } from '../utils';
export function createUserFormat() {
    return (column) => {
        return {
            cell(value) {
                // 处理空值：如果值为 null、undefined 或空字符串，显示空值占位符
                if (isNil(value) || value === '') {
                    return renderValueHandleEmpty(value);
                }
                const { showDepartTag = false } = column || {};
                function renderUserOne(_value, key) {
                    if (!isPlainObject(_value))
                        return null;
                    const { name, nickName, workNo, workStatus } = _value;
                    const dom = (React.createElement("div", { key: key, className: "table-format-user-content" },
                        React.createElement("img", { src: getUserAvatarUrl(workNo), className: "table-format-user-avatar", alt: name }),
                        name,
                        nickName && `(${nickName})`,
                        showDepartTag && workStatus === false && (React.createElement("span", { className: "table-format-user-depart" }, $i18n.get({ id: 'Resigned', dm: '已离职' })))));
                    if (workNo) {
                        return (React.createElement(CnTooltip, { key: key, align: "t", trigger: dom }, workNo));
                    }
                    return dom;
                }
                let result;
                if (Array.isArray(value)) {
                    // 如果数组为空，显示空值占位符
                    if (value.length === 0) {
                        return renderValueHandleEmpty(value);
                    }
                    result = value.map((item, index) => renderUserOne(item, index));
                }
                else if (isPlainObject(value)) {
                    result = renderUserOne(value);
                }
                else {
                    // 其他情况显示空值占位符
                    return renderValueHandleEmpty(value);
                }
                // 如果 result 为 null 或 undefined，显示空值占位符
                if (!result) {
                    return renderValueHandleEmpty(value);
                }
                return React.createElement("div", { className: "table-format-user-wrap" }, result);
            },
        };
    };
}
