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

export interface LinkButtonProps {
	"class"?: string
	id?: string
	href: string
	external?: boolean
	onClick?: (ev: Event) => void
}

export interface FormButtonProps {
	"class"?: string
	id?: string
	type?: HTMLButtonElement["type"]
	href?: null
	external?: null
	name?: string
	value?: string
	disabled?: boolean
	onClick?: (ev: Event) => void
}

export function LinkButton({"class": className, id, href, external, onClick, children}: LinkButtonProps & PropsWithChildren) {
	return <a
		class={`button${className ? " " + className : ""}`}
		href={href}
		{...(external ? {rel: "external nofollow noreferrer"} : {})}
		{...(id ? {id} : {})}
		{...(onClick ? {onClick} : {})}
		draggable={false}>
		{children}
	</a>
}

export function FormButton({"class": className, id, name, value, disabled, type = "button", onClick, children}: FormButtonProps & PropsWithChildren) {
	return <button
		type={type}
		{...(id ? {id} : {})}
		{...(onClick ? {onClick} : {})}
		{...(name ? {name} : {})}
		{...(value ? {value} : {})}
		{...(typeof disabled === "boolean" ? {disabled} : {})}
		class={`button${className ? " " + className : ""}`}>
		{children}
	</button>
}
