import { jsxs, jsx } from "react/jsx-runtime";
import { tcv, IconButton } from "@choiceform/design-system";
import { FileCode, ClipboardSmall, Enlarge } from "@choiceform/icons-react";
import { memo } from "react";
import { t } from "../../../../i18n/index.js";
import { getIconFromFilename, getLanguageIcon } from "../utils/language-icon-map.js";
const codeBlockHeaderTv = 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 = 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 = getIconFromFilename(filename);
    if (filenameIcon) iconSrc = filenameIcon;
  }
  if (!iconSrc) {
    iconSrc = getLanguageIcon(language);
  }
  const copyTooltipContent = copied ? t("common", "copied") : t("common", "copy");
  const expandTooltipContent = isExpanded ? t("common", "collapse") : t("common", "expand");
  return /* @__PURE__ */ jsxs("div", { className: tv.header({ className }), children: [
    /* @__PURE__ */ jsxs("div", { className: tv.title(), children: [
      iconSrc ? /* @__PURE__ */ jsx(
        "img",
        {
          src: iconSrc,
          alt: language,
          className: "size-4"
        }
      ) : /* @__PURE__ */ jsx(FileCode, {}),
      filename && /* @__PURE__ */ jsx("span", { className: tv.filename(), children: filename }),
      lineCount > 0 && /* @__PURE__ */ jsx("span", { className: tv.lineCount(), children: `+ ${lineCount}` })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: tv.actions(), children: [
      isExpanded && /* @__PURE__ */ jsx(
        IconButton,
        {
          className: tv.copyButton(),
          variant: "ghost",
          onClick: () => handleCopy(),
          tooltip: { content: copyTooltipContent },
          children: /* @__PURE__ */ jsx(ClipboardSmall, {})
        }
      ),
      expandable && /* @__PURE__ */ jsx(
        IconButton,
        {
          variant: "ghost",
          onClick: handleExpand,
          tooltip: {
            content: expandTooltipContent
          },
          children: /* @__PURE__ */ jsx(Enlarge, {})
        }
      )
    ] })
  ] });
});
export {
  Header
};
//# sourceMappingURL=header.js.map
