'use client';

import { KanbanBoard } from './Board';
import { SwimlanesBoard } from './SwimlanesBoard';
import { PrioritySwimlanesBoard } from './PrioritySwimlanesBoard';
import { Task, TaskStatus } from '@/lib/types';
import { CreateTaskData } from '@/clients/tasks-client';
import type { KanbanFilters } from '@/lib/types';
import { useIsMobile } from '@/hooks/useIsMobile';

interface BoardRouterProps {
  tasks: Task[];
  kanbanFilters: KanbanFilters;
  onCreateTask: (data: CreateTaskData) => Promise<void>;
  onEditTask: (task: Task) => void;
  onUpdateStatus: (taskId: string, newStatus: TaskStatus) => Promise<void>;
  visibleStatuses: TaskStatus[];
  loading: boolean;
}

export function BoardRouter({
  tasks,
  kanbanFilters,
  onCreateTask,
  onEditTask,
  onUpdateStatus,
  visibleStatuses,
  loading,
}: BoardRouterProps) {
  const isMobile = useIsMobile(768); // Tailwind md breakpoint

  // Sur mobile, toujours utiliser le board standard pour une meilleure UX
  const shouldUseSwimlanes = kanbanFilters.swimlanesByTags && !isMobile;

  // Logique de routage des boards selon les filtres
  if (shouldUseSwimlanes) {
    if (kanbanFilters.swimlanesMode === 'priority') {
      return (
        <PrioritySwimlanesBoard
          tasks={tasks}
          onCreateTask={onCreateTask}
          onEditTask={onEditTask}
          onUpdateStatus={onUpdateStatus}
          compactView={kanbanFilters.compactView as boolean}
          visibleStatuses={visibleStatuses}
          loading={loading}
        />
      );
    } else {
      return (
        <SwimlanesBoard
          tasks={tasks}
          onCreateTask={onCreateTask}
          onEditTask={onEditTask}
          onUpdateStatus={onUpdateStatus}
          compactView={kanbanFilters.compactView as boolean}
          visibleStatuses={visibleStatuses}
          loading={loading}
        />
      );
    }
  }

  // Board standard
  return (
    <KanbanBoard
      tasks={tasks}
      onCreateTask={onCreateTask}
      onEditTask={onEditTask}
      onUpdateStatus={onUpdateStatus}
      compactView={kanbanFilters.compactView as boolean}
      visibleStatuses={visibleStatuses}
    />
  );
}
