import { cx } from '@linaria/core';
import { useCTErrorMsg } from '../../hooks/useCTErrorMsg.js';
import useParrotTranslation from '../../hooks/useParrotTranslation.js';
import React__default, { useMemo } from 'react';
import { Typo } from '../Typo/index.js';
import { BasicCTErrorStyle } from './BasicCTError.style.js';

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

export { BasicCTError };
