import React from "react";
import { SelectMultiple } from "./SelectMultiple";
import { SelectProps } from "./SelectProps";
import { NativeSelect } from "./NativeSelect";
import { SimulateSelect } from "./SimulateSelect";
import { forwardRefWithStatics } from "../_util/forward-ref-with-statics";

export const Select = forwardRefWithStatics(
  function Select(
    { type, ...props }: SelectProps,
    ref: React.Ref<HTMLElement>
  ) {
    // 兼容早期原生下拉选择
    if (type === "native") {
      return <NativeSelect ref={ref as any} {...props} />;
    }

    return <SimulateSelect ref={ref} {...props} />;
  },
  {
    Multiple: SelectMultiple,
    defaultLabelAlign: "middle",
  }
);

Select.displayName = "Select";
