import { SplitButton } from "@progress/kendo-react-buttons";
import withToolTip from "../../../hoc/withToolTip";
import { ComprehensiveProps } from "../../DomainProps";

export interface ButtonDropdownProps extends ComprehensiveProps {
  dropdownItems?: any[];
  title?: string;
  fillMode?: "link" | "solid" | "outline" | "flat";
  name?: string;
  popupSettings?: any;
}

function ButtonDropdownWidget({
  id,
  widgetStyle,
  dropdownItems,
  fillMode,
  title,
  disabled,
  name,
  popupSettings,
}: ButtonDropdownProps) {
  // Handle fillMode to ensure it's a valid value
  const validFillMode = fillMode && ["link", "solid", "outline", "flat"].includes(fillMode) ? fillMode : undefined;

  return (
    <SplitButton
      id={widgetStyle?.id}
      className={widgetStyle?.className || ""}
      text={title}
      items={dropdownItems}
      fillMode={validFillMode}
      disabled={disabled}
      popupSettings={popupSettings}
    />
  );
}

export default withToolTip(ButtonDropdownWidget);