import React from 'react';
import { SupportedCardGalleryItemProps } from './SupportedCardGalleryItemProps';

type RenderItemRawProps = Omit<
  Partial<SupportedCardGalleryItemProps>,
  'title' | 'subtitle>'
>;

type GridPresetFullProps<T, P> = P & {
  preset: 'full';
  renderItem?: (
    item: T,
    index: number,
  ) => RenderItemRawProps & {
    title?: React.ReactNode;
    subtitle?: React.ReactNode;
  };
};

type GridPresetFooterProps<T, P> = P & {
  preset: 'footer';
  renderItem?: (
    item: T,
    index: number,
  ) => RenderItemRawProps & {
    title?: React.ReactNode;
    subtitle?: React.ReactNode;
  };
};

type GridPresetTitleProps<T, P> = P & {
  preset?: 'title';
  renderItem?: (
    item: T,
    index: number,
  ) => RenderItemRawProps & {
    title?: React.ReactNode;
    subtitle?: undefined;
  };
};

type GridPresetEmptyProps<T, P> = P & {
  preset: 'empty';
  renderItem?: (
    item: T,
    index: number,
  ) => RenderItemRawProps & {
    title?: undefined;
    subtitle?: undefined;
  };
};

export type Preset = 'full' | 'footer' | 'title' | 'empty';

type GridPresetGenericProps<T, P> = P & {
  preset?: Preset;
  renderItem?: (
    item: T,
    index: number,
  ) => RenderItemRawProps & {
    title?: React.ReactNode;
    subtitle?: React.ReactNode;
  };
};

export type GridPresetProps<T, P> =
  | GridPresetFullProps<T, P>
  | GridPresetTitleProps<T, P>
  | GridPresetEmptyProps<T, P>
  | GridPresetGenericProps<T, P>
  | GridPresetFooterProps<T, P>;
