var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import * as React from "react";
import { cn } from "@utils";
import { truncateVariants } from "./truncateVariants";
import { Button } from "../button";
import { Modal } from "../modal";
import { ModalBody } from "../modal/modal";
/**
 * Truncate component for displaying limited text with a "Show more" button
 */
export const Truncate = React.forwardRef((_a, ref) => {
    var { as = "div", children, limit = 100, className } = _a, props = __rest(_a, ["as", "children", "limit", "className"]);
    const [showModal, setShowModal] = React.useState(false);
    // Convert the HTML tag string to an ElementType
    const Tag = as;
    // Check if truncation is needed
    const isTruncated = typeof children === "string" && limit > 0 && children.length > limit;
    // If children is not a string or limit is invalid, return null
    if (typeof children !== "string" || limit <= 0) {
        return null;
    }
    return isTruncated ? (_jsxs(_Fragment, { children: [_jsxs(Tag, Object.assign({ ref: ref, className: cn(truncateVariants({ truncated: true }), className) }, props, { children: [children.substring(0, limit), "...", " ", _jsx(Button, { variant: "text", onClick: () => setShowModal(true), className: "inline-block text-inherit", style: { fontSize: "inherit" }, children: "Show more" })] })), showModal && (_jsx(Modal, { showModal: showModal, onHide: () => setShowModal(false), children: _jsx(ModalBody, { className: "max-w-3xl", children: children }) }))] })) : (_jsx(Tag, Object.assign({ ref: ref, className: cn(truncateVariants({ truncated: false }), className) }, props, { children: children })));
});
Truncate.displayName = "Truncate";
//# sourceMappingURL=truncate.js.map