"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeDataListWithTree = exports.makeDataList = exports.makeColumns = exports.makeRandomDate = void 0;
const faker_1 = require("@ui/dev/faker");
const utils_1 = require("./utils");
const RECIPIENTS = [
    'ИП Иванов О.В.',
    'ООО "Новая организация"',
    'ООО "Волшебные документы"',
];
const makeRandomDate = () => {
    const randomDate = faker_1.faker.date.between({
        from: new Date(2024, 10, 10),
        to: new Date(2025, 10, 10),
    });
    return randomDate.toISOString();
};
exports.makeRandomDate = makeRandomDate;
const makeColumns = (columnsTemplate, mergedColumns = []) => {
    const mergedColumnsMap = mergedColumns.reduce((acc, column) => {
        if (!(0, utils_1.isGroupColumns)(column) && column.field) {
            const { field, ...columnsOptions } = column;
            return {
                ...acc,
                [field]: columnsOptions,
            };
        }
        return acc;
    }, {});
    return columnsTemplate.map((column) => {
        if ((0, utils_1.isGroupColumns)(column) || !column.field) {
            return column;
        }
        return {
            ...column,
            ...(mergedColumnsMap[column.field] || {}),
        };
    });
};
exports.makeColumns = makeColumns;
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_1.faker.number.int({ min: 0, max: RECIPIENTS.length })],
        createDate: (0, exports.makeRandomDate)(),
        options: Math.random() < 0.5 ? options : {},
    }));
};
exports.makeDataList = makeDataList;
const makeDataListWithTree = (length = 10, options) => {
    const { isNotSelectable, childrenCount = 3, childrenColumns } = options || {};
    return Array.from({ length }).map((_, i) => {
        const recipient = RECIPIENTS[faker_1.faker.number.int({ min: 0, max: RECIPIENTS.length })];
        const createDate = (0, exports.makeRandomDate)();
        const isTree = Math.random() > 0.5;
        return {
            id: faker_1.faker.string.uuid(),
            documentName: isTree ? 'Пакет документов' : `Договор №${i + 1}`,
            recipient,
            createDate,
            options: {
                isNotSelectable,
                childrenColumns,
            },
            children: isTree
                ? Array.from({ length: childrenCount }).map((__, childrenIndex) => ({
                    id: faker_1.faker.string.uuid(),
                    documentName: `Договор №${i + Number(`1${childrenIndex}0`)}`,
                    recipient,
                    createDate,
                }))
                : undefined,
        };
    });
};
exports.makeDataListWithTree = makeDataListWithTree;
