/**
 * Navigation Utilities
 *
 * Centralized functions for generating navigation URLs with proper parameters
 */

import PILOT_CONFIG from '../config/pilot';
import type { SubscriptionTier } from '../api';

/**
 * Generate register URL with proper query parameters
 *
 * @param planTier - Optional subscription plan tier (starter, professional, enterprise)
 * @param billingCycle - Optional billing cycle ('monthly' or 'yearly')
 * @returns Register URL with appropriate query parameters
 *
 * @example
 * // In pilot mode with plan and billing cycle selected
 * getRegisterUrl('starter', 'yearly') // => '/register?pilot=true&plan=starter&billing_cycle=yearly'
 *
 * // In pilot mode with plan selected
 * getRegisterUrl('starter') // => '/register?pilot=true&plan=starter'
 *
 * // In pilot mode without plan
 * getRegisterUrl() // => '/register?pilot=true'
 *
 * // Not in pilot mode with plan
 * getRegisterUrl('professional') // => '/register?plan=professional'
 */
export const getRegisterUrl = (planTier?: SubscriptionTier | string, billingCycle?: 'monthly' | 'yearly'): string => {
  const params = new URLSearchParams();

  // Add pilot parameter if pilot mode is enabled globally
  if (PILOT_CONFIG.enabled) {
    params.set('pilot', 'true');
  }

  // Add plan parameter if specified
  if (planTier) {
    params.set('plan', planTier);
  }

  // Add billing cycle parameter if specified
  if (billingCycle) {
    params.set('billing_cycle', billingCycle);
  }

  const queryString = params.toString();
  return `/register${queryString ? '?' + queryString : ''}`;
};

/**
 * Generate login URL
 */
export const getLoginUrl = (): string => {
  return '/login';
};

/**
 * Generate demo URL
 */
export const getDemoUrl = (): string => {
  return '/demo';
};

/**
 * Check if current URL has pilot parameter
 */
export const isPilotUrl = (): boolean => {
  const searchParams = new URLSearchParams(window.location.search);
  return searchParams.get('pilot') === 'true';
};

/**
 * Get plan from current URL
 */
export const getPlanFromUrl = (): string | null => {
  const searchParams = new URLSearchParams(window.location.search);
  return searchParams.get('plan');
};
