'use strict';
import { jsx, jsxs } from 'react/jsx-runtime';
import { cn } from '../../../../fd-toolbox/lib/utils.js';
import { Avatar, AvatarImage, AvatarFallback } from '../../../fd-component-toolbox/avatar/Avatar.js';
import { Badge } from '../../../fd-component-toolbox/badge/Badge.js';
import { Link } from '../../../fd-component-toolbox/link/Link.js';
import { ViewCell } from './ViewCell.js';
import { BlobBodyCell } from './BlobBodyCell.js';
import BodyExpandPropertyCell from './BodyExpandPropertyCell.js';
import { getMailToUrl, getAbsoluteUrl } from '../../../../fd-toolbox/routing/routers.js';
import { isColorfulCell, getBodyBackgroundColorClassNameByCellContext, getLabelUrl } from './BodyCellValue.funcs.js';
import { isEmailCell, isUrlCell, isDescriptionPropertyCell, isCellNavigationDisabled, isImageCell, isExpandPropertyCell, isBlobCell } from '../services/table-private-cell.js';
import { isRichText, isMarkdown } from '../../core/property-types.js';
import { firstOrUndefined } from '../../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function BodyCellValue({
  cellContext,
  onRefreshItems,
  cellValue,
  imageSrc,
  onViewClick,
  parsedMarkdown,
  parsedRichText
}) {
  switch (true) {
    case isExpandPropertyCell(cellContext):
      if (isBlobCell(cellContext)) {
        return /* @__PURE__ */jsx(BlobBodyCell, {
          cellContext
        });
      } else if (!isCellNavigationDisabled(cellContext)) {
        return /* @__PURE__ */jsx(BodyExpandPropertyCell, {
          cellContext,
          onRefreshItems,
          children: /* @__PURE__ */jsx("div", {
            children: cellValue
          })
        });
      } else {
        return /* @__PURE__ */jsx("div", {
          children: cellValue
        });
      }
    case isDescriptionPropertyCell(cellContext):
      return !isCellNavigationDisabled(cellContext) ? /* @__PURE__ */jsx(ViewCell, {
        cellContext,
        onRefreshResources: onRefreshItems,
        onViewClick,
        children: /* @__PURE__ */jsxs("div", {
          className: "flex items-center",
          children: [isImageCell(cellContext) && /* @__PURE__ */jsxs(Avatar, {
            className: "mr-2 size-5",
            children: [/* @__PURE__ */jsx(AvatarImage, {
              src: imageSrc,
              alt: "Resource image"
            }), /* @__PURE__ */jsx(AvatarFallback, {})]
          }), /* @__PURE__ */jsx("div", {
            children: cellValue
          })]
        })
      }) : /* @__PURE__ */jsx("div", {
        children: cellValue
      });
    case isUrlCell(cellContext):
      return cellValue && /* @__PURE__ */jsx(Link, {
        href: getAbsoluteUrl(cellValue),
        openInNewTab: true,
        className: "text-fd-accent truncate",
        children: getLabelUrl(cellContext) ?? cellValue
      });
    case isEmailCell(cellContext):
      return /* @__PURE__ */jsx(Link, {
        href: getMailToUrl(cellValue),
        openInNewTab: true,
        className: "text-fd-accent",
        children: cellValue
      });
    case isColorfulCell(cellContext):
      return /* @__PURE__ */jsx(Badge, {
        className: cn("rounded-md px-1 py-px font-normal select-text", getBodyBackgroundColorClassNameByCellContext(cellContext)),
        children: cellValue
      });
    case isMarkdown(cellContext.internalTableColumn.propertyType, cellContext.internalTableColumn.propertyTypeFormat):
      return /* @__PURE__ */jsx("div", {
        dangerouslySetInnerHTML: {
          __html: parsedMarkdown
        }
      });
    case isRichText(cellContext.internalTableColumn.propertyType, cellContext.internalTableColumn.propertyTypeFormat):
      return firstOrUndefined(parsedRichText) ?? /* @__PURE__ */jsx("div", {
        children: cellValue
      });
    case true:
    default:
      return /* @__PURE__ */jsx("div", {
        children: cellValue
      });
  }
}
__name(BodyCellValue, "BodyCellValue");

export { BodyCellValue };
