"use client";
import { jsx } from 'react/jsx-runtime';
import { cx } from '../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js';
import { forwardRef } from 'react';
import { Button } from '../button/button.js';
import { CopyButton } from '../copy-button/copy-button.js';
import { Flex } from '../flex/flex.js';
import { Text } from '../text/text.js';
import { useCodeBlockContext } from './code-block-root.js';
import styles from './code-block.module.css.js';

const CodeBlockContent = forwardRef(({ children, className, ...props }, ref) => {
    return (jsx("div", { ref: ref, className: cx(styles.content, className), ...props, children: children }));
});
CodeBlockContent.displayName = 'CodeBlockContent';
const CodeBlockHeader = forwardRef(({ children, className, ...props }, ref) => {
    return (jsx(Flex, { ref: ref, align: 'center', gap: 4, className: cx(styles.header, className), ...props, children: children }));
});
CodeBlockHeader.displayName = 'CodeBlockHeader';
const CodeBlockLabel = forwardRef(({ children, className, ...props }, ref) => {
    return (jsx(Text, { ref: ref, className: cx(styles.label, className), ...props, children: children }));
});
CodeBlockLabel.displayName = 'CodeBlockLabel';
const CodeBlockCollapseTrigger = forwardRef(({ className, children = 'Show Code', onClick, ...props }, ref) => {
    const { maxLines, collapsed, toggleCollapsed, code } = useCodeBlockContext();
    const canCollapse = maxLines && maxLines > 0;
    const lineCount = code?.split('\n').length ?? 0;
    if (!canCollapse || !collapsed || lineCount < maxLines)
        return null;
    return (jsx(Button, { ref: ref, onClick: e => {
            toggleCollapsed();
            onClick?.(e);
        }, variant: 'text', color: 'neutral', className: cx(styles.collapseTrigger, className), ...props, children: children }));
});
CodeBlockCollapseTrigger.displayName = 'CodeBlockCollapseTrigger';
const CodeBlockCopyButton = forwardRef(({ className, variant = 'default', ...props }, ref) => {
    const { code = '' } = useCodeBlockContext();
    return (jsx(CopyButton, { ref: ref, text: code, size: variant === 'floating' ? 2 : 3, className: cx(styles.copyButton, variant === 'floating' && styles.floatingCopyButton, className), ...props }));
});
CodeBlockCopyButton.displayName = 'CodeBlockCopyButton';

export { CodeBlockCollapseTrigger, CodeBlockContent, CodeBlockCopyButton, CodeBlockHeader, CodeBlockLabel };
//# sourceMappingURL=code-block-misc.js.map
