import { forwardRef } from "react";
import Box from "@mui/material/Box";
import { StyledCircular } from "./styles";
import Typography from "@mui/material/Typography";

interface ProgressProps {
  variant?: "determinate" | "indeterminate";
  size?: string | number;
  disableShrink?: boolean;
  thickness?: number;
  value?: number;
  color?:
    | "inherit"
    | "primary"
    | "secondary"
    | "success"
    | "error"
    | "info"
    | "warning";

  method?: "normal" | "label";
  labelvalue?: any;
  valueBuffer?: number;
  sx?: any;
}

const Progress = forwardRef(
  ({
    variant,
    method="normal",
    labelvalue,
    size=40,
    color="primary",
    sx,
    value=40,
    disableShrink=false,
    thickness=3.6,
  }: ProgressProps) => {
    return (
      <Box sx={{ display: "flex" }}>
        {method === "normal" && (
          <StyledCircular
            variant={variant}
            color={color}
            size={size}
            sx={sx}
            value={value}
            thickness={thickness}
            disableShrink={disableShrink}
          />
        )}
        {method === "label" && (
          <Box sx={{ position: "relative", display: "inline-flex" }}>
            <StyledCircular
              variant={variant}
              color={color}
              size={size}
              sx={sx}
              value={value}
              thickness={thickness}
              disableShrink={disableShrink}
            />
            <Box
              sx={{
                top: 0,
                left: 0,
                bottom: 0,
                right: 0,
                position: "absolute",
                display: "flex",
                alignItems: "center",
                justifyContent: "center",
              }}
            >
              <Typography
                variant="caption"
                component="div"
                color="text.secondary"
              >{`${Math.round(labelvalue)}%`}</Typography>
            </Box>
          </Box>
        )}
      </Box>
    );
  }
);
export default Progress;
