import {
  type Member,
  StatusUser,
} from 'src/pages/dashboard/Conversations/types';

export const MAX_EMOJIS_LIMIT = 8;

export const CONVERSATIONS_SPACING = {
  gifHorizontalWidth: 272,
  gifVerticalWidth: 160,
  gifSquareWidth: 160,
};

export const MAX_CHARACTERS = 10000;
export const MAX_GROUP_DESCRIPTION_LENGTH = 2047;
export const DIFF_TO_SHOW_WARNING = 50;
export const MAX_PINNED_CONVERSATIONS = 5;
export const MAX_PINNED_MESSAGES = 3;
export const MAX_UNREAD_CHANNEL_PAGES = 10;

export const CONVERSATION_TYPE = {
  GROUP: 'group',
  INDIVIDUAL: 'individual',
};

export const CONVERSATION_LEFT_REASON = {
  VOLUNTARY: 'voluntary',
  KICKED: 'kicked',
};

export const MESSAGE_TYPE = {
  TEXT: 'text',
  IMAGE: 'image',
  IMAGE_AND_TEXT: 'imageAndText',
  FILE: 'file',
  FILE_AND_TEXT: 'fileAndText',
  VOICE_NOTE: 'voiceNote',
  VIDEO: 'video',
  VIDEO_AND_TEXT: 'videoAndText',
  IMAGES_AND_VIDEO: 'imagesAndVideo',
  IMAGES_AND_VIDEO_AND_TEXT: 'imagesAndVideoAndText',
  IMAGES_AND_FILE: 'imagesAndFile',
  VIDEOS_AND_FILE: 'videosAndFile',
  IMAGES_AND_VIDEOS_AND_FILE: 'imagesAndVideosAndFile',
};

export const MEDIA_ORIGIN = {
  PASTE: 'paste',
  DRAG_AND_DROP: 'dragAndDrop',
  GALLERY: 'gallery',
  FILE_EXPLORER: 'fileExplorer',
};

// Regex to match user mentions in format <@U{numbers}>
// Validates if text contains mentions with specific user ID format
export const userMentionRegex = /<@U\d+>/;

// Regex to extract any mention in backend-serialized form in a single pass:
// - User mentions: <@U{numbers}> (the digits are captured in group 1)
// - @all mention: <!channel> (no capture group; identified by match[1] === undefined)
export const mentionTagRegex = /<@U(\d+)>|<!channel>/g;

// Regex to match user mentions in flexible format <@U...>
// Captures anything between <@U and > for broader mention support
export const flexibleUserMentionRegex = /<@U[^>]+>/g;

// Combined regex to match URLs and user mentions
// Matches: URLs (http/https/www) and user mentions in <@U...> format
export const urlAndMentionCombinedRegex =
  /(https?:\/\/[^\s]+|www\.[^\s]+|<@U[^>]+>|<!channel>)/g;

// Regex to validate if a string contains only numeric characters
// Used to determine if extracted user ID is a valid number
export const numericOnlyRegex = /^\d+$/;

// Regex to extract content between <@U and >
// Used to parse user mentions and extract the ID portion
export const mentionContentRegex = /<@U([^>]+)>/;

export const BUBBLE_CLASS = 'message-bubble';

export const AUTO_HIDE_DURATION = 3000;
export const CONVERSATIONS_THREAD_FOOTER_ID = 'conversations-thread-footer';
export const MAX_RETRY_ATTEMPTS = 3;
export const RETRY_DELAY_MS = 1000;
export const RETRY_TIMEOUT_MS = 10000;
export const MAX_RECORDING_DURATION = 10 * 60 * 1000;
export const CONVERSATIONS_GORUP_INFO_ID = 'conversations-group-info';

export const THREE_MINUTES = 3 * 60 * 1000;
export const GLOBAL_COOLDOWN = 60 * 3000;
export const CONVERSATIONS_MESSAGES_CONTAINER =
  'conversation-messages-container';
export const CONVERSATIONS_LIST_CONTAINER = 'conversations-list-container';
export const CONVERSATIONS_SIDEBAR_SCROLLBAR =
  'conversations-sidebar-scrollbar';
