import { useMemo } from "react";
import { tableNames } from "../constants/names.js";
import { allGroupTransactionTypes } from "../constants/transactions.js";
import { isoDateStringToDateInput } from "../utils/date.js";
export function useDefaultFormValues(args) {
    const { tableName, tableItem, fixedIncomeTypes, spvs, accounts } = args;
    return useMemo(() => {
        if (!tableItem) {
            switch (tableName) {
                case tableNames.ASSET:
                    return {
                        fixedIncomeTypeId: fixedIncomeTypes[0]?.id ?? null,
                        spvId: spvs[0]?.id ?? null,
                        name: null,
                        maturity: null,
                        ISIN: null,
                        CUSIP: null,
                        coupon: null,
                    };
                case tableNames.TRANSACTION:
                    return {
                        type: allGroupTransactionTypes[0],
                        entryTime: isoDateStringToDateInput(new Date().toISOString(), true),
                        cashAmount: null,
                        fixedIncomeId: null,
                        fixedIncomeAmount: null,
                        serviceProviderFeeTypeId: null,
                        fees: null,
                        txRef: null,
                    };
                case tableNames.SPV:
                    return {
                        name: null,
                    };
                case tableNames.SERVICE_PROVIDER_FEE_TYPE:
                    return {
                        name: null,
                        feeType: null,
                        accountId: accounts[0]?.id ?? null,
                    };
                case tableNames.FIXED_INCOME_TYPE:
                    return {
                        name: null,
                    };
                case tableNames.ACCOUNT:
                    return {
                        label: null,
                        reference: null,
                    };
            }
        }
        switch (tableName) {
            case tableNames.ASSET: {
                const item = tableItem;
                return {
                    id: item.id,
                    fixedIncomeTypeId: item.fixedIncomeTypeId,
                    spvId: item.spvId,
                    name: item.name,
                    maturity: item.maturity
                        ? isoDateStringToDateInput(item.maturity)
                        : null,
                    ISIN: item.ISIN,
                    CUSIP: item.CUSIP,
                    coupon: item.coupon,
                };
            }
            case tableNames.TRANSACTION: {
                const item = tableItem;
                return {
                    id: item.id,
                    type: item.type,
                    entryTime: item.entryTime
                        ? isoDateStringToDateInput(item.entryTime, true)
                        : null,
                    cashAmount: item.cashTransaction.amount ?? null,
                    fixedIncomeId: item.fixedIncomeTransaction?.assetId ?? null,
                    fixedIncomeAmount: item.fixedIncomeTransaction?.amount ?? null,
                    serviceProviderFeeTypeId: item.serviceProviderFeeTypeId ?? null,
                    fees: item.fees ?? null,
                    txRef: item.txRef ?? null,
                };
            }
            case tableNames.SPV: {
                const item = tableItem;
                return {
                    id: item.id,
                    name: item.name,
                };
            }
            case tableNames.SERVICE_PROVIDER_FEE_TYPE: {
                const item = tableItem;
                return {
                    id: item.id,
                    name: item.name,
                    feeType: item.feeType,
                    accountId: item.accountId,
                };
            }
            case tableNames.FIXED_INCOME_TYPE: {
                const item = tableItem;
                return {
                    id: item.id,
                    name: item.name,
                };
            }
            case tableNames.ACCOUNT: {
                const item = tableItem;
                return {
                    id: item.id,
                    label: item.label,
                    reference: item.reference,
                };
            }
        }
    }, [accounts, fixedIncomeTypes, spvs, tableItem, tableName]);
}
//# sourceMappingURL=useDefaultFormValues.js.map