import {useMemo} from "react";
import {MRT_ColumnDef} from "mantine-react-table";
import {DealStatusHistorySchema} from "../../../../client";
import {DealStatus, DealStatusDictionary} from "../../../../shared/enums/DealStatus.ts";
import {Spoiler, Text} from "@mantine/core";

export const useDealStatusChangeTableColumns = () => {
    return useMemo<MRT_ColumnDef<DealStatusHistorySchema>[]>(() => [
        {
            accessorKey: "changedAt",
            header: "Дата",
            accessorFn: (row) => new Date(row.changedAt).toLocaleString('ru-RU'),
        },
        {
            header: "Пользователь",
            accessorFn: (row) => `${row.user.firstName} ${row.user.secondName}`
        },
        {
            accessorKey: "fromStatus",
            header: "Из статуса",
            accessorFn: (row) => DealStatusDictionary[row.fromStatus as DealStatus],
        },
        {
            accessorKey: "toStatus",
            header: "В статус",
            accessorFn: (row) => DealStatusDictionary[row.toStatus as DealStatus],
        },
        {
            accessorKey: "comment",
            header: "Комментарий",
            Cell: ({row}) =>
                <Spoiler maxHeight={80} showLabel={"Показать весь"} hideLabel={"Скрыть"}>
                    <Text style={{wordWrap: "break-word", wordBreak: "break-all", whiteSpace: "normal"}} span>
                        {row.original.comment}<br/>
                    </Text>
                </Spoiler>
            ,

        }
    ], []);
}
