import { EventPostType } from 'src/types/events';
import { GroupPost } from 'src/types/groups';
import { MarketplacePost } from 'src/types/marketplace';
import { Post } from 'src/types/posts';

export type PostCardContext = 'feed' | 'groups' | 'marketplace' | 'events';

/** MarketplacePost with dates normalized to strings for consistency with other post types */
export type NormalizedMarketplacePost = Omit<
  MarketplacePost,
  'createdAt' | 'updatedAt' | 'publicationDatetime'
> & {
  createdAt: string;
  updatedAt: string;
  publicationDatetime: string;
};

// Common UI props
export type CommonPostCardProps = {
  isDetail?: boolean;
  hideReactions?: boolean;
  hideComments?: boolean;
  hideTranslation?: boolean;
  hideAction?: boolean;
  hideKeyUpdateHeader?: boolean;
  hideFeatures?: boolean;
  matchText?: string;
  openProfileInNewTab?: boolean;
  showExternalLink?: boolean;
  elementId?: string;
  abbreviateDate?: boolean;
  mediaMaxHeight?: number;
  postApprovalControls?: {
    handleApprove: () => void;
    handleReject: () => void;
  };
  showSeeMoreToggle?: boolean;
  onShowMore?: () => void;
  onShowLess?: () => void;
  onClick?: () => void;

  // Reaction callbacks
  onAddReaction?: (postId: number, emoji: string, unified: string) => void;
  onRemoveReaction?: (postId: number, emoji: string) => void;
};

// Feed-specific props
export type FeedPostCardProps = CommonPostCardProps & {
  context: 'feed';
  post: Post;
  // Feed-specific
  isPinned?: boolean;
  hidePinIcon?: boolean;
};

// Groups-specific props
export type GroupsPostCardProps = CommonPostCardProps & {
  context: 'groups';
  post: GroupPost;
  groupId: string;
  // Group-specific
  isPinned?: boolean;
  hidePinIcon?: boolean;
  showBreadcrumb?: boolean;
  viewed?: boolean;
  // Group member info
  userIsMember?: boolean;
  isGroupArchived?: boolean;
  isGroupAdmin?: boolean;
};

// Marketplace-specific props
export type MarketplacePostCardProps = CommonPostCardProps & {
  context: 'marketplace';
  post: NormalizedMarketplacePost;
  // Contact handling
  onContact?: () => void;
  showContact?: boolean;
};

export type EventsPostCardProps = CommonPostCardProps & {
  context: 'events';
  post: EventPostType;
  eventId: number;
  isEventManager?: boolean;
  isEventCreator?: boolean;
  onEditPost?: (post: EventPostType) => void;
  onDeletePost?: (post: EventPostType) => void;
};

export type UnifiedPostCardProps =
  | FeedPostCardProps
  | GroupsPostCardProps
  | MarketplacePostCardProps
  | EventsPostCardProps;

export type ReactionsEnabledProps = {
  hideReactions?: false;
  onAddReaction: (postId: number, emoji: string, unified: string) => void;
  onRemoveReaction: (postId: number, emoji: string) => void;
};

export type ReactionsDisabledProps = {
  hideReactions: true;
  onAddReaction?: never;
  onRemoveReaction?: never;
};
