import { type ForwardRefExoticComponent, type RefAttributes } from 'react';

import { type Icon, type IconProps } from '@material-hu/icons/tabler';

import {
  type NotificationChannelCodes,
  type NotificationModuleCodes,
} from './constants';

export enum RedBubbles {
  ARTICLE = 'ARTICLE',
  CHAT = 'CHAT',
  FORM_CHAT = 'FORM_CHAT',
  ONBOARDING = 'ONBOARDING',
  SURVEY = 'SURVEY',
  DOCUMENT = 'DOCUMENT',
  GROUP = 'GROUP',
}

export enum NotificationIconType {
  REACTION = 'REACTION',
  URL = 'URL',
}

export type NotificationIcon = {
  source: string;
  bgColor?: string;
  type: NotificationIconType;
};

// Sockets
export type ClearNotificationsSocket = {
  type: RedBubbles;
  id?: number;
};

export type NotificationItem = {
  id: string;
  title: string;
  description: string;
  text?: string | null;
  icon?: NotificationIcon | null;
  reaction?: string;
  iconUrl?: string;
  iconBackgroundColor?: string;
  type: unknown;
  module: unknown;
  userId: number;
  instanceId: number;
  imageUrl: string;
  deepLink: string | null;
  extraData: Record<string, unknown>;
  isRead: boolean;
  createdAt: string;
  updatedAt: string;
};

export type GetChannelsPreferencesResponse = {
  channels: Record<NotificationChannelCodes, boolean>;
};

export type GetModulesPreferencesResponse = {
  modules: Record<NotificationModuleCodes, GetChannelsPreferencesResponse>;
};

export enum FeedNotificationConfigurationMode {
  EMAIL = 'EMAIL',
}

export type GetFeedNotificationConfigurationResponse = {
  configs: {
    enabled: boolean;
    mode: FeedNotificationConfigurationMode;
  }[];
};

export type NotificationsStatsData = {
  unRead: number;
  newSinceLastSeen: number;
  capped: boolean;
};

export type ChannelPreferences = Record<NotificationChannelCodes, boolean>;

export type NotificationChannelConfig = {
  id: NotificationChannelCodes;
  title: string;
  description: string;
  isActive: boolean;
  disabled: boolean;
  icon: ForwardRefExoticComponent<IconProps & RefAttributes<Icon>>;
};

export type NotificationModuleConfig = Record<
  string,
  {
    channels: ChannelPreferences;
  }
>;

export type UseNotificationsBellOpenStateOptions = {
  /** Called on every bell click before applying open/toggle (e.g. clear bubble, close other menus). */
  onBeforeToggle?: () => void;
};
