const filterFieldsByUserRole = (fields, hasRole) => fields.filter((field) => !field.role || hasRole(field.role));
const convertEnum = (values, t, prefix) => {
    if (!t)
        return Object.entries(values).map(([key, label]) => ({
            value: key,
            label,
        }));
    return Object.entries(values).map(([key, label]) => ({
        value: key,
        label: t(`${prefix ? `${prefix}:` : ''}${label}`),
    }));
};
const sortByLabel = (items) => {
    return [...items].sort((a, b) => a.label.localeCompare(b.label));
};
const convertList = (values, labelAttr, valueAttr) => {
    if (!values)
        return [];
    let fields = [];
    values.map((value) => {
        fields = [...fields, { label: value[labelAttr], value: value[valueAttr] }];
    });
    return fields;
};
const convertMap = (values) => {
    if (!values)
        return [];
    let fields = [];
    Object.keys(values).map((key) => {
        fields = [...fields, { label: values[key], value: key }];
    });
    return fields;
};
const convertStringArray = (values) => {
    if (!values)
        return [];
    let fields = [];
    values.map((value) => {
        fields = [...fields, { label: value, value }];
    });
    return fields;
};
const booleanOptions = (t) => {
    return [
        { label: t('message:generic.option.true'), value: 'true' },
        { label: t('message:generic.option.false'), value: 'false' },
    ];
};
const FormUtils = {
    convertEnum,
    convertList,
    convertStringArray,
    booleanOptions,
    convertMap,
    sortByLabel,
    filterFieldsByUserRole,
};
export default FormUtils;
