"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var link_preview_viewer_exports = {};
__export(link_preview_viewer_exports, {
  LinkPreviewViewer: () => LinkPreviewViewer
});
module.exports = __toCommonJS(link_preview_viewer_exports);
var import_react = __toESM(require("react"));
var import_ricos_types = require("./../../ricos-types/index.js");
var import_theme_color_token = require("./../../_shared/theme-color-token.js");
var import_ui_components = require("./../../ui-components/index.js");
var import_data_hooks = require("../data-hooks.js");
var import_link_preview_scss = __toESM(require("../statics/styles/link-preview-scss.js"));
var import_types = require("../types.js");
var import_utils = require("./utils.js");
const LinkPreviewViewer = ({ node, helpers }) => {
  const onLinkPreviewClick = () => {
    if (node.type === "LINK_PREVIEW") {
      helpers?.onViewerAction?.(
        import_types.LINK_PREVIEW_TYPE,
        "Click",
        node.linkPreviewData.link?.url || "",
        node.id,
        {
          type: import_ricos_types.Node_Type.LINK_PREVIEW,
          linkPreviewData: node.linkPreviewData
        }
      );
    }
  };
  const { title = "", description, thumbnailUrl, link, styles } = node.linkPreviewData;
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: import_link_preview_scss.default.linkPreviewContainer,
      "data-hook": import_data_hooks.LINK_PREVIEW_VIEWER,
      style: {
        "--link-preview-border-width": styles?.borderWidth !== void 0 ? `${styles.borderWidth}px` : void 0,
        "--link-preview-border-color": (0, import_theme_color_token.resolveDocumentColorToCss)(styles?.borderColor),
        "--link-preview-bg-color": (0, import_theme_color_token.resolveDocumentColorToCss)(styles?.backgroundColor),
        "--link-preview-border-radius": styles?.borderRadius !== void 0 ? `${styles.borderRadius}px` : void 0,
        "--link-preview-link-color": (0, import_theme_color_token.resolveDocumentColorToCss)(styles?.linkColor),
        "--link-preview-title-color": (0, import_theme_color_token.resolveDocumentColorToCss)(styles?.titleColor),
        "--link-preview-subtitle-color": (0, import_theme_color_token.resolveDocumentColorToCss)(styles?.subtitleColor)
      }
    },
    /* @__PURE__ */ import_react.default.createElement(
      "figure",
      {
        className: `${import_link_preview_scss.default.linkPreview} ${styles?.thumbnailPosition === "END" ? import_link_preview_scss.default.thumbnailEnd : styles?.thumbnailPosition === "START" ? import_link_preview_scss.default.thumbnailStart : styles?.thumbnailPosition === "TOP" ? import_link_preview_scss.default.thumbnailTop : ""}`,
        onClick: onLinkPreviewClick,
        style: {
          height: "auto",
          alignItems: styles?.thumbnailPosition === "TOP" ? "center" : void 0
        }
      },
      thumbnailUrl && styles?.thumbnailPosition !== "HIDDEN" && /* @__PURE__ */ import_react.default.createElement(
        import_ui_components.Image,
        {
          containerProps: {
            className: styles?.thumbnailPosition === "TOP" ? import_link_preview_scss.default.linkPreviewResponsiveImage : import_link_preview_scss.default.linkPreviewImage
          },
          uri: thumbnailUrl,
          width: 400,
          height: 200,
          displayMode: "fill",
          alt: title
        }
      ),
      /* @__PURE__ */ import_react.default.createElement("section", { className: import_link_preview_scss.default.linkPreviewInfo }, /* @__PURE__ */ import_react.default.createElement("div", { className: import_link_preview_scss.default.linkPreviewUrl, dir: "auto" }, (0, import_utils.getUrlForDisplay)((0, import_utils.getHost)(link?.url) || link?.url || "")), /* @__PURE__ */ import_react.default.createElement("figcaption", { className: import_link_preview_scss.default.linkPreviewTitle, dir: "auto" }, title), description && /* @__PURE__ */ import_react.default.createElement("div", { className: import_link_preview_scss.default.linkPreviewDescription, dir: "auto" }, description))
    )
  );
};
//# sourceMappingURL=link-preview-viewer.js.map
