import {ReactNode, RefObject} from 'react';

import {RenderSceneProps, TabItem} from './interfaces';

export function buildRenderSceneWithActive(
  routes: TabItem[],
  indexRef: RefObject<number>,
  renderScene: (props: RenderSceneProps) => ReactNode,
) {
  return (props: RenderSceneProps): ReactNode => {
    const activeRouteKey = routes[indexRef.current]?.key ?? routes[0]?.key;

    return renderScene({
      ...props,
      isActive: props.route.key === activeRouteKey,
    });
  };
}
