import TableStatusText from './TableStatusText.mjs';
import StatusIcon from '../statusIcon/StatusIcon.mjs';
import { Flag } from '@wise/art';
import 'react';
import { clsx } from 'clsx';
import Body from '../body/Body.mjs';
import Money from '../money/Money.mjs';
import AvatarView from '../avatarView/AvatarView.mjs';
import { jsxs, jsx } from 'react/jsx-runtime';

const TableCell = ({
  cell,
  alignment = 'left',
  className,
  colSpan,
  children
}) => {
  const getContentMedia = () => {
    let mediaContent = null;
    if (cell?.type === 'leading' && cell?.avatar) {
      mediaContent = /*#__PURE__*/jsx(AvatarView, {
        size: 40,
        ...cell.avatar,
        imgSrc: cell.avatar.imgSrc ?? cell.avatar.src,
        children: cell.avatar.asset
      });
    }
    if (cell?.type === 'currency' && cell?.primaryCurrency?.currency && cell?.flag !== false) {
      mediaContent = /*#__PURE__*/jsx(Flag, {
        code: cell?.primaryCurrency?.currency?.toLowerCase(),
        intrinsicSize: 24
      });
    }
    if (cell?.type === 'status') {
      mediaContent = /*#__PURE__*/jsx(StatusIcon, {
        size: 24,
        sentiment: cell?.sentiment ?? 'neutral'
      });
    }
    if (cell?.type === 'media' && cell.media) {
      // eslint-disable-next-line jsx-a11y/alt-text
      mediaContent = /*#__PURE__*/jsx("img", {
        ...cell.media
      });
    }
    if (mediaContent) {
      return /*#__PURE__*/jsx("div", {
        "aria-hidden": "true",
        className: "np-table-content-media",
        "data-testid": "np-table-content-media",
        children: mediaContent
      });
    }
  };
  const formatCurrencyValue = currency => {
    if (currency) {
      return /*#__PURE__*/jsx(Money, {
        amount: currency.amount,
        currency: currency.currency,
        alwaysShowDecimals: true
      });
    }
    return '';
  };
  return /*#__PURE__*/jsxs("td", {
    className: clsx('np-table-cell', cell?.type ? `np-table-cell--${cell?.type}` : '', `np-table-cell--${alignment}`, className),
    colSpan: colSpan,
    children: [cell?.type === 'text' && cell?.text && /*#__PURE__*/jsx(TableStatusText, {
      text: cell?.text,
      status: cell?.status
    }), cell?.type && ['leading', 'currency', 'status', 'media'].includes(cell?.type) && /*#__PURE__*/jsxs("div", {
      className: clsx('np-table-content', {
        'np-table-content--reversed': alignment === 'right'
      }),
      "data-testid": "np-table-content",
      children: [getContentMedia(), /*#__PURE__*/jsxs("div", {
        className: "np-table-content-body",
        children: [(cell?.primaryCurrency ?? cell?.primaryText) && /*#__PURE__*/jsx(TableStatusText, {
          text: cell?.type === 'currency' ? formatCurrencyValue(cell?.primaryCurrency) : cell?.primaryText ?? '',
          status: cell?.type !== 'status' ? cell?.status : undefined,
          typography: "default-bold"
        }), (cell?.secondaryCurrency ?? cell?.secondaryText) && /*#__PURE__*/jsx(Body, {
          children: cell?.type === 'currency' ? formatCurrencyValue(cell?.secondaryCurrency) : cell?.secondaryText
        })]
      })]
    }), children]
  });
};

export { TableCell as default };
//# sourceMappingURL=TableCell.mjs.map
