import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Tooltip } from '../../components/Tooltip';
import { classNames } from '../../components/utils/classNames';
import { editableTextClassnames } from './constants';
import { EditingForm } from './EditingForm';
import { DisplayValue, StyledEditIcon, StyledLoader, StyledPopover, } from './styles';
import { useLogic } from './useLogic';
const getShowEditIconMode = ({ showEditIcon, isShowIcon = true, }) => {
    if (showEditIcon !== undefined) {
        return showEditIcon;
    }
    return isShowIcon === false ? 'none' : 'always';
};
// biome-ignore lint/complexity/noUselessTypeConstraint: Фикс типизации в тестах
export const EditableText = (props) => {
    const { isIconOnLeft, onClose, displayValueProps, tooltipProps, popoverProps, } = useLogic(props);
    const { className, children, isShowIcon = true, isLoading, showEditIcon, iconPosition = 'right', ...restProps } = props;
    const showEditIconMode = getShowEditIconMode({ showEditIcon, isShowIcon });
    const renderIcon = () => {
        if (isLoading) {
            return _jsx(StyledLoader, { "$iconPosition": iconPosition });
        }
        if (showEditIconMode === 'none') {
            return null;
        }
        return (_jsx(StyledEditIcon, { "$iconPosition": iconPosition, className: classNames({
                [editableTextClassnames.showIconOnHover]: showEditIconMode === 'onHover',
            }) }));
    };
    return (_jsxs(_Fragment, { children: [_jsx(Tooltip, { ...tooltipProps, placement: "bottom", children: _jsxs(DisplayValue, { "$isLoading": isLoading, className: className, variant: "inherit", ...displayValueProps, children: [isIconOnLeft && renderIcon(), children, !isIconOnLeft && renderIcon()] }) }), _jsx(StyledPopover, { anchorOrigin: {
                    vertical: 'bottom',
                    horizontal: 'left',
                }, ...popoverProps, children: _jsx(EditingForm, { children: children, onClose: onClose, ...restProps }) })] }));
};
