"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const enums_1 = require("../enums");
const useLogic = ({ children, copyPosition = 'right', copyText, isShowCopyText, showCopyIcon = 'always', color, isOverflow = false, tooltipProps, ...restProps }) => {
    const [status, setStatus] = (0, react_1.useState)(enums_1.CopyStatus.CanCopy);
    const handleMouseLeave = () => {
        if (status !== enums_1.CopyStatus.CanCopy) {
            setTimeout(() => {
                setStatus(enums_1.CopyStatus.CanCopy);
            }, 100);
        }
    };
    const handleClick = (event) => {
        event.stopPropagation();
        navigator.clipboard
            .writeText(copyText || (typeof children === 'string' ? children : ''))
            .then(() => setStatus(enums_1.CopyStatus.Copied))
            .catch(() => setStatus(enums_1.CopyStatus.Error));
    };
    const tooltipTitle = isShowCopyText ? `${status}: ${copyText}` : status;
    const isShowCopyIcon = showCopyIcon !== 'none';
    const isIconOnLeft = isShowCopyIcon && copyPosition === 'left';
    const isIconOnRight = isShowCopyIcon && copyPosition === 'right';
    return {
        handleMouseLeave,
        handleClick,
        tooltipTitle,
        isIconOnLeft,
        isIconOnRight,
        restProps,
        copyPosition,
        color,
        showCopyIcon,
        isOverflow,
        children,
        tooltipProps,
    };
};
exports.useLogic = useLogic;
