import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import classNames from 'classnames';
import { hasLineBreaker } from './util';
import Icon from '../../../Icon';
import { checkEmpty } from '../../../../utils/checkEmpty/checkEmpty';
import TruncatedTooltip from '../../../TruncatedTooltip';
export const TRUE_TEXT = 'TRUE';
export 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) }));
};
export default DataViewer;
function getValue(cell, evaluatedCell) {
    const baseValue = evaluatedCell?.value ?? cell?.value;
    if (baseValue && typeof baseValue === 'object') {
        return baseValue.toString();
    }
    return baseValue;
}
export function convertBooleanToText(value) {
    return value ? TRUE_TEXT : FALSE_TEXT;
}
//# sourceMappingURL=DataViewer.js.map