import { BrowserRouter, Routes, Route } from 'react-router-dom';
import Layout from './components/Layout';
import ModelList from './components/ModelList';
import ModelPs from './components/ModelPs';
import ModelPull from './components/ModelPull';
import KMSPull from './components/KMSPull';
import CatalogList from './components/CatalogList';
import LibsPull from './components/LibsPull';
import BuckyLibs from './components/BuckyLibs';
import BuckyModels from './components/BuckyModels';
import SecurityKeyList from './components/SecurityKeyList';
import SecurityKeyCreate from './components/SecurityKeyCreate';
import SecurityKeyDelete from './components/SecurityKeyDelete';
import SecurityTokenCreate from './components/SecurityTokenCreate';
import Settings from './components/Settings';
import Chat from './components/Chat';
import Translator from './components/Translator';
import DocsSDK from './components/DocsSDK';
import DocsSDKKronk from './components/DocsSDKKronk';
import DocsSDKModel from './components/DocsSDKModel';
import DocsSDKPool from './components/DocsSDKPool';
import DocsSDKBucky from './components/DocsSDKBucky';
import DocsSDKBuckyModel from './components/DocsSDKBuckyModel';
import DocsSDKExamples from './components/DocsSDKExamples';
import DocsCLICatalog from './components/DocsCLICatalog';
import DocsCLILibs from './components/DocsCLILibs';
import DocsCLIModel from './components/DocsCLIModel';
import DocsCLIRun from './components/DocsCLIRun';
import DocsCLISecurity from './components/DocsCLISecurity';
import DocsCLIServer from './components/DocsCLIServer';
import DocsAPIChat from './components/DocsAPIChat';
import DocsAPIMessages from './components/DocsAPIMessages';
import DocsAPIResponses from './components/DocsAPIResponses';
import DocsAPIEmbeddings from './components/DocsAPIEmbeddings';
import DocsAPIRerank from './components/DocsAPIRerank';
import DocsAPITokenize from './components/DocsAPITokenize';
import DocsAPITools from './components/DocsAPITools';
import DocsManual from './components/DocsManual';
import VRAMCalculator from './components/VRAMCalculator';
import TestingBasic from './components/TestingBasic';
import TestingSampling from './components/TestingSampling';
import TestingConfiguration from './components/TestingConfiguration';
import Accuracy from './components/Accuracy';
import { ModelListProvider } from './contexts/ModelListContext';
import { TokenProvider } from './contexts/TokenContext';
import { DownloadProvider } from './contexts/DownloadContext';
import { ChatProvider } from './contexts/ChatContext';
import { ChatHistoryProvider } from './contexts/ChatHistoryContext';
import { SamplingProvider } from './contexts/SamplingContext';
import { AutoTestRunnerProvider } from './contexts/AutoTestRunnerContext';
import { AccuracyRunnerProvider } from './contexts/AccuracyRunnerContext';
import { PlaygroundProvider } from './contexts/PlaygroundContext';
import { ThemeProvider } from './contexts/ThemeContext';

export type Page =
  | 'home'
  | 'chat'
  | 'vram-calculator'
  | 'accuracy'
  | 'testing-basic'
  | 'testing-sampling'
  | 'testing-configurator'
  | 'model-list'
  | 'model-ps'
  | 'model-pull'
  | 'kms-pull'
  | 'catalog-list'
  | 'libs-pull'
  | 'bucky-libs'
  | 'bucky-model-list'
  | 'translator'
  | 'security-key-list'
  | 'security-key-create'
  | 'security-key-delete'
  | 'security-token-create'
  | 'settings'
  | 'docs-sdk'
  | 'docs-sdk-kronk'
  | 'docs-sdk-model'
  | 'docs-sdk-pool'
  | 'docs-sdk-bucky'
  | 'docs-sdk-bucky-model'
  | 'docs-sdk-examples'
  | 'docs-cli-catalog'
  | 'docs-cli-libs'
  | 'docs-cli-model'
  | 'docs-cli-run'
  | 'docs-cli-security'
  | 'docs-cli-server'
  | 'docs-api-chat'
  | 'docs-api-messages'
  | 'docs-api-responses'
  | 'docs-api-embeddings'
  | 'docs-api-rerank'
  | 'docs-api-tokenize'
  | 'docs-api-tools'
  | 'docs-manual';

