/**
 * Dashboard navigation utility functions
 */

import { DateRange } from '@/services/dashboard.service';
import { FileText, Clock, Settings, Activity, LucideIcon } from 'lucide-react';

/**
 * Build filter URL params for navigation
 */
export function buildFilterUrl(filters: {
  status?: string;
  priority?: string;
  slaCompliance?: string;
  department?: string;
  dateRange?: DateRange;
  startDate?: Date;
  endDate?: Date;
  targetPage?: 'requests' | 'open-requests' | 'my-requests';
}): string {
  const params = new URLSearchParams();
  if (filters.status) params.set('status', filters.status);
  if (filters.priority) params.set('priority', filters.priority);
  if (filters.slaCompliance) params.set('slaCompliance', filters.slaCompliance);
  if (filters.department) params.set('department', filters.department);
  if (filters.dateRange) params.set('dateRange', filters.dateRange);
  if (filters.startDate) params.set('startDate', filters.startDate.toISOString());
  if (filters.endDate) params.set('endDate', filters.endDate.toISOString());
  const queryString = params.toString();
  
  // Determine target page
  const targetPage = filters.targetPage || 'requests';
  const basePath = targetPage === 'open-requests' ? '/open-requests' 
    : targetPage === 'my-requests' ? '/my-requests' 
    : '/requests';
  
  return queryString ? `${basePath}?${queryString}` : basePath;
}

export interface QuickAction {
  label: string;
  icon: LucideIcon;
  action: () => void;
  color: string;
}

/**
 * Get quick actions for dashboard
 */
export function getQuickActions(
  isAdmin: boolean,
  onNewRequest?: () => void,
  onNavigate?: (page: string) => void,
  isDealer?: boolean
): QuickAction[] {
  const actions: QuickAction[] = [];
  
  // Only add "New Request" action if user is not a dealer
  if (!isDealer) {
    actions.push({ label: 'New Request', icon: FileText, action: () => onNewRequest?.(), color: 'bg-emerald-600 hover:bg-emerald-700' });
  }
  
  actions.push(
    { label: 'View Pending', icon: Clock, action: () => onNavigate?.('open-requests'), color: 'bg-blue-600 hover:bg-blue-700' },
    { label: 'Settings', icon: Settings, action: () => onNavigate?.('settings'), color: 'bg-slate-600 hover:bg-slate-700' }
  );
  
  if (isAdmin) {
    actions.splice(actions.length - 1, 0, { label: 'Reports', icon: Activity, action: () => onNavigate?.('detailed-reports'), color: 'bg-purple-600 hover:bg-purple-700' });
  }
  
  return actions;
}

