/**
 * 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 (
		<button
			class="inline-code"
			onClick={handleClick}
			title="Click to copy"
			{...props}
		>
			<span>{children}</span>
		</button>
	);
}