export const routeMap: Record<Page, string> = {
  'home': '/',
  'chat': '/chat',
  'vram-calculator': '/vram-calculator',
  'accuracy': '/accuracy',
  'testing-basic': '/testing/basic',
  'testing-sampling': '/testing/sampling',
  'testing-configurator': '/testing/configurator',
  'model-list': '/models',
  'model-ps': '/models/running',
  'model-pull': '/models/pull',
  'kms-pull': '/models/kms-pull',
  'catalog-list': '/catalog',
  'libs-pull': '/libs/pull',
  'bucky-libs': '/bucky/libs',
  'bucky-model-list': '/bucky/models',
  'translator': '/bucky/translator',
  'security-key-list': '/security/keys',
  'security-key-create': '/security/keys/create',
  'security-key-delete': '/security/keys/delete',
  'security-token-create': '/security/tokens/create',
  'settings': '/settings',
  'docs-sdk': '/docs/sdk',
  'docs-sdk-kronk': '/docs/sdk/kronk',
  'docs-sdk-model': '/docs/sdk/model',
  'docs-sdk-pool': '/docs/sdk/pool',
  'docs-sdk-bucky': '/docs/sdk/bucky',
  'docs-sdk-bucky-model': '/docs/sdk/bucky/model',
  'docs-sdk-examples': '/docs/sdk/examples',
  'docs-cli-catalog': '/docs/cli/catalog',
  'docs-cli-libs': '/docs/cli/libs',
  'docs-cli-model': '/docs/cli/model',
  'docs-cli-run': '/docs/cli/run',
  'docs-cli-security': '/docs/cli/security',
  'docs-cli-server': '/docs/cli/server',
  'docs-api-chat': '/docs/api/chat',
  'docs-api-messages': '/docs/api/messages',
  'docs-api-responses': '/docs/api/responses',
  'docs-api-embeddings': '/docs/api/embeddings',
  'docs-api-rerank': '/docs/api/rerank',
  'docs-api-tokenize': '/docs/api/tokenize',
  'docs-api-tools': '/docs/api/tools',
  'docs-manual': '/docs/manual',
};

export const pathToPage: Record<string, Page> = Object.fromEntries(
  Object.entries(routeMap).map(([page, path]) => [path, page as Page])
);

function HomePage() {
  return (
    <div className="home-page">
      <div className="hero-section">
        <img
          src="https://raw.githubusercontent.com/ardanlabs/kronk/refs/heads/main/images/project/kronk_banner.jpg"
          alt="Kronk Banner"
          className="hero-banner"
        />
        <p className="hero-tagline">
          Hardware-accelerated local inference with llama.cpp directly integrated into your Go applications
        </p>
      </div>

      <div className="features-grid">
        <div className="feature-card">
          <div className="feature-icon">🚀</div>
          <h3>High-Level Go API</h3>
          <p>Feels similar to using an OpenAI compatible API, but runs entirely on your hardware</p>
        </div>
        <div className="feature-card">
          <div className="feature-icon">🔧</div>
          <h3>OpenAI Compatible Server</h3>
          <p>Model server for chat completions and embeddings, compatible with OpenWebUI</p>
        </div>
        <div className="feature-card">
          <div className="feature-icon">🎯</div>
          <h3>Multimodal Support</h3>
          <p>Text, vision, and audio models with full hardware acceleration</p>
        </div>
        <div className="feature-card">
          <div className="feature-icon">⚡</div>
          <h3>GPU Acceleration</h3>
          <p>Metal on macOS, CUDA/Vulkan/ROCm on Linux, CUDA/Vulkan on Windows</p>
        </div>
      </div>

      <div className="home-cta">
        <p>Use the sidebar to manage models, browse the catalog, or explore the SDK documentation.</p>
      </div>
    </div>
  );
}

