import type { JSX } from "solid-js";

import { Dynamic } from "solid-js/web";
import clsx from "clsx";

type ProseProps = JSX.IntrinsicElements["div"] & {
	class?: string;
	as?: keyof JSX.IntrinsicElements;
};

export function Prose(props: ProseProps) {
	const Component = props.as ?? "div";

	return (
		<Dynamic
			component={Component}
			class={clsx(
				props.class,
				"prose max-w-none prose-slate dark:text-slate-400 dark:prose-invert",
				// headings
				"prose-headings:scroll-mt-28 prose-headings:font-display prose-headings:font-normal lg:prose-headings:scroll-mt-[8.5rem]",
				// lead
				"prose-lead:text-slate-500 dark:prose-lead:text-slate-400",
				// links
				"prose-a:font-semibold dark:prose-a:text-violet-400",
				// link underline
				"dark:[--tw-prose-background:var(--color-slate-900)] prose-a:no-underline prose-a:shadow-[inset_0_-2px_0_0_var(--tw-prose-background,#fff),inset_0_calc(-1*(var(--tw-prose-underline-size,4px)+2px))_0_0_var(--tw-prose-underline,var(--color-violet-300))] prose-a:hover:[--tw-prose-underline-size:6px] dark:prose-a:shadow-[inset_0_calc(-1*var(--tw-prose-underline-size,2px))_0_0_var(--tw-prose-underline,var(--color-violet-800))] dark:prose-a:hover:[--tw-prose-underline-size:6px]",
				// pre
				"prose-pre:rounded-xl prose-pre:bg-slate-900 prose-pre:shadow-lg dark:prose-pre:bg-slate-800/60 dark:prose-pre:ring-1 dark:prose-pre:shadow-none dark:prose-pre:ring-slate-300/10",
				// hr
				"dark:prose-hr:border-slate-800",
			)}
			{...props}
		/>
	);
}
