import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import { useTranslation } from 'react-i18next';
import { formatSwitchFieldValue } from './AppFormField';
import { getFieldFlexStyle, groupFieldsIntoRows } from './groupFieldsIntoRows';
import './style.scss';
import { Icon } from '../../basic';
import UsabilityUtils from '../../functions/UsabilityUtils';
function truncateValue(value, truncate, t) {
    if (!value) {
        return t('label.notavailable');
    }
    if (value.length <= truncate) {
        return value;
    }
    return `${value.slice(0, truncate)}…`;
}
function getFieldDisplayContent(field, raw, t) {
    if (field.truncate) {
        return truncateValue(raw, field.truncate, t);
    }
    if (field.display) {
        return field.display(raw);
    }
    if (field.fn) {
        return field.fn(raw);
    }
    if (field.type === 'switch') {
        return formatSwitchFieldValue(raw, {
            trueLabel: t('generic.boolean.true'),
            falseLabel: t('generic.boolean.false'),
            notAvailable: t('label.notavailable'),
        });
    }
    if (raw) {
        return raw;
    }
    return t('label.notavailable');
}
export default function AppFormInfo({ fields, data }) {
    const { t } = useTranslation('common');
    return (_jsx("div", { className: "app-form-info-container", children: groupFieldsIntoRows(fields).map((row, rowIdx) => (_jsx("div", { className: "app-form-row", children: row.map((field, idx) => (_jsx("div", { className: "app-form-field", style: getFieldFlexStyle(field), children: _jsxs("div", { className: "item", ...(field.title && { title: field.title }), children: [_jsxs("span", { className: "label", children: [field.name, ":"] }), _jsx("span", { className: "value", children: getFieldDisplayContent(field, data[field.attr], t) }), field.copyToClipboard && (_jsx(Icon, { name: "content_copy", size: "small", className: "ds-copy-icon", filled: true, onClick: () => {
                                UsabilityUtils.copy(data[field.attr]);
                            } }))] }) }, field.attr ?? idx))) }, rowIdx))) }));
}
