/**
 * Copyright (c) 2025 xwra
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import { ComponentChildren } from "preact";

interface CodeProps {
  children: ComponentChildren;
  [key: string]: any;
}

export default function Code({ children, ...props }: CodeProps) {
  const handleClick = () => {
    if (typeof children === "string") {
      navigator.clipboard.writeText(children);
    }
  };
  return (
    <code
      class="inline-code"
      onClick={handleClick}
      style={{ cursor: "pointer" }}
      title={"Click to copy"}
      {...props}
    >
      <span>{children}</span>
    </code>
  );
}
