import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from "react";
import { faFilePdf } from "@fortawesome/free-solid-svg-icons/faFilePdf";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { DetailContainer, DetailTextContent, DetailTitle, HighlightableText, MoreDetailCard, ResultLinkTwo, } from "../../../renderer-components";
import { css } from "styled-components";
export function PdfDetail({ result }) {
    const lastEdit = new Date(result.source.file.lastModifiedDate)
        .toLocaleString()
        .replace(",", " |");
    return (_jsxs(DetailContainer, { children: [_jsx(DetailTitle, { fontSize: "19px", fontweigth: "600", children: _jsx(HighlightableText, { result: result, path: "document.title" }) }), "document.content" in result.highlight ? (_jsx("div", { css: css `
            margin-top: 8px;
            max-width: 100%;
            line-height: 1em;
            max-height: 18em;
            overflow: hidden;
            text-overflow: ellipsis;
            word-wrap: break-word;
            word-break: break-word;
          `, children: _jsx(HighlightableText, { result: result, path: "document.content" }) })) : (_jsx("div", { css: css `
            margin-top: 8px;
            max-width: 100%;
            line-height: 1em;
            max-height: 6em;
            overflow: hidden;
            text-overflow: ellipsis;
            word-wrap: break-word;
            word-break: break-word;
            font-style: normal;
            font-weight: 400;
            font-size: 15px;
            color: #71717a;
          `, children: _jsx(DetailTextContent, { result: result, path: "document.summary" }) })), _jsx(MoreDetailCard, { icon: _jsx(FontAwesomeIcon, { icon: faFilePdf }), date: lastEdit }), _jsx("div", { css: css `
          margin-top: 10px;
          margin-left: 5px;
        `, children: _jsx(ResultLinkTwo, { href: result.source.document.url, title: "Link Documento", children: _jsx(HighlightableText, { result: result, path: "document.url" }) }) }), _jsx("div", { css: css `
          margin-top: 15px;
        `, children: result.source.resources?.binaries.map((binary) => {
                    const url = `/api/file-manager/v1/download/byte/${binary.resourceId}/${result.source.tenantId}`;
                    return (_jsx(ViewIfUrlOk, { url: url, children: _jsx("iframe", { title: binary.id, src: url, css: css `
                  width: 100%;
                  height: 50vh;
                  background-color: white;
                  border-radius: 4px;
                  border: 1px solid
                    var(--openk9-embeddable-search--border-color);
                ` }) }, binary.id));
                }) })] }));
}
function ViewIfUrlOk({ url, children, }) {
    const [isOk, setIsOk] = React.useState(false);
    React.useEffect(() => {
        fetch(url).then((response) => {
            if (response.ok)
                setIsOk(true);
        });
        return () => setIsOk(false);
    }, [url]);
    return _jsx(React.Fragment, { children: isOk ? children : null });
}
