import { Slider, SxProps, Theme, useTheme } from "@mui/material";

type CustomSliderProps = {
  defaultValue?: number;
  value?: number | number[];
  min?: number;
  max?: number;
  step?: number;
  sx?: SxProps<Theme>;
  onChange?: (_: Event, value: number | number[]) => void;
  onChangeCommitted?: (
    _: React.SyntheticEvent | Event,
    value: number | number[],
  ) => void;
  className: string;
};

export const CustomSlider = ({
  defaultValue,
  value,
  min = 0,
  max = 100,
  step,
  onChange,
  onChangeCommitted,
  sx,
  className,
}: CustomSliderProps) => {
  const theme = useTheme();

  return (
    <Slider
      className={className || ""}
      value={value}
      defaultValue={defaultValue}
      min={min}
      max={max}
      step={step}
      onChange={onChange}
      valueLabelDisplay="on"
      onChangeCommitted={onChangeCommitted}
      onMouseDown={(e) => e.stopPropagation()}
      data-cy="slider"
      sx={{
        color: "#7E2AEA",
        padding: "0",
        marginTop: "75px",
        "& .MuiSlider-valueLabel": {
          background: "#7E2AEA",
          borderRadius: "8px",
          minWidth: "60px",
          width: "auto",
          whiteSpace: "nowrap",
          textAlign: "center",
          height: "36px",
        },
        "& .MuiSlider-valueLabel::before": {
          width: "6px",
          height: "2px",
          transform: "translate(-50%, 50%) rotate(90deg)",
          bottom: "-5px",
        },
        "& .MuiSlider-rail": {
          backgroundColor: "#F2F3F7",
          border: `1px solid #9A9AAF`,
          height: "12px",
        },
        "& .MuiSlider-thumb": {
          border: "3px #f2f3f7 solid",
          height: "23px",
          width: "23px",
        },
        "& .MuiSlider-track": {
          height: "12px",
        },
        ...sx,
      }}
    />
  );
};
