import React__default from 'react';
import { useUniqueId } from '../../../utils/uniqueId.mjs';
import { CODE_HORIZONTAL_PADDING } from './Code.mjs';
import styled from '../../../../../../node_modules/@mui/material/styles/styled.mjs';

const Container = styled('div')({
    display: 'flex',
    flexDirection: 'column',
    gap: '4px'
});
const Wrapper = styled('span')(({ theme, noWrap, hasCopiedIcon })=>[
        {
            '&:hover': {
                marginRight: 0,
                '& svg': {
                    display: 'block'
                },
                cursor: 'pointer'
            },
            borderRadius: 4,
            display: 'flex',
            alignItems: 'center',
            height: 'fit-content',
            width: 'fit-content',
            // Make sure when not hovered that the component takes up the same space as with the copy icon
            marginRight: hasCopiedIcon ? 0 : theme.spacing(3.5)
        },
        noWrap ? {
            wordBreak: 'unset',
            whiteSpace: 'nowrap'
        } : {},
        !hasCopiedIcon && {
            '& svg': {
                marginRight: theme.spacing(CODE_HORIZONTAL_PADDING),
                display: 'none'
            }
        }
    ]);
const CopyIconWrapper = styled('div')(({ theme })=>({
        display: 'flex',
        alignItems: 'center',
        height: '100%',
        '& svg': {
            marginRight: theme.spacing(CODE_HORIZONTAL_PADDING)
        }
    }));
const CopyableTextCore = ({ children, textToCopy, noWrap, id, label, wrapperSx, CodeComponent: Code, LabelComponent: Label, TypographyComponent: Typography, useClickToCopy })=>{
    const inputId = useUniqueId(id);
    if (children && typeof children !== 'string') {
        throw new Error('CopyableText children must be a string');
    }
    const childrenString = typeof children === 'string' ? children : '';
    const { copied, copyToClipboard, CopyIcon } = useClickToCopy({
        text: textToCopy ?? childrenString
    });
    return /*#__PURE__*/ React__default.createElement(Container, null, label && /*#__PURE__*/ React__default.createElement(Label, {
        htmlFor: inputId
    }, label), !children && /*#__PURE__*/ React__default.createElement(Typography, null, "–"), children && /*#__PURE__*/ React__default.createElement(Wrapper, {
        hasCopiedIcon: copied,
        noWrap: noWrap,
        onClick: copyToClipboard,
        sx: wrapperSx
    }, /*#__PURE__*/ React__default.createElement(Code, null, children), /*#__PURE__*/ React__default.createElement(CopyIconWrapper, null, CopyIcon)));
};

export { CopyableTextCore };
//# sourceMappingURL=CopyableText.mjs.map
