import CONSTANTS from "../../config/constants";

const getMatchedTransactionFor = (searchVal: string) => {
  searchVal = searchVal.toUpperCase();

  let transactionForValue = null;
  const matchedKey = Object.keys(CONSTANTS.TRANSACTION_FOR).find(
    (key: string) => key.includes(searchVal)
  );

  if (matchedKey) {
    transactionForValue =
      CONSTANTS.TRANSACTION_FOR[
        matchedKey as keyof typeof CONSTANTS.TRANSACTION_FOR
      ];
  }

  return { transactionForValue };
};

export const getMatchedStaffLedgerType = (searchVal: string) => {
  searchVal = searchVal.toUpperCase();
  let staffLedgerType = null;
  const matchedKey = Object.keys(CONSTANTS.STAFF_LEDGER_TYPES).find(
    (key: string) => key.includes(searchVal)
  );
  if (matchedKey) {
    staffLedgerType = CONSTANTS.STAFF_LEDGER_TYPES[
      matchedKey as keyof typeof CONSTANTS.STAFF_LEDGER_TYPES
    ];
  }
  return { staffLedgerType };
};

export default getMatchedTransactionFor;
