import { useConfig } from '../core/ConfigProvider/index.js';
import { parseCTError } from '../utils/cterror.js';
import { merge } from 'lodash';
import { useMemo } from 'react';
import useParrotTranslation from './useParrotTranslation.js';

const useCTErrorMsg = (error, options) => {
  const { t } = useParrotTranslation();
  const globalConfig = useConfig();
  const err = parseCTError(error);
  const ns = (options == null ? void 0 : options.CTErrorI18nNs) || (globalConfig == null ? void 0 : globalConfig.CTErrorI18nNs) || "CTError";
  const errMsg = useMemo(() => {
    return err.map((e) => {
      if ("code" in e) {
        return t(`${ns}.${e.code}`, merge(options == null ? void 0 : options.tOptions, e.params));
      }
      return e.message;
    });
  }, [err, t, ns, options == null ? void 0 : options.tOptions]);
  return errMsg;
};

export { useCTErrorMsg };
