import { cn } from "../../utils/cn.mjs";
import { Container } from "../Container/index.mjs";
import { ExpandCollapse } from "../ExpandCollapse/ExpandCollapse.mjs";
import { CodeBlock } from "./CodeBlockClient.mjs";
import { CodeConditionalRender } from "./CodeConditionalRenderer.mjs";
import { CodeFormatSelector } from "./CodeFormatSelector.mjs";
import { ContentDeclarationFormatSelector } from "./ContentDeclarationFormatSelector.mjs";
import { CopyCode } from "./CopyCode.mjs";
import { PackageManagerSelector } from "./PackageManagerSelector.mjs";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";

//#region src/components/IDE/Code.tsx
const MIN_HEIGHT = 700;
const Code = ({ children, language, isDarkMode, showHeader = true, showLineNumbers = true, className, fileName, packageManager, codeFormat, contentDeclarationFormat, isRollable = true, ...props }) => {
	const code = children?.endsWith("\n") ? children.slice(0, -1) : children;
	const hadSelectInHeader = packageManager || codeFormat || contentDeclarationFormat;
	return /* @__PURE__ */ jsx(CodeConditionalRender, {
		packageManager,
		codeFormat,
		contentDeclarationFormat,
		children: /* @__PURE__ */ jsxs(Container, {
			className: cn("relative min-w-0 max-w-full text-sm leading-6", showLineNumbers && "with-line-number ml-0", className),
			transparency: "lg",
			...props,
			children: [showHeader && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
				className: "grid w-full grid-cols-[1fr_auto] items-center justify-between rounded-t-xl bg-card/50 py-1.5 pr-12 pl-4 text-neutral text-xs",
				children: [/* @__PURE__ */ jsx("span", {
					className: "truncate",
					children: fileName ?? language
				}), /* @__PURE__ */ jsxs("div", {
					className: "flex items-center gap-2",
					children: [
						packageManager && /* @__PURE__ */ jsx(PackageManagerSelector, {}),
						codeFormat && /* @__PURE__ */ jsx(CodeFormatSelector, {}),
						contentDeclarationFormat && /* @__PURE__ */ jsx(ContentDeclarationFormatSelector, {})
					]
				})]
			}), /* @__PURE__ */ jsx("div", {
				className: "sticky top-46 z-20",
				children: /* @__PURE__ */ jsx("div", {
					className: cn("absolute right-2 bottom-0 flex h-7 items-center", hadSelectInHeader && "h-11"),
					children: /* @__PURE__ */ jsx(CopyCode, { code })
				})
			})] }), /* @__PURE__ */ jsx(ExpandCollapse, {
				minHeight: MIN_HEIGHT,
				isRollable,
				className: "min-w-0 max-w-full overflow-x-auto p-2",
				children: /* @__PURE__ */ jsx(CodeBlock, {
					lang: language,
					isDarkMode,
					children: code
				})
			})]
		})
	});
};

//#endregion
export { Code };
//# sourceMappingURL=Code.mjs.map