import React from 'react';
import { CompanySelector } from '@d8d/allin-company-management-ui';

interface CompanySelectorWrapperProps {
  value?: number | null;
  onChange?: (value: number | null) => void;
  placeholder?: string;
  disabled?: boolean;
  className?: string;
  'data-testid'?: string;
  platformId?: number;
}

export const CompanySelectorWrapper: React.FC<CompanySelectorWrapperProps> = ({
  value,
  onChange,
  placeholder = "请选择公司",
  disabled = false,
  className,
  'data-testid': testId,
  platformId,
}) => {
  // 将null转换为undefined传递给CompanySelector
  const handleChange = (newValue: number) => {
    onChange?.(newValue);
  };

  // CompanySelector期望number | undefined，我们将null转换为undefined
  const selectorValue = value === null ? undefined : value;

  return (
    <CompanySelector
      value={selectorValue}
      onChange={handleChange}
      placeholder={placeholder}
      disabled={disabled}
      className={className}
      data-testid={testId}
      platformId={platformId}
    />
  );
};

export default CompanySelectorWrapper;