import React from 'react';
import { SxProps, Theme, TooltipProps } from '@mui/material';
import { DIDProps } from '../DID';
import { AvatarProps } from '../Avatar';
import { ShortenLabelProps } from './Content/shorten-label';

type UserPublicInfo = {
  avatar: string;
  did: string;
  fullName: string;
};
export type UserMetadataLink = {
  url: string;
  favicon?: string;
};

export enum DurationEnum {
  NoClear = 'no_clear',
  ThirtyMinutes = '30_minutes',
  OneHour = '1_hour',
  FourHours = '4_hours',
  Today = 'today',
  ThisWeek = 'this_week',
  Custom = 'custom',
}

export enum StatusEnum {
  Meeting = 'meeting',
  Community = 'community',
  Holiday = 'holiday',
  OffSick = 'off_sick',
  WorkingRemotely = 'working_remotely',
}
export type UserPhoneProps = {
  country: string;
  phoneNumber?: string;
};

export type UserMetadata = {
  bio?: string;
  location?: string;
  timezone?: string;
  joinedAt?: string;
  status?: {
    value: string;
    duration?: DurationEnum;
    dateRange?: Date[];
  };
  links?: UserMetadataLink[];
  cover?: string;
  // 这两个字段是 User, 方便数据更新，在保存时同步
  email?: string;
  phone?: UserPhoneProps;
};

export type UserAddress = {
  country?: string;
  province?: string;
  city?: string;
  line1?: string;
  line2?: string;
  postalCode?: string;
};

export type User = UserPublicInfo & {
  email?: string;
  phone?: string;
  sourceProvider?: string;
  sourceAppPid?: string;
  lastLoginAt?: string;
  lastLoginIp?: string;
  createdAt?: string;
  passports?: any[];
  didSpace?: Record<string, any>;
  connectedAccounts?: any[];
  locale?: string;
  url?: string;
  inviter?: string;
  emailVerified?: boolean;
  phoneVerified?: boolean;
  // 1.16.40 新增
  metadata?: UserMetadata;
  // 1.16.41 新增
  address?: UserAddress;
};

// 头像大小
export const AvatarSize = {
  small: 32,
  medium: 40,
  large: 48,
  xlarge: 64,
};

// 卡片类型
export enum CardType {
  AvatarOnly = 'AvatarOnly', // 仅头像
  Detailed = 'Detailed', // 详细卡片
}

// 信息类型
export enum InfoType {
  NameOnly = 'NameOnly', // 仅显示名称
  Minimal = 'Minimal', // 极简模式，显示头像、名称和DID
  Basic = 'Basic', // 基本信息模式
}

// 定义UserCard属性接口
export interface UserCardProps {
  user?: User;
  did?: string;
  cardType?: CardType;
  infoType?: InfoType;
  popupInfoType?: InfoType;
  avatarSize?: number;
  showHoverCard?: boolean;
  showDid?: boolean;
  didProps?: Partial<DIDProps>;
  popupDidProps?: Partial<DIDProps>;
  popupShowDid?: boolean;

  avatarProps?: Partial<AvatarProps>;
  popupAvatarProps?: Partial<AvatarProps>;

  // 弹出层相关属性
  tooltipProps?: Partial<TooltipProps>;

  // 样式相关属性
  sx?: SxProps<Theme>;
  popupSx?: SxProps<Theme>;

  // fullName 相关属性
  shortenLabelProps?: Partial<ShortenLabelProps>;
  popupShortenLabelProps?: Partial<ShortenLabelProps>;

  // 自定义渲染 name
  // 如果设置了 renderName，shortenLabelProps 无效
  renderName?: (user: User) => React.ReactNode;
  popupRenderName?: (user: User) => React.ReactNode;

  // 自定义渲染字段
  renderFields?: string[];
  popupRenderFields?: string[];

  // 右上角内容相关属性
  renderTopRightContent?: () => React.ReactNode;
  topRightMaxWidth?: number;

  // 自定义内容渲染函数
  renderCustomContent?: () => React.ReactNode;

  // 头像点击事件
  onAvatarClick?: (user: User, e?: React.MouseEvent<HTMLDivElement>) => void;
}
