"use client";
'use strict';

var jsxRuntime = require('react/jsx-runtime');
var index = require('../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.cjs');
var React = require('react');
var button = require('../button/button.cjs');
var copyButton = require('../copy-button/copy-button.cjs');
var flex = require('../flex/flex.cjs');
var text = require('../text/text.cjs');
var codeBlockRoot = require('./code-block-root.cjs');
var codeBlock_module = require('./code-block.module.css.cjs');

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

exports.CodeBlockCollapseTrigger = CodeBlockCollapseTrigger;
exports.CodeBlockContent = CodeBlockContent;
exports.CodeBlockCopyButton = CodeBlockCopyButton;
exports.CodeBlockHeader = CodeBlockHeader;
exports.CodeBlockLabel = CodeBlockLabel;
//# sourceMappingURL=code-block-misc.cjs.map
