"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 codeBlock_module = require('./code-block.module.css.cjs');

const CodeBlockContext = React.createContext(undefined);
const useCodeBlockContext = () => {
    const context = React.useContext(CodeBlockContext);
    if (!context) {
        throw new Error('useCodeBlockContext must be used within a CodeBlock');
    }
    return context;
};
const CodeBlockRoot = React.forwardRef(({ children, value: providedValue, onValueChange, defaultValue, hideLineNumbers = false, maxLines, maxHeight, className, collapsed: providedCollapsed, defaultCollapsed = true, onCollapseChange, ...props }, ref) => {
    const [internalValue, setInternalValue] = React.useState(defaultValue);
    const [code, setCode] = React.useState();
    const [internalCollapsed, setInternalCollapsed] = React.useState(defaultCollapsed ?? false);
    const collapsed = providedCollapsed ?? internalCollapsed;
    const value = providedValue ?? internalValue ?? defaultValue;
    const setValue = React.useCallback((newValue) => {
        setInternalValue(newValue);
        onValueChange?.(newValue);
    }, [onValueChange]);
    const toggleCollapsed = React.useCallback(() => {
        setInternalCollapsed(_internalCollapsed => {
            onCollapseChange?.(!_internalCollapsed);
            return !_internalCollapsed;
        });
    }, [onCollapseChange]);
    return (jsxRuntime.jsx(CodeBlockContext.Provider, { value: {
            hideLineNumbers,
            value,
            setValue,
            code,
            setCode,
            maxLines: maxLines && maxLines + 1, // to compensate for the absolute collapse trigger
            collapsed,
            toggleCollapsed
        }, children: jsxRuntime.jsx("div", { ref: ref, className: index.cx(codeBlock_module.default.container, className), ...props, children: children }) }));
});
CodeBlockRoot.displayName = 'CodeBlock';

exports.CodeBlockRoot = CodeBlockRoot;
exports.useCodeBlockContext = useCodeBlockContext;
//# sourceMappingURL=code-block-root.cjs.map
