import {Button, ButtonProps} from "antd";
import React, {FC, ReactNode} from "react";
import "./Button.scss";
import Loading from "./Loading";
import { ReactComponent as Downicon } from "../../Assets/Caret-Down.svg";
import { ReactComponent as Circle } from "../../Assets/Circle.svg";

export type StyleType =
    | "positive"
    | "negative"
    | "neutral"
    | "primary"
    | "ghost"
    | "badge"
    | "tertiary"
    | "secondary"
    | "link";

export interface StarshipButtonProps {
    styleType?: StyleType;
    leftIcon?: ReactNode;
    rightIcon?: ReactNode;
    badge?: ReactNode;
    isDropdown?: boolean;
    rounded?: boolean;
}
//Partial<{ styleType: StyleType }>;

const StarshipButton: FC<StarshipButtonProps & ButtonProps> = props => {
    const {
        className,
        styleType = "primary",
        type = "primary",
        shape,
        ...buttonProps
    } = props;
    const btnType: {[key in StyleType]: string} = {
        positive: "starship-btn-positive",
        negative: "starship-btn-negative",
        neutral: "starship-btn-neutral",
        primary: "starship-btn-primary",
        ghost: "starship-btn-ghost",
        badge: "starship-btn-badge",
        tertiary: "starship-btn-tertiary",
        secondary: "starship-btn-secondary",
        link: "starship-btn-link",
    };
    return (
        <Button
            
            {...buttonProps}
            type={type}
            className={`${
                shape === "round" && "round"
            } starship-btn ${props.className} ${btnType[styleType]}`}
        >
            {buttonProps.leftIcon && !buttonProps.loading ? buttonProps.leftIcon : null}
            {buttonProps.loading ? <Loading /> : buttonProps.children}
            {buttonProps.rightIcon  && !buttonProps.loading ?  buttonProps.rightIcon : null}
            {buttonProps.badge  && !buttonProps.loading && <span className={"badge"}>{buttonProps.badge}</span>}
            {buttonProps.isDropdown  && !buttonProps.loading && <Downicon/>}
        </Button>
    );
};

export default StarshipButton;
