'use strict';
import { jsx, jsxs } from 'react/jsx-runtime';
import '../../../../fd-component-toolbox/client/framework/index.js';
import { Link } from '../../../../fd-component-toolbox/link/Link.js';
import { Badge } from '../../../../fd-component-toolbox/badge/Badge.js';
import { ViewSheet } from '../../../view/ViewSheet.js';
import { Avatar, AvatarImage, AvatarFallback } from '../../../../fd-component-toolbox/avatar/Avatar.js';
import { isEmail, isUrl } from '../../../core/property-types.js';
import { getMailToUrl, getAbsoluteUrl } from '../../../../../fd-toolbox/routing/routers.js';
import { getOptionalPropertyValue } from '../../../../../fd-toolbox/objects/property-value.js';
import { getRelatedResourceImageUrl, isColorful, getBackgroundColorClassName, isDescriptionProperty, onViewClick, isExpandProperty } from './DataCardPropertyValue.funcs.js';
import FrameworkImage from 'next/image.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function DataCardPropertyValue({
  property,
  resource,
  resourceMeta,
  itemId
}) {
  const propertyMeta = property.propertyMeta;
  const resourceName = resourceMeta.resourceName;
  const relationName = propertyMeta.relation?.relatedResourceName;
  const relationId = getOptionalPropertyValue(resource, property.name);
  const imageUrl = getRelatedResourceImageUrl(resource, propertyMeta);
  let content = /* @__PURE__ */jsx("p", {
    children: property.value
  });
  if (isEmail(propertyMeta.type, propertyMeta.typeFormat)) {
    content = /* @__PURE__ */jsx(Link, {
      className: "text-fd-accent cursor-pointer hover:cursor-pointer",
      href: getMailToUrl(property.value),
      openInNewTab: true,
      children: property.value
    });
  } else if (isColorful(propertyMeta, property.uiPropertyMeta)) {
    content = /* @__PURE__ */jsx(Badge, {
      className: `rounded-md px-1 py-px font-normal ${getBackgroundColorClassName(property.name, resource)}`,
      children: property.value
    });
  } else if (isUrl(propertyMeta.type, propertyMeta.typeFormat)) {
    content = /* @__PURE__ */jsx(Link, {
      className: "text-fd-accent cursor-pointer hover:cursor-pointer",
      href: getAbsoluteUrl(property.value),
      openInNewTab: true,
      children: property.value
    });
  } else if (isDescriptionProperty(resourceMeta, property.name)) {
    content = /* @__PURE__ */jsx("div", {
      className: "text-fd-accent cursor-pointer hover:cursor-pointer",
      children: /* @__PURE__ */jsx(ViewSheet, {
        id: resource.id,
        resourceName,
        onEditClick: () => onViewClick(resourceName, itemId),
        children: /* @__PURE__ */jsx("p", {
          children: property.value
        })
      })
    });
  } else if (isExpandProperty(propertyMeta)) {
    content = /* @__PURE__ */jsxs("div", {
      className: "text-fd-accent flex cursor-pointer items-center hover:cursor-pointer",
      children: [imageUrl && /* @__PURE__ */jsxs(Avatar, {
        className: "mr-2 size-5",
        children: [/* @__PURE__ */jsx(AvatarImage, {}), /* @__PURE__ */jsx(AvatarFallback, {
          children: /* @__PURE__ */jsx(FrameworkImage, {
            className: "object-fill",
            src: imageUrl,
            alt: "Resource image",
            width: 40,
            height: 40
          })
        })]
      }), /* @__PURE__ */jsx(ViewSheet, {
        id: relationId,
        resourceName: relationName,
        onEditClick: () => onViewClick(relationName, relationId),
        children: /* @__PURE__ */jsx("p", {
          children: property.value
        })
      })]
    });
  }
  return content;
}
__name(DataCardPropertyValue, "DataCardPropertyValue");

export { DataCardPropertyValue };
