"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require$$0 = require("react/jsx-runtime");
const designSystem = require("@choiceform/design-system");
const iconsReact = require("@choiceform/icons-react");
const React = require("react");
const index = require("../../../../i18n/index.cjs");
const languageIconMap = require("../utils/language-icon-map.cjs");
const codeBlockHeaderTv = designSystem.tcv({
  slots: {
    header: "text-body-medium code-header flex h-8 items-center justify-between pr-1 pl-2",
    title: "flex items-center gap-1",
    filename: "text-secondary-foreground",
    actions: "flex items-center",
    copyButton: "opacity-0 group-hover:opacity-100",
    lineCount: "text-success-foreground ml-2 font-strong"
  },
  variants: {
    isExpanded: {
      true: { header: "bg-secondary-background" },
      false: {}
    }
  },
  defaultVariants: {
    isExpanded: true
  }
});
const Header = React.memo(function Header2(props) {
  const { className, codeBlock } = props;
  if (!codeBlock) return null;
  const {
    language,
    filename,
    lineCount,
    isExpanded,
    copied,
    expandable,
    handleExpand,
    handleCopy
  } = codeBlock;
  const tv = codeBlockHeaderTv({ isExpanded });
  let iconSrc = void 0;
  if (filename) {
    const filenameIcon = languageIconMap.getIconFromFilename(filename);
    if (filenameIcon) iconSrc = filenameIcon;
  }
  if (!iconSrc) {
    iconSrc = languageIconMap.getLanguageIcon(language);
  }
  const copyTooltipContent = copied ? index.t("common", "copied") : index.t("common", "copy");
  const expandTooltipContent = isExpanded ? index.t("common", "collapse") : index.t("common", "expand");
  return /* @__PURE__ */ require$$0.jsxs("div", { className: tv.header({ className }), children: [
    /* @__PURE__ */ require$$0.jsxs("div", { className: tv.title(), children: [
      iconSrc ? /* @__PURE__ */ require$$0.jsx(
        "img",
        {
          src: iconSrc,
          alt: language,
          className: "size-4"
        }
      ) : /* @__PURE__ */ require$$0.jsx(iconsReact.FileCode, {}),
      filename && /* @__PURE__ */ require$$0.jsx("span", { className: tv.filename(), children: filename }),
      lineCount > 0 && /* @__PURE__ */ require$$0.jsx("span", { className: tv.lineCount(), children: `+ ${lineCount}` })
    ] }),
    /* @__PURE__ */ require$$0.jsxs("div", { className: tv.actions(), children: [
      isExpanded && /* @__PURE__ */ require$$0.jsx(
        designSystem.IconButton,
        {
          className: tv.copyButton(),
          variant: "ghost",
          onClick: () => handleCopy(),
          tooltip: { content: copyTooltipContent },
          children: /* @__PURE__ */ require$$0.jsx(iconsReact.ClipboardSmall, {})
        }
      ),
      expandable && /* @__PURE__ */ require$$0.jsx(
        designSystem.IconButton,
        {
          variant: "ghost",
          onClick: handleExpand,
          tooltip: {
            content: expandTooltipContent
          },
          children: /* @__PURE__ */ require$$0.jsx(iconsReact.Enlarge, {})
        }
      )
    ] })
  ] });
});
exports.Header = Header;
//# sourceMappingURL=header.cjs.map
