import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import classNames from '../../../../_virtual/index.js';
import { hasLineBreaker } from './util.js';
import Icon from '../../../Icon/Icon.js';
import { checkEmpty } from '../../../../utils/checkEmpty/checkEmpty.js';
import TruncatedTooltip from '../../../TruncatedTooltip/TruncatedTooltip.js';

const TRUE_TEXT = 'TRUE';
const FALSE_TEXT = 'FALSE';
/** The default Spreadsheet DataViewer component */
const DataViewer = ({ cell, evaluatedCell, active, }) => {
    const value = getValue(cell, evaluatedCell);
    const getFileList = (value) => {
        if (checkEmpty(value)) {
            return jsx(Fragment, {});
        }
        const fileList = JSON.parse(value);
        return fileList.map((file) => {
            return (jsx("div", { className: "ff-spreadsheet-data-viewer--fileType", children: jsx(TruncatedTooltip, { width: cell?.style?.width ?? 100, title: file?.name?.split('*')?.[0] ?? '' }) }, file.name));
        });
    };
    return typeof value === 'boolean' ? (jsx("span", { className: "ff-spreadsheet-data-viewer ff-spreadsheet-data-viewer--boolean", children: convertBooleanToText(value) })) : (jsx("span", { className: classNames('ff-spreadsheet-data-viewer', {
            'ff-spreadsheet-data-viewer--preserve-breaks': hasLineBreaker(value),
        }), children: !active && cell?.inputType?.type === 'dropDown' ? (jsxs("div", { className: "ff-spreadsheet-data-viewer--dropdownType", children: [value, jsx(Icon, { name: "arrow_down", height: 8, className: "dropdownType-icon" })] })) : !active && cell?.inputType?.type === 'file' ? (jsx(Fragment, { children: checkEmpty(cell?.value) ? (jsxs("div", { className: "ff-spreadsheet-data-viewer--without-fileType", children: [jsx(Icon, { name: "attachment_icon" }), " Attachment"] })) : (getFileList(value)) })) : (!active && value) }));
};
function getValue(cell, evaluatedCell) {
    const baseValue = evaluatedCell?.value ?? cell?.value;
    if (baseValue && typeof baseValue === 'object') {
        return baseValue.toString();
    }
    return baseValue;
}
function convertBooleanToText(value) {
    return value ? TRUE_TEXT : FALSE_TEXT;
}

export { FALSE_TEXT, TRUE_TEXT, convertBooleanToText, DataViewer as default };
//# sourceMappingURL=DataViewer.js.map
