import { Button as BaseButton } from "@mosaic/ui";
import type { ButtonProps as BaseButtonProps } from "@mosaic/ui";
import type { ReactNode } from "react";

// Extend Button to support additional variants
type ExtendedVariant =
  | "default"
  | "primary"
  | "secondary"
  | "danger"
  | "ghost"
  | "outline"
  | "destructive"
  | "link";

export interface ButtonProps extends Omit<BaseButtonProps, "variant" | "size"> {
  variant?: ExtendedVariant;
  size?: "sm" | "md" | "lg" | "icon";
  children: ReactNode;
}

// Map extended variants to base variants
const variantMap: Record<string, "primary" | "secondary" | "danger" | "ghost"> = {
  default: "primary",
  outline: "ghost",
  destructive: "danger",
  link: "ghost",
};

export function Button({
  variant = "primary",
  size = "md",
  ...props
}: ButtonProps): React.JSX.Element {
  const mappedVariant = variantMap[variant] ?? variant;
  const mappedSize = size === "icon" ? "sm" : size;

  return (
    <BaseButton
      variant={mappedVariant as "primary" | "secondary" | "danger" | "ghost"}
      size={mappedSize}
      {...props}
    />
  );
}