export const CONVERSATIONS_LIST_DIVIDER = 'conversations-list-divider';
export const CONVERSATIONS_ROW_LIST_ITEM = 'conversations-row-list-item';
export const MESSAGE_EDIT_DIALOG_ID = 'setting-message-edit';
export const MESSAGE_FORWARD_DIALOG_ID = 'setting-message-forward';
export const MESSAGE_PIN_DIALOG_ID = 'setting-message-pin';
export const MESSAGE_DELETE_DIALOG_ID = 'setting-message-delete';

export const USER_ALL: Member = {
  employee_internal_id: '<!channel>',
  first_name: '',
  id: -1,
  last_name: 'all',
  picture_url: '',
  status: StatusUser.ACTIVE,
};

export const MIN_QUERY_LENGTH = 2;

// Regex to validate if a string contains at least one letter or number (any script/locale)
// \p{L} = any Unicode letter (Latin, Cyrillic, Greek, etc.), \p{N} = any numeric character
export const ALPHANUMERIC_REGEX = /[\p{L}\p{N}]/u;
export const TUTORIAL_VIEWED_KEY = 'conversations_tutorial_viewed';

export const MAX_MEDIA_SIZE_MB = 150;

export const CONVERSATIONS_LIST_DIVIDER_STACK_SX = {
  [`.${CONVERSATIONS_ROW_LIST_ITEM}:hover + .${CONVERSATIONS_LIST_DIVIDER}`]: {
    marginInline: 0,
  },
  [`.${CONVERSATIONS_ROW_LIST_ITEM}[data-selected="true"] + .${CONVERSATIONS_LIST_DIVIDER}`]:
    {
      marginInline: 0,
    },
  [`& #${CONVERSATIONS_LIST_CONTAINER} [data-index]:has(+ [data-index]:hover) > .${CONVERSATIONS_LIST_DIVIDER}`]:
    {
      marginInline: 0,
    },
  [`& #${CONVERSATIONS_LIST_CONTAINER} [data-index]:has(+ [data-index] .${CONVERSATIONS_ROW_LIST_ITEM}[data-selected="true"]) > .${CONVERSATIONS_LIST_DIVIDER}`]:
    {
      marginInline: 0,
    },
} as const;

export const SEE_MEDIA_MODAL_DIALOG_PROPS = {
  fullWidth: true,
  maxWidth: 'md' as const,
  transitionDuration: 0,
  disableRestoreFocus: true,
};

export const CONVERSATIONS_SERVICE_UNAVAILABLE = 542;

export const PIN_DUPLICATED_ACTION_ERRORS = ['already_pinned', 'no_pin'];

/**
 * For detail see:
 * @see https://www.notion.so/humand-co/Bunny-definitions-2cb7dc53cfb0436a9afea692776b5142
 */

export const BUNNY_IMAGE_CLASSES = {
  AVATAR: 'cwAvatar',
  AVATAR_LG: 'cwAvatarLg',
  FA_THUMB: 'cwFaThumb',
  MSG_IMG_LG: 'cwMsgImgLg',
  MSG_IMG_SM: 'cwMsgImgSm',
} as const;

export type BunnyImageClass =
  (typeof BUNNY_IMAGE_CLASSES)[keyof typeof BUNNY_IMAGE_CLASSES];

// MediaVisualizer
export const HIDE_TIMEOUT_MS = 3000;
export const MAX_ZOOM = 8;
export const THUMBNAIL_SIZE = 70;
export const THUMBNAIL_ICON_SIZE = 20;
export const FLOATING_MESSAGE_MAX_WIDTH = 400;
export const FLOATING_MESSAGE_EXPANDED_MAX_HEIGHT = 150;
export const FLOATING_MESSAGE_COLLAPSED_LINES = 2;
export const FLOATING_MESSAGE_CHARS_PER_LINE = 60;
export const FLOATING_MESSAGE_LONG_TEXT_THRESHOLD =
  FLOATING_MESSAGE_COLLAPSED_LINES * FLOATING_MESSAGE_CHARS_PER_LINE;
