import type { PropsWithChildren } from 'preact/compat';

export interface LinkButtonProps {
	"class"?: string
	type?: "link"
	href: string
	external?: boolean
}

export interface FormButtonProps {
	"class"?: string
	type: HTMLButtonElement["type"]
	href?: null
	external?: null
}

export type ButtonProps = LinkButtonProps|FormButtonProps

export function Button({"class": className, type, href, external, children}: ButtonProps & PropsWithChildren) {
	if (href) {
		return <a
			class={`button${className ? " " + className : ""}`}
			href={href}
			{...(external ? {rel: "external nofollow noreferrer"} : {})}
			draggable={false}>
			{children}
		</a>
	} else {
		return <button type={type} class={`button${className ? " " + className : ""}`}>
			{children}
		</button>
	}
}
