import {FlatListProps, StyleProp, ViewStyle} from 'react-native';
import {AvatarProps} from '@components/_HuGo/Avatar';
import {TitleProps} from '@components/_HuGo/Title';

import {InputAccessibilities, InputCommonProps} from '../../interfaces';
import {UseInputControllerProps} from '../../hooks/useInputController';

export type OnChangeCallback<T> = (newValue: T) => void;

export interface InputSelectOption<T = number> {
  id: T;
  label: string;
  description?: string;
  AvatarProps?: Pick<
    AvatarProps,
    | 'Icon'
    | 'name'
    | 'url'
    | 'emoji'
    | 'iconColor'
    | 'size'
    | 'rounded'
    | 'variant'
  >;
  disabled?: boolean;
  titleProps?: Pick<TitleProps, 'topText'>;
  children?: React.ReactNode;
}

interface BaseInputProps<T> extends InputCommonProps, InputAccessibilities {
  createButtonLabel?: string;
  filterable?: boolean;
  ListEmptyComponent?: FlatListProps<
    InputSelectOption<T>
  >['ListEmptyComponent'];
  enableDynamicSizing?: boolean;
  onClose?: () => void;
  onCreatePress?: () => void;
  onFilterText?: (filterText: string) => void;
  searchPlaceholder?: string;
  options: InputSelectOption<T>[];
  snapPoints?: (string | number)[];
  withCreateButton?: boolean;
  withDivider?: boolean;
  onEndReached?: () => void;
  formatSelectedItem?: (selectedItem: InputSelectOption<T>) => string;
  /**
   * Show Radio component on the left o items. Only for not multipleSelect
   */
  showRadioButtonItem?: boolean;
  /**
   * If true, shows the avatar in the collapsed input field when an item is selected.
   * @default true
   */
  showAvatarInCollapsedInput?: boolean;
  style?: StyleProp<ViewStyle>;
  modalTitleNumberOfLines?: number;
  menuTitle?: string;
}

export interface SingleSelectProps<T> extends BaseInputProps<T> {
  value?: T;
  onChange?: OnChangeCallback<T>;
  multipleSelect?: boolean;
}

export interface MultiSelectProps<T> extends BaseInputProps<T> {
  value?: T[];
  onChange?: OnChangeCallback<T[]>;
  multipleSelect: boolean;
}

export type InputSelectProps<T> = SingleSelectProps<T> | MultiSelectProps<T>;

type SingleSelectControllerProps<T> = SingleSelectProps<T> &
  UseInputControllerProps;

type MultiSelectControllerProps<T> = MultiSelectProps<T> &
  UseInputControllerProps;

export type InputSelectControllerProps<T> =
  | SingleSelectControllerProps<T>
  | MultiSelectControllerProps<T>;
