import { jsx as _jsx } from "react/jsx-runtime";
/* eslint-disable no-useless-escape*/
import EmbedContainer from "react-oembed-container";
import reactStringReplace from "react-string-replace";
import isNil from "lodash/isNil";
import { useOembed } from "../hooks/useOembed";
import { Spin } from "./Spin";
import isEmpty from "lodash/isEmpty";
export const ContentPreview = ({ content, embedContentHeight, embedContentWidth, style }) => {
    const sanitizedContent = content?.replace(/\n/g, " ");
    const findUrls = sanitizedContent?.match("(https?:\/\/[^ ]*)"); // prettier-ignore
    const embedableUrl = !isNil(findUrls) && findUrls?.length > 0 ? findUrls[0] : "";
    const { isLoading, error, oembed } = useOembed(embedableUrl, embedContentHeight, embedContentWidth);
    return (_jsx("div", { className: "nl-embed-preview", style: style, children: isLoading && !isEmpty(findUrls) ? (_jsx(Spin, {})) : (reactStringReplace(sanitizedContent, new RegExp("(https?:\/\/[^ ]*)"), // prettier-ignore
        (match, i) => {
            return i === 1 && !error && oembed?.html && oembed ? (_jsx(EmbedContainer, { markup: oembed?.html, className: "nl-embed-container-preview", children: _jsx("div", { dangerouslySetInnerHTML: { __html: oembed?.html } }) }, i + match)) : (_jsx("a", { href: match, children: match }));
        })) }));
};
//# sourceMappingURL=ContentPreview.js.map