import { useMemo } from "react";
import { useEditorContext } from "../context/editor-context.js";
export function useDependentItemProps(tableName, itemId) {
    const { fixedIncomes, serviceProviderFeeTypes, transactions } = useEditorContext();
    const dependentItemProps = useMemo(() => {
        if (!itemId)
            return [];
        switch (tableName) {
            case "TRANSACTION":
                return [];
            case "SPV":
                return [
                    {
                        dependentTableName: "ASSET",
                        dependentItems: makeDependentAssetsList(tableName, itemId, fixedIncomes),
                    },
                ];
            case "FIXED_INCOME_TYPE":
                return [
                    {
                        dependentTableName: "ASSET",
                        dependentItems: makeDependentAssetsList(tableName, itemId, fixedIncomes),
                    },
                ];
            case "ASSET":
                return [
                    {
                        dependentTableName: "TRANSACTION",
                        dependentItems: makeDependentTransactionsList(tableName, itemId, transactions),
                    },
                ];
            case "SERVICE_PROVIDER_FEE_TYPE":
                return [
                    {
                        dependentTableName: "TRANSACTION",
                        dependentItems: makeDependentTransactionsList(tableName, itemId, transactions),
                    },
                ];
            case "ACCOUNT":
                return [
                    {
                        dependentTableName: "TRANSACTION",
                        dependentItems: makeDependentTransactionsList(tableName, itemId, transactions),
                    },
                    {
                        dependentTableName: "SERVICE_PROVIDER_FEE_TYPE",
                        dependentItems: makeDependentServiceProviderFeeTypesList(itemId, serviceProviderFeeTypes),
                    },
                ];
        }
    }, [fixedIncomes, itemId, serviceProviderFeeTypes, tableName, transactions]);
    return dependentItemProps;
}
export function makeDependentServiceProviderFeeTypesList(itemId, serviceProviderFeeTypes) {
    const makeLabel = (asset) => ({
        id: asset.id,
        label: asset.name,
    });
    return serviceProviderFeeTypes
        .filter((f) => f.accountId === itemId)
        .map(makeLabel);
}
export function makeDependentAssetsList(tableName, itemId, assets) {
    const makeLabel = (asset) => ({
        id: asset.id,
        label: asset.name,
    });
    switch (tableName) {
        case "FIXED_INCOME_TYPE":
            return assets
                .filter((asset) => asset.fixedIncomeTypeId === itemId)
                .map(makeLabel);
        case "SPV":
            return assets.filter((asset) => asset.spvId === itemId).map(makeLabel);
    }
}
export function makeDependentTransactionsList(tableName, itemId, transactions) {
    const makeLabel = (t, index) => ({
        id: t.id,
        label: `Transaction #${index + 1}`,
    });
    switch (tableName) {
        case "ASSET":
            return transactions
                .filter((t) => t.fixedIncomeTransaction?.assetId === itemId)
                .map(makeLabel);
        case "ACCOUNT":
            return transactions
                .filter((t) => t.cashTransaction.accountId === itemId ||
                t.fixedIncomeTransaction?.accountId === itemId)
                .map(makeLabel);
        case "SERVICE_PROVIDER_FEE_TYPE":
            return transactions
                .filter((t) => t.fees?.some((f) => f.serviceProviderFeeTypeId === itemId))
                .map(makeLabel);
    }
}
//# sourceMappingURL=dependent-items.js.map