import { ComponentType } from 'react';

interface KanbanCommonLocalization {
    backToBoards: string;
    actions: string;
    create: string;
    edit: string;
    delete: string;
    cancel: string;
    save: string;
    loading: string;
    saving: string;
    deleting: string;
    board: string;
    boards: string;
    column: string;
    columns: string;
    task: string;
    tasks: string;
    priorityLow: string;
    priorityMedium: string;
    priorityHigh: string;
    priorityUrgent: string;
    noBoards: string;
    noColumns: string;
    noTasks: string;
    errorGeneric: string;
    errorNotFound: string;
}

interface KanbanFormsLocalization {
    boardName: string;
    boardNamePlaceholder: string;
    boardDescription: string;
    boardDescriptionPlaceholder: string;
    createBoard: string;
    updateBoard: string;
    deleteBoard: string;
    deleteBoardConfirm: string;
    columnTitle: string;
    columnTitlePlaceholder: string;
    createColumn: string;
    updateColumn: string;
    deleteColumn: string;
    deleteColumnConfirm: string;
    taskTitle: string;
    taskTitlePlaceholder: string;
    taskDescription: string;
    taskDescriptionPlaceholder: string;
    taskPriority: string;
    taskColumn: string;
    taskAssignee: string;
    createTask: string;
    updateTask: string;
    deleteTask: string;
    deleteTaskConfirm: string;
    nameRequired: string;
    titleRequired: string;
}

interface KanbanListLocalization {
    kanbanBoards: string;
    manageProjects: string;
    createNewBoard: string;
    boardDetails: string;
    newBoard: string;
    addColumn: string;
    addTask: string;
    columnsCount: string;
    noBoardsDescription: string;
    noColumnsDescription: string;
    noTasksDescription: string;
}

type KanbanLocalization = Partial<KanbanCommonLocalization & KanbanFormsLocalization & KanbanListLocalization>;

/**
 * User information for assignee display/selection
 * Framework-agnostic - consumers map their auth system to this shape
 */
interface KanbanUser {
    id: string;
    name: string;
    avatarUrl?: string;
    email?: string;
}
/**
 * Context passed to lifecycle hooks
 */
interface RouteContext {
    /** Current route path */
    path: string;
    /** Route parameters (e.g., { boardId: "abc123" }) */
    params?: Record<string, string>;
    /** Whether rendering on server (true) or client (false) */
    isSSR: boolean;
    /** Additional context properties */
    [key: string]: unknown;
}
/**
 * Overridable components and functions for the Kanban plugin
 *
 * External consumers can provide their own implementations of these
 * to customize the behavior for their framework (Next.js, React Router, etc.)
 */
interface KanbanPluginOverrides {
    /**
     * Link component for navigation
     */
    Link?: ComponentType<React.ComponentProps<"a"> & Record<string, unknown>>;
    /**
     * Navigation function for programmatic navigation
     */
    navigate: (path: string) => void | Promise<void>;
    /**
     * Refresh function to invalidate server-side cache (e.g., Next.js router.refresh())
     */
    refresh?: () => void | Promise<void>;
    /**
     * Image component for displaying images
     */
    Image?: ComponentType<React.ImgHTMLAttributes<HTMLImageElement> & Record<string, unknown>>;
    /**
     * Localization object for the kanban plugin
     */
    localization?: KanbanLocalization;
    /**
     * API base URL
     */
    apiBaseURL: string;
    /**
     * API base path
     */
    apiBasePath: string;
    /**
     * Whether to show the attribution
     */
    showAttribution?: boolean;
    /**
     * Optional headers to pass with API requests (e.g., for SSR auth)
     */
    headers?: HeadersInit;
    /**
     * Resolve user info from an assigneeId
     * Called when rendering task cards/forms that have an assignee
     * Return null for unknown users (will show fallback UI)
     */
    resolveUser: (userId: string) => Promise<KanbanUser | null> | KanbanUser | null;
    /**
     * Search/list users available for assignment
     * Called when user opens the assignee picker
     * @param query - Search query (empty string for initial load)
     * @param boardId - Optional board context for scoped user lists
     */
    searchUsers: (query: string, boardId?: string) => Promise<KanbanUser[]> | KanbanUser[];
    /**
     * Called when a route is rendered
     * @param routeName - Name of the route (e.g., 'boards', 'board', 'newBoard')
     * @param context - Route context with path, params, etc.
     */
    onRouteRender?: (routeName: string, context: RouteContext) => void | Promise<void>;
    /**
     * Called when a route encounters an error
     * @param routeName - Name of the route
     * @param error - The error that occurred
     * @param context - Route context
     */
    onRouteError?: (routeName: string, error: Error, context: RouteContext) => void | Promise<void>;
    /**
     * Called before the boards list page is rendered
     * Return false to prevent rendering (e.g., for authorization)
     * @param context - Route context
     */
    onBeforeBoardsPageRendered?: (context: RouteContext) => boolean;
    /**
     * Called before a single board page is rendered
     * Return false to prevent rendering (e.g., for authorization)
     * @param boardId - The board ID
     * @param context - Route context
     */
    onBeforeBoardPageRendered?: (boardId: string, context: RouteContext) => boolean;
    /**
     * Called before the new board page is rendered
     * Return false to prevent rendering (e.g., for authorization)
     * @param context - Route context
     */
    onBeforeNewBoardPageRendered?: (context: RouteContext) => boolean;
}

export type { KanbanPluginOverrides as K, KanbanUser as a };
