import { cn } from "@/lib/utils";
import { CircleNotchIcon } from "@phosphor-icons/react/dist/ssr";
import Link, { type LinkProps } from "next/link";
import React from "react";
import { ButtonProps, extendedButtonVariants } from "./helpers";
export function Button(props: ButtonProps) {
const {
className,
variant,
size,
loading = false,
leftIcon,
rightIcon,
children,
as = "button",
...restProps
} = props;
const disabled = "disabled" in props ? props.disabled : false;
const isDisabled = disabled;
const buttonContent = (
<>
{loading && (
)}
{!loading && leftIcon}
{children}
{!loading && rightIcon}
>
);
if (loading) {
const loadingClassName =
variant === "ghost"
? cn(
extendedButtonVariants({ variant, size, className }),
"pointer-events-none",
)
: cn(
extendedButtonVariants({ variant: "primary", size, className }),
"pointer-events-none border-zinc-500 bg-zinc-500 text-white",
);
return as === "NextLink" ? (
{children}
) : (
);
}
if (as === "NextLink") {
return (
{buttonContent}
);
}
return (
);
}