/**
 * Author component types and utilities
 * This file provides type extensions and utilities for author components
 * while maintaining alignment with the shared schema.
 */

import type { Author, TimelineEvent } from "@shared/schema";

// Extended author type for UI components with computed properties
export interface AuthorWithStats extends Author {
  /**
   * Number of works by the author (computed)
   */
  worksCount?: number;
  /**
   * Number of followers/readers (computed)
   */
  followersCount?: number;
  /**
   * Whether the author is followed by the current user (computed)
   */
  isFollowed?: boolean;
  /**
   * Whether the author is featured (computed)
   */
  isFeatured?: boolean;
  /**
   * Author's primary genres (computed from works)
   */
  genres?: string[];
  /**
   * Literary influences (computed)
   */
  influences?: string[];
  /**
   * Geographic location display (computed from country/city)
   */
  location?: string;
  /**
   * Literary era(s) the author is associated with (computed)
   */
  era?: string;
  /**
   * Author's nationality (computed from country)
   */
  nationality?: string;
  /**
   * Stats about the author (computed)
   */
  stats?: {
    views?: number;
    likes?: number;
    comments?: number;
  };
}

// Component variant types
export type AuthorCardVariant =
  | "default"
  | "compact"
  | "detailed"
  | "minimal"
  | "featured";
export type AuthorCardOrientation = "vertical" | "horizontal";
export type AuthorHeaderVariant =
  | "default"
  | "compact"
  | "detailed"
  | "minimal";
export type AuthorChipSize = "sm" | "md" | "lg";

// Author display utilities
export interface AuthorDisplayUtils {
  /**
   * Get formatted lifespan display (e.g., "1821 - 1881" or "1821 - present")
   */
  getLifespan: (author: Author) => string;

  /**
   * Get author initials for avatar fallback
   */
  getInitials: (name: string) => string;

  /**
   * Get display location from country/city
   */
  getLocation: (author: Author) => string | undefined;

  /**
   * Format bio with truncation
   */
  formatBio: (
    bio: string | undefined,
    maxLength: number,
    expanded?: boolean
  ) => {
    text: string;
    isTruncated: boolean;
  };
}

// Timeline event for author pages
export interface AuthorTimelineEvent extends TimelineEvent {
  /**
   * Associated author for the event
   */
  author?: Author;
}

// Author filter and search types
export interface AuthorFilters {
  country?: string;
  birthYearStart?: number;
  birthYearEnd?: number;
  genres?: string[];
  hasWorks?: boolean;
  featured?: boolean;
}

export interface AuthorSearchParams {
  query?: string;
  filters?: AuthorFilters;
  sort?: "name" | "birthYear" | "worksCount" | "popularity";
  order?: "asc" | "desc";
  limit?: number;
  offset?: number;
}

// Author action handlers
export interface AuthorActionHandlers {
  onFollow?: (author: Author, isFollowed: boolean) => void;
  onShare?: (author: Author) => void;
  onEdit?: (author: Author) => void;
  onView?: (author: Author) => void;
}

// Component prop base interfaces
export interface BaseAuthorComponentProps {
  /**
   * Author data (using shared schema)
   */
  author: Author | AuthorWithStats;

  /**
   * Whether the component is in a loading state
   */
  isLoading?: boolean;

  /**
   * Additional CSS classes
   */
  className?: string;
}

// Re-export shared types for convenience
export type { Author, TimelineEvent } from "@shared/schema";
