'use strict';

var React = require('react');
var core = require('@linaria/core');
var BasicCTError_style = require('./BasicCTError.style.js');
var index = require('../Typo/index.js');
var useCTErrorMsg = require('../../hooks/useCTErrorMsg.js');
var useParrotTranslation = require('../../hooks/useParrotTranslation.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

const defaultErrorContainerRender = ({
  children,
  className
}) => {
  return /* @__PURE__ */ React__default.default.createElement("span", { className: core.cx(index.Typo.Label.l3_regular, BasicCTError_style.BasicCTErrorStyle, className) }, children);
};
const BasicCTError = (props) => {
  const {
    error,
    className,
    ErrorItemRender,
    ErrorContainerRender,
    errorMsgOptions
  } = props;
  const msgs = useCTErrorMsg.useCTErrorMsg(error, errorMsgOptions);
  const { t } = useParrotTranslation();
  const ContainerRender = ErrorContainerRender || defaultErrorContainerRender;
  const child = React.useMemo(() => {
    if (ErrorItemRender) {
      return msgs.map((errorMsg, index) => /* @__PURE__ */ React__default.default.createElement(ErrorItemRender, { errorMsg, index, key: index }));
    }
    return msgs.join("");
  }, [msgs, ErrorItemRender, t]);
  return /* @__PURE__ */ React__default.default.createElement(ContainerRender, { className, errorMsgs: msgs, children: child });
};

exports.BasicCTError = BasicCTError;
