import type { TourSection } from './types';
import { gettingStartedSteps } from './sections/getting-started';
import { dashboardSteps } from './sections/dashboard';
import { settingsSteps } from './sections/settings';
import { campaignsSteps } from './sections/campaigns';
import { mapLocationsSteps } from './sections/map-locations';
import { mediaLibrarySteps } from './sections/media-library';
import { userManagementSteps } from './sections/user-management';

export const tourRegistry: TourSection[] = [
  {
    id: 'getting-started',
    title: 'Getting Started',
    description: 'First-time setup: change your password, explore the sidebar, and configure your organization.',
    icon: 'RocketOutlined',
    route: null,
    featureFlag: null,
    order: 0,
    category: 'essentials',
    estimatedMinutes: 2,
    buildSteps: gettingStartedSteps,
  },
  {
    id: 'dashboard',
    title: 'Dashboard Overview',
    description: 'Learn to read your metrics, service health, and activity feed.',
    icon: 'DashboardOutlined',
    route: '/app',
    featureFlag: null,
    order: 1,
    category: 'essentials',
    estimatedMinutes: 3,
    buildSteps: dashboardSteps,
  },
  {
    id: 'settings',
    title: 'Settings & Configuration',
    description: 'Configure your organization, theme, email, and feature toggles.',
    icon: 'SettingOutlined',
    route: '/app/settings',
    featureFlag: null,
    order: 2,
    category: 'essentials',
    estimatedMinutes: 4,
    buildSteps: settingsSteps,
  },
  {
    id: 'campaigns',
    title: 'Advocacy Campaigns',
    description: 'Create letter-writing campaigns to elected representatives.',
    icon: 'SendOutlined',
    route: '/app/campaigns',
    featureFlag: 'enableInfluence',
    order: 10,
    category: 'features',
    estimatedMinutes: 4,
    buildSteps: campaignsSteps,
  },
  {
    id: 'map-locations',
    title: 'Map & Locations',
    description: 'Manage geographic locations, import data, and track supporters.',
    icon: 'EnvironmentOutlined',
    route: '/app/map',
    featureFlag: 'enableMap',
    order: 11,
    category: 'features',
    estimatedMinutes: 3,
    buildSteps: mapLocationsSteps,
  },
  {
    id: 'media-library',
    title: 'Media Library',
    description: 'Upload, organize, and publish videos and photos.',
    icon: 'PlaySquareOutlined',
    route: '/app/media/library',
    featureFlag: 'enableMediaFeatures',
    order: 12,
    category: 'features',
    estimatedMinutes: 3,
    buildSteps: mediaLibrarySteps,
  },
  {
    id: 'user-management',
    title: 'User Management',
    description: 'Create accounts, assign roles, and manage access.',
    icon: 'TeamOutlined',
    route: '/app/users',
    featureFlag: null,
    order: 13,
    category: 'features',
    estimatedMinutes: 3,
    buildSteps: userManagementSteps,
  },
];

/**
 * Get sections available for the current user/settings context.
 * Filters by feature flags — role filtering is done at the component level.
 */
export function getAvailableSections(
  settings: Record<string, unknown>
): TourSection[] {
  return tourRegistry.filter((section) => {
    if (section.featureFlag && !settings[section.featureFlag]) return false;
    return true;
  }).sort((a, b) => a.order - b.order);
}
