import { ResolvedLayoutProps, ResolvedPageProps, ResolvedRootLayoutProps } from '../../types';
import React, { JSX } from 'react';

type SegmentType = 'client-root' | 'layout' | 'page';

interface SegmentDefaultsOptions {
  segmentType: SegmentType;
}

export const withSegmentDefaults =
  <T extends ResolvedPageProps | ResolvedLayoutProps | ResolvedRootLayoutProps>(
    Component: (
      props?: T
    ) => null | JSX.Element | Promise<JSX.Element> | Promise<JSX.Element[]>,
    options: SegmentDefaultsOptions
  ) =>
  (props: T) => {
    const componentProps = { ...props };

    return (
      <>
        <Component {...componentProps} />
      </>
    );
  };