function App() {
  return (
    <BrowserRouter>
      <ThemeProvider>
      <TokenProvider>
        <ModelListProvider>
          <AccuracyRunnerProvider>
          <DownloadProvider>
            <AutoTestRunnerProvider>
            <PlaygroundProvider>
            <ChatProvider>
              <ChatHistoryProvider>
              <SamplingProvider>
                <Layout>
              <Routes>
                <Route path="/" element={<HomePage />} />
                <Route path="/chat" element={<Chat />} />
                <Route path="/vram-calculator" element={<VRAMCalculator />} />
                <Route path="/accuracy" element={<Accuracy />} />
                <Route path="/testing/basic" element={<TestingBasic />} />
                <Route path="/testing/sampling" element={<TestingSampling />} />
                <Route path="/testing/configurator" element={<TestingConfiguration />} />
                <Route path="/models" element={<ModelList />} />
                <Route path="/models/running" element={<ModelPs />} />
                <Route path="/models/pull" element={<ModelPull />} />
                <Route path="/models/kms-pull" element={<KMSPull />} />
                <Route path="/catalog" element={<CatalogList />} />
                <Route path="/libs/pull" element={<LibsPull />} />
                <Route path="/bucky/libs" element={<BuckyLibs />} />
                <Route path="/bucky/models" element={<BuckyModels />} />
                <Route path="/bucky/translator" element={<Translator />} />
                <Route path="/security/keys" element={<SecurityKeyList />} />
                <Route path="/security/keys/create" element={<SecurityKeyCreate />} />
                <Route path="/security/keys/delete" element={<SecurityKeyDelete />} />
                <Route path="/security/tokens/create" element={<SecurityTokenCreate />} />
                <Route path="/settings" element={<Settings />} />
                <Route path="/docs/sdk" element={<DocsSDK />} />
                <Route path="/docs/sdk/kronk" element={<DocsSDKKronk />} />
                <Route path="/docs/sdk/model" element={<DocsSDKModel />} />
                <Route path="/docs/sdk/pool" element={<DocsSDKPool />} />
                <Route path="/docs/sdk/bucky" element={<DocsSDKBucky />} />
                <Route path="/docs/sdk/bucky/model" element={<DocsSDKBuckyModel />} />
                <Route path="/docs/sdk/examples" element={<DocsSDKExamples />} />
                <Route path="/docs/cli/catalog" element={<DocsCLICatalog />} />
                <Route path="/docs/cli/libs" element={<DocsCLILibs />} />
                <Route path="/docs/cli/model" element={<DocsCLIModel />} />
                <Route path="/docs/cli/run" element={<DocsCLIRun />} />
                <Route path="/docs/cli/security" element={<DocsCLISecurity />} />
                <Route path="/docs/cli/server" element={<DocsCLIServer />} />
                <Route path="/docs/api/chat" element={<DocsAPIChat />} />
                <Route path="/docs/api/messages" element={<DocsAPIMessages />} />
                <Route path="/docs/api/responses" element={<DocsAPIResponses />} />
                <Route path="/docs/api/embeddings" element={<DocsAPIEmbeddings />} />
                <Route path="/docs/api/rerank" element={<DocsAPIRerank />} />
                <Route path="/docs/api/tokenize" element={<DocsAPITokenize />} />
                <Route path="/docs/api/tools" element={<DocsAPITools />} />
                <Route path="/docs/manual" element={<DocsManual />} />
              </Routes>
                </Layout>
              </SamplingProvider>
              </ChatHistoryProvider>
            </ChatProvider>
            </PlaygroundProvider>
            </AutoTestRunnerProvider>
          </DownloadProvider>
          </AccuracyRunnerProvider>
        </ModelListProvider>
      </TokenProvider>
      </ThemeProvider>
    </BrowserRouter>
  );
}

export default App;
