'use strict';

var useParrotTranslation = require('./useParrotTranslation.js');
var cterror = require('../utils/cterror.js');
var React = require('react');
var _ = require('lodash');
var index = require('../core/ConfigProvider/index.js');

const useCTErrorMsg = (error, options) => {
  const { t } = useParrotTranslation();
  const globalConfig = index.useConfig();
  const err = cterror.parseCTError(error);
  const ns = (options == null ? void 0 : options.CTErrorI18nNs) || (globalConfig == null ? void 0 : globalConfig.CTErrorI18nNs) || "CTError";
  const errMsg = React.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;
};

exports.useCTErrorMsg = useCTErrorMsg;
