import { type CSSProperties } from 'react';
import {
  type GridImperativeAPI,
  List,
  type ListImperativeAPI,
  type ListProps,
  useGridCallbackRef,
  useGridRef,
  useListCallbackRef,
  useListRef,
} from 'react-window';

export type VirtualizedListProps<RowProps extends object> = ListProps<RowProps>;

const VirtualizedList = <RowProps extends object>({
  ...props
}: VirtualizedListProps<RowProps>) => {
  return <List {...props} />;
};

// These types had to be rebuilt do to TypeScript resctrictions on tsc.
export type DefaultRowComponentProps = {
  ariaAttributes: {
    'aria-posinset': number;
    'aria-setsize': number;
    role: 'listitem';
  };
  index: number;
  style: CSSProperties;
};

type RowComponentProps<RowProps extends object> = DefaultRowComponentProps &
  RowProps;

export type { ListImperativeAPI, GridImperativeAPI, RowComponentProps };

export { useListRef, useListCallbackRef, useGridRef, useGridCallbackRef };

export default VirtualizedList;
