import { faker } from '@ui/dev/faker';
import { isGroupColumns } from './utils';
const RECIPIENTS = [
    'ИП Иванов О.В.',
    'ООО "Новая организация"',
    'ООО "Волшебные документы"',
];
export const makeRandomDate = () => {
    const randomDate = faker.date.between({
        from: new Date(2024, 10, 10),
        to: new Date(2025, 10, 10),
    });
    return randomDate.toISOString();
};
export const makeColumns = (columnsTemplate, mergedColumns = []) => {
    const mergedColumnsMap = mergedColumns.reduce((acc, column) => {
        if (!isGroupColumns(column) && column.field) {
            const { field, ...columnsOptions } = column;
            return {
                ...acc,
                [field]: columnsOptions,
            };
        }
        return acc;
    }, {});
    return columnsTemplate.map((column) => {
        if (isGroupColumns(column) || !column.field) {
            return column;
        }
        return {
            ...column,
            ...(mergedColumnsMap[column.field] || {}),
        };
    });
};
export const makeDataList = (dataObjTemplate, options) => {
    const DATA_ARRAY_LENGTH = 50;
    return Array.from({ length: DATA_ARRAY_LENGTH })
        .fill(dataObjTemplate)
        .map((_, i) => ({
        id: String(i + 1),
        documentName: `Договор №${i + 1}`,
        info: 'Тестовый документ',
        code: '9999',
        recipient: RECIPIENTS[faker.number.int({ min: 0, max: RECIPIENTS.length })],
        createDate: makeRandomDate(),
        options: Math.random() < 0.5 ? options : {},
    }));
};
export const makeDataListWithTree = (length = 10, options) => {
    const { isNotSelectable, childrenCount = 3, childrenColumns } = options || {};
    return Array.from({ length }).map((_, i) => {
        const recipient = RECIPIENTS[faker.number.int({ min: 0, max: RECIPIENTS.length })];
        const createDate = makeRandomDate();
        const isTree = Math.random() > 0.5;
        return {
            id: faker.string.uuid(),
            documentName: isTree ? 'Пакет документов' : `Договор №${i + 1}`,
            recipient,
            createDate,
            options: {
                isNotSelectable,
                childrenColumns,
            },
            children: isTree
                ? Array.from({ length: childrenCount }).map((__, childrenIndex) => ({
                    id: faker.string.uuid(),
                    documentName: `Договор №${i + Number(`1${childrenIndex}0`)}`,
                    recipient,
                    createDate,
                }))
                : undefined,
        };
    });
};
