import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import '@burtson-labs/flow-builder/dist/assets/flow-builder.css'
import App from './App.tsx'
import { ChatProvider } from '@burtson-labs/bandit-engine'
import { CustomThemeProvider } from './theme/CustomThemeProvider'

console.log(
  "%c" +
  "    ╔══════════════════════════════════════════════════════════════╗\n" +
  "    ║  ██████╗ ██╗   ██╗██████╗ ████████╗███████╗ ██████╗ ███╗   ██╗║\n" +
  "    ║  ██╔══██╗██║   ██║██╔══██╗╚══██╔══╝██╔════╝██╔═══██╗████╗  ██║║\n" +
  "    ║  ██████╔╝██║   ██║██████╔╝   ██║   ███████╗██║   ██║██╔██╗ ██║║\n" +
  "    ║  ██╔══██╗██║   ██║██╔══██╗   ██║   ╚════██║██║   ██║██║╚██╗██║║\n" +
  "    ║  ██████╔╝╚██████╔╝██║  ██║   ██║   ███████║╚██████╔╝██║ ╚████║║\n" +
  "    ║  ╚═════╝  ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝ ╚═════╝ ╚═╝  ╚═══╝║\n" +
  "    ║                                                              ║\n" +
  "    ║                        █████╗ ██╗                            ║\n" +
  "    ║                       ██╔══██╗██║                            ║\n" +
  "    ║                       ███████║██║                            ║\n" +
  "    ║                       ██╔══██║██║                            ║\n" +
  "    ║                       ██║  ██║██║                            ║\n" +
  "    ║                       ╚═╝  ╚═╝╚═╝                            ║\n" +
  "    ║                                                              ║\n" +
  "    ║          Open-source AI coding agents · Kansas City          ║\n" +
  "    ╚══════════════════════════════════════════════════════════════╝",
  "color: #58a6ff; font-family: 'Courier New', monospace; font-weight: bold; line-height: 1.2;"
);

console.log(
  "%cBandit Stealth is open source (Apache-2.0). Read the code, file an issue, send a PR:\n" +
  "   https://github.com/Burtson-Labs/bandit-agent-framework",
  "color: #8b949e; font-size: 11px; line-height: 1.4;"
);

const chatPackageSettings = {
  // New Gateway Provider Configuration (Recommended)
  aiProvider: {
    type: "gateway" as const,
    gatewayUrl: import.meta.env.VITE_GATEWAY_API_URL!,
    provider: "bandit" as const, // Backend: bandit, openai, azure-openai, anthropic, xai, ollama
    tokenFactory: () => localStorage.getItem('authToken'),
  },

  // Model Configuration
  defaultModel: import.meta.env.VITE_DEFAULT_MODEL!,
  fallbackModel: import.meta.env.VITE_FALLBACK_MODEL,

  // All services route through gateway
  gatewayApiUrl: import.meta.env.VITE_GATEWAY_API_URL!,

  // Branding and optional overrides
  brandingConfigUrl: "/config.json",
  // fileStorageApiUrl: import.meta.env.VITE_FILE_STORAGE_API_URL,
  // homeUrl: "https://yourapp.com",
  // feedbackEmail: "feedback@yourapp.com",
  dataPersist: "indexedDB" as const,

  // Feature flag configuration with team mode
  featureFlags: {
    subscriptionType: "team" as const, // Team mode for enterprise features
    rolesClaimKey: "roles", // JWT claim key for roles
    subscriptionTypeClaimKey: "subscriptionType", // JWT claim for subscription type
    isSubscribedClaimKey: "isSubscribed", // JWT claim for subscription status
    jwtStorageKey: "authToken", // Use same key as tokenFactory
    adminRole: "admin",
    debug: import.meta.env.NODE_ENV === "development", // Enable debug logging in development

    // Team-specific feature overrides (all premium features enabled)
    featureMatrix: {
      memory: true, // Conversation memory
      documentKnowledge: true, // Document upload and knowledge
      moodAdaptation: true, // AI mood adaptation
      chatSuggestions: true, // Smart suggestions
      tts: true, // Text-to-speech
      stt: true, // Speech-to-text
      limitedAdminDashboard: true, // Basic admin features
      fullAdminDashboard: true, // Complete admin dashboard (team exclusive)
      simpleSearch: true, // Basic search
      premiumSearch: true, // Advanced search capabilities
      teamCollaboration: true, // Team features
      analytics: true, // Usage analytics
      customBranding: true, // Custom branding options
      apiAccess: true, // API access for integrations
      prioritySupport: true // Priority customer support
    }
  }
};

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <CustomThemeProvider>
      <ChatProvider
        packageSettings={chatPackageSettings}
      >
        <App />
      </ChatProvider>
    </CustomThemeProvider>
  </StrictMode>
)
