import { jsx, jsxs } from "react/jsx-runtime";
import "react";
import { usePrefixCls } from "@tachybase/components";
import { css } from "@emotion/css";
import { Typography } from "antd";
import classnames from "classnames";
import { useCompile } from "../../index.mjs";
import { EllipsisWithTooltip } from "./EllipsisWithTooltip.mjs";
import { HTMLEncode } from "./shared.mjs";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n          margin-bottom: 0;\n          line-height: 1.5;\n          font-size: 90%;\n        "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const ReadPretty = ()=>null;
const _Input = (props)=>{
    const prefixCls = usePrefixCls("description-input", props);
    const compile = useCompile();
    return /*#__PURE__*/ jsxs("div", {
        className: classnames(prefixCls, props.className),
        style: {
            display: 'flex',
            alignItems: 'center',
            overflowWrap: 'break-word',
            whiteSpace: 'normal',
            ...props.style
        },
        children: [
            compile(props.addonBefore),
            compile(props.prefix),
            /*#__PURE__*/ jsx(EllipsisWithTooltip, {
                ellipsis: props.ellipsis,
                children: compile(props.value)
            }),
            compile(props.suffix),
            compile(props.addonAfter)
        ]
    });
};
const _TextArea = (props)=>{
    const prefixCls = usePrefixCls("description-textarea", props);
    const compile = useCompile();
    var _props_value;
    const value = compile(null != (_props_value = props.value) ? _props_value : '');
    const { autop = true, ellipsis, text } = props;
    const html = /*#__PURE__*/ jsx("div", {
        style: {
            lineHeight: 1.612
        },
        dangerouslySetInnerHTML: {
            __html: HTMLEncode(value).split('\n').join('<br/>')
        }
    });
    const content = ellipsis ? /*#__PURE__*/ jsx(EllipsisWithTooltip, {
        ellipsis: ellipsis,
        popoverContent: autop ? html : value,
        children: text || value
    }) : autop ? html : value;
    return /*#__PURE__*/ jsxs("div", {
        className: classnames(prefixCls, props.className),
        style: {
            overflowWrap: 'break-word',
            ...props.style
        },
        children: [
            props.addonBefore,
            props.prefix,
            content,
            props.suffix,
            props.addonAfter
        ]
    });
};
function convertToText(html) {
    const temp = document.createElement('div');
    temp.innerHTML = html;
    const text = temp.innerText;
    return (null == text ? void 0 : text.replace(/[\n\r]/g, '')) || '';
}
const _Html = (props)=>{
    const prefixCls = usePrefixCls("description-textarea", props);
    const compile = useCompile();
    var _props_value;
    const value = compile(null != (_props_value = props.value) ? _props_value : '');
    const { autop = true, ellipsis } = props;
    const html = /*#__PURE__*/ jsx("div", {
        dangerouslySetInnerHTML: {
            __html: value
        }
    });
    const text = convertToText(value);
    const content = /*#__PURE__*/ jsx(EllipsisWithTooltip, {
        ellipsis: ellipsis,
        popoverContent: autop ? html : value,
        children: ellipsis ? text : html
    });
    return /*#__PURE__*/ jsxs("div", {
        className: classnames(prefixCls, props.className),
        style: {
            overflowWrap: 'break-word',
            ...props.style
        },
        children: [
            props.addonBefore,
            props.prefix,
            content,
            props.suffix,
            props.addonAfter
        ]
    });
};
const _URL = (props)=>{
    var _props_value;
    const prefixCls = usePrefixCls("description-url", props);
    const content = props.value && /*#__PURE__*/ jsx(Typography.Link, {
        ellipsis: true,
        target: '_blank',
        href: props.value,
        children: null == (_props_value = props.value) ? void 0 : _props_value.toString()
    });
    return /*#__PURE__*/ jsxs("div", {
        className: classnames(prefixCls, props.className),
        style: props.style,
        children: [
            props.addonBefore,
            props.prefix,
            content,
            props.suffix,
            props.addonAfter
        ]
    });
};
const _JSON = (props)=>{
    const prefixCls = usePrefixCls('json', props);
    var _props_space;
    return /*#__PURE__*/ jsx("pre", {
        className: classnames(prefixCls, props.className, css(_templateObject())),
        style: props.style,
        children: null != props.value ? JSON.stringify(props.value, null, null != (_props_space = props.space) ? _props_space : 2) : ''
    });
};
ReadPretty.Input = _Input;
ReadPretty.TextArea = _TextArea;
ReadPretty.URL = _URL;
ReadPretty.Html = _Html;
ReadPretty.JSON = _JSON;
export { ReadPretty };
